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

Add very basic create interface for Pholio

Summary:
Nothing app-specific yet, just stitching groundwork together from readymade components.

{F22347}

Test Plan: Created some mocks via web UI.

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T2097

Differential Revision: https://secure.phabricator.com/D3830
This commit is contained in:
epriestley 2012-11-21 17:23:28 -08:00
parent fc9ad37b26
commit a6cd41ff7d
5 changed files with 213 additions and 2 deletions

View file

@ -1205,6 +1205,7 @@ phutil_register_library_map(array(
'PholioImage' => 'applications/pholio/storage/PholioImage.php', 'PholioImage' => 'applications/pholio/storage/PholioImage.php',
'PholioIndexer' => 'applications/pholio/indexer/PholioIndexer.php', 'PholioIndexer' => 'applications/pholio/indexer/PholioIndexer.php',
'PholioMock' => 'applications/pholio/storage/PholioMock.php', 'PholioMock' => 'applications/pholio/storage/PholioMock.php',
'PholioMockEditController' => 'applications/pholio/controller/PholioMockEditController.php',
'PholioMockEditor' => 'applications/pholio/editor/PholioMockEditor.php', 'PholioMockEditor' => 'applications/pholio/editor/PholioMockEditor.php',
'PholioMockListController' => 'applications/pholio/controller/PholioMockListController.php', 'PholioMockListController' => 'applications/pholio/controller/PholioMockListController.php',
'PholioMockQuery' => 'applications/pholio/query/PholioMockQuery.php', 'PholioMockQuery' => 'applications/pholio/query/PholioMockQuery.php',
@ -2405,6 +2406,7 @@ phutil_register_library_map(array(
2 => 'PhabricatorPolicyInterface', 2 => 'PhabricatorPolicyInterface',
3 => 'PhabricatorSubscribableInterface', 3 => 'PhabricatorSubscribableInterface',
), ),
'PholioMockEditController' => 'PholioController',
'PholioMockEditor' => 'PhabricatorEditor', 'PholioMockEditor' => 'PhabricatorEditor',
'PholioMockListController' => 'PholioController', 'PholioMockListController' => 'PholioController',
'PholioMockQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PholioMockQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',

View file

@ -56,6 +56,9 @@ final class PhabricatorApplicationPholio extends PhabricatorApplication {
'/M(?P<id>[1-9]\d*)' => 'PholioMockViewController', '/M(?P<id>[1-9]\d*)' => 'PholioMockViewController',
'/pholio/' => array( '/pholio/' => array(
'' => 'PholioMockListController', '' => 'PholioMockListController',
'view/(?P<view>\w+)/' => 'PholioMockListController',
'new/' => 'PholioMockEditController',
'edit/(?P<id>\d+)/' => 'PholioMockEditController',
), ),
); );
} }

View file

@ -21,5 +21,18 @@
*/ */
abstract class PholioController extends PhabricatorController { abstract class PholioController extends PhabricatorController {
public function buildSideNav() {
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
$nav->addLabel('Create');
$nav->addFilter('new', pht('Create Mock'));
$nav->addLabel('Mocks');
$nav->addFilter('view/all', pht('All Mocks'));
return $nav;
}
} }

View file

