1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

Give users a modal VCS choice when creating a new repository

Summary:
Ref T10748. Allow the new EditEngine workflow to create repositories by giving the user a modal repository type choice upfront.

(The rest of this flow is still confusing/weird, though.)

Test Plan:
  - Created a new repository.

{F1249626}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10748

Differential Revision: https://secure.phabricator.com/D15813
This commit is contained in:
epriestley 2016-04-27 16:01:29 -07:00
parent 311de580d6
commit 0459e95242
5 changed files with 139 additions and 24 deletions

View file

@ -4,9 +4,66 @@ final class DiffusionRepositoryEditproController
extends DiffusionRepositoryEditController {
public function handleRequest(AphrontRequest $request) {
return id(new DiffusionRepositoryEditEngine())
->setController($this)
->buildResponse();
$engine = id(new DiffusionRepositoryEditEngine())
->setController($this);
$id = $request->getURIData('id');
if (!$id) {
$this->requireApplicationCapability(
DiffusionCreateRepositoriesCapability::CAPABILITY);
$vcs = $request->getStr('vcs');
$vcs_types = PhabricatorRepositoryType::getRepositoryTypeMap();
if (empty($vcs_types[$vcs])) {
return $this->buildVCSTypeResponse();
}
$engine
->addContextParameter('vcs', $vcs)
->setVersionControlSystem($vcs);
}
return $engine->buildResponse();
}
private function buildVCSTypeResponse() {
$vcs_types = PhabricatorRepositoryType::getRepositoryTypeMap();
$request = $this->getRequest();
$viewer = $this->getViewer();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Create Repository'));
$crumbs->setBorder(true);
$title = pht('Choose Repository Type');
$header = id(new PHUIHeaderView())
->setHeader(pht('Create Repository'))
->setHeaderIcon('fa-plus-square');
$layout = id(new AphrontMultiColumnView())
->setFluidLayout(true);
$create_uri = $request->getRequestURI();
foreach ($vcs_types as $vcs_key => $vcs_type) {
$action = id(new PHUIActionPanelView())
->setIcon(idx($vcs_type, 'icon'))
->setHeader(idx($vcs_type, 'create.header'))
->setHref($create_uri->alter('vcs', $vcs_key))
->setSubheader(idx($vcs_type, 'create.subheader'));
$layout->addColumn($action);
}
$view = id(new PHUITwoColumnView())
->setHeader($header)
->setFooter($layout);
return $this->newPage()
->setTitle($title)
->setCrumbs($crumbs)
->appendChild($view);
}
}

View file

