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

Implement update and history controllers in Phragment

Summary: Depends on D7726.  This adds a history controller (for viewing a list of patches associated with a fragment) and an update controller, for creating a new patch of a fragment.

Test Plan: Updated and viewed history of fragments.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Maniphest Tasks: T4205

Differential Revision: https://secure.phabricator.com/D7727
This commit is contained in:
James Rhodes 2013-12-07 12:56:55 +11:00
parent 4c143ad3b2
commit f7f5a5dd34
7 changed files with 248 additions and 30 deletions

View file

@ -2182,9 +2182,11 @@ phutil_register_library_map(array(
'PhragmentFragmentQuery' => 'applications/phragment/query/PhragmentFragmentQuery.php',
'PhragmentFragmentVersion' => 'applications/phragment/storage/PhragmentFragmentVersion.php',
'PhragmentFragmentVersionQuery' => 'applications/phragment/query/PhragmentFragmentVersionQuery.php',
'PhragmentHistoryController' => 'applications/phragment/controller/PhragmentHistoryController.php',
'PhragmentPHIDTypeFragment' => 'applications/phragment/phid/PhragmentPHIDTypeFragment.php',
'PhragmentPHIDTypeFragmentVersion' => 'applications/phragment/phid/PhragmentPHIDTypeFragmentVersion.php',
'PhragmentPatchUtil' => 'applications/phragment/util/PhragmentPatchUtil.php',
'PhragmentUpdateController' => 'applications/phragment/controller/PhragmentUpdateController.php',
'PhrequentController' => 'applications/phrequent/controller/PhrequentController.php',
'PhrequentDAO' => 'applications/phrequent/storage/PhrequentDAO.php',
'PhrequentListController' => 'applications/phrequent/controller/PhrequentListController.php',
@ -4778,9 +4780,11 @@ phutil_register_library_map(array(
1 => 'PhabricatorPolicyInterface',
),
'PhragmentFragmentVersionQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhragmentHistoryController' => 'PhragmentController',
'PhragmentPHIDTypeFragment' => 'PhabricatorPHIDType',
'PhragmentPHIDTypeFragmentVersion' => 'PhabricatorPHIDType',
'PhragmentPatchUtil' => 'Phobject',
'PhragmentUpdateController' => 'PhragmentController',
'PhrequentController' => 'PhabricatorController',
'PhrequentDAO' => 'PhabricatorLiskDAO',
'PhrequentListController' =>

View file

@ -36,6 +36,8 @@ final class PhabricatorApplicationPhragment extends PhabricatorApplication {
'' => 'PhragmentBrowseController',
'browse/(?P<dblob>.*)' => 'PhragmentBrowseController',
'create/(?P<dblob>.*)' => 'PhragmentCreateController',
'update/(?P<dblob>.*)' => 'PhragmentUpdateController',
'history/(?P<dblob>.*)' => 'PhragmentHistoryController',
),
);
}

View file

@ -30,7 +30,7 @@ final class PhragmentBrowseController extends PhragmentController {
->setHref($this->getApplicationURI('/create/'.$path))
->setIcon('create'));
$current_box = $this->createCurrentFragmentView($current);
$current_box = $this->createCurrentFragmentView($current, false);
$list = id(new PHUIObjectItemListView())
->setUser($viewer);
@ -74,35 +74,8 @@ final class PhragmentBrowseController extends PhragmentController {
$current_box,
$list),
array(
'title' => pht('Browse Phragments'),
'title' => pht('Browse Fragments'),
'device' => true));
}
private function createCurrentFragmentView($fragment) {
if ($fragment === null) {
return null;
}
$viewer = $this->getRequest()->getUser();
$header = id(new PHUIHeaderView())
->setHeader($fragment->getName())
->setPolicyObject($fragment)
->setUser($viewer);
$properties = new PHUIPropertyListView();
$phids = array();
$phids[] = $fragment->getLatestVersionPHID();
$this->loadHandles($phids);
$properties->addProperty(
pht('Latest Version'),
$this->renderHandlesForPHIDs(array($fragment->getLatestVersionPHID())));
return id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties);
}
}

View file

@ -20,6 +20,7 @@ abstract class PhragmentController extends PhabricatorController {
$fragments = array();
$results = id(new PhragmentFragmentQuery())
->setViewer($this->getRequest()->getUser())
->needLatestVersion(true)
->withPaths($combinations)
->execute();
foreach ($combinations as $combination) {
@ -53,4 +54,74 @@ abstract class PhragmentController extends PhabricatorController {
return $crumbs;
}
protected function createCurrentFragmentView($fragment, $is_history_view) {
if ($fragment === null) {
return null;
}
$viewer = $this->getRequest()->getUser();
$phids = array();
$phids[] = $fragment->getLatestVersionPHID();
$this->loadHandles($phids);
$file = id(new PhabricatorFileQuery())
->setViewer($viewer)
->withPHIDs(array($fragment->getLatestVersion()->getFilePHID()))
->executeOne();
$file_uri = null;
if ($file !== null) {
$file_uri = $file->getBestURI();
}
$header = id(new PHUIHeaderView())
->setHeader($fragment->getName())
->setPolicyObject($fragment)
->setUser($viewer);
$actions = id(new PhabricatorActionListView())
->setUser($viewer)
->setObject($fragment)
->setObjectURI($fragment->getURI());
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('Download Fragment'))
->setHref($file_uri)
->setDisabled($file === null)
->setIcon('download'));
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('Update Fragment'))
->setHref($this->getApplicationURI("update/".$fragment->getPath()))
->setDisabled(false) // TODO: Policy
->setIcon('edit'));
if ($is_history_view) {
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('View Child Fragments'))
->setHref($this->getApplicationURI("browse/".$fragment->getPath()))
->setIcon('browse'));
} else {
$actions->addAction(
id(new PhabricatorActionView())
->setName(pht('View History'))
->setHref($this->getApplicationURI("history/".$fragment->getPath()))
->setIcon('history'));
}
$properties = id(new PHUIPropertyListView())
->setUser($viewer)
->setObject($fragment)
->setActionList($actions);
$properties->addProperty(
pht('Latest Version'),
$this->renderHandlesForPHIDs(array($fragment->getLatestVersionPHID())));
return id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties);
}
}

