From 0d0480afea390a7a466821aa59e9d0a3dfa55b97 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 13:43:56 +0200 Subject: [PATCH 01/27] Introduce controller DashboardsController --- application/controllers/DashboardsController.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 application/controllers/DashboardsController.php diff --git a/application/controllers/DashboardsController.php b/application/controllers/DashboardsController.php new file mode 100644 index 000000000..d4e68e983 --- /dev/null +++ b/application/controllers/DashboardsController.php @@ -0,0 +1,13 @@ + Date: Tue, 29 Sep 2015 13:45:12 +0200 Subject: [PATCH 02/27] DashboardsController: Add index action --- .../controllers/DashboardsController.php | 24 +++++++++++++++ .../views/scripts/dashboards/index.phtml | 29 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 application/views/scripts/dashboards/index.phtml diff --git a/application/controllers/DashboardsController.php b/application/controllers/DashboardsController.php index d4e68e983..5d413b0db 100644 --- a/application/controllers/DashboardsController.php +++ b/application/controllers/DashboardsController.php @@ -4,10 +4,34 @@ namespace Icinga\Controllers; use Icinga\Web\Controller; +use Icinga\Web\Widget\Dashboard; /** * Dashboards */ class DashboardsController extends Controller { + /** + * Display the dashboard with the pane set in the "pane" request parameter + * + * If no pane is given or the given one doesn't exist, the default pane is displayed + */ + public function indexAction() + { + $dashboard = new Dashboard(); + $dashboard->setUser($this->Auth()->getUser()); + $dashboard->load(); + + $this->view->title = 'Dashboard'; + $this->view->tabs = $dashboard->getTabs(); + + if ($dashboard->hasPanes()) { + if (($pane = $this->params->get('pane')) !== null) { + $dashboard->activate($pane); + } + + $this->view->dashboard = $dashboard; + $this->view->title = $dashboard->getActivePane()->getTitle() . ' :: Dashboard'; + } + } } diff --git a/application/views/scripts/dashboards/index.phtml b/application/views/scripts/dashboards/index.phtml new file mode 100644 index 000000000..85a41b81e --- /dev/null +++ b/application/views/scripts/dashboards/index.phtml @@ -0,0 +1,29 @@ +compact): ?> +
+ +
+ + +
+ +
+ +
+

escape($this->translate('Welcome to Icinga Web 2!')); ?>

+

+ hasPermission('config/modules')): ?> + escape($this->translate( + 'Currently there is no dashboard available. Please contact the administrator.' + )); ?> + + escape($this->translate( + 'Currently there is no dashboard available. This might change once you enabled some of the available %smodules%s.' + )), + substr($this->qlink(null, 'config/modules'), 0, -4), + '' + ); ?> + +

