/** * Get service actions from hook * * @return Navigation */ protected function getServiceActions() { $navigation = new Navigation(); foreach (Hook::all('Monitoring\\ServiceActions') as $hook) { $navigation->merge($hook->getNavigation($this->object)); } return $navigation; }
/** * {@inheritdoc} */ public function render() { $url = Url::fromRequest(); $activeLimit = (int) $url->getParam('limit', $this->getDefaultLimit()); $navigation = new Navigation(); $navigation->setLayout(Navigation::LAYOUT_TABS); foreach (static::$limits as $limit => $label) { $navigation->addItem('limit_' . $limit, array('priority' => $limit, 'label' => $label, 'active' => $activeLimit === $limit, 'url' => $url->with(array('limit' => $limit)), 'title' => sprintf(t('Show %u rows on this page'), $limit))); } if ($activeLimit === 0) { $navigation->addItem('limit_0', array('active' => true, 'label' => t('all'), 'title' => t('Show all items on this page'), 'priority' => max(array_keys(static::$limits)) + 1)); } return $navigation->getRenderer()->setCssClass(static::CSS_CLASS_LIMITER)->setHeading(t('Limiter'))->render(); }
/** * Load Pane items provided by all enabled modules * * @return $this */ public function load() { $navigation = new Navigation(); $navigation->load('dashboard-pane'); $panes = array(); foreach ($navigation as $dashboardPane) { /** @var DashboardPane $dashboardPane */ $pane = new Pane($dashboardPane->getLabel()); foreach ($dashboardPane->getDashlets() as $title => $url) { $pane->addDashlet($title, $url); } $panes[] = $pane; } $this->mergePanes($panes); return $this; }
/** * {@inheritdoc} */ public function render() { $url = Url::fromRequest(); $activeLimit = (int) $url->getParam('limit', $this->getDefaultLimit()); $navigation = new Navigation(); $navigation->setLayout(Navigation::LAYOUT_TABS); foreach (static::$limits as $limit => $label) { $navigationItem = new NavigationItem($limit); $navigationItem->setActive($activeLimit === $limit)->setAttribute('title', sprintf(t('Show %u rows on this page'), $limit))->setLabel($label)->setUrl($url->with(array('limit' => $limit))); $navigation->addItem($navigationItem); } if ($activeLimit === 0) { $navigationItem = new NavigationItem(0); $navigationItem->setActive(true)->setAttribute('title', t('Show all items on this page'))->setLabel(t('all')); $navigation->addItem($navigationItem); } return $navigation->getRenderer()->setCssClass(static::CSS_CLASS_LIMITER)->setHeading(t('Limiter'))->render(); }
/** * Return the opening markup for multiple navigation items * * @return string */ public function beginChildrenMarkup() { $cssClass = array(static::CSS_CLASS_NAV); if ($this->navigation->getLayout() === Navigation::LAYOUT_TABS) { $cssClass[] = static::CSS_CLASS_NAV_TABS; } elseif ($this->navigation->getLayout() === Navigation::LAYOUT_DROPDOWN) { $cssClass[] = static::CSS_CLASS_NAV_DROPDOWN; } return '<ul class="' . join(' ', $cssClass) . '">'; }
/** * 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' . DIRECTORY_SEPARATOR . $username : '******') . DIRECTORY_SEPARATOR . $filename); }
/** * Return the app's menu * * @return Navigation */ public function getMenu() { if ($this->user !== null) { $menu = array('dashboard' => array('label' => t('Dashboard'), 'url' => 'dashboard', 'icon' => 'dashboard', 'priority' => 10), 'system' => array('label' => t('System'), 'icon' => 'services', 'priority' => 700, 'renderer' => array('SummaryNavigationItemRenderer', 'state' => 'critical'), 'children' => array('about' => array('label' => t('About'), 'url' => 'about', 'priority' => 700), 'announcements' => array('label' => t('Announcements'), 'url' => 'announcements', 'priority' => 710))), 'configuration' => array('label' => t('Configuration'), 'icon' => 'wrench', 'permission' => 'config/*', 'priority' => 800, 'children' => array('application' => array('label' => t('Application'), 'url' => 'config/general', 'permission' => 'config/application/*', 'priority' => 810), 'authentication' => array('label' => t('Authentication'), 'permission' => 'config/authentication/*', 'priority' => 830, 'url' => 'role/list'), 'navigation' => array('label' => t('Shared Navigation'), 'url' => 'navigation/shared', 'permission' => 'config/application/navigation', 'priority' => 840), 'modules' => array('label' => t('Modules'), 'url' => 'config/modules', 'permission' => 'config/modules', 'priority' => 890))), 'user' => array('cssClass' => 'user-nav-item', 'label' => $this->user->getUsername(), 'icon' => 'user', 'priority' => 900, 'children' => array('account' => array('label' => t('My Account'), 'priority' => 100, 'url' => 'account'), 'logout' => array('label' => t('Logout'), 'priority' => 200, 'attributes' => array('target' => '_self'), 'url' => 'authentication/logout')))); if (Logger::writesToFile()) { $menu['system']['children']['application_log'] = array('label' => t('Application Log'), 'url' => 'list/applicationlog', 'permission' => 'application/log', 'priority' => 900); } } else { $menu = array(); } return Navigation::fromArray($menu)->load('menu-item'); }
/** * {@inheritdoc} */ public function init() { parent::init(); $this->itemTypeConfig = Navigation::getItemTypeConfiguration(); }
/** * Create and return a new navigation for the given menu items * * @param MenuItemContainer[] $items * * @return Navigation */ private function createMenu(array $items) { $navigation = new Navigation(); foreach ($items as $item) { /** @var MenuItemContainer $item */ $navigationItem = $navigation->createItem($item->getName(), $item->getProperties()); $navigationItem->setChildren($this->createMenu($item->getChildren())); $navigationItem->setLabel($this->translate($item->getName())); $navigation->addItem($navigationItem); } return $navigation; }
/** * Load and return this user's configured navigation of the given type * * @param string $type * * @return Navigation */ public function getNavigation($type) { $config = $this->loadNavigationConfig(); $config->getConfigObject()->setKeyColumn('name'); if ($type === 'dashboard-pane') { $panes = array(); foreach ($config->select()->where('type', 'dashlet') as $dashletName => $dashletConfig) { // TODO: Throw ConfigurationError if pane or url is missing $panes[$dashletConfig->pane][$dashletName] = $dashletConfig->url; } $navigation = new Navigation(); foreach ($panes as $paneName => $dashlets) { $navigation->addItem($paneName, array('type' => 'dashboard-pane', 'dashlets' => $dashlets)); } } else { $navigation = Navigation::fromConfig($config->select()->where('type', $type)); } return $navigation; }
/** * Create and return a new Navigation object * * @param array $actions Optional array of actions to add to the returned object * * @return Navigation */ protected function createNavigation(array $actions = null) { return empty($actions) ? new Navigation() : Navigation::fromArray($actions); }
/** * 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'; } if ($username) { $path = static::resolvePath(implode(DIRECTORY_SEPARATOR, array('preferences', $username, $filename))); if (realpath($path) === false) { $path = static::resolvePath(implode(DIRECTORY_SEPARATOR, array('preferences', strtolower($username), $filename))); } } else { $path = static::resolvePath('navigation' . DIRECTORY_SEPARATOR . $filename); } return $path; }
/** * Load and return this user's configured navigation of the given type * * @param string $type * * @return Navigation */ public function getNavigation($type) { $config = Config::navigation($type === 'dashboard-pane' ? 'dashlet' : $type, $this->getUsername()); if ($type === 'dashboard-pane') { $panes = array(); foreach ($config as $dashletName => $dashletConfig) { // TODO: Throw ConfigurationError if pane or url is missing $panes[$dashletConfig->pane][$dashletName] = $dashletConfig->url; } $navigation = new Navigation(); foreach ($panes as $paneName => $dashlets) { $navigation->addItem($paneName, array('type' => 'dashboard-pane', 'dashlets' => $dashlets)); } } else { $navigation = Navigation::fromConfig($config); } return $navigation; }
/** * {@inheritdoc} */ public function render() { $badges = new Navigation(); $badges->setLayout(Navigation::LAYOUT_TABS); $this->createBadgeGroup(array(static::STATE_CRITICAL, static::STATE_CRITICAL_HANDLED), $badges)->createBadgeGroup(array(static::STATE_DOWN, static::STATE_DOWN_HANDLED), $badges)->createBadgeGroup(array(static::STATE_WARNING, static::STATE_WARNING_HANDLED), $badges)->createBadgeGroup(array(static::STATE_UNREACHABLE, static::STATE_UNREACHABLE_HANDLED), $badges)->createBadge(static::STATE_UNKNOWN, $badges)->createBadge(static::STATE_OK, $badges)->createBadge(static::STATE_UP, $badges)->createBadge(static::STATE_PENDING, $badges); return $badges->getRenderer()->setCssClass(static::CSS_CLASS)->render(); }
/** * Return the app's menu * * @return Navigation */ public function getMenu() { if ($this->user !== null) { $menu = array('dashboard' => array('label' => t('Dashboard'), 'url' => 'dashboard', 'icon' => 'dashboard', 'priority' => 10), 'system' => array('label' => t('System'), 'icon' => 'services', 'priority' => 700, 'renderer' => array('SummaryNavigationItemRenderer', 'state' => 'critical'), 'children' => array('about' => array('label' => t('About'), 'url' => 'about', 'priority' => 701))), 'configuration' => array('label' => t('Configuration'), 'icon' => 'wrench', 'permission' => 'config/*', 'priority' => 800, 'children' => array('application' => array('label' => t('Application'), 'url' => 'config/general', 'permission' => 'config/application/*', 'priority' => 810), 'navigation' => array('label' => t('Shared Navigation'), 'url' => 'navigation/shared', 'permission' => 'config/application/navigation', 'priority' => 820), 'authentication' => array('label' => t('Authentication'), 'url' => 'config/userbackend', 'permission' => 'config/authentication/*', 'priority' => 830), 'roles' => array('label' => t('Roles'), 'url' => 'role/list', 'permission' => 'config/authentication/roles/show', 'priority' => 840), 'users' => array('label' => t('Users'), 'url' => 'user/list', 'permission' => 'config/authentication/users/show', 'priority' => 850), 'groups' => array('label' => t('Usergroups'), 'url' => 'group/list', 'permission' => 'config/authentication/groups/show', 'priority' => 860), 'modules' => array('label' => t('Modules'), 'url' => 'config/modules', 'permission' => 'config/modules', 'priority' => 890))), 'user' => array('label' => $this->user->getUsername(), 'icon' => 'user', 'priority' => 900, 'children' => array('preferences' => array('label' => t('Preferences'), 'url' => 'preference', 'priority' => 910), 'navigation' => array('label' => t('Navigation'), 'url' => 'navigation', 'priority' => 920), 'logout' => array('label' => t('Logout'), 'url' => 'authentication/logout', 'priority' => 990, 'renderer' => array('NavigationItemRenderer', 'target' => '_self'))))); if (Logger::writesToFile()) { $menu['system']['children']['application_log'] = array('label' => t('Application Log'), 'url' => 'list/applicationlog', 'priority' => 710); } } else { $menu = array(); } return Navigation::fromArray($menu)->load('menu-item'); }
/** * Set this item's children * * @param array|Navigation $children * * @return $this */ public function setChildren($children) { if (is_array($children)) { $children = Navigation::fromArray($children); } elseif (!$children instanceof Navigation) { throw new InvalidArgumentException('Argument $children must be of type array or Navigation'); } foreach ($children as $item) { $item->setParent($this); } $this->children = $children; return $this; }
/** * Return this module's menu * * @return Navigation */ public function getMenu() { $this->launchConfigScript(); return Navigation::fromArray($this->createMenu($this->menuItems)); }