diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 6b71c24..d6e343f 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1,69 +1,73 @@ 2, 'class' => array( 'SemiStructuredBaseController' => 'applications/semistruct/controller/SemiStructuredBaseController.php', 'SemiStructuredDAO' => 'applications/semistruct/storage/SemiStructuredDAO.php', 'SemiStructuredDataApplication' => 'applications/semistruct/application/SemiStructuredDataApplication.php', 'SemiStructuredObjectInstance' => 'applications/semistruct/storage/SemiStructuredObjectInstance.php', 'SemiStructuredObjectInstancePHIDType' => 'applications/semistruct/phid/SemiStructuredObjectInstancePHIDType.php', 'SemiStructuredObjectInstanceQuery' => 'applications/semistruct/query/SemiStructuredObjectInstanceQuery.php', 'SemiStructuredObjectType' => 'applications/semistruct/storage/SemiStructuredObjectType.php', + 'SemiStructuredObjectTypeController' => 'applications/semistruct/controller/class/SemiStructuredObjectTypeController.php', 'SemiStructuredObjectTypeDescriptionTransaction' => 'applications/semistruct/xaction/class/SemiStructuredObjectTypeDescriptionTransaction.php', 'SemiStructuredObjectTypeEditController' => 'applications/semistruct/controller/class/SemiStructuredObjectTypeEditController.php', 'SemiStructuredObjectTypeEditEngine' => 'applications/semistruct/editor/SemiStructuredObjectTypeEditEngine.php', 'SemiStructuredObjectTypeFerretEngine' => 'applications/semistruct/engine/SemiStructuredObjectTypeFerretEngine.php', 'SemiStructuredObjectTypeListController' => 'applications/semistruct/controller/class/SemiStructuredObjectTypeListController.php', 'SemiStructuredObjectTypeNameTransaction' => 'applications/semistruct/xaction/class/SemiStructuredObjectTypeNameTransaction.php', 'SemiStructuredObjectTypePHIDType' => 'applications/semistruct/phid/SemiStructuredObjectTypePHIDType.php', 'SemiStructuredObjectTypeQuery' => 'applications/semistruct/query/SemiStructuredObjectTypeQuery.php', 'SemiStructuredObjectTypeSearchEngine' => 'applications/semistruct/query/SemiStructuredObjectTypeSearchEngine.php', 'SemiStructuredObjectTypeTransaction' => 'applications/semistruct/storage/SemiStructuredObjectTypeTransaction.php', 'SemiStructuredObjectTypeTransactionEditor' => 'applications/semistruct/editor/SemiStructuredObjectTypeTransactionEditor.php', 'SemiStructuredObjectTypeTransactionType' => 'applications/semistruct/xaction/class/SemiStructuredObjectTypeTransactionType.php', + 'SemiStructuredObjectTypeViewController' => 'applications/semistruct/controller/class/SemiStructuredObjectTypeViewController.php', 'SemiStructuredPatchList' => 'applications/semistruct/storage/SemiStructuredPatchList.php', ), 'function' => array(), 'xmap' => array( 'SemiStructuredBaseController' => 'PhabricatorController', 'SemiStructuredDAO' => 'PhabricatorLiskDAO', 'SemiStructuredDataApplication' => 'PhabricatorApplication', 'SemiStructuredObjectInstance' => array( 'SemiStructuredDAO', 'PhabricatorPolicyInterface', 'PhabricatorApplicationTransactionInterface', 'PhabricatorFlaggableInterface', 'PhabricatorDestructibleInterface', ), 'SemiStructuredObjectInstancePHIDType' => 'PhabricatorPHIDType', 'SemiStructuredObjectInstanceQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'SemiStructuredObjectType' => array( 'SemiStructuredDAO', 'PhabricatorPolicyInterface', 'PhabricatorApplicationTransactionInterface', 'PhabricatorFlaggableInterface', 'PhabricatorDestructibleInterface', 'PhabricatorFerretInterface', ), + 'SemiStructuredObjectTypeController' => 'SemiStructuredBaseController', 'SemiStructuredObjectTypeDescriptionTransaction' => 'SemiStructuredObjectTypeTransactionType', 'SemiStructuredObjectTypeEditController' => 'PhabricatorDashboardController', 'SemiStructuredObjectTypeEditEngine' => 'PhabricatorEditEngine', 'SemiStructuredObjectTypeFerretEngine' => 'PhabricatorFerretEngine', 'SemiStructuredObjectTypeListController' => 'SemiStructuredBaseController', 'SemiStructuredObjectTypeNameTransaction' => 'SemiStructuredObjectTypeTransactionType', 'SemiStructuredObjectTypePHIDType' => 'PhabricatorPHIDType', 'SemiStructuredObjectTypeQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'SemiStructuredObjectTypeSearchEngine' => 'PhabricatorApplicationSearchEngine', 'SemiStructuredObjectTypeTransaction' => 'PhabricatorModularTransaction', 'SemiStructuredObjectTypeTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 'SemiStructuredObjectTypeTransactionType' => 'PhabricatorModularTransactionType', + 'SemiStructuredObjectTypeViewController' => 'SemiStructuredObjectTypeController', 'SemiStructuredPatchList' => 'PhabricatorSQLPatchList', ), )); diff --git a/src/application/SemiStructuredDataApplication.php b/src/application/SemiStructuredDataApplication.php index 4639307..31f0911 100644 --- a/src/application/SemiStructuredDataApplication.php +++ b/src/application/SemiStructuredDataApplication.php @@ -1,27 +1,29 @@ array( '(?:query/(?P[^/]+)/)?' => 'SemiStructuredObjectTypeListController', $this->getEditRoutePattern('editclass/') => 'SemiStructuredObjectTypeEditController', - ), + 'type/(?:(?P\d+)/)?' => 'SemiStructuredObjectTypeViewController', + + ), ); } } diff --git a/src/controller/class/SemiStructuredObjectTypeController.php b/src/controller/class/SemiStructuredObjectTypeController.php new file mode 100644 index 0000000..71391f3 --- /dev/null +++ b/src/controller/class/SemiStructuredObjectTypeController.php @@ -0,0 +1,89 @@ +objectType = $object_type; + return $this; + } + + public function getObjectType() { + return $this->objectType; + } + + // TODO ??? + public function buildApplicationMenu() { + return $this->buildSideNavView()->getMenu(); + } + + + protected function buildHeaderView() { + $viewer = $this->getViewer(); + $object_type = $this->getObjectType(); + + + if ($object_type->isArchived()) { + $status_icon = 'fa-ban'; + $status_color = 'dark'; + } else { + $status_icon = 'fa-check'; + $status_color = 'bluegrey'; + } + $status_name = idx( + SemiStructuredObjectType::getStatusNameMap(), + $object_type->getStatus()); + + return id(new PHUIHeaderView()) + ->setHeader($object_type->getName()) + ->setUser($viewer) + ->setPolicyObject($object_type) + ->setStatus($status_icon, $status_color, $status_name) + ->setHeaderIcon('fa-trophy'); + } + + protected function buildApplicationCrumbs() { + $object_type = $this->getObjectType(); + $uri = $object_type->getURI(); + + $crumbs = parent::buildApplicationCrumbs(); + $crumbs->addTextCrumb($object_type->getName(), $uri); + $crumbs->setBorder(true); + return $crumbs; + } + + protected function buildSideNavView($filter = null) { + $viewer = $this->getViewer(); + $object_type = $this->getObjectType(); + $id = $object_type->getID(); + + $can_edit = PhabricatorPolicyFilter::hasCapability( + $viewer, + $object_type, + PhabricatorPolicyCapability::CAN_EDIT); + + $nav = id(new AphrontSideNavFilterView()) + ->setBaseURI(new PhutilURI($this->getApplicationURI())); + + $nav->addLabel(pht('Object Type')); + + $nav->addFilter( + 'view', + pht('View Object Type'), + $object_type->getURI(), + 'fa-trophy'); + + $nav->addFilter( + 'instances', + pht('View Instances'), + $this->getApplicationURI("/recipients/{$id}/"), + 'fa-group'); + + $nav->selectFilter($filter); + + return $nav; + } + +} diff --git a/src/controller/class/SemiStructuredObjectTypeViewController.php b/src/controller/class/SemiStructuredObjectTypeViewController.php new file mode 100644 index 0000000..d75b288 --- /dev/null +++ b/src/controller/class/SemiStructuredObjectTypeViewController.php @@ -0,0 +1,114 @@ +getViewer(); + $id = $request->getURIData('id'); + + $object_type = id(new SemiStructuredObjectTypeQuery()) + ->setViewer($viewer) + ->withIDs(array($id)) + ->executeOne(); + if (!$object_type) { + return new Aphront404Response(); + } + + $this->setObjectType($object_type); + + $crumbs = $this->buildApplicationCrumbs(); + $title = $object_type->getName(); + + $header = $this->buildHeaderView(); + $curtain = $this->buildCurtain(); + $details = $this->buildDetailsView(); + + // $timeline = $this->buildTransactionTimeline( + // $object_type, + // new PhabricatorBadgesTransactionQuery()); /// TODO + $timeline = null; + + $comment_view = id(new SemiStructuredObjectTypeEditEngine()) + ->setViewer($viewer) + ->buildEditEngineCommentView($object_type); + + $view = id(new PHUITwoColumnView()) + ->setHeader($header) + ->setCurtain($curtain) + ->setMainColumn(array( + $timeline, + $comment_view, + )) + ->addPropertySection(pht('Description'), $details); + + $navigation = $this->buildSideNavView('view'); + + return $this->newPage() + ->setTitle($title) + ->setCrumbs($crumbs) + ->setPageObjectPHIDs(array($object_type->getPHID())) + ->setNavigation($navigation) + ->appendChild($view); + } + +private function buildDetailsView() { + $viewer = $this->getViewer(); + $object_type = $this->getObjectType(); + + $view = id(new PHUIPropertyListView()) + ->setUser($viewer); + + $description = $object_type->getDescription(); + if (strlen($description)) { + $view->addTextContent( + new PHUIRemarkupView($viewer, $description)); + } + + return $view; + } + + private function buildCurtain() { + $viewer = $this->getViewer(); + $object_type = $this->getObjectType(); + + $can_edit = PhabricatorPolicyFilter::hasCapability( + $viewer, + $object_type, + PhabricatorPolicyCapability::CAN_EDIT); + + $id = $object_type->getID(); + $edit_uri = $this->getApplicationURI("/editclass/{$id}/"); + $archive_uri = $this->getApplicationURI("/archive/{$id}/"); + + $curtain = $this->newCurtainView($object_type); + + $curtain->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Edit Object Type')) + ->setIcon('fa-pencil') + ->setDisabled(!$can_edit) + ->setHref($edit_uri)); + + if ($object_type->isArchived()) { + $curtain->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Activate Object Type')) + ->setIcon('fa-check') + ->setDisabled(!$can_edit) + ->setWorkflow($can_edit) + ->setHref($archive_uri)); + } else { + $curtain->addAction( + id(new PhabricatorActionView()) + ->setName(pht('Archive Object Type')) + ->setIcon('fa-ban') + ->setDisabled(!$can_edit) + ->setWorkflow($can_edit) + ->setHref($archive_uri)); + } + + return $curtain; + } + +} diff --git a/src/editor/SemiStructuredObjectTypeTransactionEditor.php b/src/editor/SemiStructuredObjectTypeTransactionEditor.php index 6d9dc24..05c241d 100644 --- a/src/editor/SemiStructuredObjectTypeTransactionEditor.php +++ b/src/editor/SemiStructuredObjectTypeTransactionEditor.php @@ -1,28 +1,28 @@