[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/dashboard/controller/ -> PhabricatorDashboardPanelViewController.php (source)

   1  <?php
   2  
   3  final class PhabricatorDashboardPanelViewController
   4    extends PhabricatorDashboardController {
   5  
   6    private $id;
   7  
   8    public function shouldAllowPublic() {
   9      return true;
  10    }
  11  
  12    public function willProcessRequest(array $data) {
  13      $this->id = $data['id'];
  14    }
  15  
  16    public function processRequest() {
  17      $request = $this->getRequest();
  18      $viewer = $request->getUser();
  19  
  20      $panel = id(new PhabricatorDashboardPanelQuery())
  21        ->setViewer($viewer)
  22        ->withIDs(array($this->id))
  23        ->executeOne();
  24      if (!$panel) {
  25        return new Aphront404Response();
  26      }
  27  
  28      $title = $panel->getMonogram().' '.$panel->getName();
  29      $crumbs = $this->buildApplicationCrumbs();
  30      $crumbs->addTextCrumb(
  31        pht('Panels'),
  32        $this->getApplicationURI('panel/'));
  33      $crumbs->addTextCrumb($panel->getMonogram());
  34  
  35      $header = $this->buildHeaderView($panel);
  36      $actions = $this->buildActionView($panel);
  37      $properties = $this->buildPropertyView($panel);
  38      $timeline = $this->buildTransactions($panel);
  39  
  40      $properties->setActionList($actions);
  41      $box = id(new PHUIObjectBoxView())
  42        ->setHeader($header)
  43        ->addPropertyList($properties);
  44  
  45      $rendered_panel = id(new PhabricatorDashboardPanelRenderingEngine())
  46        ->setViewer($viewer)
  47        ->setPanel($panel)
  48        ->setParentPanelPHIDs(array())
  49        ->renderPanel();
  50  
  51      $view = id(new PHUIBoxView())
  52        ->addMargin(PHUI::MARGIN_LARGE_LEFT)
  53        ->addMargin(PHUI::MARGIN_LARGE_RIGHT)
  54        ->addMargin(PHUI::MARGIN_LARGE_TOP)
  55        ->appendChild($rendered_panel);
  56  
  57      return $this->buildApplicationPage(
  58        array(
  59          $crumbs,
  60          $box,
  61          $view,
  62          $timeline,
  63        ),
  64        array(
  65          'title' => $title,
  66        ));
  67    }
  68  
  69    private function buildHeaderView(PhabricatorDashboardPanel $panel) {
  70      $viewer = $this->getRequest()->getUser();
  71  
  72      return id(new PHUIHeaderView())
  73        ->setUser($viewer)
  74        ->setHeader($panel->getName())
  75        ->setPolicyObject($panel);
  76    }
  77  
  78    private function buildActionView(PhabricatorDashboardPanel $panel) {
  79      $viewer = $this->getRequest()->getUser();
  80      $id = $panel->getID();
  81  
  82      $actions = id(new PhabricatorActionListView())
  83        ->setObjectURI('/'.$panel->getMonogram())
  84        ->setUser($viewer);
  85  
  86      $can_edit = PhabricatorPolicyFilter::hasCapability(
  87        $viewer,
  88        $panel,
  89        PhabricatorPolicyCapability::CAN_EDIT);
  90  
  91      $actions->addAction(
  92        id(new PhabricatorActionView())
  93          ->setName(pht('Edit Panel'))
  94          ->setIcon('fa-pencil')
  95          ->setHref($this->getApplicationURI("panel/edit/{$id}/"))
  96          ->setDisabled(!$can_edit)
  97          ->setWorkflow(!$can_edit));
  98  
  99      if (!$panel->getIsArchived()) {
 100        $archive_text = pht('Archive Panel');
 101        $archive_icon = 'fa-times';
 102      } else {
 103        $archive_text = pht('Activate Panel');
 104        $archive_icon = 'fa-plus';
 105      }
 106  
 107      $actions->addAction(
 108        id(new PhabricatorActionView())
 109          ->setName($archive_text)
 110          ->setIcon($archive_icon)
 111          ->setHref($this->getApplicationURI("panel/archive/{$id}/"))
 112          ->setDisabled(!$can_edit)
 113          ->setWorkflow(true));
 114  
 115      $actions->addAction(
 116        id(new PhabricatorActionView())
 117          ->setName(pht('View Standalone'))
 118          ->setIcon('fa-eye')
 119          ->setHref($this->getApplicationURI("panel/render/{$id}/")));
 120  
 121      return $actions;
 122    }
 123  
 124    private function buildPropertyView(PhabricatorDashboardPanel $panel) {
 125      $viewer = $this->getRequest()->getUser();
 126  
 127      $properties = id(new PHUIPropertyListView())
 128        ->setUser($viewer)
 129        ->setObject($panel);
 130  
 131      $descriptions = PhabricatorPolicyQuery::renderPolicyDescriptions(
 132        $viewer,
 133        $panel);
 134  
 135      $panel_type = $panel->getImplementation();
 136      if ($panel_type) {
 137        $type_name = $panel_type->getPanelTypeName();
 138      } else {
 139        $type_name = phutil_tag(
 140          'em',
 141          array(),
 142          nonempty($panel->getPanelType(), pht('null')));
 143      }
 144  
 145      $properties->addProperty(
 146        pht('Panel Type'),
 147        $type_name);
 148  
 149      $properties->addProperty(
 150        pht('Editable By'),
 151        $descriptions[PhabricatorPolicyCapability::CAN_EDIT]);
 152  
 153      $dashboard_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
 154        $panel->getPHID(),
 155        PhabricatorEdgeConfig::TYPE_PANEL_HAS_DASHBOARD);
 156      $this->loadHandles($dashboard_phids);
 157  
 158      $does_not_appear = pht(
 159        'This panel does not appear on any dashboards.');
 160  
 161      $properties->addProperty(
 162        pht('Appears On'),
 163        $dashboard_phids
 164          ? $this->renderHandlesForPHIDs($dashboard_phids)
 165          : phutil_tag('em', array(), $does_not_appear));
 166  
 167      return $properties;
 168    }
 169  
 170    private function buildTransactions(PhabricatorDashboardPanel $panel) {
 171      $viewer = $this->getRequest()->getUser();
 172  
 173      $xactions = id(new PhabricatorDashboardPanelTransactionQuery())
 174        ->setViewer($viewer)
 175        ->withObjectPHIDs(array($panel->getPHID()))
 176        ->execute();
 177  
 178      $engine = id(new PhabricatorMarkupEngine())
 179        ->setViewer($viewer);
 180  
 181      $timeline = id(new PhabricatorApplicationTransactionView())
 182        ->setUser($viewer)
 183        ->setShouldTerminate(true)
 184        ->setObjectPHID($panel->getPHID())
 185        ->setTransactions($xactions);
 186  
 187      return $timeline;
 188    }
 189  
 190  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1