Path: blob/master/src/applications/differential/view/DifferentialChangesetListView.php
12256 views
<?php12final class DifferentialChangesetListView extends AphrontView {34private $changesets = array();5private $visibleChangesets = array();6private $references = array();7private $inlineURI;8private $renderURI = '/differential/changeset/';9private $background;10private $header;11private $isStandalone;1213private $standaloneURI;14private $leftRawFileURI;15private $rightRawFileURI;16private $inlineListURI;1718private $symbolIndexes = array();19private $repository;20private $branch;21private $diff;22private $vsMap = array();2324private $title;25private $parser;26private $formationView;2728public function setParser(DifferentialChangesetParser $parser) {29$this->parser = $parser;30return $this;31}3233public function getParser() {34return $this->parser;35}3637public function setTitle($title) {38$this->title = $title;39return $this;40}41private function getTitle() {42return $this->title;43}4445public function setBranch($branch) {46$this->branch = $branch;47return $this;48}49private function getBranch() {50return $this->branch;51}5253public function setChangesets($changesets) {54$this->changesets = $changesets;55return $this;56}5758public function setVisibleChangesets($visible_changesets) {59$this->visibleChangesets = $visible_changesets;60return $this;61}6263public function setInlineCommentControllerURI($uri) {64$this->inlineURI = $uri;65return $this;66}6768public function setInlineListURI($uri) {69$this->inlineListURI = $uri;70return $this;71}7273public function getInlineListURI() {74return $this->inlineListURI;75}7677public function setRepository(PhabricatorRepository $repository) {78$this->repository = $repository;79return $this;80}8182public function getRepository() {83return $this->repository;84}8586public function setDiff(DifferentialDiff $diff) {87$this->diff = $diff;88return $this;89}9091public function getDiff() {92return $this->diff;93}9495public function setRenderingReferences(array $references) {96$this->references = $references;97return $this;98}99100public function setSymbolIndexes(array $indexes) {101$this->symbolIndexes = $indexes;102return $this;103}104105public function setRenderURI($render_uri) {106$this->renderURI = $render_uri;107return $this;108}109110public function setVsMap(array $vs_map) {111$this->vsMap = $vs_map;112return $this;113}114115public function getVsMap() {116return $this->vsMap;117}118119public function setStandaloneURI($uri) {120$this->standaloneURI = $uri;121return $this;122}123124public function setRawFileURIs($l, $r) {125$this->leftRawFileURI = $l;126$this->rightRawFileURI = $r;127return $this;128}129130public function setIsStandalone($is_standalone) {131$this->isStandalone = $is_standalone;132return $this;133}134135public function getIsStandalone() {136return $this->isStandalone;137}138139public function setBackground($background) {140$this->background = $background;141return $this;142}143144public function setHeader($header) {145$this->header = $header;146return $this;147}148149public function setFormationView(PHUIFormationView $formation_view) {150$this->formationView = $formation_view;151return $this;152}153154public function getFormationView() {155return $this->formationView;156}157158public function render() {159$viewer = $this->getViewer();160161$this->requireResource('differential-changeset-view-css');162163$changesets = $this->changesets;164165$repository = $this->getRepository();166$diff = $this->getDiff();167168$output = array();169$ids = array();170foreach ($changesets as $key => $changeset) {171172$file = $changeset->getFilename();173$ref = $this->references[$key];174175$detail = id(new DifferentialChangesetDetailView())176->setViewer($viewer);177178if ($repository) {179$detail->setRepository($repository);180}181182if ($diff) {183$detail->setDiff($diff);184}185186$uniq_id = 'diff-'.$changeset->getAnchorName();187$detail->setID($uniq_id);188189$view_options = $this->renderViewOptionsDropdown(190$detail,191$ref,192$changeset);193194$detail->setChangeset($changeset);195$detail->addButton($view_options);196$detail->setSymbolIndex(idx($this->symbolIndexes, $key));197$detail->setVsChangesetID(idx($this->vsMap, $changeset->getID()));198$detail->setEditable(true);199$detail->setRenderingRef($ref);200$detail->setBranch($this->getBranch());201202$detail->setRenderURI($this->renderURI);203204$parser = $this->getParser();205if ($parser) {206$response = $parser->newChangesetResponse();207$detail->setChangesetResponse($response);208} else {209$detail->setAutoload(isset($this->visibleChangesets[$key]));210if (isset($this->visibleChangesets[$key])) {211$load = pht('Loading...');212} else {213$load = javelin_tag(214'a',215array(216'class' => 'button button-grey',217'href' => '#'.$uniq_id,218'sigil' => 'differential-load',219'meta' => array(220'id' => $detail->getID(),221'kill' => true,222),223'mustcapture' => true,224),225pht('Load File'));226}227$detail->appendChild(228phutil_tag(229'div',230array(231'id' => $uniq_id,232),233phutil_tag(234'div',235array('class' => 'differential-loading'),236$load)));237}238239$output[] = $detail->render();240$ids[] = $detail->getID();241}242243$this->requireResource('aphront-tooltip-css');244245$formation_id = null;246$formation_view = $this->getFormationView();247if ($formation_view) {248$formation_id = $formation_view->getID();249}250251$this->initBehavior(252'differential-populate',253array(254'changesetViewIDs' => $ids,255'formationViewID' => $formation_id,256'inlineURI' => $this->inlineURI,257'inlineListURI' => $this->inlineListURI,258'isStandalone' => $this->getIsStandalone(),259'pht' => array(260'Open in Editor' => pht('Open in Editor'),261'Show All Context' => pht('Show All Context'),262'All Context Shown' => pht('All Context Shown'),263'Expand File' => pht('Expand File'),264'Hide Changeset' => pht('Hide Changeset'),265'Show Path in Repository' => pht('Show Path in Repository'),266'Show Directory in Repository' => pht('Show Directory in Repository'),267'View Standalone' => pht('View Standalone'),268'Show Raw File (Left)' => pht('Show Raw File (Left)'),269'Show Raw File (Right)' => pht('Show Raw File (Right)'),270'Configure Editor' => pht('Configure Editor'),271'Load Changes' => pht('Load Changes'),272'View Side-by-Side Diff' => pht('View Side-by-Side Diff'),273'View Unified Diff' => pht('View Unified Diff'),274'Change Text Encoding...' => pht('Change Text Encoding...'),275'Highlight As...' => pht('Highlight As...'),276'View As Document Type...' => pht('View As Document Type...'),277278'Loading...' => pht('Loading...'),279280'Editing Comment' => pht('Editing Comment'),281282'Jump to next change.' => pht('Jump to next change.'),283'Jump to previous change.' => pht('Jump to previous change.'),284'Jump to next file.' => pht('Jump to next file.'),285'Jump to previous file.' => pht('Jump to previous file.'),286'Jump to next inline comment.' => pht('Jump to next inline comment.'),287'Jump to previous inline comment.' =>288pht('Jump to previous inline comment.'),289'Jump to the table of contents.' =>290pht('Jump to the table of contents.'),291292'Edit selected inline comment.' =>293pht('Edit selected inline comment.'),294'You must select a comment to edit.' =>295pht('You must select a comment to edit.'),296297'Reply to selected inline comment or change.' =>298pht('Reply to selected inline comment or change.'),299'You must select a comment or change to reply to.' =>300pht('You must select a comment or change to reply to.'),301'Reply and quote selected inline comment.' =>302pht('Reply and quote selected inline comment.'),303304'Mark or unmark selected inline comment as done.' =>305pht('Mark or unmark selected inline comment as done.'),306'You must select a comment to mark done.' =>307pht('You must select a comment to mark done.'),308309'Collapse or expand inline comment.' =>310pht('Collapse or expand inline comment.'),311'You must select a comment to hide.' =>312pht('You must select a comment to hide.'),313314'Jump to next inline comment, including collapsed comments.' =>315pht('Jump to next inline comment, including collapsed comments.'),316'Jump to previous inline comment, including collapsed comments.' =>317pht('Jump to previous inline comment, including collapsed comments.'),318319'Hide or show the current changeset.' =>320pht('Hide or show the current changeset.'),321'You must select a file to hide or show.' =>322pht('You must select a file to hide or show.'),323324'Unsaved' => pht('Unsaved'),325'Unsubmitted' => pht('Unsubmitted'),326'Comments' => pht('Comments'),327328'Hide "Done" Inlines' => pht('Hide "Done" Inlines'),329'Hide Collapsed Inlines' => pht('Hide Collapsed Inlines'),330'Hide Older Inlines' => pht('Hide Older Inlines'),331'Hide All Inlines' => pht('Hide All Inlines'),332'Show All Inlines' => pht('Show All Inlines'),333334'List Inline Comments' => pht('List Inline Comments'),335'Display Options' => pht('Display Options'),336337'Hide or show all inline comments.' =>338pht('Hide or show all inline comments.'),339340'Finish editing inline comments before changing display modes.' =>341pht('Finish editing inline comments before changing display modes.'),342343'Open file in external editor.' =>344pht('Open file in external editor.'),345346'You must select a file to edit.' =>347pht('You must select a file to edit.'),348349'You must select a file to open.' =>350pht('You must select a file to open.'),351352'No external editor is configured.' =>353pht('No external editor is configured.'),354355'Hide or show the paths panel.' =>356pht('Hide or show the paths panel.'),357358'Show path in repository.' =>359pht('Show path in repository.'),360'Show directory in repository.' =>361pht('Show directory in repository.'),362363'Jump to the comment area.' =>364pht('Jump to the comment area.'),365366'Show Changeset' => pht('Show Changeset'),367368'You must select source text to create a new inline comment.' =>369pht('You must select source text to create a new inline comment.'),370371'New Inline Comment' => pht('New Inline Comment'),372373'Add new inline comment on selected source text.' =>374pht('Add new inline comment on selected source text.'),375376'Suggest Edit' => pht('Suggest Edit'),377'Discard Edit' => pht('Discard Edit'),378),379));380381if ($this->header) {382$header = $this->header;383} else {384$header = id(new PHUIHeaderView())385->setHeader($this->getTitle());386}387388$content = phutil_tag(389'div',390array(391'class' => 'differential-review-stage',392'id' => 'differential-review-stage',393),394$output);395396$object_box = id(new PHUIObjectBoxView())397->setHeader($header)398->setBackground($this->background)399->setCollapsed(true)400->appendChild($content);401402return $object_box;403}404405private function renderViewOptionsDropdown(406DifferentialChangesetDetailView $detail,407$ref,408DifferentialChangeset $changeset) {409$viewer = $this->getViewer();410411$meta = array();412413$qparams = array(414'ref' => $ref,415);416417if ($this->standaloneURI) {418$uri = new PhutilURI($this->standaloneURI);419$uri = $this->appendDefaultQueryParams($uri, $qparams);420$meta['standaloneURI'] = (string)$uri;421}422423$change = $changeset->getChangeType();424425if ($this->leftRawFileURI) {426if ($change != DifferentialChangeType::TYPE_ADD) {427$uri = new PhutilURI($this->leftRawFileURI);428$uri = $this->appendDefaultQueryParams($uri, $qparams);429$meta['leftURI'] = (string)$uri;430}431}432433if ($this->rightRawFileURI) {434if ($change != DifferentialChangeType::TYPE_DELETE &&435$change != DifferentialChangeType::TYPE_MULTICOPY) {436$uri = new PhutilURI($this->rightRawFileURI);437$uri = $this->appendDefaultQueryParams($uri, $qparams);438$meta['rightURI'] = (string)$uri;439}440}441442$meta['containerID'] = $detail->getID();443444return id(new PHUIButtonView())445->setTag('a')446->setText(pht('View Options'))447->setIcon('fa-bars')448->setColor(PHUIButtonView::GREY)449->setHref(idx($meta, 'detailURI', '#'))450->setMetadata($meta)451->addSigil('differential-view-options');452}453454private function appendDefaultQueryParams(PhutilURI $uri, array $params) {455// Add these default query parameters to the query string if they do not456// already exist.457458$have = array();459foreach ($uri->getQueryParamsAsPairList() as $pair) {460list($key, $value) = $pair;461$have[$key] = true;462}463464foreach ($params as $key => $value) {465if (!isset($have[$key])) {466$uri->appendQueryParam($key, $value);467}468}469470return $uri;471}472473}474475476