@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 196 lines 5.8 kB view raw
1<?php 2 3final class PhabricatorOwnersPathsController 4 extends PhabricatorOwnersController { 5 6 public function handleRequest(AphrontRequest $request) { 7 $viewer = $request->getUser(); 8 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, 16 )) 17 ->needPaths(true) 18 ->executeOne(); 19 if (!$package) { 20 return new Aphront404Response(); 21 } 22 23 if ($request->isFormPost()) { 24 $paths = $request->getArr('path'); 25 $repos = $request->getArr('repo'); 26 $excludes = $request->getArr('exclude'); 27 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)); 35 } 36 37 if (!isset($excludes[$key])) { 38 throw new Exception( 39 pht( 40 'No exclusion value for path "%s"!', 41 $key)); 42 } 43 44 $path_refs[] = array( 45 'repositoryPHID' => $repos[$key], 46 'path' => $path, 47 'excluded' => (int)$excludes[$key], 48 ); 49 } 50 51 $type_paths = PhabricatorOwnersPackagePathsTransaction::TRANSACTIONTYPE; 52 53 $xactions = array(); 54 $xactions[] = id(new PhabricatorOwnersPackageTransaction()) 55 ->setTransactionType($type_paths) 56 ->setNewValue($path_refs); 57 58 $editor = id(new PhabricatorOwnersPackageTransactionEditor()) 59 ->setActor($viewer) 60 ->setContentSourceFromRequest($request) 61 ->setContinueOnNoEffect(true) 62 ->setContinueOnMissingFields(true); 63 64 $editor->applyTransactions($package, $xactions); 65 66 return id(new AphrontRedirectResponse()) 67 ->setURI($package->getURI()); 68 } else { 69 $paths = $package->getPaths(); 70 $path_refs = mpull($paths, 'getRef'); 71 } 72 73 $template = new AphrontTokenizerTemplateView(); 74 75 $datasource = id(new DiffusionRepositoryDatasource()) 76 ->setViewer($viewer); 77 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, 85 ), 86 ); 87 88 foreach ($path_refs as $key => $path_ref) { 89 $path_refs[$key]['repositoryValue'] = $datasource->getWireTokens( 90 array( 91 $path_ref['repositoryPHID'], 92 )); 93 } 94 95 $icon_test = id(new PHUIIconView()) 96 ->setIcon('fa-spinner grey') 97 ->setTooltip(pht('Validating...')); 98 99 $icon_okay = id(new PHUIIconView()) 100 ->setIcon('fa-check-circle green') 101 ->setTooltip(pht('Path Exists in Repository')); 102 103 $icon_fail = id(new PHUIIconView()) 104 ->setIcon('fa-question-circle-o red') 105 ->setTooltip(pht('Path Not Found On Default Branch')); 106 107 $template = new AphrontTypeaheadTemplateView(); 108 $template = $template->render(); 109 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), 125 ), 126 'modeOptions' => array( 127 0 => pht('Include'), 128 1 => pht('Exclude'), 129 ), 130 )); 131 132 require_celerity_resource('owners-path-editor-css'); 133 134 $cancel_uri = $package->getURI(); 135 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, 149 ), 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', 160 ), 161 ''))) 162 ->appendChild( 163 id(new AphrontFormSubmitControl()) 164 ->addCancelButton($cancel_uri) 165 ->setValue(pht('Save Paths'))); 166 167 $box = id(new PHUIObjectBoxView()) 168 ->setHeaderText(pht('Paths')) 169 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 170 ->setForm($form); 171 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); 178 179 $header = id(new PHUIHeaderView()) 180 ->setHeader(pht('Edit Paths: %s', $package->getName())) 181 ->setHeaderIcon('fa-pencil'); 182 183 $view = id(new PHUITwoColumnView()) 184 ->setHeader($header) 185 ->setFooter($box); 186 187 $title = array($package->getName(), pht('Edit Paths')); 188 189 return $this->newPage() 190 ->setTitle($title) 191 ->setCrumbs($crumbs) 192 ->appendChild($view); 193 194 } 195 196}