[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/diffusion/controller/ -> DiffusionHistoryController.php (source)

   1  <?php
   2  
   3  final class DiffusionHistoryController extends DiffusionController {
   4  
   5    public function shouldAllowPublic() {
   6      return true;
   7    }
   8  
   9    public function processRequest() {
  10      $drequest = $this->diffusionRequest;
  11      $request = $this->getRequest();
  12      $viewer = $request->getUser();
  13      $repository = $drequest->getRepository();
  14  
  15      $page_size = $request->getInt('pagesize', 100);
  16      $offset = $request->getInt('offset', 0);
  17  
  18      $params = array(
  19        'commit' => $drequest->getCommit(),
  20        'path' => $drequest->getPath(),
  21        'offset' => $offset,
  22        'limit' => $page_size + 1,
  23      );
  24  
  25      if (!$request->getBool('copies')) {
  26        $params['needDirectChanges'] = true;
  27        $params['needChildChanges'] = true;
  28      }
  29  
  30      $history_results = $this->callConduitWithDiffusionRequest(
  31        'diffusion.historyquery',
  32        $params);
  33      $history = DiffusionPathChange::newFromConduit(
  34        $history_results['pathChanges']);
  35  
  36      $pager = new AphrontPagerView();
  37      $pager->setPageSize($page_size);
  38      $pager->setOffset($offset);
  39      $history = $pager->sliceResults($history);
  40  
  41      $pager->setURI($request->getRequestURI(), 'offset');
  42  
  43      $show_graph = !strlen($drequest->getPath());
  44      $content = array();
  45  
  46      $history_table = new DiffusionHistoryTableView();
  47      $history_table->setUser($request->getUser());
  48      $history_table->setDiffusionRequest($drequest);
  49      $history_table->setHistory($history);
  50      $history_table->loadRevisions();
  51  
  52      $phids = $history_table->getRequiredHandlePHIDs();
  53      $handles = $this->loadViewerHandles($phids);
  54      $history_table->setHandles($handles);
  55  
  56      if ($show_graph) {
  57        $history_table->setParents($history_results['parents']);
  58        $history_table->setIsHead($offset == 0);
  59      }
  60  
  61      $history_panel = new AphrontPanelView();
  62      $history_panel->appendChild($history_table);
  63      $history_panel->appendChild($pager);
  64      $history_panel->setNoBackground();
  65  
  66      $content[] = $history_panel;
  67  
  68      $header = id(new PHUIHeaderView())
  69        ->setUser($viewer)
  70        ->setPolicyObject($repository)
  71        ->setHeader($this->renderPathLinks($drequest, $mode = 'history'));
  72  
  73      $actions = $this->buildActionView($drequest);
  74      $properties = $this->buildPropertyView($drequest, $actions);
  75  
  76      $object_box = id(new PHUIObjectBoxView())
  77        ->setHeader($header)
  78        ->addPropertyList($properties);
  79  
  80      $crumbs = $this->buildCrumbs(
  81        array(
  82          'branch' => true,
  83          'path'   => true,
  84          'view'   => 'history',
  85        ));
  86  
  87      return $this->buildApplicationPage(
  88        array(
  89          $crumbs,
  90          $object_box,
  91          $content,
  92        ),
  93        array(
  94          'title' => array(
  95            pht('History'),
  96            pht('%s Repository', $drequest->getRepository()->getCallsign()),
  97          ),
  98        ));
  99    }
 100  
 101    private function buildActionView(DiffusionRequest $drequest) {
 102      $viewer = $this->getRequest()->getUser();
 103  
 104      $view = id(new PhabricatorActionListView())
 105        ->setUser($viewer);
 106  
 107      $browse_uri = $drequest->generateURI(
 108        array(
 109          'action' => 'browse',
 110        ));
 111  
 112      $view->addAction(
 113        id(new PhabricatorActionView())
 114          ->setName(pht('Browse Content'))
 115          ->setHref($browse_uri)
 116          ->setIcon('fa-files-o'));
 117  
 118      // TODO: Sometimes we do have a change view, we need to look at the most
 119      // recent history entry to figure it out.
 120  
 121      $request = $this->getRequest();
 122      if ($request->getBool('copies')) {
 123        $branch_name = pht('Hide Copies/Branches');
 124        $branch_uri = $request->getRequestURI()
 125          ->alter('offset', null)
 126          ->alter('copies', null);
 127      } else {
 128        $branch_name = pht('Show Copies/Branches');
 129        $branch_uri = $request->getRequestURI()
 130          ->alter('offset', null)
 131          ->alter('copies', true);
 132      }
 133  
 134      $view->addAction(
 135        id(new PhabricatorActionView())
 136          ->setName($branch_name)
 137          ->setIcon('fa-code-fork')
 138          ->setHref($branch_uri));
 139  
 140      return $view;
 141    }
 142  
 143    protected function buildPropertyView(
 144      DiffusionRequest $drequest,
 145      PhabricatorActionListView $actions) {
 146  
 147      $viewer = $this->getRequest()->getUser();
 148  
 149      $view = id(new PHUIPropertyListView())
 150        ->setUser($viewer)
 151        ->setActionList($actions);
 152  
 153      $stable_commit = $drequest->getStableCommit();
 154      $callsign = $drequest->getRepository()->getCallsign();
 155  
 156      $view->addProperty(
 157        pht('Commit'),
 158        phutil_tag(
 159          'a',
 160          array(
 161            'href' => $drequest->generateURI(
 162              array(
 163                'action' => 'commit',
 164                'commit' => $stable_commit,
 165              )),
 166          ),
 167          $drequest->getRepository()->formatCommitName($stable_commit)));
 168  
 169      return $view;
 170    }
 171  
 172  
 173  
 174  }


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