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:
parent
311de580d6
commit
0459e95242
5 changed files with 139 additions and 24 deletions
|
@ -4,9 +4,66 @@ final class DiffusionRepositoryEditproController
|
||||||
extends DiffusionRepositoryEditController {
|
extends DiffusionRepositoryEditController {
|
||||||
|
|
||||||
public function handleRequest(AphrontRequest $request) {
|
public function handleRequest(AphrontRequest $request) {
|
||||||
return id(new DiffusionRepositoryEditEngine())
|
$engine = id(new DiffusionRepositoryEditEngine())
|
||||||
->setController($this)
|
->setController($this);
|
||||||
->buildResponse();
|
|
||||||
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,17 @@ final class DiffusionRepositoryEditEngine
|
||||||
|
|
||||||
const ENGINECONST = 'diffusion.repository';
|
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() {
|
public function isEngineConfigurable() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +38,14 @@ final class DiffusionRepositoryEditEngine
|
||||||
|
|
||||||
protected function newEditableObject() {
|
protected function newEditableObject() {
|
||||||
$viewer = $this->getViewer();
|
$viewer = $this->getViewer();
|
||||||
return PhabricatorRepository::initializeNewRepository($viewer);
|
$repository = PhabricatorRepository::initializeNewRepository($viewer);
|
||||||
|
|
||||||
|
$vcs = $this->getVersionControlSystem();
|
||||||
|
if ($vcs) {
|
||||||
|
$repository->setVersionControlSystem($vcs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $repository;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function newObjectQuery() {
|
protected function newObjectQuery() {
|
||||||
|
|
|
@ -46,8 +46,12 @@ final class DiffusionRepositoryStatusManagementPanel
|
||||||
pht('Update Frequency'),
|
pht('Update Frequency'),
|
||||||
$this->buildRepositoryUpdateInterval($repository));
|
$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);
|
$view->addProperty(pht('Status'), $status);
|
||||||
if ($raw_error) {
|
if ($raw_error) {
|
||||||
|
@ -80,17 +84,14 @@ final class DiffusionRepositoryStatusManagementPanel
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildRepositoryStatus(
|
private function buildRepositoryStatus(
|
||||||
PhabricatorRepository $repository) {
|
PhabricatorRepository $repository,
|
||||||
|
array $messages) {
|
||||||
|
|
||||||
$viewer = $this->getViewer();
|
$viewer = $this->getViewer();
|
||||||
$is_cluster = $repository->getAlmanacServicePHID();
|
$is_cluster = $repository->getAlmanacServicePHID();
|
||||||
|
|
||||||
$view = new PHUIStatusListView();
|
$view = new PHUIStatusListView();
|
||||||
|
|
||||||
$messages = id(new PhabricatorRepositoryStatusMessage())
|
|
||||||
->loadAllWhere('repositoryID = %d', $repository->getID());
|
|
||||||
$messages = mpull($messages, null, 'getStatusType');
|
|
||||||
|
|
||||||
if ($repository->isTracked()) {
|
if ($repository->isTracked()) {
|
||||||
$view->addItem(
|
$view->addItem(
|
||||||
id(new PHUIStatusItemView())
|
id(new PHUIStatusItemView())
|
||||||
|
@ -361,8 +362,6 @@ final class DiffusionRepositoryStatusManagementPanel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$raw_error = null;
|
|
||||||
|
|
||||||
$message = idx($messages, PhabricatorRepositoryStatusMessage::TYPE_FETCH);
|
$message = idx($messages, PhabricatorRepositoryStatusMessage::TYPE_FETCH);
|
||||||
if ($message) {
|
if ($message) {
|
||||||
switch ($message->getStatusCode()) {
|
switch ($message->getStatusCode()) {
|
||||||
|
@ -377,8 +376,6 @@ final class DiffusionRepositoryStatusManagementPanel
|
||||||
'access the repository.');
|
'access the repository.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$raw_error = $message;
|
|
||||||
|
|
||||||
$view->addItem(
|
$view->addItem(
|
||||||
id(new PHUIStatusItemView())
|
id(new PHUIStatusItemView())
|
||||||
->setIcon(PHUIStatusItemView::ICON_WARNING, 'red')
|
->setIcon(PHUIStatusItemView::ICON_WARNING, 'red')
|
||||||
|
@ -432,11 +429,30 @@ final class DiffusionRepositoryStatusManagementPanel
|
||||||
->setNote(pht('This repository will be updated soon!')));
|
->setNote(pht('This repository will be updated soon!')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $view;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function buildRepositoryRawError(
|
||||||
|
PhabricatorRepository $repository,
|
||||||
|
array $messages) {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
$can_edit = PhabricatorPolicyFilter::hasCapability(
|
||||||
$viewer,
|
$viewer,
|
||||||
$repository,
|
$repository,
|
||||||
PhabricatorPolicyCapability::CAN_EDIT);
|
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 ($raw_error !== null) {
|
||||||
if (!$can_edit) {
|
if (!$can_edit) {
|
||||||
$raw_message = pht(
|
$raw_message = pht(
|
||||||
|
@ -450,7 +466,7 @@ final class DiffusionRepositoryStatusManagementPanel
|
||||||
$raw_message = null;
|
$raw_message = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array($view, $raw_message);
|
return $raw_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ final class DiffusionRepositoryURIsManagementPanel
|
||||||
));
|
));
|
||||||
|
|
||||||
$doc_href = PhabricatorEnv::getDoclink(
|
$doc_href = PhabricatorEnv::getDoclink(
|
||||||
'Diffusion User Guide: Repository URIs');
|
'Diffusion User Guide: URIs');
|
||||||
|
|
||||||
$header = id(new PHUIHeaderView())
|
$header = id(new PHUIHeaderView())
|
||||||
->setHeader(pht('Repository URIs'))
|
->setHeader(pht('Repository URIs'))
|
||||||
|
|
|
@ -7,17 +7,41 @@ final class PhabricatorRepositoryType extends Phobject {
|
||||||
const REPOSITORY_TYPE_MERCURIAL = 'hg';
|
const REPOSITORY_TYPE_MERCURIAL = 'hg';
|
||||||
|
|
||||||
public static function getAllRepositoryTypes() {
|
public static function getAllRepositoryTypes() {
|
||||||
$map = array(
|
$map = self::getRepositoryTypeMap();
|
||||||
self::REPOSITORY_TYPE_GIT => pht('Git'),
|
return ipull($map, 'name');
|
||||||
self::REPOSITORY_TYPE_MERCURIAL => pht('Mercurial'),
|
|
||||||
self::REPOSITORY_TYPE_SVN => pht('Subversion'),
|
|
||||||
);
|
|
||||||
return $map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getNameForRepositoryType($type) {
|
public static function getNameForRepositoryType($type) {
|
||||||
$map = self::getAllRepositoryTypes();
|
$spec = self::getRepositoryTypeSpec($type);
|
||||||
return idx($map, $type, pht('Unknown'));
|
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.'),
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue