Remove BaseConfigController, User\Message and Widget\AlertMesageBox
refs #6758
This commit is contained in:
parent
2d86e6ba3b
commit
1ba3df310c
|
@ -2,8 +2,7 @@
|
|||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
use Icinga\Web\Controller\BaseConfigController;
|
||||
use Icinga\Web\Widget\AlertMessageBox;
|
||||
use Icinga\Web\Controller\ActionController;
|
||||
use Icinga\Web\Notification;
|
||||
use Icinga\Application\Modules\Module;
|
||||
use Icinga\Web\Widget;
|
||||
|
@ -21,7 +20,7 @@ use Icinga\Data\ResourceFactory;
|
|||
/**
|
||||
* Application wide controller for application preferences
|
||||
*/
|
||||
class ConfigController extends BaseConfigController
|
||||
class ConfigController extends ActionController
|
||||
{
|
||||
public function init()
|
||||
{
|
||||
|
@ -302,7 +301,6 @@ class ConfigController extends BaseConfigController
|
|||
*/
|
||||
public function configurationerrorAction()
|
||||
{
|
||||
$this->view->messageBox = new AlertMessageBox(true);
|
||||
$this->render('error/error', null, true);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,4 @@
|
|||
<hr />
|
||||
<pre><?= $this->escape($stackTrace) ?></pre>
|
||||
<?php endif ?>
|
||||
<?php if (isset($this->messageBox)) : ?>
|
||||
<?= $this->messageBox->render(); ?>
|
||||
<? endif ?>
|
||||
</div>
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace Icinga;
|
|||
use DateTimeZone;
|
||||
use InvalidArgumentException;
|
||||
use Icinga\User\Preferences;
|
||||
use Icinga\User\Message;
|
||||
|
||||
/**
|
||||
* This class represents an authorized user
|
||||
|
@ -98,13 +97,6 @@ class User
|
|||
*/
|
||||
protected $preferences;
|
||||
|
||||
/**
|
||||
* Queued notifications for this user.
|
||||
*
|
||||
* @var array()
|
||||
*/
|
||||
protected $messages;
|
||||
|
||||
/**
|
||||
* Creates a user object given the provided information
|
||||
*
|
||||
|
@ -382,38 +374,6 @@ class User
|
|||
return new DateTimeZone($tz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a message that can be accessed from future requests, to this user.
|
||||
*
|
||||
* This function does NOT automatically write to the session, messages will not be persisted until you do.
|
||||
*
|
||||
* @param Message $msg The message
|
||||
*/
|
||||
public function addMessage(Message $msg)
|
||||
{
|
||||
$this->messages[] = $msg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all currently pending messages
|
||||
*
|
||||
* @return array The messages
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
return isset($this->messages) ? $this->messages : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all messages from this user
|
||||
*
|
||||
* This function does NOT automatically write the session, messages will not be persisted until you do.
|
||||
*/
|
||||
public function clearMessages()
|
||||
{
|
||||
$this->messages = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set additional remote user information
|
||||
*
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\User;
|
||||
|
||||
use Zend_Log;
|
||||
|
||||
/**
|
||||
* Class Message
|
||||
*
|
||||
* A Message with an additional logging level to indicate the type.
|
||||
*
|
||||
* @package Icinga\User
|
||||
*/
|
||||
class Message
|
||||
{
|
||||
/**
|
||||
* The content of this message
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $message;
|
||||
|
||||
/**
|
||||
* The logging-level of this message
|
||||
*/
|
||||
private $level;
|
||||
|
||||
/**
|
||||
* Create a new Message
|
||||
*
|
||||
* @param string $message The message content
|
||||
* @param $level The status of the message
|
||||
* * Zend_Log::INFO
|
||||
* * Zend_Log::ERR
|
||||
*/
|
||||
public function __construct($message, $level = Zend_Log::INFO)
|
||||
{
|
||||
$this->message = $message;
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMessage()
|
||||
{
|
||||
return $this->message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The
|
||||
*/
|
||||
public function getLevel()
|
||||
{
|
||||
return $this->level;
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Web\Controller;
|
||||
|
||||
use Zend_Log;
|
||||
use Icinga\Web\Session;
|
||||
use Icinga\User\Message;
|
||||
use Icinga\Authentication\Manager as AuthenticationManager;
|
||||
|
||||
/**
|
||||
* Base class for Configuration Controllers
|
||||
*
|
||||
* Module preferences use this class to make sure they are automatically
|
||||
* added to the application's configuration dialog. If you create a subclass of
|
||||
* BasePreferenceController and overwrite @see init(), make sure you call
|
||||
* parent::init(), otherwise you won't have the $tabs property in your view.
|
||||
*/
|
||||
class BaseConfigController extends ActionController
|
||||
{
|
||||
/**
|
||||
* Send a message with the logging level Zend_Log::INFO to the current user and
|
||||
* commit the changes to the underlying session.
|
||||
*
|
||||
* @param $msg The message content
|
||||
*/
|
||||
protected function addSuccessMessage($msg)
|
||||
{
|
||||
AuthenticationManager::getInstance()->getUser()->addMessage(
|
||||
new Message($msg, Zend_Log::INFO)
|
||||
);
|
||||
Session::getSession()->write();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message with the logging level Zend_Log::ERR to the current user and
|
||||
* commit the changes to the underlying session.
|
||||
*
|
||||
* @param $msg The message content
|
||||
*/
|
||||
protected function addErrorMessage($msg)
|
||||
{
|
||||
AuthenticationManager::getInstance()->getUser()->addMessage(
|
||||
new Message($msg, Zend_Log::ERR)
|
||||
);
|
||||
Session::getSession()->write();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a message with the logging level Zend_Log::WARN to the current user and
|
||||
* commit the changes to the underlying session.
|
||||
*
|
||||
* @param $msg The message content
|
||||
*/
|
||||
protected function addWarningMessage($msg)
|
||||
{
|
||||
AuthenticationManager::getInstance()->getUser()->addMessage(
|
||||
new Message($msg, Zend_Log::WARN)
|
||||
);
|
||||
Session::getSession()->write();
|
||||
}
|
||||
|
||||
/*
|
||||
* Return an array of tabs provided by this configuration controller.
|
||||
*
|
||||
* Those tabs will automatically be added to the application's configuration dialog
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function createProvidedTabs()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
<?php
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
// {{{ICINGA_LICENSE_HEADER}}}
|
||||
|
||||
namespace Icinga\Web\Widget;
|
||||
|
||||
use Zend_Log;
|
||||
use Zend_Form;
|
||||
use Zend_View_Abstract;
|
||||
use Icinga\User;
|
||||
use Icinga\User\Message;
|
||||
use Icinga\Web\Session;
|
||||
use Icinga\Authentication\Manager as AuthenticationManager;
|
||||
|
||||
/**
|
||||
* Displays a set of alert messages to the user.
|
||||
*
|
||||
* The messages are fetched automatically from the current AuthenticationManager,
|
||||
* but this is done lazily when render() is called, to ensure that messages will
|
||||
* always be displayed before they are cleared.
|
||||
*/
|
||||
class AlertMessageBox extends AbstractWidget
|
||||
{
|
||||
/**
|
||||
* Remove all messages from the current user, return them and commit
|
||||
* changes to the underlying session.
|
||||
*
|
||||
* @return array The messages
|
||||
*/
|
||||
protected function getAndClearMessages()
|
||||
{
|
||||
$messages = $this->user->getMessages();
|
||||
$this->user->clearMessages();
|
||||
Session::getSession()->write();
|
||||
return $messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* The displayed alert messages
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $messages = array();
|
||||
|
||||
/**
|
||||
* The user to fetch the messages from
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* The available states.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $states = array(
|
||||
Zend_Log::INFO => array(
|
||||
'state' => 'alert-success',
|
||||
'icon' => 'success.png'
|
||||
),
|
||||
Zend_Log::NOTICE => array(
|
||||
'state' => 'alert-info',
|
||||
'icon' => 'info.png'
|
||||
),
|
||||
Zend_Log::WARN => array(
|
||||
'state' => 'alert-warning',
|
||||
'icon' => 'warning.png'
|
||||
),
|
||||
Zend_Log::ERR => array(
|
||||
'state' => 'alert-danger',
|
||||
'icon' => 'error.png'
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a new AlertBox
|
||||
*
|
||||
* @param boolean showUserMessages If the current user messages should be displayed
|
||||
* in this AlertMessageBox. Defaults to false
|
||||
*/
|
||||
public function __construct($showUserMessages = false)
|
||||
{
|
||||
if ($showUserMessages) {
|
||||
$this->user = AuthenticationManager::getInstance()->getUser();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new error
|
||||
*
|
||||
* @param $error
|
||||
*/
|
||||
public function addError($error)
|
||||
{
|
||||
$this->messages[] = new Message($error, Zend_Log::ERR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the error messages of the given Zend_Form
|
||||
*/
|
||||
public function addForm(Zend_Form $form)
|
||||
{
|
||||
foreach ($form->getErrorMessages() as $error) {
|
||||
$this->addError($error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the HTML of the AlertBox
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render(Zend_View_Abstract $view = null)
|
||||
{
|
||||
$html = '';
|
||||
if (isset($this->user)) {
|
||||
$this->messages = array_merge($this->messages, $this->getAndClearMessages());
|
||||
}
|
||||
foreach ($this->messages as $message) {
|
||||
$level = $message->getLevel();
|
||||
if (!array_key_exists($level, $this->states)) {
|
||||
continue;
|
||||
}
|
||||
$alert = $this->states[$level];
|
||||
$html .= '<div class="alert ' . $alert['state']. '">' .
|
||||
$this->view()->icon($alert['icon']) .
|
||||
'<strong>' . htmlspecialchars($message->getMessage()) . '</strong>' .
|
||||
'</div>';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue