Use a tokenizer, not a gigantic poorly-ordered "<select />", to choose repositories in Owners

Summary: Depends on D19190. Fixes T12590. Ref T13099. Replaces the barely-usable, gigantic, poorly ordered "<select />" control with a tokenizer. Attempts to fix various minor issues.

Test Plan:
  - Edited paths: include/exclude paths, from different repositories, different actual paths.
  - Used "Add New Path" to add rows, got repository selector prepopulated with last value.
  - Used "remove".
  - Used validation typeahead, got reasonable behaviors?

The error behavior if you delete the repository for a path is a little sketchy still, but roughly okay.

Maniphest Tasks: T13099, T12590

Differential Revision: https://secure.phabricator.com/D19191
This commit is contained in:
epriestley
2018-03-07 17:29:06 -08:00
parent b41a0e6ddd
commit a4cc1373d3
8 changed files with 310 additions and 198 deletions

View File

@@ -45,19 +45,6 @@ final class DiffusionPathValidateController extends DiffusionController {
'valid' => (bool)$valid,
);
if (!$valid) {
$branch = $drequest->getBranch();
if ($branch) {
$message = pht('Not found in %s', $branch);
} else {
$message = pht('Not found at %s', 'HEAD');
}
} else {
$message = pht('OK');
}
$output['message'] = $message;
return id(new AphrontAjaxResponse())->setContent($output);
}
}

View File

@@ -27,7 +27,7 @@ final class PhabricatorOwnersPathsController
$path_refs = array();
foreach ($paths as $key => $path) {
if (!isset($repos[$key])) {
if (!isset($repos[$key]) || !strlen($repos[$key])) {
throw new Exception(
pht(
'No repository PHID for path "%s"!',
@@ -70,17 +70,39 @@ final class PhabricatorOwnersPathsController
$path_refs = mpull($paths, 'getRef');
}
$repos = id(new PhabricatorRepositoryQuery())
->setViewer($viewer)
->execute();
$template = new AphrontTokenizerTemplateView();
$repo_map = array();
foreach ($repos as $key => $repo) {
$monogram = $repo->getMonogram();
$name = $repo->getName();
$repo_map[$repo->getPHID()] = "{$monogram} {$name}";
$datasource = id(new DiffusionRepositoryDatasource())
->setViewer($viewer);
$tokenizer_spec = array(
'markup' => $template->render(),
'config' => array(
'src' => $datasource->getDatasourceURI(),
'browseURI' => $datasource->getBrowseURI(),
'placeholder' => $datasource->getPlaceholderText(),
'limit' => 1,
),
);
foreach ($path_refs as $key => $path_ref) {
$path_refs[$key]['repositoryValue'] = $datasource->getWireTokens(
array(
$path_ref['repositoryPHID'],
));
}
asort($repos);
$icon_test = id(new PHUIIconView())
->setIcon('fa-spinner grey')
->setTooltip(pht('Validating...'));
$icon_okay = id(new PHUIIconView())
->setIcon('fa-check-circle green')
->setTooltip(pht('Path Exists in Repository'));
$icon_fail = id(new PHUIIconView())
->setIcon('fa-question-circle-o red')
->setTooltip(pht('Path Not Found On Default Branch'));
$template = new AphrontTypeaheadTemplateView();
$template = $template->render();
@@ -88,15 +110,23 @@ final class PhabricatorOwnersPathsController
Javelin::initBehavior(
'owners-path-editor',
array(
'root' => 'path-editor',
'table' => 'paths',
'add_button' => 'addpath',
'repositories' => $repo_map,
'input_template' => $template,
'pathRefs' => $path_refs,
'completeURI' => '/diffusion/services/path/complete/',
'validateURI' => '/diffusion/services/path/validate/',
'root' => 'path-editor',
'table' => 'paths',
'add_button' => 'addpath',
'input_template' => $template,
'pathRefs' => $path_refs,
'completeURI' => '/diffusion/services/path/complete/',
'validateURI' => '/diffusion/services/path/validate/',
'repositoryTokenizerSpec' => $tokenizer_spec,
'icons' => array(
'test' => hsprintf('%s', $icon_test),
'okay' => hsprintf('%s', $icon_okay),
'fail' => hsprintf('%s', $icon_fail),
),
'modeOptions' => array(
0 => pht('Include'),
1 => pht('Exclude'),
),
));
require_celerity_resource('owners-path-editor-css');