[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/releeph/controller/branch/ -> ReleephBranchViewController.php (source)

   1  <?php
   2  
   3  final class ReleephBranchViewController extends ReleephBranchController
   4    implements PhabricatorApplicationSearchResultsControllerInterface {
   5  
   6    private $queryKey;
   7    private $branchID;
   8  
   9    public function shouldAllowPublic() {
  10      return true;
  11    }
  12  
  13    public function willProcessRequest(array $data) {
  14      $this->branchID = $data['branchID'];
  15      $this->queryKey = idx($data, 'queryKey');
  16    }
  17  
  18    public function processRequest() {
  19      $request = $this->getRequest();
  20      $viewer = $request->getUser();
  21  
  22      $branch = id(new ReleephBranchQuery())
  23        ->setViewer($viewer)
  24        ->withIDs(array($this->branchID))
  25        ->executeOne();
  26      if (!$branch) {
  27        return new Aphront404Response();
  28      }
  29      $this->setBranch($branch);
  30  
  31      $controller = id(new PhabricatorApplicationSearchController())
  32        ->setPreface($this->renderPreface())
  33        ->setQueryKey($this->queryKey)
  34        ->setSearchEngine($this->getSearchEngine())
  35        ->setNavigation($this->buildSideNavView());
  36  
  37      return $this->delegateToController($controller);
  38    }
  39  
  40    public function renderResultsList(
  41      array $requests,
  42      PhabricatorSavedQuery $query) {
  43  
  44      assert_instances_of($requests, 'ReleephRequest');
  45      $viewer = $this->getRequest()->getUser();
  46  
  47      // TODO: This is generally a bit sketchy, but we don't do this kind of
  48      // thing elsewhere at the moment. For the moment it shouldn't be hugely
  49      // costly, and we can batch things later. Generally, this commits fewer
  50      // sins than the old code did.
  51  
  52      $engine = id(new PhabricatorMarkupEngine())
  53        ->setViewer($viewer);
  54  
  55      $list = array();
  56      foreach ($requests as $pull) {
  57        $field_list = PhabricatorCustomField::getObjectFields(
  58          $pull,
  59          PhabricatorCustomField::ROLE_VIEW);
  60  
  61        $field_list
  62          ->setViewer($viewer)
  63          ->readFieldsFromStorage($pull);
  64  
  65        foreach ($field_list->getFields() as $field) {
  66          if ($field->shouldMarkup()) {
  67            $field->setMarkupEngine($engine);
  68          }
  69        }
  70  
  71        $list[] = id(new ReleephRequestView())
  72          ->setUser($viewer)
  73          ->setCustomFields($field_list)
  74          ->setPullRequest($pull)
  75          ->setIsListView(true);
  76      }
  77  
  78      // This is quite sketchy, but the list has not actually rendered yet, so
  79      // this still allows us to batch the markup rendering.
  80      $engine->process();
  81  
  82      return $list;
  83    }
  84  
  85    public function buildSideNavView($for_app = false) {
  86      $user = $this->getRequest()->getUser();
  87  
  88      $nav = new AphrontSideNavFilterView();
  89      $nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
  90  
  91      $this->getSearchEngine()->addNavigationItems($nav->getMenu());
  92  
  93      $nav->selectFilter(null);
  94  
  95      return $nav;
  96    }
  97  
  98    private function getSearchEngine() {
  99      $branch = $this->getBranch();
 100      return id(new ReleephRequestSearchEngine())
 101        ->setBranch($branch)
 102        ->setBaseURI($this->getApplicationURI('branch/'.$branch->getID().'/'))
 103        ->setViewer($this->getRequest()->getUser());
 104    }
 105  
 106    public function buildApplicationCrumbs() {
 107      $crumbs = parent::buildApplicationCrumbs();
 108  
 109      $branch = $this->getBranch();
 110      if ($branch) {
 111        $pull_uri = $this->getApplicationURI('branch/pull/'.$branch->getID().'/');
 112        $crumbs->addAction(
 113          id(new PHUIListItemView())
 114            ->setHref($pull_uri)
 115            ->setName(pht('New Pull Request'))
 116            ->setIcon('fa-plus-square')
 117            ->setDisabled(!$branch->isActive()));
 118      }
 119  
 120      return $crumbs;
 121    }
 122  
 123    private function renderPreface() {
 124      $viewer = $this->getRequest()->getUser();
 125  
 126      $branch = $this->getBranch();
 127      $id = $branch->getID();
 128  
 129      $header = id(new PHUIHeaderView())
 130        ->setHeader($branch->getDisplayName())
 131        ->setUser($viewer)
 132        ->setPolicyObject($branch);
 133  
 134      if ($branch->getIsActive()) {
 135        $header->setStatus('fa-check', 'bluegrey', pht('Active'));
 136      } else {
 137        $header->setStatus('fa-ban', 'dark', pht('Closed'));
 138      }
 139  
 140      $actions = id(new PhabricatorActionListView())
 141        ->setUser($viewer)
 142        ->setObject($branch)
 143        ->setObjectURI($this->getRequest()->getRequestURI());
 144  
 145      $can_edit = PhabricatorPolicyFilter::hasCapability(
 146        $viewer,
 147        $branch,
 148        PhabricatorPolicyCapability::CAN_EDIT);
 149  
 150      $edit_uri = $this->getApplicationURI("branch/edit/{$id}/");
 151      $close_uri = $this->getApplicationURI("branch/close/{$id}/");
 152      $reopen_uri = $this->getApplicationURI("branch/re-open/{$id}/");
 153      $history_uri = $this->getApplicationURI("branch/{$id}/history/");
 154  
 155      $actions->addAction(
 156        id(new PhabricatorActionView())
 157          ->setName(pht('Edit Branch'))
 158          ->setHref($edit_uri)
 159          ->setIcon('fa-pencil')
 160          ->setDisabled(!$can_edit)
 161          ->setWorkflow(!$can_edit));
 162  
 163      if ($branch->getIsActive()) {
 164        $actions->addAction(
 165          id(new PhabricatorActionView())
 166            ->setName(pht('Close Branch'))
 167            ->setHref($close_uri)
 168            ->setIcon('fa-times')
 169            ->setDisabled(!$can_edit)
 170            ->setWorkflow(true));
 171      } else {
 172        $actions->addAction(
 173          id(new PhabricatorActionView())
 174            ->setName(pht('Reopen Branch'))
 175            ->setHref($reopen_uri)
 176            ->setIcon('fa-plus')
 177            ->setUser($viewer)
 178            ->setDisabled(!$can_edit)
 179            ->setWorkflow(true));
 180      }
 181  
 182      $actions->addAction(
 183        id(new PhabricatorActionView())
 184          ->setName(pht('View History'))
 185          ->setHref($history_uri)
 186          ->setIcon('fa-list'));
 187  
 188      $properties = id(new PHUIPropertyListView())
 189        ->setUser($viewer)
 190        ->setObject($branch)
 191        ->setActionList($actions);
 192  
 193      $properties->addProperty(
 194        pht('Branch'),
 195        $branch->getName());
 196  
 197      return id(new PHUIObjectBoxView())
 198        ->setHeader($header)
 199        ->addPropertyList($properties);
 200    }
 201  
 202  }


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