@ -5,6 +5,17 @@ final class DiffusionRepositoryEditEngine
const ENGINECONST = 'diffusion.repository';
private $versionControlSystem;
public function setVersionControlSystem($version_control_system) {
$this->versionControlSystem = $version_control_system;
return $this;
}
public function getVersionControlSystem() {
return $this->versionControlSystem;
}
public function isEngineConfigurable() {
return false;
}
@ -27,7 +38,14 @@ final class DiffusionRepositoryEditEngine
protected function newEditableObject() {
$viewer = $this->getViewer();
return PhabricatorRepository::initializeNewRepository($viewer);
$repository = PhabricatorRepository::initializeNewRepository($viewer);
$vcs = $this->getVersionControlSystem();
if ($vcs) {
$repository->setVersionControlSystem($vcs);
}
return $repository;
}
protected function newObjectQuery() {

View file

@ -46,8 +46,12 @@ final class DiffusionRepositoryStatusManagementPanel
pht('Update Frequency'),
$this->buildRepositoryUpdateInterval($repository));
$messages = id(new PhabricatorRepositoryStatusMessage())
->loadAllWhere('repositoryID = %d', $repository->getID());
$messages = mpull($messages, null, 'getStatusType');
list($status, $raw_error) = $this->buildRepositoryStatus($repository);
$status = $this->buildRepositoryStatus($repository, $messages);
$raw_error = $this->buildRepositoryRawError($repository, $messages);
$view->addProperty(pht('Status'), $status);
if ($raw_error) {
@ -80,17 +84,14 @@ final class DiffusionRepositoryStatusManagementPanel
}
private function buildRepositoryStatus(
PhabricatorRepository $repository) {
PhabricatorRepository $repository,
array $messages) {
$viewer = $this->getViewer();
$is_cluster = $repository->getAlmanacServicePHID();
$view = new PHUIStatusListView();
$messages = id(new PhabricatorRepositoryStatusMessage())
->loadAllWhere('repositoryID = %d', $repository->getID());
$messages = mpull($messages, null, 'getStatusType');
if ($repository->isTracked()) {
$view->addItem(
id(new PHUIStatusItemView())
@ -361,8 +362,6 @@ final class DiffusionRepositoryStatusManagementPanel
}
}
$raw_error = null;
$message = idx($messages, PhabricatorRepositoryStatusMessage::TYPE_FETCH);
if ($message) {
switch ($message->getStatusCode()) {
@ -377,8 +376,6 @@ final class DiffusionRepositoryStatusManagementPanel
'access the repository.');
}
$raw_error = $message;
$view->addItem(
id(new PHUIStatusItemView())
->setIcon(PHUIStatusItemView::ICON_WARNING, 'red')
@ -432,11 +429,30 @@ final class DiffusionRepositoryStatusManagementPanel
->setNote(pht('This repository will be updated soon!')));
}
return $view;
}
private function buildRepositoryRawError(
PhabricatorRepository $repository,
array $messages) {
$viewer = $this->getViewer();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$repository,
PhabricatorPolicyCapability::CAN_EDIT);
$raw_error = null;
$message = idx($messages, PhabricatorRepositoryStatusMessage::TYPE_FETCH);
if ($message) {
switch ($message->getStatusCode()) {
case PhabricatorRepositoryStatusMessage::CODE_ERROR:
$raw_error = $message->getParameter('message');
break;
}
}
if ($raw_error !== null) {
if (!$can_edit) {
$raw_message = pht(
@ -450,7 +466,7 @@ final class DiffusionRepositoryStatusManagementPanel
$raw_message = null;
}
return array($view, $raw_message);
return $raw_message;
}

View file

@ -106,7 +106,7 @@ final class DiffusionRepositoryURIsManagementPanel
));
$doc_href = PhabricatorEnv::getDoclink(
'Diffusion User Guide: Repository URIs');
'Diffusion User Guide: URIs');
$header = id(new PHUIHeaderView())
->setHeader(pht('Repository URIs'))

View file

@ -7,17 +7,41 @@ final class PhabricatorRepositoryType extends Phobject {
const REPOSITORY_TYPE_MERCURIAL = 'hg';
public static function getAllRepositoryTypes() {
$map = array(
self::REPOSITORY_TYPE_GIT => pht('Git'),
self::REPOSITORY_TYPE_MERCURIAL => pht('Mercurial'),
self::REPOSITORY_TYPE_SVN => pht('Subversion'),
);
return $map;
$map = self::getRepositoryTypeMap();
return ipull($map, 'name');
}
public static function getNameForRepositoryType($type) {
$map = self::getAllRepositoryTypes();
return idx($map, $type, pht('Unknown'));
$spec = self::getRepositoryTypeSpec($type);
return idx($spec, 'name', pht('Unknown ("%s")', $type));
}
public static function getRepositoryTypeSpec($type) {
$map = self::getRepositoryTypeMap();
return idx($map, $type, array());
}
public static function getRepositoryTypeMap() {
return array(
self::REPOSITORY_TYPE_GIT => array(
'name' => pht('Git'),
'icon' => 'fa-git',
'create.header' => pht('Create Git Repository'),
'create.subheader' => pht('Create a new Git repository.'),
),
self::REPOSITORY_TYPE_MERCURIAL => array(
'name' => pht('Mercurial'),
'icon' => 'fa-code-fork',
'create.header' => pht('Create Mercurial Repository'),
'create.subheader' => pht('Create a new Mercurial repository.'),
),
self::REPOSITORY_TYPE_SVN => array(
'name' => pht('Subversion'),
'icon' => 'fa-database',
'create.header' => pht('Create Subversion Repository'),
'create.subheader' => pht('Create a new Subversion repository.'),
),
);
}
}