+
+ \ No newline at end of file From f60a8ef60d7ba0670ebd7a44cf0bad5e5d416b54 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:06:22 +0200 Subject: [PATCH 03/27] NavigationConfigForm: Require argument $type in method getUserConfig() refs #10246 --- .../forms/Navigation/NavigationConfigForm.php | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/application/forms/Navigation/NavigationConfigForm.php b/application/forms/Navigation/NavigationConfigForm.php index ba1f20d30..7ec2db9d9 100644 --- a/application/forms/Navigation/NavigationConfigForm.php +++ b/application/forms/Navigation/NavigationConfigForm.php @@ -123,12 +123,18 @@ class NavigationConfigForm extends ConfigForm /** * Return the user's navigation configuration * + * @param string $type + * * @return Config */ - public function getUserConfig() + public function getUserConfig($type = null) { if ($this->userConfig === null) { - $this->setUserConfig($this->getUser()->loadNavigationConfig()); + if ($type === null) { + throw new ProgrammingError('You need to pass a type if no user configuration is set'); + } + + $this->setUserConfig($this->getItemConfig($type, $this->getUser()->getUsername())); } return $this->userConfig; @@ -205,10 +211,9 @@ class NavigationConfigForm extends ConfigForm } } - foreach ($this->getUserConfig() as $sectionName => $sectionConfig) { + foreach ($this->getUserConfig($type) as $sectionName => $sectionConfig) { if ( $sectionName !== $this->itemToLoad - && $sectionConfig->type === $type && !in_array($sectionName, $children, true) ) { $names[] = $sectionName; @@ -271,17 +276,19 @@ class NavigationConfigForm extends ConfigForm * * @return $this * - * @throws InvalidArgumentException In case $data does not contain a navigation item name + * @throws InvalidArgumentException In case $data does not contain a navigation item name or type * @throws IcingaException In case a navigation item with the same name already exists */ public function add(array $data) { if (! isset($data['name'])) { throw new InvalidArgumentException('Key \'name\' missing'); + } elseif (! isset($data['type'])) { + throw new InvalidArgumentException('Key \'type\' missing'); } $shared = false; - $config = $this->getUserConfig(); + $config = $this->getUserConfig($data['type']); if ((isset($data['users']) && $data['users']) || (isset($data['groups']) && $data['groups'])) { if ($this->getUser()->can('application/share/navigation')) { $data['owner'] = $this->getUser()->getUsername(); @@ -301,7 +308,7 @@ class NavigationConfigForm extends ConfigForm $exists = $config->hasSection($itemName); if (! $exists) { if ($shared) { - $exists = $this->getUserConfig()->hasSection($itemName); + $exists = $this->getUserConfig($data['type'])->hasSection($itemName); } else { $exists = (bool) $this->getShareConfig() ->select() @@ -821,4 +828,24 @@ class NavigationConfigForm extends ConfigForm return $form; } + + /** + * Return the configuration file for the given type of navigation item + * + * @param string $type + * @param string $username + * + * @return Config + */ + protected function getItemConfig($type, $username = null) + { + $itemTypes = $this->getItemTypes(); + if (isset($itemTypes[$type]['config'])) { + $configName = $itemTypes[$type]['config']; + } else { + $configName = $type . 's'; + } + + return Config::app($username ? "preferences/$username/" : 'navigation/' . $configName); + } } From 6fdfef4f4a1bf4b24c541024569b474a2968614b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:07:04 +0200 Subject: [PATCH 04/27] NavigationConfigForm: Require argument $type in method getShareConfig() refs #10246 --- .../forms/Navigation/NavigationConfigForm.php | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/application/forms/Navigation/NavigationConfigForm.php b/application/forms/Navigation/NavigationConfigForm.php index 7ec2db9d9..cf3923d47 100644 --- a/application/forms/Navigation/NavigationConfigForm.php +++ b/application/forms/Navigation/NavigationConfigForm.php @@ -157,10 +157,20 @@ class NavigationConfigForm extends ConfigForm /** * Return the shared navigation configuration * + * @param string $type + * * @return Config */ - public function getShareConfig() + public function getShareConfig($type = null) { + if ($this->shareConfig === null) { + if ($type === null) { + throw new ProgrammingError('You need to pass a type if no share configuration is set'); + } + + $this->setShareConfig($this->getItemConfig($type)); + } + return $this->shareConfig; } @@ -200,10 +210,9 @@ class NavigationConfigForm extends ConfigForm $children = $this->itemToLoad ? $this->getFlattenedChildren($this->itemToLoad) : array(); $names = array(); - foreach ($this->getShareConfig() as $sectionName => $sectionConfig) { + foreach ($this->getShareConfig($type) as $sectionName => $sectionConfig) { if ( $sectionName !== $this->itemToLoad - && $sectionConfig->type === $type && $sectionConfig->owner === ($owner ?: $this->getUser()->getUsername()) && !in_array($sectionName, $children, true) ) { @@ -292,15 +301,15 @@ class NavigationConfigForm extends ConfigForm if ((isset($data['users']) && $data['users']) || (isset($data['groups']) && $data['groups'])) { if ($this->getUser()->can('application/share/navigation')) { $data['owner'] = $this->getUser()->getUsername(); - $config = $this->getShareConfig(); + $config = $this->getShareConfig($data['type']); $shared = true; } else { unset($data['users']); unset($data['groups']); } - } elseif (isset($data['parent']) && $data['parent'] && $this->hasBeenShared($data['parent'])) { + } elseif (isset($data['parent']) && $data['parent'] && $this->hasBeenShared($data['parent'], $data['type'])) { $data['owner'] = $this->getUser()->getUsername(); - $config = $this->getShareConfig(); + $config = $this->getShareConfig($data['type']); $shared = true; } @@ -310,7 +319,7 @@ class NavigationConfigForm extends ConfigForm if ($shared) { $exists = $this->getUserConfig($data['type'])->hasSection($itemName); } else { - $exists = (bool) $this->getShareConfig() + $exists = (bool) $this->getShareConfig($data['type']) ->select() ->where('name', $itemName) ->where('owner', $this->getUser()->getUsername()) @@ -774,12 +783,13 @@ class NavigationConfigForm extends ConfigForm * Return whether the given navigation item has been shared * * @param string $name + * @param string $type * * @return bool */ - protected function hasBeenShared($name) + protected function hasBeenShared($name, $type = null) { - return $this->getConfigForItem($name) === $this->getShareConfig(); + return $this->getShareConfig($type) === $this->getConfigForItem($name); } /** From 5d4f7cf2c027f6836c88af773b1d4b067507b0db Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:07:56 +0200 Subject: [PATCH 05/27] NavigationConfigForm: Do not show a type selection for a single choice refs #10246 --- .../forms/Navigation/NavigationConfigForm.php | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/application/forms/Navigation/NavigationConfigForm.php b/application/forms/Navigation/NavigationConfigForm.php index cf3923d47..efbe73d60 100644 --- a/application/forms/Navigation/NavigationConfigForm.php +++ b/application/forms/Navigation/NavigationConfigForm.php @@ -565,6 +565,13 @@ class NavigationConfigForm extends ConfigForm $shared = false; $itemTypes = $this->getItemTypes(); $itemType = isset($formData['type']) ? $formData['type'] : key($itemTypes); + if ($itemType === null) { + throw new ProgrammingError( + 'This should actually not happen. Create a bug report at dev.icinga.org' + . ' or remove this assertion if you know what you\'re doing' + ); + } + $itemForm = $this->getItemForm($itemType); $this->addElement( @@ -622,17 +629,33 @@ class NavigationConfigForm extends ConfigForm } } - $this->addElement( - 'select', - 'type', - array( - 'required' => true, - 'autosubmit' => true, - 'label' => $this->translate('Type'), - 'description' => $this->translate('The type of this navigation item'), - 'multiOptions' => $itemTypes - ) - ); + if (empty($itemTypes) || count($itemTypes) === 1) { + $this->addElement( + 'hidden', + 'type', + array( + 'disabled' => true, + 'value' => $itemType + ) + ); + } else { + $multiOptions = array(); + foreach ($itemTypes as $type => $options) { + $multiOptions[$type] = isset($options['label']) ? $options['label'] : $type; + } + + $this->addElement( + 'select', + 'type', + array( + 'required' => true, + 'autosubmit' => true, + 'label' => $this->translate('Type'), + 'description' => $this->translate('The type of this navigation item'), + 'multiOptions' => $multiOptions + ) + ); + } if (! $shared && $itemForm->requiresParentSelection()) { if ($this->itemToLoad && $this->hasBeenShared($this->itemToLoad)) { From 565704141c0d54cb346c084e12ee17d434b648e8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:08:53 +0200 Subject: [PATCH 06/27] NavigationController: Add method getConfigPath() refs #10246 --- .../controllers/NavigationController.php | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index f5c1d785a..78d1e89b5 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -62,6 +62,35 @@ class NavigationController extends Controller return $types; } + /** + * Return the path to the configuration file for the given navigation item type and user + * + * @param string $type + * @param string $username + * + * @return string + * + * @throws IcingaException In case the given type is unknown + */ + protected function getConfigPath($type, $username = null) + { + if (isset($this->defaultItemTypes[$type])) { + $options = $this->defaultItemTypes[$type]; + } elseif (isset($this->moduleItemTypes[$type])) { + $options = $this->moduleItemTypes[$type]; + } else { + throw new IcingaException('Invalid navigation item type %s provided', $type); + } + + if (isset($options['config'])) { + $filename = $options['config'] . '.ini'; + } else { + $filename = $type . 's.ini'; + } + + return Config::resolvePath(($username ? "preferences/$username/" : 'navigation/') . $filename); + } + /** * Show the current user a list of his/her navigation items */ From 4921b1a62e56fee4c25a87e2431c249f6bd4552e Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:09:32 +0200 Subject: [PATCH 07/27] NavigationController: Add method getItemLabel() refs #10246 --- .../controllers/NavigationController.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index 78d1e89b5..cb2012fd9 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -40,6 +40,26 @@ class NavigationController extends Controller ); } + /** + * Return the label for the given navigation item type + * + * @param string $type + * + * @return string It's $type if no label can be found + */ + protected function getItemLabel($type) + { + if (isset($this->moduleItemTypes[$type]['label'])) { + return $this->moduleItemTypes[$type]['label']; + } + + if (isset($this->defaultItemTypes[$type]['label'])) { + return $this->defaultItemTypes[$type]['label']; + } + + return $type; + } + /** * Return a list of available navigation item types * From b4bcfa4e08d425559e6b4b40d913185a063fce91 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:12:57 +0200 Subject: [PATCH 08/27] NavigationController: Register navigation item types differently refs #10246 --- .../controllers/NavigationController.php | 50 ++++++++++++++----- library/Icinga/Application/Modules/Module.php | 11 ++-- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index cb2012fd9..b7d0aa0d6 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -6,6 +6,7 @@ namespace Icinga\Controllers; use Exception; use Icinga\Application\Config; use Icinga\Application\Icinga; +use Icinga\Exception\IcingaException; use Icinga\Exception\NotFoundError; use Icinga\Data\DataArray\ArrayDatasource; use Icinga\Forms\ConfirmRemovalForm; @@ -27,17 +28,43 @@ class NavigationController extends Controller */ protected $defaultItemTypes; + /** + * The item types provided by Icinga Web 2's modules + * + * @var array + */ + protected $moduleItemTypes; + /** * {@inheritdoc} */ public function init() { parent::init(); - $this->defaultItemTypes = array( - 'menu-item' => $this->translate('Menu Entry'), - 'dashlet' => 'Dashlet' + 'menu-item' => array( + 'label' => $this->translate('Menu Entry'), + 'config' => 'menu' + ), + 'dashlet' => array( + 'label' => 'Dashlet', + 'config' => 'dashboard' + ) ); + + $moduleItemTypes = array(); + $moduleManager = Icinga::app()->getModuleManager(); + foreach ($moduleManager->getLoadedModules() as $module) { + if ($this->hasPermission($moduleManager::MODULE_PERMISSION_NS . $module->getName())) { + foreach ($module->getNavigationItems() as $type => $options) { + if (! isset($moduleItemTypes[$type])) { + $moduleItemTypes[$type] = $options; + } + } + } + } + + $this->moduleItemTypes = $moduleItemTypes; } /** @@ -67,16 +94,13 @@ class NavigationController extends Controller */ protected function listItemTypes() { - $moduleManager = Icinga::app()->getModuleManager(); + $types = array(); + foreach ($this->defaultItemTypes as $type => $options) { + $types[$type] = isset($options['label']) ? $options['label'] : $type; + } - $types = $this->defaultItemTypes; - foreach ($moduleManager->getLoadedModules() as $module) { - if ($this->hasPermission($moduleManager::MODULE_PERMISSION_NS . $module->getName())) { - $moduleTypes = $module->getNavigationItems(); - if (! empty($moduleTypes)) { - $types = array_merge($types, $moduleTypes); - } - } + foreach ($this->moduleItemTypes as $type => $options) { + $types[$type] = isset($options['label']) ? $options['label'] : $type; } return $types; @@ -205,8 +229,8 @@ class NavigationController extends Controller { $form = new NavigationConfigForm(); $form->setRedirectUrl('navigation'); - $form->setItemTypes($this->listItemTypes()); $form->setTitle($this->translate('Create New Navigation Item')); + $form->setItemTypes(array_merge($this->defaultItemTypes, $this->moduleItemTypes)); $form->addDescription($this->translate('Create a new navigation item, such as a menu entry or dashlet.')); $form->setUser($this->Auth()->getUser()); $form->setShareConfig(Config::app('navigation')); diff --git a/library/Icinga/Application/Modules/Module.php b/library/Icinga/Application/Modules/Module.php index ebbfc3d98..842a581a9 100644 --- a/library/Icinga/Application/Modules/Module.php +++ b/library/Icinga/Application/Modules/Module.php @@ -1014,16 +1014,21 @@ class Module } /** - * Provide a new type of configurable navigation item with a optional label + * Provide a new type of configurable navigation item with a optional label and config filename * * @param string $type * @param string $label + * @param string $config * * @return $this */ - protected function provideNavigationItem($type, $label = null) + protected function provideNavigationItem($type, $label = null, $config = null) { - $this->navigationItems[$type] = $label ?: $type; + $this->navigationItems[$type] = array( + 'label' => $label, + 'config' => $config + ); + return $this; } From 8d0e57c95e429090715b2f753d707bad1c4d0606 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:13:45 +0200 Subject: [PATCH 09/27] NavigationController: Require parameter type and owner in action unshare refs #10246 --- application/controllers/NavigationController.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index b7d0aa0d6..26776e5da 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -364,9 +364,13 @@ class NavigationController extends Controller $this->assertPermission('config/application/navigation'); $this->assertHttpMethod('POST'); + $itemType = $this->params->getRequired('type'); + $itemOwner = $this->params->getRequired('owner'); + $navigationConfigForm = new NavigationConfigForm(); $navigationConfigForm->setUser($this->Auth()->getUser()); - $navigationConfigForm->setShareConfig(Config::app('navigation')); + $navigationConfigForm->setShareConfig(Config::fromIni($this->getConfigPath($itemType))); + $navigationConfigForm->setUserConfig(Config::fromIni($this->getConfigPath($itemType, $itemOwner))); $form = new Form(array( 'onSuccess' => function ($form) use ($navigationConfigForm) { From eb970b14679819e0062d95019e33639c35f2859a Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:14:17 +0200 Subject: [PATCH 10/27] NavigationController: Require paramter type in action remove refs #10246 --- application/controllers/NavigationController.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index 26776e5da..64abe9a51 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -321,13 +321,17 @@ class NavigationController extends Controller public function removeAction() { $itemName = $this->params->getRequired('name'); + $itemType = $this->params->getRequired('type'); + $user = $this->Auth()->getUser(); $navigationConfigForm = new NavigationConfigForm(); - $navigationConfigForm->setUser($this->Auth()->getUser()); - $navigationConfigForm->setShareConfig(Config::app('navigation')); + $navigationConfigForm->setUser($user); + $navigationConfigForm->setShareConfig(Config::fromIni($this->getConfigPath($itemType))); + $navigationConfigForm->setUserConfig(Config::fromIni($this->getConfigPath($itemType, $user->getUsername()))); + $form = new ConfirmRemovalForm(); $form->setRedirectUrl('navigation'); - $form->setTitle(sprintf($this->translate('Remove Navigation Item %s'), $itemName)); + $form->setTitle(sprintf($this->translate('Remove %s %s'), $this->getItemLabel($itemType), $itemName)); $form->setOnSuccess(function (ConfirmRemovalForm $form) use ($itemName, $navigationConfigForm) { try { $itemConfig = $navigationConfigForm->delete($itemName); From 4b761153993d39b25f1526c0bea889e03f4957c0 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:15:03 +0200 Subject: [PATCH 11/27] NavigationController: Require parameter type in action edit refs #10246 --- application/controllers/NavigationController.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index 64abe9a51..e8f7879f3 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -267,14 +267,22 @@ class NavigationController extends Controller public function editAction() { $itemName = $this->params->getRequired('name'); + $itemType = $this->params->getRequired('type'); $referrer = $this->params->get('referrer', 'index'); + $user = $this->Auth()->getUser(); + if ($user->can('config/application/navigation')) { + $itemOwner = $this->params->get('owner', $user->getUsername()); + } else { + $itemOwner = $user->getUsername(); + } + $form = new NavigationConfigForm(); + $form->setUser($user); + $form->setShareConfig(Config::fromIni($this->getConfigPath($itemType))); + $form->setUserConfig(Config::fromIni($this->getConfigPath($itemType, $itemOwner))); $form->setRedirectUrl($referrer === 'shared' ? 'navigation/shared' : 'navigation'); - $form->setItemTypes($this->listItemTypes()); - $form->setTitle(sprintf($this->translate('Edit Navigation Item %s'), $itemName)); - $form->setUser($this->Auth()->getUser()); - $form->setShareConfig(Config::app('navigation')); + $form->setTitle(sprintf($this->translate('Edit %s %s'), $this->getItemLabel($itemType), $itemName)); $form->setOnSuccess(function (NavigationConfigForm $form) use ($itemName) { $data = array_map( function ($v) { From 1c44a3306bdad56f42754e1ca87fe614421271a2 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:15:57 +0200 Subject: [PATCH 12/27] NavigationController: Add new parameters to all view script's links refs #10246 --- application/controllers/NavigationController.php | 1 - application/views/scripts/navigation/index.phtml | 10 ++++++++-- application/views/scripts/navigation/shared.phtml | 15 +++++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index e8f7879f3..1844a30b4 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -182,7 +182,6 @@ class NavigationController extends Controller $removeForm = new Form(); $removeForm->setUidDisabled(); - $removeForm->setAction(Url::fromPath('navigation/unshare')); $removeForm->addElement('hidden', 'name', array( 'decorators' => array('ViewHelper') )); diff --git a/application/views/scripts/navigation/index.phtml b/application/views/scripts/navigation/index.phtml index 7c81ba5a8..1cf0374f9 100644 --- a/application/views/scripts/navigation/index.phtml +++ b/application/views/scripts/navigation/index.phtml @@ -27,7 +27,10 @@ qlink( $name, 'navigation/edit', - array('name' => $name), + array( + 'name' => $name, + 'type' => $item->type + ), array( 'title' => sprintf($this->translate('Edit navigation item %s'), $name) ) @@ -39,7 +42,10 @@ qlink( '', 'navigation/remove', - array('name' => $name), + array( + 'name' => $name, + 'type' => $item->type + ), array( 'icon' => 'trash', 'title' => sprintf($this->translate('Remove navigation item %s'), $name) diff --git a/application/views/scripts/navigation/shared.phtml b/application/views/scripts/navigation/shared.phtml index 939249f84..e35b01539 100644 --- a/application/views/scripts/navigation/shared.phtml +++ b/application/views/scripts/navigation/shared.phtml @@ -1,4 +1,8 @@ -compact): ?> +compact): ?>
tabs; ?> sortBox; ?> @@ -26,6 +30,8 @@ 'navigation/edit', array( 'name' => $name, + 'type' => $item->type, + 'owner' => $item->owner, 'referrer' => 'shared' ), array( @@ -48,7 +54,12 @@ ) ); ?> - setDefault('name', $name); ?> + setDefault('name', $name) + ->setAction(Url::fromPath( + 'navigation/unshare', + array('type' => $item->type, 'owner' => $item->owner) + )); ?> From dcb4f7f52d5e93e99ce0774b5fa8c22f78dd7f46 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:17:41 +0200 Subject: [PATCH 13/27] Revert "DashboardsController: Add index action" This reverts commit 2be8835f0609ba886678699e3e472a1d426ddc53. --- .../controllers/DashboardsController.php | 24 --------------- .../views/scripts/dashboards/index.phtml | 29 ------------------- 2 files changed, 53 deletions(-) delete mode 100644 application/views/scripts/dashboards/index.phtml diff --git a/application/controllers/DashboardsController.php b/application/controllers/DashboardsController.php index 5d413b0db..d4e68e983 100644 --- a/application/controllers/DashboardsController.php +++ b/application/controllers/DashboardsController.php @@ -4,34 +4,10 @@ namespace Icinga\Controllers; use Icinga\Web\Controller; -use Icinga\Web\Widget\Dashboard; /** * Dashboards */ class DashboardsController extends Controller { - /** - * Display the dashboard with the pane set in the "pane" request parameter - * - * If no pane is given or the given one doesn't exist, the default pane is displayed - */ - public function indexAction() - { - $dashboard = new Dashboard(); - $dashboard->setUser($this->Auth()->getUser()); - $dashboard->load(); - - $this->view->title = 'Dashboard'; - $this->view->tabs = $dashboard->getTabs(); - - if ($dashboard->hasPanes()) { - if (($pane = $this->params->get('pane')) !== null) { - $dashboard->activate($pane); - } - - $this->view->dashboard = $dashboard; - $this->view->title = $dashboard->getActivePane()->getTitle() . ' :: Dashboard'; - } - } } diff --git a/application/views/scripts/dashboards/index.phtml b/application/views/scripts/dashboards/index.phtml deleted file mode 100644 index 85a41b81e..000000000 --- a/application/views/scripts/dashboards/index.phtml +++ /dev/null @@ -1,29 +0,0 @@ -compact): ?> -
- -
- - -
- -
- -
-

