Path: blob/master/src/applications/dashboard/editor/PhabricatorDashboardPanelEditEngine.php
13434 views
<?php12final class PhabricatorDashboardPanelEditEngine3extends PhabricatorEditEngine {45const ENGINECONST = 'dashboard.panel';67private $panelType;8private $contextObject;9private $columnKey;1011public function setPanelType($panel_type) {12$this->panelType = $panel_type;13return $this;14}1516public function getPanelType() {17return $this->panelType;18}1920public function setContextObject($context) {21$this->contextObject = $context;22return $this;23}2425public function getContextObject() {26return $this->contextObject;27}2829public function setColumnKey($column_key) {30$this->columnKey = $column_key;31return $this;32}3334public function getColumnKey() {35return $this->columnKey;36}3738public function isEngineConfigurable() {39return false;40}4142public function getEngineName() {43return pht('Dashboard Panels');44}4546public function getSummaryHeader() {47return pht('Edit Dashboard Panels');48}4950protected function supportsSearch() {51return true;52}5354public function getSummaryText() {55return pht('This engine is used to modify dashboard panels.');56}5758public function getEngineApplicationClass() {59return 'PhabricatorDashboardApplication';60}6162protected function newEditableObject() {63$viewer = $this->getViewer();64$panel = PhabricatorDashboardPanel::initializeNewPanel($viewer);6566if ($this->panelType) {67$panel->setPanelType($this->panelType);68}6970return $panel;71}7273protected function newEditableObjectForDocumentation() {74$panel = parent::newEditableObjectForDocumentation();7576$text_type = id(new PhabricatorDashboardTextPanelType())77->getPanelTypeKey();7879$panel->setPanelType($text_type);8081return $panel;82}8384protected function newObjectQuery() {85return new PhabricatorDashboardPanelQuery();86}8788protected function getObjectCreateTitleText($object) {89return pht('Create Dashboard Panel');90}9192protected function getObjectCreateButtonText($object) {93return pht('Create Panel');94}9596protected function getObjectCreateCancelURI($object) {97$context = $this->getContextObject();98if ($context) {99return $context->getURI();100}101102return parent::getObjectCreateCancelURI($object);103}104105public function getEffectiveObjectEditDoneURI($object) {106$context = $this->getContextObject();107if ($context) {108return $context->getURI();109}110111return parent::getEffectiveObjectEditDoneURI($object);112}113114protected function getObjectEditCancelURI($object) {115$context = $this->getContextObject();116if ($context) {117return $context->getURI();118}119120return parent::getObjectEditCancelURI($object);121}122123protected function getObjectEditTitleText($object) {124return pht('Edit Panel: %s', $object->getName());125}126127protected function getObjectEditShortText($object) {128return pht('Edit Panel');129}130131protected function getObjectCreateShortText() {132return pht('Edit Panel');133}134135protected function getObjectName() {136return pht('Dashboard Panel');137}138139protected function getObjectViewURI($object) {140return $object->getURI();141}142143protected function didApplyTransactions($object, array $xactions) {144$context = $this->getContextObject();145146if ($context instanceof PhabricatorDashboard) {147// Only add the panel to the dashboard when we're creating a new panel,148// not if we're editing an existing panel.149if (!$this->getIsCreate()) {150return;151}152153$viewer = $this->getViewer();154$controller = $this->getController();155$request = $controller->getRequest();156157$dashboard = $context;158159$xactions = array();160161$ref_list = clone $dashboard->getPanelRefList();162163$ref_list->newPanelRef($object, $this->getColumnKey());164$new_panels = $ref_list->toDictionary();165166$xactions[] = $dashboard->getApplicationTransactionTemplate()167->setTransactionType(168PhabricatorDashboardPanelsTransaction::TRANSACTIONTYPE)169->setNewValue($new_panels);170171$editor = $dashboard->getApplicationTransactionEditor()172->setActor($viewer)173->setContentSourceFromRequest($request)174->setContinueOnNoEffect(true)175->setContinueOnMissingFields(true);176177$editor->applyTransactions($dashboard, $xactions);178}179}180181protected function buildCustomEditFields($object) {182$fields = array(183id(new PhabricatorTextEditField())184->setKey('name')185->setLabel(pht('Name'))186->setDescription(pht('Name of the panel.'))187->setConduitDescription(pht('Rename the panel.'))188->setConduitTypeDescription(pht('New panel name.'))189->setTransactionType(190PhabricatorDashboardPanelNameTransaction::TRANSACTIONTYPE)191->setIsRequired(true)192->setValue($object->getName()),193);194195$panel_fields = $object->getEditEngineFields();196foreach ($panel_fields as $panel_field) {197$fields[] = $panel_field;198}199200return $fields;201}202203}204205206