@ -0,0 +1,177 @@
<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @group pholio
*/
final class PholioMockEditController extends PholioController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
if ($this->id) {
// TODO: Support!
throw new Exception("NOT SUPPORTED YET");
} else {
$mock = new PholioMock();
$mock->setAuthorPHID($user->getPHID());
$mock->setViewPolicy(PhabricatorPolicies::POLICY_USER);
$title = pht('Create Mock');
}
$e_name = true;
$e_images = true;
$errors = array();
if ($request->isFormPost()) {
$mock->setName($request->getStr('name'));
$mock->setDescription($request->getStr('description'));
$mock->setViewPolicy($request->getStr('can_view'));
if (!strlen($mock->getName())) {
$e_name = 'Required';
$errors[] = pht('You must name the mock.');
}
$files = array();
$file_phids = $request->getArr('file_phids');
if ($file_phids) {
$files = id(new PhabricatorFileQuery())
->setViewer($user)
->withPHIDs($file_phids)
->execute();
}
if (!$files) {
$e_images = 'Required';
$errors[] = pht('You must add at least one image to the mock.');
} else {
$mock->setCoverPHID(head($files)->getPHID());
}
$sequence = 0;
$images = array();
foreach ($files as $file) {
$image = new PholioImage();
$image->setName('');
$image->setDescription('');
$image->setFilePHID($file->getPHID());
$image->setSequence($sequence++);
$images[] = $image;
}
if (!$errors) {
// TODO: Make transaction-object based and move to editor.
$mock->openTransaction();
$mock->save();
foreach ($images as $image) {
$image->setMockID($mock->getID());
$image->save();
}
$mock->saveTransaction();
return id(new AphrontRedirectResponse())
->setURI('/M'.$mock->getID());
}
}
if ($errors) {
$error_view = id(new AphrontErrorView())
->setTitle(pht('Form Errors'))
->setErrors($errors);
} else {
$error_view = null;
}
if ($this->id) {
$submit = id(new AphrontFormSubmitControl())
->addCancelButton('/M'.$this->id)
->setValue(pht('Save'));
} else {
$submit = id(new AphrontFormSubmitControl())
->addCancelButton($this->getApplicationURI())
->setValue(pht('Create'));
}
$policies = id(new PhabricatorPolicyQuery())
->setViewer($user)
->setObject($mock)
->execute();
$form = id(new AphrontFormView())
->setUser($user)
->setFlexible(true)
->appendChild(
id(new AphrontFormTextControl())
->setName('name')
->setValue($mock->getName())
->setLabel(pht('Name'))
->setError($e_name))
->appendChild(
id(new PhabricatorRemarkupControl())
->setName('description')
->setValue($mock->getDescription())
->setLabel(pht('Description')))
->appendChild(
id(new AphrontFormDragAndDropUploadControl($request))
->setName('file_phids')
->setLabel(pht('Images'))
->setError($e_images))
->appendChild(
id(new AphrontFormPolicyControl())
->setUser($user)
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
->setPolicyObject($mock)
->setPolicies($policies)
->setName('can_view'))
->appendChild($submit);
$header = id(new PhabricatorHeaderView())
->setHeader($title);
$content = array(
$header,
$error_view,
$form,
);
$nav = $this->buildSideNav();
$nav->selectFilter(null);
$nav->appendChild($content);
return $this->buildApplicationPage(
$nav,
array(
'title' => $title,
));
}
}

View file

@ -21,6 +21,12 @@
*/ */
final class PholioMockListController extends PholioController { final class PholioMockListController extends PholioController {
private $view;
public function willProcessRequest(array $data) {
$this->view = idx($data, 'view');
}
public function processRequest() { public function processRequest() {
$request = $this->getRequest(); $request = $this->getRequest();
$user = $request->getUser(); $user = $request->getUser();
@ -28,7 +34,15 @@ final class PholioMockListController extends PholioController {
$query = id(new PholioMockQuery()) $query = id(new PholioMockQuery())
->setViewer($user); ->setViewer($user);
$nav = $this->buildSideNav();
$filter = $nav->selectFilter('view/'.$this->view, 'view/all');
switch ($filter) {
case 'view/all':
default:
$title = 'All Mocks'; $title = 'All Mocks';
break;
}
$pager = new AphrontCursorPagerView(); $pager = new AphrontCursorPagerView();
$pager->readFromRequest($request); $pager->readFromRequest($request);
@ -52,8 +66,10 @@ final class PholioMockListController extends PholioController {
$pager, $pager,
); );
$nav->appendChild($content);
return $this->buildApplicationPage( return $this->buildApplicationPage(
$content, $nav,
array( array(
'title' => $title, 'title' => $title,
)); ));