3 final class PhabricatorOwnersPathsController
4 extends PhabricatorOwnersController
{
6 public function handleRequest(AphrontRequest
$request) {
7 $viewer = $request->getUser();
9 $package = id(new PhabricatorOwnersPackageQuery())
11 ->withIDs(array($request->getURIData('id')))
12 ->requireCapabilities(
14 PhabricatorPolicyCapability
::CAN_VIEW
,
15 PhabricatorPolicyCapability
::CAN_EDIT
,
20 return new Aphront404Response();
23 if ($request->isFormPost()) {
24 $paths = $request->getArr('path');
25 $repos = $request->getArr('repo');
26 $excludes = $request->getArr('exclude');
29 foreach ($paths as $key => $path) {
30 if (!isset($repos[$key]) ||
!strlen($repos[$key])) {
33 'No repository PHID for path "%s"!',
37 if (!isset($excludes[$key])) {
40 'No exclusion value for path "%s"!',
45 'repositoryPHID' => $repos[$key],
47 'excluded' => (int)$excludes[$key],
51 $type_paths = PhabricatorOwnersPackagePathsTransaction
::TRANSACTIONTYPE
;
54 $xactions[] = id(new PhabricatorOwnersPackageTransaction())
55 ->setTransactionType($type_paths)
56 ->setNewValue($path_refs);
58 $editor = id(new PhabricatorOwnersPackageTransactionEditor())
60 ->setContentSourceFromRequest($request)
61 ->setContinueOnNoEffect(true)
62 ->setContinueOnMissingFields(true);
64 $editor->applyTransactions($package, $xactions);
66 return id(new AphrontRedirectResponse())
67 ->setURI($package->getURI());
69 $paths = $package->getPaths();
70 $path_refs = mpull($paths, 'getRef');
73 $template = new AphrontTokenizerTemplateView();
75 $datasource = id(new DiffusionRepositoryDatasource())
78 $tokenizer_spec = array(
79 'markup' => $template->render(),
81 'src' => $datasource->getDatasourceURI(),
82 'browseURI' => $datasource->getBrowseURI(),
83 'placeholder' => $datasource->getPlaceholderText(),
88 foreach ($path_refs as $key => $path_ref) {
89 $path_refs[$key]['repositoryValue'] = $datasource->getWireTokens(
91 $path_ref['repositoryPHID'],
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',
113 'root' => 'path-editor',
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,
122 'test' => hsprintf('%s', $icon_test),
123 'okay' => hsprintf('%s', $icon_okay),
124 'fail' => hsprintf('%s', $icon_fail),
126 'modeOptions' => array(
132 require_celerity_resource('owners-path-editor-css');
134 $cancel_uri = $package->getURI();
136 $form = id(new AphrontFormView())
139 id(new PHUIFormInsetView())
140 ->setTitle(pht('Paths'))
141 ->addDivAttributes(array('id' => 'path-editor'))
142 ->setRightButton(javelin_tag(
146 'class' => 'button button-green',
147 'sigil' => 'addpath',
148 'mustcapture' => true,
150 pht('Add New Path')))
153 'Specify the files and directories which comprise '.
155 ->setContent(javelin_tag(
158 'class' => 'owners-path-editor-table',
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
)
172 $crumbs = $this->buildApplicationCrumbs();
173 $crumbs->addTextCrumb(
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())
187 $title = array($package->getName(), pht('Edit Paths'));
189 return $this->newPage()
192 ->appendChild($view);