diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 9f6804f..8192900 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1,123 +1,125 @@ 2, 'class' => array( 'SemiStructuredBaseController' => 'applications/semistruct/controller/SemiStructuredBaseController.php', 'SemiStructuredDAO' => 'applications/semistruct/storage/SemiStructuredDAO.php', 'SemiStructuredDataApplication' => 'applications/semistruct/application/SemiStructuredDataApplication.php', 'SemiStructuredInstanceConfiguredCustomField' => 'applications/semistruct/customfield/SemiStructuredConfiguredCustomField.php', 'SemiStructuredInstanceConfiguredCustomFieldStorage' => 'applications/semistruct/storage/SemiStructuredInstanceConfiguredCustomFieldStorage.php', 'SemiStructuredInstanceCustomField' => 'applications/semistruct/customfield/SemiStructuredInstanceCustomField.php', 'SemiStructuredInstanceCustomFieldNumericIndex' => 'applications/semistruct/storage/SemiStructuredInstanceCustomFieldNumericIndex.php', 'SemiStructuredInstanceCustomFieldStringIndex' => 'applications/semistruct/storage/SemiStructuredInstanceCustomFieldStringIndex.php', 'SemiStructuredObjectInstance' => 'applications/semistruct/storage/SemiStructuredObjectInstance.php', 'SemiStructuredObjectInstanceClassTransaction' => 'applications/semistruct/xaction/instance/SemiStructuredObjectInstanceClassTransaction.php', 'SemiStructuredObjectInstanceController' => 'applications/semistruct/controller/instance/SemiStructuredObjectInstanceController.php', 'SemiStructuredObjectInstanceDescriptionTransaction' => 'applications/semistruct/xaction/instance/SemiStructuredObjectInstanceDescriptionTransaction.php', 'SemiStructuredObjectInstanceEditController' => 'applications/semistruct/controller/instance/SemiStructuredObjectInstanceEditController.php', 'SemiStructuredObjectInstanceEditEngine' => 'applications/semistruct/editor/SemiStructuredObjectInstanceEditEngine.php', + 'SemiStructuredObjectInstanceListController' => 'applications/semistruct/controller/instance/SemiStructuredObjectInstanceListController.php', 'SemiStructuredObjectInstanceNameTransaction' => 'applications/semistruct/xaction/instance/SemiStructuredObjectInstanceNameTransaction.php', 'SemiStructuredObjectInstancePHIDType' => 'applications/semistruct/phid/SemiStructuredObjectInstancePHIDType.php', 'SemiStructuredObjectInstanceQuery' => 'applications/semistruct/query/SemiStructuredObjectInstanceQuery.php', 'SemiStructuredObjectInstanceRawDataTransaction' => 'applications/semistruct/xaction/instance/SemiStructuredObjectInstanceRawDataTransaction.php', 'SemiStructuredObjectInstanceSearchEngine' => 'applications/semistruct/query/SemiStructuredObjectInstanceSearchEngine.php', 'SemiStructuredObjectInstanceTransaction' => 'applications/semistruct/storage/SemiStructuredObjectInstanceTransaction.php', 'SemiStructuredObjectInstanceTransactionComment' => 'applications/semistruct/storage/SemiStructuredObjectInstanceTransactionComment.php', 'SemiStructuredObjectInstanceTransactionEditor' => 'applications/semistruct/editor/SemiStructuredObjectInstanceTransactionEditor.php', 'SemiStructuredObjectInstanceTransactionQuery' => 'applications/semistruct/query/SemiStructuredObjectInstanceTransactionQuery.php', 'SemiStructuredObjectInstanceTransactionType' => 'applications/semistruct/xaction/instance/SemiStructuredObjectInstanceTransactionType.php', 'SemiStructuredObjectInstanceViewController' => 'applications/semistruct/controller/instance/SemiStructuredObjectInstanceViewController.php', 'SemiStructuredObjectNewInstanceController' => 'applications/semistruct/controller/class/SemiStructuredObjectNewInstanceController.php', 'SemiStructuredObjectType' => 'applications/semistruct/storage/SemiStructuredObjectType.php', 'SemiStructuredObjectTypeController' => 'applications/semistruct/controller/class/SemiStructuredObjectTypeController.php', 'SemiStructuredObjectTypeCustomFieldsTransaction' => 'applications/semistruct/xaction/class/SemiStructuredObjectTypeCustomFieldsTransaction.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', 'SemiStructuredObjectTypeTransactionComment' => 'applications/semistruct/storage/SemiStructuredObjectTypeTransactionComment.php', 'SemiStructuredObjectTypeTransactionEditor' => 'applications/semistruct/editor/SemiStructuredObjectTypeTransactionEditor.php', 'SemiStructuredObjectTypeTransactionQuery' => 'applications/semistruct/query/SemiStructuredObjectTypeTransactionQuery.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', 'SemiStructuredInstanceConfiguredCustomField' => array( 'SemiStructuredInstanceCustomField', 'PhabricatorStandardCustomFieldInterface', ), 'SemiStructuredInstanceConfiguredCustomFieldStorage' => 'PhabricatorCustomFieldStorage', 'SemiStructuredInstanceCustomField' => 'PhabricatorCustomField', 'SemiStructuredInstanceCustomFieldNumericIndex' => 'PhabricatorCustomFieldNumericIndexStorage', 'SemiStructuredInstanceCustomFieldStringIndex' => 'PhabricatorCustomFieldStringIndexStorage', 'SemiStructuredObjectInstance' => array( 'SemiStructuredDAO', 'PhabricatorPolicyInterface', 'PhabricatorApplicationTransactionInterface', 'PhabricatorFlaggableInterface', 'PhabricatorCustomFieldInterface', 'PhabricatorDestructibleInterface', ), 'SemiStructuredObjectInstanceClassTransaction' => 'SemiStructuredObjectInstanceTransactionType', 'SemiStructuredObjectInstanceController' => 'SemiStructuredBaseController', 'SemiStructuredObjectInstanceDescriptionTransaction' => 'SemiStructuredObjectInstanceTransactionType', 'SemiStructuredObjectInstanceEditController' => 'SemiStructuredBaseController', 'SemiStructuredObjectInstanceEditEngine' => 'PhabricatorEditEngine', + 'SemiStructuredObjectInstanceListController' => 'SemiStructuredObjectTypeController', 'SemiStructuredObjectInstanceNameTransaction' => 'SemiStructuredObjectInstanceTransactionType', 'SemiStructuredObjectInstancePHIDType' => 'PhabricatorPHIDType', 'SemiStructuredObjectInstanceQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'SemiStructuredObjectInstanceRawDataTransaction' => 'SemiStructuredObjectInstanceTransactionType', 'SemiStructuredObjectInstanceSearchEngine' => 'PhabricatorApplicationSearchEngine', 'SemiStructuredObjectInstanceTransaction' => 'PhabricatorModularTransaction', 'SemiStructuredObjectInstanceTransactionComment' => 'PhabricatorApplicationTransactionComment', 'SemiStructuredObjectInstanceTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 'SemiStructuredObjectInstanceTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'SemiStructuredObjectInstanceTransactionType' => 'PhabricatorModularTransactionType', 'SemiStructuredObjectInstanceViewController' => 'SemiStructuredObjectInstanceController', 'SemiStructuredObjectNewInstanceController' => 'SemiStructuredObjectTypeController', 'SemiStructuredObjectType' => array( 'SemiStructuredDAO', 'PhabricatorPolicyInterface', 'PhabricatorApplicationTransactionInterface', 'PhabricatorFlaggableInterface', 'PhabricatorDestructibleInterface', 'PhabricatorFerretInterface', ), 'SemiStructuredObjectTypeController' => 'SemiStructuredBaseController', 'SemiStructuredObjectTypeCustomFieldsTransaction' => 'SemiStructuredObjectTypeTransactionType', 'SemiStructuredObjectTypeDescriptionTransaction' => 'SemiStructuredObjectTypeTransactionType', 'SemiStructuredObjectTypeEditController' => 'SemiStructuredBaseController', 'SemiStructuredObjectTypeEditEngine' => 'PhabricatorEditEngine', 'SemiStructuredObjectTypeFerretEngine' => 'PhabricatorFerretEngine', 'SemiStructuredObjectTypeListController' => 'SemiStructuredBaseController', 'SemiStructuredObjectTypeNameTransaction' => 'SemiStructuredObjectTypeTransactionType', 'SemiStructuredObjectTypePHIDType' => 'PhabricatorPHIDType', 'SemiStructuredObjectTypeQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'SemiStructuredObjectTypeSearchEngine' => 'PhabricatorApplicationSearchEngine', 'SemiStructuredObjectTypeTransaction' => 'PhabricatorModularTransaction', 'SemiStructuredObjectTypeTransactionComment' => 'PhabricatorApplicationTransactionComment', 'SemiStructuredObjectTypeTransactionEditor' => 'PhabricatorApplicationTransactionEditor', 'SemiStructuredObjectTypeTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 'SemiStructuredObjectTypeTransactionType' => 'PhabricatorModularTransactionType', 'SemiStructuredObjectTypeViewController' => 'SemiStructuredObjectTypeController', 'SemiStructuredPatchList' => 'PhabricatorSQLPatchList', ), )); diff --git a/src/application/SemiStructuredDataApplication.php b/src/application/SemiStructuredDataApplication.php index 132a0dd..6e349d9 100644 --- a/src/application/SemiStructuredDataApplication.php +++ b/src/application/SemiStructuredDataApplication.php @@ -1,42 +1,43 @@ array( '(?:query/(?P[^/]+)/)?' => 'SemiStructuredObjectTypeListController', $this->getEditRoutePattern('editclass/') => 'SemiStructuredObjectTypeEditController', 'type/(?:(?P\d+)/)?' => array( '' => 'SemiStructuredObjectTypeViewController', 'new/' => 'SemiStructuredObjectNewInstanceController', + 'items/' => 'SemiStructuredObjectInstanceListController', ), $this->getEditRoutePattern('editinstance/') => 'SemiStructuredObjectInstanceEditController', 'instance/(?:(?P\d+)/)?' => 'SemiStructuredObjectInstanceViewController', ), ); } } diff --git a/src/controller/class/SemiStructuredObjectNewInstanceController.php b/src/controller/class/SemiStructuredObjectNewInstanceController.php index dd040fa..76522aa 100644 --- a/src/controller/class/SemiStructuredObjectNewInstanceController.php +++ b/src/controller/class/SemiStructuredObjectNewInstanceController.php @@ -1,29 +1,30 @@ 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); $object = SemiStructuredObjectInstance::initializeNewObjectInstance( $viewer, $object_type); return id(new SemiStructuredObjectInstanceEditEngine()) + ->setObjectType($object_type) ->setTargetObject($object) ->setController($this) ->buildResponse(); } } diff --git a/src/controller/class/SemiStructuredObjectTypeController.php b/src/controller/class/SemiStructuredObjectTypeController.php index 71391f3..c997967 100644 --- a/src/controller/class/SemiStructuredObjectTypeController.php +++ b/src/controller/class/SemiStructuredObjectTypeController.php @@ -1,89 +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}/"), + $this->getApplicationURI("/type/{$id}/items/"), 'fa-group'); $nav->selectFilter($filter); return $nav; } } diff --git a/src/controller/instance/SemiStructuredObjectInstanceController.php b/src/controller/instance/SemiStructuredObjectInstanceController.php index f1415c3..4630a25 100644 --- a/src/controller/instance/SemiStructuredObjectInstanceController.php +++ b/src/controller/instance/SemiStructuredObjectInstanceController.php @@ -1,88 +1,88 @@ object = $object; return $this; } public function getObject() { return $this->object; } // TODO ??? public function buildApplicationMenu() { return $this->buildSideNavView()->getMenu(); } protected function buildHeaderView() { $viewer = $this->getViewer(); $object = $this->getObject(); $object_type = $object->getClass(); 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(pht('%s: %d %s', $object_type->getName(), $object->getID(), $object->getName())) ->setUser($viewer) ->setPolicyObject($object_type) ->setStatus($status_icon, $status_color, $status_name) ->setHeaderIcon('fa-trophy'); } protected function buildApplicationCrumbs() { $object = $this->getObject(); $object_type = $object->getClass(); $crumbs = parent::buildApplicationCrumbs(); $crumbs->addTextCrumb($object_type->getName(), $object_type->getURI()); $crumbs->addTextCrumb(pht('%d %s', $object->getID(), $object->getName()), $object->getURI()); $crumbs->setBorder(true); return $crumbs; } protected function buildSideNavView($filter = null) { $viewer = $this->getViewer(); $object = $this->getObject(); $object_type = $object->getClass(); $id = $object->getID(); $nav = id(new AphrontSideNavFilterView()) ->setBaseURI(new PhutilURI($this->getApplicationURI())); $nav->addLabel(pht('Instance of %s', $object_type->getName())); // TODO figure out menu $nav->addFilter( 'view', pht('View Object Type'), $object_type->getURI(), 'fa-trophy'); $nav->addFilter( 'instances', pht('View Instances'), - $this->getApplicationURI("/recipients/{$id}/"), + $this->getApplicationURI("/type/{$id}/items/"), 'fa-group'); $nav->selectFilter($filter); return $nav; } } diff --git a/src/controller/instance/SemiStructuredObjectInstanceListController.php b/src/controller/instance/SemiStructuredObjectInstanceListController.php new file mode 100644 index 0000000..bc44057 --- /dev/null +++ b/src/controller/instance/SemiStructuredObjectInstanceListController.php @@ -0,0 +1,70 @@ +objectType = $object_type; + return $this; + } + + public function getObjectType() { + return $this->objectType; + } + + public function handleRequest(AphrontRequest $request) { + $viewer = $request->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); + + + $query_key = $request->getURIData('queryKey'); + $controller = id(new PhabricatorApplicationSearchController()) + ->setQueryKey($query_key) + ->setSearchEngine( + id(new SemiStructuredObjectInstanceSearchEngine()) + ->setObjectType($object_type)) + ->setNavigation($this->buildSideNavView()); + + return $this->delegateToController($controller); + } + + public function buildSideNavView($filter = null) { + $user = $this->getRequest()->getUser(); + + $nav = new AphrontSideNavFilterView(); + $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); + + id(new SemiStructuredObjectInstanceSearchEngine()) + ->setViewer($user) + ->addNavigationItems($nav->getMenu()); + + $nav->selectFilter($filter); + + return $nav; + } + + protected function buildApplicationCrumbs() { + $crumbs = parent::buildApplicationCrumbs(); + + $object_type = $this->getObjectType(); + + id(new SemiStructuredObjectInstanceEditEngine()) + ->setObjectType($object_type) + ->setViewer($this->getViewer()) + ->addActionToCrumbs($crumbs); + + return $crumbs; + } +} diff --git a/src/editor/SemiStructuredObjectInstanceEditEngine.php b/src/editor/SemiStructuredObjectInstanceEditEngine.php index e097734..a0b1103 100644 --- a/src/editor/SemiStructuredObjectInstanceEditEngine.php +++ b/src/editor/SemiStructuredObjectInstanceEditEngine.php @@ -1,133 +1,143 @@ objectType = $object_type; return $this; } protected function newEditableObject() { $viewer = $this->getViewer(); return SemiStructuredObjectInstance::initializeNewObjectInstance( $viewer, $this->objectType); } protected function newObjectQuery() { return new SemiStructuredObjectInstanceQuery(); } protected function getObjectCreateTitleText($object) { return pht('Create Object Instance'); } protected function getObjectCreateButtonText($object) { return pht('Create Object Instance'); } protected function getObjectCreateCancelURI($object) { // TODO if objjec has link to class - go to that class return '/semistructured/'; } protected function getEditorURI() { return $this->getApplication()->getApplicationURI('editinstance/'); } + public function getCreateURI($form_key) { + + if ($this->objectType) { + return $this->getApplication()->getApplicationURI( + "type/{$this->objectType->getID()}/new/"); + } + + return null; + } + protected function getObjectEditTitleText($object) { return pht('Edit Object: %d', $object->getID()); } protected function getObjectEditShortText($object) { return pht('Edit Object'); } protected function getObjectCreateShortText() { return pht('Create Object Instance'); } protected function getObjectName() { return pht('Object Instance'); } protected function getObjectViewURI($object) { return $object->getURI(); } protected function buildCustomEditFields($object) { $fields = array( id(id(new PhabricatorStaticEditField()) ->setKey('objecttype') ->setLabel(pht('Object Type')) ->setValue($object->getClass()->getName())), id(new PhabricatorIntEditField()) ->setKey('classPHID') ->setLabel(pht('Object Type')) ->setDescription(pht('Type of the object.')) ->setConduitDescription(pht('Set type of object.')) ->setIsHidden(true) ->setTransactionType( SemiStructuredObjectInstanceClassTransaction::TRANSACTIONTYPE) ->setIsRequired(true) ->setValue($object->getClassPHID()), id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setDescription(pht('Name of the object.')) ->setConduitDescription(pht('Rename the object.')) ->setConduitTypeDescription(pht('New object name.')) ->setTransactionType( SemiStructuredObjectInstanceNameTransaction::TRANSACTIONTYPE) ->setValue($object->getName()), id(new PhabricatorRemarkupEditField()) ->setKey('description') ->setLabel(pht('Free text')) ->setDescription(pht('Object instance free text (Remarkup).')) ->setConduitTypeDescription(pht('New object free type.')) ->setTransactionType( SemiStructuredObjectInstanceDescriptionTransaction::TRANSACTIONTYPE) ->setValue($object->getDescription()), id(new PhabricatorTextAreaEditField()) ->setKey('rawdata') ->setLabel(pht('Structured content')) ->setDescription(pht('Object structured data (JSON).')) ->setConduitTypeDescription(pht('Object body (JSON).')) ->setMonospaced(true) ->setIsRequired(true) ->setTransactionType( SemiStructuredObjectInstanceRawDataTransaction::TRANSACTIONTYPE) ->setValue($object->getRawData()), ); return $fields; } } diff --git a/src/editor/SemiStructuredObjectTypeEditEngine.php b/src/editor/SemiStructuredObjectTypeEditEngine.php index 146f2f2..d59282f 100644 --- a/src/editor/SemiStructuredObjectTypeEditEngine.php +++ b/src/editor/SemiStructuredObjectTypeEditEngine.php @@ -1,121 +1,121 @@ getViewer(); return SemiStructuredObjectType::initializeNewObjectType($viewer); } protected function newObjectQuery() { return new SemiStructuredObjectTypeQuery(); } protected function getObjectCreateTitleText($object) { return pht('Create Object Type'); } protected function getObjectCreateButtonText($object) { return pht('Create Object Type'); } protected function getObjectCreateCancelURI($object) { return '/semistructured/'; } protected function getEditorURI() { return $this->getApplication()->getApplicationURI('editclass/'); } protected function getObjectEditTitleText($object) { return pht('Edit Object Type: %s', $object->getName()); } protected function getObjectEditShortText($object) { return pht('Edit Object Type'); } protected function getObjectCreateShortText() { return pht('Create Object Type'); } protected function getObjectName() { return pht('Object Type'); } protected function getObjectViewURI($object) { return $object->getURI(); } protected function buildCustomEditFields($object) { $custom_field_help = pht( 'See [[ %s | Custom Field Configuration ]] document '. 'for help with **%s**.', - 'https://we.phorge.it/book/phorge/article/' . + 'https://we.phorge.it/book/phorge/article/'. 'custom_fields/#custom-field-configuration', pht('Custom Fields Definition')); $fields = array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setDescription(pht('Name of the object type.')) ->setConduitDescription(pht('Rename the type.')) ->setConduitTypeDescription(pht('New type name.')) ->setTransactionType( SemiStructuredObjectTypeNameTransaction::TRANSACTIONTYPE) ->setIsRequired(true) ->setValue($object->getName()), id(new PhabricatorRemarkupEditField()) ->setKey('description') ->setLabel(pht('Description')) ->setDescription(pht('Object Type long description.')) ->setConduitTypeDescription(pht('New type description.')) ->setTransactionType( SemiStructuredObjectTypeDescriptionTransaction::TRANSACTIONTYPE) ->setValue($object->getDescription()), id(new PhabricatorInstructionsEditField()) ->setValue($custom_field_help), id(new PhabricatorTextAreaEditField()) ->setKey('customfieldsdef') ->setLabel(pht('Custom Fields Definition')) ->setDescription(pht('Custom fields for the instances of this type(JSON).')) ->setConduitTypeDescription(pht('Custom Fields Definition (JSON).')) ->setMonospaced(true) ->setIsRequired(false) ->setTransactionType( SemiStructuredObjectTypeCustomFieldsTransaction::TRANSACTIONTYPE) ->setValue( id(new PhutilJSON()) ->encodeFormatted($object->getCustomFieldsConfig())), ); return $fields; } } diff --git a/src/query/SemiStructuredObjectInstanceSearchEngine.php b/src/query/SemiStructuredObjectInstanceSearchEngine.php index 8c4f684..9cbf439 100644 --- a/src/query/SemiStructuredObjectInstanceSearchEngine.php +++ b/src/query/SemiStructuredObjectInstanceSearchEngine.php @@ -1,138 +1,155 @@ objectType = $object_type; + return $this; + } + + public function getObjectType() { + return $this->objectType; + } + public function getResultTypeDescription() { return pht('Object Instances'); } public function getApplicationClassName() { return 'SemiStructuredDataApplication'; } public function newQuery() { - return id(new SemiStructuredObjectInstanceQuery()); + $query = id(new SemiStructuredObjectInstanceQuery()); + if ($this->getObjectType()) { + $query->withClassPhids(array($this->getObjectType()->getPHID())); + } + return $query; } protected function buildCustomSearchFields() { return array( // TODO object class ); } protected function getURI($path) { return '/semistruct/'.$path; } protected function getBuiltinQueryNames() { $names = array(); $names['all'] = pht('All object'); return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); $viewer = $this->requireViewer(); switch ($query_key) { case 'all': return $query; case 'open': return $query->setParameter( 'statuses', array( SemiStructuredObjectType::STATUS_ACTIVE, )); } return parent::buildSavedQueryFromBuiltin($query_key); } protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); + // TODO type id/phid + // if ($map['statuses']) { // $query->withStatuses($map['statuses']); // } // if ($map['editable'] !== null) { // $query->withCanEdit($map['editable']); // } return $query; } protected function getRequiredHandlePHIDsForResultList( array $objects, PhabricatorSavedQuery $query) { return array(); } public function renderResultsDirectly(array $items) { return $this->renderResultList($items, new PhabricatorSavedQuery(), array()); } protected function renderResultList( array $items, PhabricatorSavedQuery $query , array $handles) { $viewer = $this->requireViewer(); if ($items) { $edge_query = id(new PhabricatorEdgeQuery()) ->withSourcePHIDs(mpull($items, 'getPHID')) ->withEdgeTypes( array( PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, )); $edge_query->execute(); } $list = id(new PHUIObjectItemListView()) ->setViewer($viewer); foreach ($items as $instance) { $item = id(new PHUIObjectItemView()) ->setViewer($viewer) ->setObjectName($instance->getName()) ->setHeader($instance->getName()) ->setHref($instance->getURI()) ->setObject($instance); $icon = id(new PHUIIconView()) ->setIcon($instance->getIcon()); $item->setImageIcon($icon); $item->setEpoch($instance->getDateModified()); $phid = $instance->getPHID(); $project_phids = $edge_query->getDestinationPHIDs(array($phid)); $project_handles = $viewer->loadHandles($project_phids); $item->addAttribute( id(new PHUIHandleTagListView()) ->setLimit(4) ->setNoDataString(pht('No Tags')) ->setSlim(true) ->setHandles($project_handles)); $list->addItem($item); } $result = new PhabricatorApplicationSearchResultView(); $result->setObjectList($list); $result->setNoDataString(pht('No objects found.')); return $result; } }