diff --git a/src/application/SemiStructuredDataApplication.php b/src/application/SemiStructuredDataApplication.php index a22528f..132a0dd 100644 --- a/src/application/SemiStructuredDataApplication.php +++ b/src/application/SemiStructuredDataApplication.php @@ -1,38 +1,42 @@ array( '(?:query/(?P[^/]+)/)?' => 'SemiStructuredObjectTypeListController', $this->getEditRoutePattern('editclass/') => 'SemiStructuredObjectTypeEditController', 'type/(?:(?P\d+)/)?' => array( '' => 'SemiStructuredObjectTypeViewController', 'new/' => 'SemiStructuredObjectNewInstanceController', ), $this->getEditRoutePattern('editinstance/') => 'SemiStructuredObjectInstanceEditController', 'instance/(?:(?P\d+)/)?' => 'SemiStructuredObjectInstanceViewController', ), ); } } diff --git a/src/editor/SemiStructuredObjectTypeEditEngine.php b/src/editor/SemiStructuredObjectTypeEditEngine.php index 91e033a..146f2f2 100644 --- a/src/editor/SemiStructuredObjectTypeEditEngine.php +++ b/src/editor/SemiStructuredObjectTypeEditEngine.php @@ -1,112 +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/' . + '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/SemiStructuredObjectTypeSearchEngine.php b/src/query/SemiStructuredObjectTypeSearchEngine.php index edd51de..55a2b17 100644 --- a/src/query/SemiStructuredObjectTypeSearchEngine.php +++ b/src/query/SemiStructuredObjectTypeSearchEngine.php @@ -1,150 +1,149 @@ setKey('statuses') ->setLabel(pht('Status')) ->setOptions(SemiStructuredObjectType::getStatusNameMap()), id(new PhabricatorSearchCheckboxesField()) ->setKey('editable') ->setLabel(pht('Editable')) ->setOptions(array('editable' => null)), ); } protected function getURI($path) { return '/semistruct/'.$path; } protected function getBuiltinQueryNames() { $names = array(); $names['all'] = pht('All Types'); $names['open'] = pht('Active Types'); 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(); 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(); } 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 $class) { $item = id(new PHUIObjectItemView()) ->setViewer($viewer) ->setObjectName($class->getObjectName()) ->setHeader($class->getName()) ->setHref($class->getURI()) ->setObject($class); if ($class->isArchived()) { $item->setDisabled(true); $bg_color = 'bg-grey'; } else { $bg_color = 'bg-dark'; } $icon = id(new PHUIIconView()) - ->setIcon($class->getIcon()) - ->setBackground($bg_color); + ->setIcon($class->getIcon()); $item->setImageIcon($icon); $item->setEpoch($class->getDateModified()); $phid = $class->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 object types found.')); return $result; } } diff --git a/src/storage/SemiStructuredObjectType.php b/src/storage/SemiStructuredObjectType.php index a67384b..e557c9a 100644 --- a/src/storage/SemiStructuredObjectType.php +++ b/src/storage/SemiStructuredObjectType.php @@ -1,144 +1,145 @@ setName('') ->setViewPolicy(PhabricatorPolicies::getMostOpenPolicy()) ->setEditPolicy($actor->getPHID()) ->setStatus(self::STATUS_ACTIVE); } public function getCustomFieldsConfig() { if (!$this->customFieldsConfig) { return array(); } return $this->customFieldsConfig; } public static function getStatusNameMap() { return array( self::STATUS_ACTIVE => pht('Active'), self::STATUS_ARCHIVED => pht('Archived'), ); } protected function getConfiguration() { return array( self::CONFIG_AUX_PHID => true, self::CONFIG_SERIALIZATION => array( 'customFieldsConfig' => self::SERIALIZATION_JSON, ), self::CONFIG_COLUMN_SCHEMA => array( 'name' => 'sort255', 'status' => 'text32', 'description' => 'text', ), ) + parent::getConfiguration(); } public function getPHIDType() { return SemiStructuredObjectTypePHIDType::TYPECONST; } public function isArchived() { return ($this->getStatus() == self::STATUS_ARCHIVED); } public function getURI() { return urisprintf('/semistruct/type/%d/', $this->getID()); } public function getObjectName() { return pht('Object Type %d', $this->getID()); } public function getIcon() { - // TODO - return 'fa-bear'; + // TODO copy the feature from Projects, where you can put a custom image + // or select from a list. + return 'fa-camera'; } /* -( PhabricatorApplicationTransactionInterface )------------------------- */ public function getApplicationTransactionEditor() { return new SemiStructuredObjectTypeTransactionEditor(); } public function getApplicationTransactionTemplate() { return new SemiStructuredObjectTypeTransaction(); } /* -( PhabricatorPolicyInterface )----------------------------------------- */ public function getCapabilities() { return array( PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT, // TODO can-create-instances ); } public function getPolicy($capability) { switch ($capability) { case PhabricatorPolicyCapability::CAN_VIEW: return $this->getViewPolicy(); case PhabricatorPolicyCapability::CAN_EDIT: return $this->getEditPolicy(); } } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { return false; } /* -( PhabricatorDestructibleInterface )----------------------------------- */ public function destroyObjectPermanently( PhabricatorDestructionEngine $engine) { $this->openTransaction(); $this->delete(); $this->saveTransaction(); } /* -( PhabricatorFerretInterface )----------------------------------------- */ public function newFerretEngine() { return new SemiStructuredObjectTypeFerretEngine(); } }