2014-10-17 05:04:24 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class AlmanacInterfaceEditController
|
|
|
|
extends AlmanacDeviceController {
|
|
|
|
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
|
|
|
|
$id = $request->getURIData('id');
|
|
|
|
if ($id) {
|
|
|
|
$interface = id(new AlmanacInterfaceQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($id))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
if (!$interface) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$device = $interface->getDevice();
|
|
|
|
|
|
|
|
$is_new = false;
|
|
|
|
$title = pht('Edit Interface');
|
|
|
|
$save_button = pht('Save Changes');
|
|
|
|
} else {
|
|
|
|
$device = id(new AlmanacDeviceQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($request->getStr('deviceID')))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
if (!$device) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$interface = AlmanacInterface::initializeNewInterface();
|
|
|
|
$is_new = true;
|
|
|
|
|
|
|
|
$title = pht('Create Interface');
|
|
|
|
$save_button = pht('Create Interface');
|
|
|
|
}
|
|
|
|
|
|
|
|
$device_uri = $device->getURI();
|
|
|
|
$cancel_uri = $device_uri;
|
|
|
|
|
|
|
|
$v_network = $interface->getNetworkPHID();
|
|
|
|
|
|
|
|
$v_address = $interface->getAddress();
|
|
|
|
$e_address = true;
|
|
|
|
|
|
|
|
$v_port = $interface->getPort();
|
|
|
|
|
|
|
|
$validation_exception = null;
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
|
|
|
$v_network = $request->getStr('networkPHID');
|
|
|
|
$v_address = $request->getStr('address');
|
|
|
|
$v_port = $request->getStr('port');
|
|
|
|
|
|
|
|
$type_interface = AlmanacDeviceTransaction::TYPE_INTERFACE;
|
|
|
|
|
|
|
|
$address = AlmanacAddress::newFromParts($v_network, $v_address, $v_port);
|
|
|
|
|
|
|
|
$xaction = id(new AlmanacDeviceTransaction())
|
|
|
|
->setTransactionType($type_interface)
|
|
|
|
->setNewValue($address->toDictionary());
|
|
|
|
|
|
|
|
if ($interface->getID()) {
|
|
|
|
$xaction->setOldValue(array(
|
|
|
|
'id' => $interface->getID(),
|
|
|
|
) + $interface->toAddress()->toDictionary());
|
|
|
|
} else {
|
|
|
|
$xaction->setOldValue(array());
|
|
|
|
}
|
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
$xactions[] = $xaction;
|
|
|
|
|
|
|
|
$editor = id(new AlmanacDeviceEditor())
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContinueOnMissingFields(true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$editor->applyTransactions($device, $xactions);
|
|
|
|
|
|
|
|
$device_uri = $device->getURI();
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($device_uri);
|
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
|
|
$validation_exception = $ex;
|
|
|
|
$e_address = $ex->getShortMessage($type_interface);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$networks = id(new AlmanacNetworkQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$form = id(new AphrontFormView())
|
|
|
|
->setUser($viewer)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel(pht('Network'))
|
|
|
|
->setName('networkPHID')
|
|
|
|
->setValue($v_network)
|
|
|
|
->setOptions(mpull($networks, 'getName', 'getPHID')))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel(pht('Address'))
|
|
|
|
->setName('address')
|
|
|
|
->setValue($v_address)
|
|
|
|
->setError($e_address))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel(pht('Port'))
|
|
|
|
->setName('port')
|
|
|
|
->setValue($v_port)
|
|
|
|
->setError($e_address))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->addCancelButton($cancel_uri)
|
|
|
|
->setValue($save_button));
|
|
|
|
|
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setValidationException($validation_exception)
|
2016-03-26 11:54:55 -07:00
|
|
|
->setHeaderText(pht('Interface'))
|
|
|
|
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
[Redesign] Add Table, Collapse support to ObjectBox
Summary: Converts most all tables to be directly set via `setTable` to an ObjectBox. I think this path is more flexible design wise, as we can change the box based on children, and not just CSS. We also already do this with PropertyList, Forms, ObjectList, and Header. `setCollapsed` is added to ObjectBox to all children objects to bleed to the edges (like diffs).
Test Plan: I did a grep of `appendChild($table)` as well as searches for `PHUIObjectBoxView`, also with manual opening of hundreds of files. I'm sure I missed 5-8 places. If you just appendChild($table) nothing breaks, it just looks a little funny.
Reviewers: epriestley, btrahan
Subscribers: Korvin, epriestley
Differential Revision: https://secure.phabricator.com/D12955
2015-05-20 12:43:34 -07:00
|
|
|
->setForm($form);
|
2014-10-17 05:04:24 -07:00
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addTextCrumb($device->getName(), $device_uri);
|
|
|
|
if ($is_new) {
|
|
|
|
$crumbs->addTextCrumb(pht('Create Interface'));
|
2016-03-26 11:54:55 -07:00
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('Create Interface'))
|
|
|
|
->setHeaderIcon('fa-plus-square');
|
2014-10-17 05:04:24 -07:00
|
|
|
} else {
|
|
|
|
$crumbs->addTextCrumb(pht('Edit Interface'));
|
2016-03-26 11:54:55 -07:00
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader(pht('Edit Interface'))
|
|
|
|
->setHeaderIcon('fa-pencil');
|
2014-10-17 05:04:24 -07:00
|
|
|
}
|
2016-03-26 11:54:55 -07:00
|
|
|
$crumbs->setBorder(true);
|
|
|
|
|
|
|
|
$view = id(new PHUITwoColumnView())
|
|
|
|
->setHeader($header)
|
|
|
|
->setFooter(array(
|
|
|
|
$box,
|
|
|
|
));
|
2014-10-17 05:04:24 -07:00
|
|
|
|
2015-11-28 14:46:19 -08:00
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title)
|
|
|
|
->setCrumbs($crumbs)
|
2016-03-26 11:54:55 -07:00
|
|
|
->appendChild($view);
|
|
|
|
|
2014-10-17 05:04:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|