diff --git a/src/applications/almanac/controller/AlmanacController.php b/src/applications/almanac/controller/AlmanacController.php --- a/src/applications/almanac/controller/AlmanacController.php +++ b/src/applications/almanac/controller/AlmanacController.php @@ -38,7 +38,7 @@ )); $builtins = $object->getAlmanacPropertyFieldSpecifications(); - $defaults = mpull($builtins, null, 'getValueForTransaction'); + $defaults = mpull($builtins, 'getValueForTransaction'); // Sort fields so builtin fields appear first, then fields are ordered // alphabetically. @@ -65,6 +65,7 @@ $value = $property->getFieldValue(); $is_builtin = isset($builtins[$key]); + $is_persistent = (bool)$property->getID(); $delete_uri = id(new PhutilURI($delete_base)) ->setQueryParams( @@ -83,7 +84,7 @@ $delete = javelin_tag( 'a', array( - 'class' => ($can_edit + 'class' => (($can_edit && $is_persistent) ? 'button button-grey small' : 'button button-grey small disabled'), 'sigil' => 'workflow', diff --git a/src/applications/almanac/editor/AlmanacPropertyEditEngine.php b/src/applications/almanac/editor/AlmanacPropertyEditEngine.php --- a/src/applications/almanac/editor/AlmanacPropertyEditEngine.php +++ b/src/applications/almanac/editor/AlmanacPropertyEditEngine.php @@ -66,8 +66,15 @@ $property_key = $this->getPropertyKey(); $xaction_type = $object->getAlmanacPropertySetTransactionType(); + $specs = $object->getAlmanacPropertyFieldSpecifications(); + if (isset($specs[$property_key])) { + $field_template = clone $specs[$property_key]; + } else { + $field_template = new PhabricatorTextEditField(); + } + return array( - id(new PhabricatorTextEditField()) + $field_template ->setKey('value') ->setMetadataValue('almanac.property', $property_key) ->setLabel($property_key) diff --git a/src/applications/almanac/query/AlmanacQuery.php b/src/applications/almanac/query/AlmanacQuery.php --- a/src/applications/almanac/query/AlmanacQuery.php +++ b/src/applications/almanac/query/AlmanacQuery.php @@ -34,10 +34,12 @@ $specs = $object->getAlmanacPropertyFieldSpecifications(); foreach ($specs as $key => $spec) { if (empty($object_properties[$key])) { + $default_value = $spec->getValueForTransaction(); + $object_properties[$key] = id(new AlmanacProperty()) ->setObjectPHID($object->getPHID()) ->setFieldName($key) - ->setFieldValue($spec->getValueForTransaction()); + ->setFieldValue($default_value); } } diff --git a/src/applications/almanac/servicetype/AlmanacClusterRepositoryServiceType.php b/src/applications/almanac/servicetype/AlmanacClusterRepositoryServiceType.php --- a/src/applications/almanac/servicetype/AlmanacClusterRepositoryServiceType.php +++ b/src/applications/almanac/servicetype/AlmanacClusterRepositoryServiceType.php @@ -24,4 +24,36 @@ ); } + public function getBindingFieldSpecifications(AlmanacBinding $binding) { + $protocols = array( + array( + 'value' => 'http', + 'port' => 80, + ), + array( + 'value' => 'https', + 'port' => 443, + ), + array( + 'value' => 'ssh', + 'port' => 22, + ), + ); + + $default_value = 'http'; + if ($binding->hasInterface()) { + $interface = $binding->getInterface(); + $port = $interface->getPort(); + + $default_ports = ipull($protocols, 'value', 'port'); + $default_value = idx($default_ports, $port, $default_value); + } + + return array( + 'protocol' => id(new PhabricatorSelectEditField()) + ->setOptions(ipull($protocols, 'value', 'value')) + ->setValue($default_value), + ); + } + } diff --git a/src/applications/almanac/servicetype/AlmanacServiceType.php b/src/applications/almanac/servicetype/AlmanacServiceType.php --- a/src/applications/almanac/servicetype/AlmanacServiceType.php +++ b/src/applications/almanac/servicetype/AlmanacServiceType.php @@ -60,6 +60,10 @@ return array(); } + public function getBindingFieldSpecifications(AlmanacBinding $binding) { + return array(); + } + /** * List all available service type implementations. * diff --git a/src/applications/almanac/storage/AlmanacBinding.php b/src/applications/almanac/storage/AlmanacBinding.php --- a/src/applications/almanac/storage/AlmanacBinding.php +++ b/src/applications/almanac/storage/AlmanacBinding.php @@ -88,6 +88,10 @@ return $this; } + public function hasInterface() { + return ($this->interface !== self::ATTACHABLE); + } + public function getInterface() { return $this->assertAttached($this->interface); } @@ -129,7 +133,7 @@ } public function getAlmanacPropertyFieldSpecifications() { - return array(); + return $this->getService()->getBindingFieldSpecifications($this); } public function newAlmanacPropertyEditEngine() { diff --git a/src/applications/almanac/storage/AlmanacService.php b/src/applications/almanac/storage/AlmanacService.php --- a/src/applications/almanac/storage/AlmanacService.php +++ b/src/applications/almanac/storage/AlmanacService.php @@ -156,6 +156,11 @@ return $this->getServiceImplementation()->getFieldSpecifications(); } + public function getBindingFieldSpecifications(AlmanacBinding $binding) { + $impl = $this->getServiceImplementation(); + return $impl->getBindingFieldSpecifications($binding); + } + public function newAlmanacPropertyEditEngine() { return new AlmanacServicePropertyEditEngine(); }