Dashboard: Write user dashboards to disk

refs #4537
This commit is contained in:
Marius Hein 2014-11-11 15:59:59 +01:00
parent f6a2f6515d
commit 979bec24a5
3 changed files with 46 additions and 10 deletions

View File

@ -8,6 +8,7 @@ use Icinga\Application\Icinga;
use Icinga\Application\Config;
use Icinga\Exception\ConfigurationError;
use Icinga\Exception\ProgrammingError;
use Icinga\File\Ini\IniWriter;
use Icinga\User;
use Icinga\Web\Widget\Dashboard\Pane;
use Icinga\Web\Widget\Dashboard\Component as DashboardComponent;
@ -80,6 +81,29 @@ class Dashboard extends AbstractWidget
return $this;
}
/**
* Write user specific dashboards to disk
*/
public function write()
{
$configFile = $this->getConfigFile();
$output = array();
foreach ($this->panes as $pane) {
if ($pane->isUserWidget() === true) {
$output[$pane->getName()] = $pane->toArray();
}
foreach ($pane->getComponents() as $component) {
if ($component->isUserWidget() === true) {
$output[$pane->getName() . '.' . $component->getTitle()] = $component->toArray();
}
}
}
$config = new Config($output);
$writer = new IniWriter(array('config' => $config, 'filename' => $configFile));
$writer->write();
}
/**
* @return bool
*/
@ -316,21 +340,30 @@ class Dashboard extends AbstractWidget
}
/**
* @param \Icinga\User $user
* Setter for user object
*
* @param User $user
*/
public function setUser($user)
public function setUser(User $user)
{
$this->user = $user;
}
/**
* @return \Icinga\User
* Getter for user object
*
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* Get config file
*
* @return string
*/
public function getConfigFile()
{
if ($this->user === null) {

View File

@ -147,7 +147,13 @@ EOD;
*/
public function toArray()
{
$array = array('url' => $this->url->getPath());
$array = array(
'url' => $this->url->getPath(),
'title' => $this->getTitle()
);
if ($this->getDisabled() === true) {
$array['disabled'] = 1;
}
foreach ($this->url->getParams()->toArray() as $param) {
$array[$param[0]] = $param[1];
}

View File

@ -247,12 +247,9 @@ class Pane extends UserWidget
*/
public function toArray()
{
$array = array($this->getName() => array('title' => $this->getTitle()));
foreach ($this->components as $title => $component) {
$array[$this->getName() . ".$title"] = $component->toArray();
}
return $array;
return array(
'title' => $this->getTitle()
);
}
/**