1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-15 11:22:40 +01:00
phorge-phorge/src/applications/almanac/controller/AlmanacController.php
epriestley fcad9435ea Allow Almanac Devices and Bindings to have properties
Summary:
Ref T5833. Adds support for arbitrary properites to Almanac devices and bindings.

  - For Devices, this allows you to maybe mark what `rack` a server is on, the `serial` number of a router, etc.
  - For Bindings, this allows you to maybe mark that a bound device is `active`, provide `credentials`, expose it as `readonly`, etc.

Test Plan: Added properties to Devices and Bindings.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5833

Differential Revision: https://secure.phabricator.com/D10781
2014-11-05 15:28:36 -08:00

62 lines
1.5 KiB
PHP

<?php
abstract class AlmanacController
extends PhabricatorController {
protected function buildAlmanacPropertiesTable(
AlmanacPropertyInterface $object) {
$viewer = $this->getViewer();
$properties = $object->getAlmanacProperties();
$rows = array();
foreach ($properties as $property) {
$value = $property->getFieldValue();
$rows[] = array(
$property->getFieldName(),
PhabricatorConfigJSON::prettyPrintJSON($value),
);
}
$table = id(new AphrontTableView($rows))
->setNoDataString(pht('No properties.'))
->setHeaders(
array(
pht('Name'),
pht('Value'),
))
->setColumnClasses(
array(
null,
'wide',
));
$phid = $object->getPHID();
$add_uri = $this->getApplicationURI("property/edit/?objectPHID={$phid}");
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$object,
PhabricatorPolicyCapability::CAN_EDIT);
$add_button = id(new PHUIButtonView())
->setTag('a')
->setHref($add_uri)
->setWorkflow(true)
->setDisabled(!$can_edit)
->setText(pht('Add Property'))
->setIcon(
id(new PHUIIconView())
->setIconFont('fa-plus'));
$header = id(new PHUIHeaderView())
->setHeader(pht('Properties'))
->addActionLink($add_button);
return id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($table);
}
}