escape($this->translate('Welcome to Icinga Web 2!')); ?>

-

- hasPermission('config/modules')): ?> - escape($this->translate( - 'Currently there is no dashboard available. Please contact the administrator.' - )); ?> - - escape($this->translate( - 'Currently there is no dashboard available. This might change once you enabled some of the available %smodules%s.' - )), - substr($this->qlink(null, 'config/modules'), 0, -4), - '' - ); ?> - -

-
- \ No newline at end of file From d2d6815c92e0faf57c3dcc5c832e63ba7df86d7c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:17:47 +0200 Subject: [PATCH 14/27] Revert "Introduce controller DashboardsController" This reverts commit 0d0480afea390a7a466821aa59e9d0a3dfa55b97. --- application/controllers/DashboardsController.php | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 application/controllers/DashboardsController.php diff --git a/application/controllers/DashboardsController.php b/application/controllers/DashboardsController.php deleted file mode 100644 index d4e68e983..000000000 --- a/application/controllers/DashboardsController.php +++ /dev/null @@ -1,13 +0,0 @@ - Date: Tue, 29 Sep 2015 17:22:59 +0200 Subject: [PATCH 15/27] NavigationConfigForm: Fix method getItemConfig() refs #10246 --- application/forms/Navigation/NavigationConfigForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/forms/Navigation/NavigationConfigForm.php b/application/forms/Navigation/NavigationConfigForm.php index efbe73d60..18ca97f47 100644 --- a/application/forms/Navigation/NavigationConfigForm.php +++ b/application/forms/Navigation/NavigationConfigForm.php @@ -879,6 +879,6 @@ class NavigationConfigForm extends ConfigForm $configName = $type . 's'; } - return Config::app($username ? "preferences/$username/" : 'navigation/' . $configName); + return Config::app(($username ? "preferences/$username/" : 'navigation/') . $configName); } } From 64ba37ad04c1a4d5e5e68042356ce0a8dd185a42 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 29 Sep 2015 17:23:27 +0200 Subject: [PATCH 16/27] NavigationController: Fix add action refs #10246 --- application/controllers/NavigationController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index 1844a30b4..98ccc325b 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -232,7 +232,6 @@ class NavigationController extends Controller $form->setItemTypes(array_merge($this->defaultItemTypes, $this->moduleItemTypes)); $form->addDescription($this->translate('Create a new navigation item, such as a menu entry or dashlet.')); $form->setUser($this->Auth()->getUser()); - $form->setShareConfig(Config::app('navigation')); $form->setOnSuccess(function (NavigationConfigForm $form) { $data = array_filter($form->getValues()); @@ -244,7 +243,7 @@ class NavigationController extends Controller } if ($form->save()) { - if (isset($data['type']) && $data['type'] === 'menu-item') { + if ($data['type'] === 'menu-item') { $form->getResponse()->setRerenderLayout(); } From 7db05fa043f7c99b0fcba42703e99d16d907b213 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 30 Sep 2015 09:47:26 +0200 Subject: [PATCH 17/27] NavigationController: Consider module types more important in method getConfigPath() refs #10246 --- application/controllers/NavigationController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index 98ccc325b..daba47a11 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -118,10 +118,10 @@ class NavigationController extends Controller */ protected function getConfigPath($type, $username = null) { - if (isset($this->defaultItemTypes[$type])) { - $options = $this->defaultItemTypes[$type]; - } elseif (isset($this->moduleItemTypes[$type])) { + if (isset($this->moduleItemTypes[$type])) { $options = $this->moduleItemTypes[$type]; + } elseif (isset($this->defaultItemTypes[$type])) { + $options = $this->defaultItemTypes[$type]; } else { throw new IcingaException('Invalid navigation item type %s provided', $type); } From 95d1ce371c5c07d1026179cb114f19bfa71364f1 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 30 Sep 2015 11:18:15 +0200 Subject: [PATCH 18/27] Navigation: Add static method getItemTypeConfiguration() refs #10246 --- .../controllers/NavigationController.php | 57 +++---------------- library/Icinga/Web/Navigation/Navigation.php | 33 +++++++++++ 2 files changed, 40 insertions(+), 50 deletions(-) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index daba47a11..2a360220c 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -5,14 +5,13 @@ namespace Icinga\Controllers; use Exception; use Icinga\Application\Config; -use Icinga\Application\Icinga; -use Icinga\Exception\IcingaException; use Icinga\Exception\NotFoundError; use Icinga\Data\DataArray\ArrayDatasource; use Icinga\Forms\ConfirmRemovalForm; use Icinga\Forms\Navigation\NavigationConfigForm; use Icinga\Web\Controller; use Icinga\Web\Form; +use Icinga\Web\Navigation\Navigation; use Icinga\Web\Notification; use Icinga\Web\Url; @@ -22,18 +21,11 @@ use Icinga\Web\Url; class NavigationController extends Controller { /** - * The default item types provided by Icinga Web 2 + * The global navigation item type configuration * * @var array */ - protected $defaultItemTypes; - - /** - * The item types provided by Icinga Web 2's modules - * - * @var array - */ - protected $moduleItemTypes; + protected $itemTypeConfig; /** * {@inheritdoc} @@ -41,30 +33,7 @@ class NavigationController extends Controller public function init() { parent::init(); - $this->defaultItemTypes = array( - 'menu-item' => array( - 'label' => $this->translate('Menu Entry'), - 'config' => 'menu' - ), - 'dashlet' => array( - 'label' => 'Dashlet', - 'config' => 'dashboard' - ) - ); - - $moduleItemTypes = array(); - $moduleManager = Icinga::app()->getModuleManager(); - foreach ($moduleManager->getLoadedModules() as $module) { - if ($this->hasPermission($moduleManager::MODULE_PERMISSION_NS . $module->getName())) { - foreach ($module->getNavigationItems() as $type => $options) { - if (! isset($moduleItemTypes[$type])) { - $moduleItemTypes[$type] = $options; - } - } - } - } - - $this->moduleItemTypes = $moduleItemTypes; + $this->itemTypeConfig = Navigation::getItemTypeConfiguration(); } /** @@ -72,19 +41,11 @@ class NavigationController extends Controller * * @param string $type * - * @return string It's $type if no label can be found + * @return string $type if no label can be found */ protected function getItemLabel($type) { - if (isset($this->moduleItemTypes[$type]['label'])) { - return $this->moduleItemTypes[$type]['label']; - } - - if (isset($this->defaultItemTypes[$type]['label'])) { - return $this->defaultItemTypes[$type]['label']; - } - - return $type; + return isset($this->itemTypeConfig[$type]['label']) ? $this->itemTypeConfig[$type]['label'] : $type; } /** @@ -95,11 +56,7 @@ class NavigationController extends Controller protected function listItemTypes() { $types = array(); - foreach ($this->defaultItemTypes as $type => $options) { - $types[$type] = isset($options['label']) ? $options['label'] : $type; - } - - foreach ($this->moduleItemTypes as $type => $options) { + foreach ($this->itemTypeConfig as $type => $options) { $types[$type] = isset($options['label']) ? $options['label'] : $type; } diff --git a/library/Icinga/Web/Navigation/Navigation.php b/library/Icinga/Web/Navigation/Navigation.php index 9cd3423a3..55101edce 100644 --- a/library/Icinga/Web/Navigation/Navigation.php +++ b/library/Icinga/Web/Navigation/Navigation.php @@ -451,6 +451,39 @@ class Navigation implements ArrayAccess, Countable, IteratorAggregate return $this; } + /** + * Return the global navigation item type configuration + * + * @return array + */ + public static function getItemTypeConfiguration() + { + $defaultItemTypes = array( + 'menu-item' => array( + 'label' => t('Menu Entry'), + 'config' => 'menu' + ), + 'dashlet' => array( + 'label' => 'Dashlet', + 'config' => 'dashboard' + ) + ); + + $moduleItemTypes = array(); + $moduleManager = Icinga::app()->getModuleManager(); + foreach ($moduleManager->getLoadedModules() as $module) { + if (Auth::getInstance()->hasPermission($moduleManager::MODULE_PERMISSION_NS . $module->getName())) { + foreach ($module->getNavigationItems() as $type => $options) { + if (! isset($moduleItemTypes[$type])) { + $moduleItemTypes[$type] = $options; + } + } + } + } + + return array_merge($defaultItemTypes, $moduleItemTypes); + } + /** * Create and return a new set of navigation items for the given configuration * From befbc6cd6acb2ea82499b8d21983a14d21b2e184 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 30 Sep 2015 11:30:38 +0200 Subject: [PATCH 19/27] Config: Add static method navigation() refs #10246 --- .../controllers/NavigationController.php | 47 +++------------ .../forms/Navigation/NavigationConfigForm.php | 31 +--------- library/Icinga/Application/Config.php | 59 +++++++++++++++++++ 3 files changed, 71 insertions(+), 66 deletions(-) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index 2a360220c..577882f2d 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -63,35 +63,6 @@ class NavigationController extends Controller return $types; } - /** - * Return the path to the configuration file for the given navigation item type and user - * - * @param string $type - * @param string $username - * - * @return string - * - * @throws IcingaException In case the given type is unknown - */ - protected function getConfigPath($type, $username = null) - { - if (isset($this->moduleItemTypes[$type])) { - $options = $this->moduleItemTypes[$type]; - } elseif (isset($this->defaultItemTypes[$type])) { - $options = $this->defaultItemTypes[$type]; - } else { - throw new IcingaException('Invalid navigation item type %s provided', $type); - } - - if (isset($options['config'])) { - $filename = $options['config'] . '.ini'; - } else { - $filename = $type . 's.ini'; - } - - return Config::resolvePath(($username ? "preferences/$username/" : 'navigation/') . $filename); - } - /** * Show the current user a list of his/her navigation items */ @@ -185,10 +156,10 @@ class NavigationController extends Controller { $form = new NavigationConfigForm(); $form->setRedirectUrl('navigation'); - $form->setTitle($this->translate('Create New Navigation Item')); - $form->setItemTypes(array_merge($this->defaultItemTypes, $this->moduleItemTypes)); - $form->addDescription($this->translate('Create a new navigation item, such as a menu entry or dashlet.')); $form->setUser($this->Auth()->getUser()); + $form->setItemTypes($this->listItemTypes()); + $form->setTitle($this->translate('Create New Navigation Item')); + $form->addDescription($this->translate('Create a new navigation item, such as a menu entry or dashlet.')); $form->setOnSuccess(function (NavigationConfigForm $form) { $data = array_filter($form->getValues()); @@ -234,8 +205,8 @@ class NavigationController extends Controller $form = new NavigationConfigForm(); $form->setUser($user); - $form->setShareConfig(Config::fromIni($this->getConfigPath($itemType))); - $form->setUserConfig(Config::fromIni($this->getConfigPath($itemType, $itemOwner))); + $form->setShareConfig(Config::navigation($itemType)); + $form->setUserConfig(Config::navigation($itemType, $itemOwner)); $form->setRedirectUrl($referrer === 'shared' ? 'navigation/shared' : 'navigation'); $form->setTitle(sprintf($this->translate('Edit %s %s'), $this->getItemLabel($itemType), $itemName)); $form->setOnSuccess(function (NavigationConfigForm $form) use ($itemName) { @@ -289,8 +260,8 @@ class NavigationController extends Controller $navigationConfigForm = new NavigationConfigForm(); $navigationConfigForm->setUser($user); - $navigationConfigForm->setShareConfig(Config::fromIni($this->getConfigPath($itemType))); - $navigationConfigForm->setUserConfig(Config::fromIni($this->getConfigPath($itemType, $user->getUsername()))); + $navigationConfigForm->setShareConfig(Config::navigation($itemType)); + $navigationConfigForm->setUserConfig(Config::navigation($itemType, $user->getUsername())); $form = new ConfirmRemovalForm(); $form->setRedirectUrl('navigation'); @@ -336,8 +307,8 @@ class NavigationController extends Controller $navigationConfigForm = new NavigationConfigForm(); $navigationConfigForm->setUser($this->Auth()->getUser()); - $navigationConfigForm->setShareConfig(Config::fromIni($this->getConfigPath($itemType))); - $navigationConfigForm->setUserConfig(Config::fromIni($this->getConfigPath($itemType, $itemOwner))); + $navigationConfigForm->setShareConfig(Config::navigation($itemType)); + $navigationConfigForm->setUserConfig(Config::navigation($itemType, $itemOwner)); $form = new Form(array( 'onSuccess' => function ($form) use ($navigationConfigForm) { diff --git a/application/forms/Navigation/NavigationConfigForm.php b/application/forms/Navigation/NavigationConfigForm.php index 18ca97f47..905ef95c6 100644 --- a/application/forms/Navigation/NavigationConfigForm.php +++ b/application/forms/Navigation/NavigationConfigForm.php @@ -134,7 +134,7 @@ class NavigationConfigForm extends ConfigForm throw new ProgrammingError('You need to pass a type if no user configuration is set'); } - $this->setUserConfig($this->getItemConfig($type, $this->getUser()->getUsername())); + $this->setUserConfig(Config::navigation($type, $this->getUser()->getUsername())); } return $this->userConfig; @@ -168,7 +168,7 @@ class NavigationConfigForm extends ConfigForm throw new ProgrammingError('You need to pass a type if no share configuration is set'); } - $this->setShareConfig($this->getItemConfig($type)); + $this->setShareConfig(Config::navigation($type)); } return $this->shareConfig; @@ -639,11 +639,6 @@ class NavigationConfigForm extends ConfigForm ) ); } else { - $multiOptions = array(); - foreach ($itemTypes as $type => $options) { - $multiOptions[$type] = isset($options['label']) ? $options['label'] : $type; - } - $this->addElement( 'select', 'type', @@ -652,7 +647,7 @@ class NavigationConfigForm extends ConfigForm 'autosubmit' => true, 'label' => $this->translate('Type'), 'description' => $this->translate('The type of this navigation item'), - 'multiOptions' => $multiOptions + 'multiOptions' => $itemTypes ) ); } @@ -861,24 +856,4 @@ class NavigationConfigForm extends ConfigForm return $form; } - - /** - * Return the configuration file for the given type of navigation item - * - * @param string $type - * @param string $username - * - * @return Config - */ - protected function getItemConfig($type, $username = null) - { - $itemTypes = $this->getItemTypes(); - if (isset($itemTypes[$type]['config'])) { - $configName = $itemTypes[$type]['config']; - } else { - $configName = $type . 's'; - } - - return Config::app(($username ? "preferences/$username/" : 'navigation/') . $configName); - } } diff --git a/library/Icinga/Application/Config.php b/library/Icinga/Application/Config.php index bfe2ddd60..3c491590a 100644 --- a/library/Icinga/Application/Config.php +++ b/library/Icinga/Application/Config.php @@ -13,7 +13,9 @@ use Icinga\Data\Selectable; use Icinga\Data\SimpleQuery; use Icinga\File\Ini\IniWriter; use Icinga\File\Ini\IniParser; +use Icinga\Exception\IcingaException; use Icinga\Exception\NotReadableError; +use Icinga\Web\Navigation\Navigation; /** * Container for INI like configuration and global registry of application and module related configuration. @@ -41,6 +43,13 @@ class Config implements Countable, Iterator, Selectable */ protected static $modules = array(); + /** + * Navigation config instances per type + * + * @var array + */ + protected static $navigation = array(); + /** * The internal ConfigObject * @@ -416,6 +425,56 @@ class Config implements Countable, Iterator, Selectable return $moduleConfigs[$configname]; } + /** + * Retrieve a navigation config + * + * @param string $type The type identifier of the navigation item for which to return its config + * @param string $username A user's name or null if the shared config is desired + * @param bool $fromDisk If true, the configuration will be read from disk + * + * @return Config The requested configuration + */ + public static function navigation($type, $username = null, $fromDisk = false) + { + if (! isset(self::$navigation[$type])) { + self::$navigation[$type] = array(); + } + + $branch = $username ?: 'shared'; + $typeConfigs = self::$navigation[$type]; + if (! isset($typeConfigs[$branch]) || $fromDisk) { + $typeConfigs[$branch] = static::fromIni(static::getNavigationConfigPath($type, $username)); + } + + return $typeConfigs[$branch]; + } + + /** + * Return the path to the configuration file for the given navigation item type and user + * + * @param string $type + * @param string $username + * + * @return string + * + * @throws IcingaException In case the given type is unknown + */ + protected static function getNavigationConfigPath($type, $username = null) + { + $itemTypeConfig = Navigation::getItemTypeConfiguration(); + if (! isset($itemTypeConfig[$type])) { + throw new IcingaException('Invalid navigation item type %s provided', $type); + } + + if (isset($itemTypeConfig[$type]['config'])) { + $filename = $itemTypeConfig[$type]['config'] . '.ini'; + } else { + $filename = $type . 's.ini'; + } + + return static::resolvePath(($username ? "preferences/$username/" : 'navigation/') . $filename); + } + /** * Return this config rendered as a INI structured string * From 037fee298ba3b94f5df733480db5a6e24fb14b58 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 30 Sep 2015 11:38:14 +0200 Subject: [PATCH 20/27] User: Drop method loadNavigationConfig() refs #10246 --- .../forms/Navigation/NavigationConfigForm.php | 6 ++--- library/Icinga/User.php | 22 +++---------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/application/forms/Navigation/NavigationConfigForm.php b/application/forms/Navigation/NavigationConfigForm.php index 905ef95c6..a02653720 100644 --- a/application/forms/Navigation/NavigationConfigForm.php +++ b/application/forms/Navigation/NavigationConfigForm.php @@ -401,8 +401,7 @@ class NavigationConfigForm extends ConfigForm if ($ownerName === $this->getUser()->getUsername()) { $exists = $this->getUserConfig()->hasSection($name); } else { - $owner = new User($ownerName); - $exists = $owner->loadNavigationConfig()->hasSection($name); + $exists = Config::navigation($itemConfig->type, $ownerName)->hasSection($name); } } else { $exists = (bool) $this->getShareConfig() @@ -537,8 +536,7 @@ class NavigationConfigForm extends ConfigForm if (! $itemConfig->owner || $itemConfig->owner === $this->getUser()->getUsername()) { $config = $this->getUserConfig(); } else { - $owner = new User($itemConfig->owner); - $config = $owner->loadNavigationConfig(); + $config = Config::navigation($itemConfig->type, $itemConfig->owner); } foreach ($children as $child) { diff --git a/library/Icinga/User.php b/library/Icinga/User.php index 114e59755..7451747e7 100644 --- a/library/Icinga/User.php +++ b/library/Icinga/User.php @@ -479,22 +479,6 @@ class User return false; } - /** - * Load and return this user's navigation configuration - * - * @return Config - */ - public function loadNavigationConfig() - { - return Config::fromIni( - Config::resolvePath('preferences') - . DIRECTORY_SEPARATOR - . $this->getUsername() - . DIRECTORY_SEPARATOR - . 'navigation.ini' - ); - } - /** * Load and return this user's configured navigation of the given type * @@ -504,12 +488,12 @@ class User */ public function getNavigation($type) { - $config = $this->loadNavigationConfig(); + $config = Config::navigation($type === 'dashboard-pane' ? 'dashlet' : $type); $config->getConfigObject()->setKeyColumn('name'); if ($type === 'dashboard-pane') { $panes = array(); - foreach ($config->select()->where('type', 'dashlet') as $dashletName => $dashletConfig) { + foreach ($config as $dashletName => $dashletConfig) { // TODO: Throw ConfigurationError if pane or url is missing $panes[$dashletConfig->pane][$dashletName] = $dashletConfig->url; } @@ -525,7 +509,7 @@ class User ); } } else { - $navigation = Navigation::fromConfig($config->select()->where('type', $type)); + $navigation = Navigation::fromConfig($config); } return $navigation; From 633dca6b76535d79eb11f396a5b4d5c46a67a00c Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 30 Sep 2015 11:38:51 +0200 Subject: [PATCH 21/27] Web: Load the new config files for shared items refs #10246 --- library/Icinga/Application/Web.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index 538afb029..c8d5aed57 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -179,12 +179,12 @@ class Web extends EmbeddedWeb */ public function getSharedNavigation($type) { - $config = Config::app('navigation')->getConfigObject(); - $config->setKeyColumn('name'); + $config = Config::navigation($type === 'dashboard-pane' ? 'dashlet' : $type); + $config->getConfigObject()->setKeyColumn('name'); if ($type === 'dashboard-pane') { $panes = array(); - foreach ($config->select()->where('type', 'dashlet') as $dashletName => $dashletConfig) { + foreach ($config as $dashletName => $dashletConfig) { if ($this->hasAccessToSharedNavigationItem($dashletConfig)) { // TODO: Throw ConfigurationError if pane or url is missing $panes[$dashletConfig->pane][$dashletName] = $dashletConfig->url; @@ -203,7 +203,7 @@ class Web extends EmbeddedWeb } } else { $items = array(); - foreach ($config->select()->where('type', $type) as $name => $typeConfig) { + foreach ($config as $name => $typeConfig) { if ($this->hasAccessToSharedNavigationItem($typeConfig)) { $items[$name] = $typeConfig; } From bbd68457aed4c0ca0040005e5aaa6fad8841bafc Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 30 Sep 2015 11:41:49 +0200 Subject: [PATCH 22/27] Config: Use DIRECTORY_SEPARATOR in static method navigation() refs #10246 --- library/Icinga/Application/Config.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Application/Config.php b/library/Icinga/Application/Config.php index 3c491590a..d25ec748c 100644 --- a/library/Icinga/Application/Config.php +++ b/library/Icinga/Application/Config.php @@ -472,7 +472,11 @@ class Config implements Countable, Iterator, Selectable $filename = $type . 's.ini'; } - return static::resolvePath(($username ? "preferences/$username/" : 'navigation/') . $filename); + return static::resolvePath( + ($username ? 'preferences' . DIRECTORY_SEPARATOR . $username : 'navigation') + . DIRECTORY_SEPARATOR + . $filename + ); } /** From a2827e0dd916345157c3e656b54e9e6abdea00b5 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 30 Sep 2015 11:47:22 +0200 Subject: [PATCH 23/27] Web: It's not necessary anymore to set a key column refs #10246 --- library/Icinga/Application/Web.php | 1 - 1 file changed, 1 deletion(-) diff --git a/library/Icinga/Application/Web.php b/library/Icinga/Application/Web.php index c8d5aed57..da11b9c1e 100644 --- a/library/Icinga/Application/Web.php +++ b/library/Icinga/Application/Web.php @@ -180,7 +180,6 @@ class Web extends EmbeddedWeb public function getSharedNavigation($type) { $config = Config::navigation($type === 'dashboard-pane' ? 'dashlet' : $type); - $config->getConfigObject()->setKeyColumn('name'); if ($type === 'dashboard-pane') { $panes = array(); From 6a61d4aa2585e14b26ccbbe1d66a430bb466a289 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 30 Sep 2015 11:47:38 +0200 Subject: [PATCH 24/27] User: Fix method getNavigation() refs #10246 --- library/Icinga/User.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/library/Icinga/User.php b/library/Icinga/User.php index 7451747e7..626905e9c 100644 --- a/library/Icinga/User.php +++ b/library/Icinga/User.php @@ -488,8 +488,7 @@ class User */ public function getNavigation($type) { - $config = Config::navigation($type === 'dashboard-pane' ? 'dashlet' : $type); - $config->getConfigObject()->setKeyColumn('name'); + $config = Config::navigation($type === 'dashboard-pane' ? 'dashlet' : $type, $this->getUsername()); if ($type === 'dashboard-pane') { $panes = array(); From 6b31898566b97568cbb232e5e611b61371588ff9 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 30 Sep 2015 12:22:48 +0200 Subject: [PATCH 25/27] NavigationController: Adjust how to load navigation items refs #10246 --- .../controllers/NavigationController.php | 59 ++++++++++++++++--- .../views/scripts/navigation/index.phtml | 12 ++-- .../views/scripts/navigation/shared.phtml | 10 ++-- 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index 577882f2d..c407b3e1a 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -63,18 +63,63 @@ class NavigationController extends Controller return $types; } + /** + * Return all shared navigation item configurations + * + * @param string $owner A username if only items shared by a specific user are desired + * + * @return array + */ + protected function fetchSharedNavigationItemConfigs($owner = null) + { + $configs = array(); + foreach ($this->itemTypeConfig as $type => $_) { + $config = Config::navigation($type); + $config->getConfigObject()->setKeyColumn('name'); + $query = $config->select(); + if ($owner !== null) { + $query->where('owner', $owner); + } + + foreach ($query as $itemConfig) { + $configs[] = $itemConfig; + } + } + + return $configs; + } + + /** + * Return all user navigation item configurations + * + * @param string $username + * + * @return array + */ + protected function fetchUserNavigationItemConfigs($username) + { + $configs = array(); + foreach ($this->itemTypeConfig as $type => $_) { + $config = Config::navigation($type, $username); + $config->getConfigObject()->setKeyColumn('name'); + foreach ($config->select() as $itemConfig) { + $configs[] = $itemConfig; + } + } + + return $configs; + } + /** * Show the current user a list of his/her navigation items */ public function indexAction() { $user = $this->Auth()->getUser(); - $ds = new ArrayDatasource(array_merge( - Config::app('navigation')->select()->where('owner', $user->getUsername())->fetchAll(), - iterator_to_array($user->loadNavigationConfig()) + $this->fetchSharedNavigationItemConfigs($user->getUsername()), + $this->fetchUserNavigationItemConfigs($user->getUsername()) )); - $ds->setKeyColumn('name'); $query = $ds->select(); $this->view->types = $this->listItemTypes(); @@ -104,9 +149,8 @@ class NavigationController extends Controller public function sharedAction() { $this->assertPermission('config/application/navigation'); - $config = Config::app('navigation'); - $config->getConfigObject()->setKeyColumn('name'); - $query = $config->select(); + $ds = new ArrayDatasource($this->fetchSharedNavigationItemConfigs()); + $query = $ds->select(); $removeForm = new Form(); $removeForm->setUidDisabled(); @@ -302,6 +346,7 @@ class NavigationController extends Controller $this->assertPermission('config/application/navigation'); $this->assertHttpMethod('POST'); + // TODO: I'd like these being form fields $itemType = $this->params->getRequired('type'); $itemOwner = $this->params->getRequired('owner'); diff --git a/application/views/scripts/navigation/index.phtml b/application/views/scripts/navigation/index.phtml index 1cf0374f9..2f77d0995 100644 --- a/application/views/scripts/navigation/index.phtml +++ b/application/views/scripts/navigation/index.phtml @@ -22,17 +22,17 @@ translate('Remove'); ?> - $item): ?> + qlink( - $name, + $item->name, 'navigation/edit', array( - 'name' => $name, + 'name' => $item->name, 'type' => $item->type ), array( - 'title' => sprintf($this->translate('Edit navigation item %s'), $name) + 'title' => sprintf($this->translate('Edit navigation item %s'), $item->name) ) ); ?> type && isset($types[$item->type]) @@ -43,12 +43,12 @@ '', 'navigation/remove', array( - 'name' => $name, + 'name' => $item->name, 'type' => $item->type ), array( 'icon' => 'trash', - 'title' => sprintf($this->translate('Remove navigation item %s'), $name) + 'title' => sprintf($this->translate('Remove navigation item %s'), $item->name) ) ); ?> diff --git a/application/views/scripts/navigation/shared.phtml b/application/views/scripts/navigation/shared.phtml index e35b01539..5d0a3107f 100644 --- a/application/views/scripts/navigation/shared.phtml +++ b/application/views/scripts/navigation/shared.phtml @@ -23,19 +23,19 @@ if (! $this->compact): ?> translate('Unshare'); ?> - $item): ?> + qlink( - $name, + $item->name, 'navigation/edit', array( - 'name' => $name, + 'name' => $item->name, 'type' => $item->type, 'owner' => $item->owner, 'referrer' => 'shared' ), array( - 'title' => sprintf($this->translate('Edit shared navigation item %s'), $name) + 'title' => sprintf($this->translate('Edit shared navigation item %s'), $item->name) ) ); ?> type && isset($types[$item->type]) @@ -55,7 +55,7 @@ if (! $this->compact): ?> ); ?> setDefault('name', $name) + ->setDefault('name', $item->name) ->setAction(Url::fromPath( 'navigation/unshare', array('type' => $item->type, 'owner' => $item->owner) From ddeed579afcbb355a26a957d618148294166851b Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 30 Sep 2015 12:28:40 +0200 Subject: [PATCH 26/27] NavigationController: Fix incorrect sort label refs #10246 --- application/controllers/NavigationController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/controllers/NavigationController.php b/application/controllers/NavigationController.php index c407b3e1a..139c22741 100644 --- a/application/controllers/NavigationController.php +++ b/application/controllers/NavigationController.php @@ -137,7 +137,7 @@ class NavigationController extends Controller array( 'type' => $this->translate('Type'), 'owner' => $this->translate('Shared'), - 'name' => $this->translate('Shared Navigation') + 'name' => $this->translate('Navigation') ), $query ); From 915b5591298d3cb2abd4a1f576b77d71db3a12e9 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Wed, 30 Sep 2015 12:33:13 +0200 Subject: [PATCH 27/27] NavigationConfigForm: Do not disable the hidden type field refs #10246 --- application/forms/Navigation/NavigationConfigForm.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/application/forms/Navigation/NavigationConfigForm.php b/application/forms/Navigation/NavigationConfigForm.php index a02653720..94ff860ae 100644 --- a/application/forms/Navigation/NavigationConfigForm.php +++ b/application/forms/Navigation/NavigationConfigForm.php @@ -632,8 +632,7 @@ class NavigationConfigForm extends ConfigForm 'hidden', 'type', array( - 'disabled' => true, - 'value' => $itemType + 'value' => $itemType ) ); } else {