Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / owners / controller / PhabricatorOwnersPathsController.php
blobd4d97290f9b8a3575be22f1798b496697c5f1ecc
1 <?php
3 final class PhabricatorOwnersPathsController
4 extends PhabricatorOwnersController {
6 public function handleRequest(AphrontRequest $request) {
7 $viewer = $request->getUser();
9 $package = id(new PhabricatorOwnersPackageQuery())
10 ->setViewer($viewer)
11 ->withIDs(array($request->getURIData('id')))
12 ->requireCapabilities(
13 array(
14 PhabricatorPolicyCapability::CAN_VIEW,
15 PhabricatorPolicyCapability::CAN_EDIT,
17 ->needPaths(true)
18 ->executeOne();
19 if (!$package) {
20 return new Aphront404Response();
23 if ($request->isFormPost()) {
24 $paths = $request->getArr('path');
25 $repos = $request->getArr('repo');
26 $excludes = $request->getArr('exclude');
28 $path_refs = array();
29 foreach ($paths as $key => $path) {
30 if (!isset($repos[$key]) || !strlen($repos[$key])) {
31 throw new Exception(
32 pht(
33 'No repository PHID for path "%s"!',
34 $key));
37 if (!isset($excludes[$key])) {
38 throw new Exception(
39 pht(
40 'No exclusion value for path "%s"!',
41 $key));
44 $path_refs[] = array(
45 'repositoryPHID' => $repos[$key],
46 'path' => $path,
47 'excluded' => (int)$excludes[$key],
51 $type_paths = PhabricatorOwnersPackagePathsTransaction::TRANSACTIONTYPE;
53 $xactions = array();
54 $xactions[] = id(new PhabricatorOwnersPackageTransaction())
55 ->setTransactionType($type_paths)
56 ->setNewValue($path_refs);
58 $editor = id(new PhabricatorOwnersPackageTransactionEditor())
59 ->setActor($viewer)
60 ->setContentSourceFromRequest($request)
61 ->setContinueOnNoEffect(true)
62 ->setContinueOnMissingFields(true);
64 $editor->applyTransactions($package, $xactions);
66 return id(new AphrontRedirectResponse())
67 ->setURI($package->getURI());
68 } else {
69 $paths = $package->getPaths();
70 $path_refs = mpull($paths, 'getRef');
73 $template = new AphrontTokenizerTemplateView();
75 $datasource = id(new DiffusionRepositoryDatasource())
76 ->setViewer($viewer);
78 $tokenizer_spec = array(
79 'markup' => $template->render(),
80 'config' => array(
81 'src' => $datasource->getDatasourceURI(),
82 'browseURI' => $datasource->getBrowseURI(),
83 'placeholder' => $datasource->getPlaceholderText(),
84 'limit' => 1,
88 foreach ($path_refs as $key => $path_ref) {
89 $path_refs[$key]['repositoryValue'] = $datasource->getWireTokens(
90 array(
91 $path_ref['repositoryPHID'],
92 ));
95 $icon_test = id(new PHUIIconView())
96 ->setIcon('fa-spinner grey')
97 ->setTooltip(pht('Validating...'));
99 $icon_okay = id(new PHUIIconView())
100 ->setIcon('fa-check-circle green')
101 ->setTooltip(pht('Path Exists in Repository'));
103 $icon_fail = id(new PHUIIconView())
104 ->setIcon('fa-question-circle-o red')
105 ->setTooltip(pht('Path Not Found On Default Branch'));
107 $template = new AphrontTypeaheadTemplateView();
108 $template = $template->render();
110 Javelin::initBehavior(
111 'owners-path-editor',
112 array(
113 'root' => 'path-editor',
114 'table' => 'paths',
115 'add_button' => 'addpath',
116 'input_template' => $template,
117 'pathRefs' => $path_refs,
118 'completeURI' => '/diffusion/services/path/complete/',
119 'validateURI' => '/diffusion/services/path/validate/',
120 'repositoryTokenizerSpec' => $tokenizer_spec,
121 'icons' => array(
122 'test' => hsprintf('%s', $icon_test),
123 'okay' => hsprintf('%s', $icon_okay),
124 'fail' => hsprintf('%s', $icon_fail),
126 'modeOptions' => array(
127 0 => pht('Include'),
128 1 => pht('Exclude'),
132 require_celerity_resource('owners-path-editor-css');
134 $cancel_uri = $package->getURI();
136 $form = id(new AphrontFormView())
137 ->setUser($viewer)
138 ->appendChild(
139 id(new PHUIFormInsetView())
140 ->setTitle(pht('Paths'))
141 ->addDivAttributes(array('id' => 'path-editor'))
142 ->setRightButton(javelin_tag(
143 'a',
144 array(
145 'href' => '#',
146 'class' => 'button button-green',
147 'sigil' => 'addpath',
148 'mustcapture' => true,
150 pht('Add New Path')))
151 ->setDescription(
152 pht(
153 'Specify the files and directories which comprise '.
154 'this package.'))
155 ->setContent(javelin_tag(
156 'table',
157 array(
158 'class' => 'owners-path-editor-table',
159 'sigil' => 'paths',
161 '')))
162 ->appendChild(
163 id(new AphrontFormSubmitControl())
164 ->addCancelButton($cancel_uri)
165 ->setValue(pht('Save Paths')));
167 $box = id(new PHUIObjectBoxView())
168 ->setHeaderText(pht('Paths'))
169 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
170 ->setForm($form);
172 $crumbs = $this->buildApplicationCrumbs();
173 $crumbs->addTextCrumb(
174 $package->getName(),
175 $this->getApplicationURI('package/'.$package->getID().'/'));
176 $crumbs->addTextCrumb(pht('Edit Paths'));
177 $crumbs->setBorder(true);
179 $header = id(new PHUIHeaderView())
180 ->setHeader(pht('Edit Paths: %s', $package->getName()))
181 ->setHeaderIcon('fa-pencil');
183 $view = id(new PHUITwoColumnView())
184 ->setHeader($header)
185 ->setFooter($box);
187 $title = array($package->getName(), pht('Edit Paths'));
189 return $this->newPage()
190 ->setTitle($title)
191 ->setCrumbs($crumbs)
192 ->appendChild($view);