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