Пример #1
1
 /**
  * Add a dashlet to this pane, optionally creating it if $dashlet is a string
  *
  * @param string|Dashlet $dashlet               The dashlet object or title
  *                                                  (if a new dashlet will be created)
  * @param string|null $url                          An Url to be used when dashlet is a string
  *
  * @return $this
  * @throws \Icinga\Exception\ConfigurationError
  */
 public function addDashlet($dashlet, $url = null)
 {
     if ($dashlet instanceof Dashlet) {
         $this->dashlets[$dashlet->getTitle()] = $dashlet;
     } elseif (is_string($dashlet) && $url !== null) {
         $this->dashlets[$dashlet] = new Dashlet($dashlet, $url, $this);
     } else {
         throw new ConfigurationError('Invalid dashlet added: %s', $dashlet);
     }
     return $this;
 }
Пример #2
0
 public function newDashletAction()
 {
     $form = new DashletForm();
     $this->createTabs();
     $dashboard = $this->dashboard;
     $form->setDashboard($dashboard);
     if ($this->_request->getParam('url')) {
         $params = $this->_request->getParams();
         $params['url'] = rawurldecode($this->_request->getParam('url'));
         $form->populate($params);
     }
     $action = $this;
     $form->setOnSuccess(function (Form $form) use($dashboard, $action) {
         try {
             $pane = $dashboard->getPane($form->getValue('pane'));
         } catch (ProgrammingError $e) {
             $pane = new Dashboard\Pane($form->getValue('pane'));
             $pane->setUserWidget();
             $dashboard->addPane($pane);
         }
         $dashlet = new Dashboard\Dashlet($form->getValue('dashlet'), $form->getValue('url'), $pane);
         $dashlet->setUserWidget();
         $pane->addDashlet($dashlet);
         $dashboardConfig = $dashboard->getConfig();
         try {
             $dashboardConfig->saveIni();
         } catch (Exception $e) {
             $action->view->error = $e;
             $action->view->config = $dashboardConfig;
             $action->render('error');
             return false;
         }
         Notification::success(t('Dashlet created'));
         return true;
     });
     $form->setTitle($this->translate('Add Dashlet To Dashboard'));
     $form->setRedirectUrl('dashboard');
     $form->handleRequest();
     $this->view->form = $form;
 }
Пример #3
0
 /**
  * @param Dashlet $dashlet
  */
 public function load(Dashlet $dashlet)
 {
     $this->populate(array('pane' => $dashlet->getPane()->getName(), 'org_pane' => $dashlet->getPane()->getName(), 'dashlet' => $dashlet->getTitle(), 'org_dashlet' => $dashlet->getTitle(), 'url' => $dashlet->getUrl()->getRelativeUrl()));
 }
Пример #4
0
 /**
  * @return bool
  */
 private function loadUserDashboards()
 {
     try {
         $config = Config::fromIni($this->getConfigFile());
     } catch (NotReadableError $e) {
         return;
     }
     if (!count($config)) {
         return false;
     }
     $panes = array();
     $dashlets = array();
     foreach ($config as $key => $part) {
         if (strpos($key, '.') === false) {
             if ($this->hasPane($part->title)) {
                 $panes[$key] = $this->getPane($part->title);
             } else {
                 $panes[$key] = new Pane($key);
                 $panes[$key]->setTitle($part->title);
             }
             $panes[$key]->setUserWidget();
             if ((bool) $part->get('disabled', false) === true) {
                 $panes[$key]->setDisabled();
             }
         } else {
             list($paneName, $dashletName) = explode('.', $key, 2);
             $part->pane = $paneName;
             $part->dashlet = $dashletName;
             $dashlets[] = $part;
         }
     }
     foreach ($dashlets as $dashletData) {
         $pane = null;
         if (array_key_exists($dashletData->pane, $panes) === true) {
             $pane = $panes[$dashletData->pane];
         } elseif (array_key_exists($dashletData->pane, $this->panes) === true) {
             $pane = $this->panes[$dashletData->pane];
         } else {
             continue;
         }
         $dashlet = new DashboardDashlet($dashletData->title, $dashletData->url, $pane);
         if ((bool) $dashletData->get('disabled', false) === true) {
             $dashlet->setDisabled(true);
         }
         $dashlet->setUserWidget();
         $pane->addDashlet($dashlet);
     }
     $this->mergePanes($panes);
     return true;
 }