Beispiel #1
0
 /**
  * {@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();
 }
Beispiel #2
0
 /**
  * {@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();
 }
Beispiel #3
0
 /**
  * Return the action navigation for the given object
  *
  * @return  Navigation
  */
 public function getNavigation(MonitoredObject $object)
 {
     $urls = $this->getActionsForObject($object);
     if (is_array($urls)) {
         $navigation = new Navigation();
         foreach ($urls as $label => $url) {
             $navigation->addItem($label, array('url' => $url));
         }
     } else {
         $navigation = $urls;
     }
     return $navigation;
 }
Beispiel #4
0
 /**
  * Load and return the shared navigation of the given type
  *
  * @param   string  $type
  *
  * @return  Navigation
  */
 public function getSharedNavigation($type)
 {
     $config = Config::navigation($type === 'dashboard-pane' ? 'dashlet' : $type);
     if ($type === 'dashboard-pane') {
         $panes = array();
         foreach ($config as $dashletName => $dashletConfig) {
             if ($this->hasAccessToSharedNavigationItem($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 {
         $items = array();
         foreach ($config as $name => $typeConfig) {
             if ($this->hasAccessToSharedNavigationItem($typeConfig)) {
                 $items[$name] = $typeConfig;
             }
         }
         $navigation = Navigation::fromConfig($items);
     }
     return $navigation;
 }
Beispiel #5
0
 /**
  * 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;
 }
Beispiel #6
0
 /**
  * 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;
 }
Beispiel #7
0
 /**
  * Create a badge group
  *
  * @param   array $states
  * @param   Navigation $badges
  *
  * @return  $this
  */
 public function createBadgeGroup(array $states, Navigation $badges)
 {
     $group = array_intersect_key($this->badges, array_flip($states));
     if (!empty($group)) {
         $groupItem = new NavigationItem(uniqid(), array('label' => '', 'priority' => $this->priority++));
         $groupBadges = new Navigation();
         $groupBadges->setLayout(Navigation::LAYOUT_TABS);
         foreach (array_keys($group) as $state) {
             $this->createBadge($state, $groupBadges);
         }
         $groupItem->setChildren($groupBadges);
         $badges->addItem($groupItem);
     }
     return $this;
 }
Beispiel #8
0
 /**
  * Create and return a new navigation for the given dashboard panes
  *
  * @param   DashboardContainer[]    $panes
  *
  * @return  Navigation
  */
 public function createDashboard(array $panes)
 {
     $navigation = new Navigation();
     foreach ($panes as $pane) {
         /** @var DashboardContainer $pane */
         $dashlets = array();
         foreach ($pane->getDashlets() as $dashletName => $dashletUrl) {
             $dashlets[$this->translate($dashletName)] = $dashletUrl;
         }
         $navigation->addItem($pane->getName(), array_merge($pane->getProperties(), array('label' => $this->translate($pane->getName()), 'type' => 'dashboard-pane', 'dashlets' => $dashlets)));
     }
     return $navigation;
 }