View file

@ -134,7 +134,7 @@ final class PhragmentCreateController extends PhragmentController {
$crumbs,
$box),
array(
'title' => pht('Create Phragment'),
'title' => pht('Create Fragment'),
'device' => true));
}

View file

@ -0,0 +1,77 @@
<?php
final class PhragmentHistoryController extends PhragmentController {
private $dblob;
public function willProcessRequest(array $data) {
$this->dblob = idx($data, "dblob", "");
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$parents = $this->loadParentFragments($this->dblob);
if ($parents === null) {
return new Aphront404Response();
}
$current = idx($parents, count($parents) - 1, null);
$path = $current->getPath();
$crumbs = $this->buildApplicationCrumbsWithPath($parents);
$crumbs->addAction(
id(new PHUIListItemView())
->setName(pht('Create Fragment'))
->setHref($this->getApplicationURI('/create/'.$path))
->setIcon('create'));
$current_box = $this->createCurrentFragmentView($current, true);
$versions = id(new PhragmentFragmentVersionQuery())
->setViewer($viewer)
->withFragmentPHIDs(array($current->getPHID()))
->execute();
$list = id(new PHUIObjectItemListView())
->setUser($viewer);
$file_phids = mpull($versions, 'getFilePHID');
$files = id(new PhabricatorFileQuery())
->setViewer($viewer)
->withPHIDs($file_phids)
->execute();
$files = mpull($files, null, 'getPHID');
foreach ($versions as $version) {
$item = id(new PHUIObjectItemView());
$item->setHeader('Version '.$version->getSequence());
$item->addAttribute(phabricator_datetime(
$version->getDateCreated(),
$viewer));
$disabled = !isset($files[$version->getFilePHID()]);
$action = id(new PHUIListItemView())
->setIcon('download')
->setDisabled($disabled)
->setRenderNameAsTooltip(true)
->setName(pht("Download"));
if (!$disabled) {
$action->setHref($files[$version->getFilePHID()]->getBestURI());
}
$item->addAction($action);
$list->addItem($item);
}
return $this->buildApplicationPage(
array(
$crumbs,
$current_box,
$list),
array(
'title' => pht('Fragment History'),
'device' => true));
}
}

View file

@ -0,0 +1,91 @@
<?php
final class PhragmentUpdateController extends PhragmentController {
private $dblob;
public function willProcessRequest(array $data) {
$this->dblob = idx($data, "dblob", "");
}
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
$parents = $this->loadParentFragments($this->dblob);
if ($parents === null) {
return new Aphront404Response();
}
$fragment = idx($parents, count($parents) - 1, null);
$error_view = null;
if ($request->isFormPost()) {
$errors = array();
$v_fileid = $request->getInt('fileID');
$file = id(new PhabricatorFile())->load($v_fileid);
if ($file === null) {
$errors[] = pht('The specified file doesn\'t exist.');
}
if (!count($errors)) {
$existing = id(new PhragmentFragmentVersionQuery())
->setViewer($viewer)
->withFragmentPHIDs(array($fragment->getPHID()))
->execute();
$sequence = count($existing);
$fragment->openTransaction();
$version = id(new PhragmentFragmentVersion());
$version->setSequence($sequence);
$version->setFragmentPHID($fragment->getPHID());
$version->setFilePHID($file->getPHID());
$version->save();
$fragment->setLatestVersionPHID($version->getPHID());
$fragment->save();
$fragment->saveTransaction();
return id(new AphrontRedirectResponse())
->setURI('/phragment/browse/'.$fragment->getPath());
} else {
$error_view = id(new AphrontErrorView())
->setErrors($errors)
->setTitle(pht('Errors while updating fragment'));
}
}
$form = id(new AphrontFormView())
->setUser($viewer)
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('File ID'))
->setName('fileID'))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Update Fragment'))
->addCancelButton(
$this->getApplicationURI('browse/'.$fragment->getPath())));
$crumbs = $this->buildApplicationCrumbsWithPath($parents);
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName(pht('Update Fragment')));
$box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Update Fragment: %s', $fragment->getPath()))
->setValidationException(null)
->setForm($form);
return $this->buildApplicationPage(
array(
$crumbs,
$box),
array(
'title' => pht('Update Fragment'),
'device' => true));
}
}