private function buildTransactions(PhabricatorDashboard $dashboard)
 {
     $viewer = $this->getRequest()->getUser();
     $xactions = id(new PhabricatorDashboardTransactionQuery())->setViewer($viewer)->withObjectPHIDs(array($dashboard->getPHID()))->execute();
     $timeline = id(new PhabricatorApplicationTransactionView())->setUser($viewer)->setShouldTerminate(true)->setObjectPHID($dashboard->getPHID())->setTransactions($xactions);
     return $timeline;
 }
 private function buildActionView(PhabricatorDashboard $dashboard)
 {
     $viewer = $this->getRequest()->getUser();
     $id = $dashboard->getID();
     $actions = id(new PhabricatorActionListView())->setObjectURI($this->getApplicationURI('view/' . $dashboard->getID() . '/'))->setObject($dashboard)->setUser($viewer);
     $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $dashboard, PhabricatorPolicyCapability::CAN_EDIT);
     $actions->addAction(id(new PhabricatorActionView())->setName(pht('View Dashboard'))->setIcon('fa-columns')->setHref($this->getApplicationURI("view/{$id}/")));
     $actions->addAction(id(new PhabricatorActionView())->setName(pht('Edit Dashboard'))->setIcon('fa-pencil')->setHref($this->getApplicationURI("edit/{$id}/"))->setDisabled(!$can_edit));
     if ($dashboard->isArchived()) {
         $actions->addAction(id(new PhabricatorActionView())->setName(pht('Activate Dashboard'))->setIcon('fa-check')->setHref($this->getApplicationURI("archive/{$id}/"))->setDisabled(!$can_edit)->setWorkflow($can_edit));
     } else {
         $actions->addAction(id(new PhabricatorActionView())->setName(pht('Archive Dashboard'))->setIcon('fa-ban')->setHref($this->getApplicationURI("archive/{$id}/"))->setDisabled(!$can_edit)->setWorkflow($can_edit));
     }
     $actions->addAction(id(new PhabricatorActionView())->setName(pht('Copy Dashboard'))->setIcon('fa-files-o')->setHref($this->getApplicationURI("copy/{$id}/"))->setWorkflow(true));
     $installed_dashboard = id(new PhabricatorDashboardInstall())->loadOneWhere('objectPHID = %s AND applicationClass = %s', $viewer->getPHID(), 'PhabricatorHomeApplication');
     if ($installed_dashboard && $installed_dashboard->getDashboardPHID() == $dashboard->getPHID()) {
         $title_install = pht('Uninstall Dashboard');
         $href_install = "uninstall/{$id}/";
     } else {
         $title_install = pht('Install Dashboard');
         $href_install = "install/{$id}/";
     }
     $actions->addAction(id(new PhabricatorActionView())->setName($title_install)->setIcon('fa-wrench')->setHref($this->getApplicationURI($href_install))->setWorkflow(true));
     $actions->addAction(id(new PhabricatorActionView())->setName(pht('View History'))->setIcon('fa-history')->setHref($this->getApplicationURI("history/{$id}/")));
     return $actions;
 }
 protected function loadPage()
 {
     $table = new PhabricatorDashboard();
     $conn_r = $table->establishConnection('r');
     $data = queryfx_all($conn_r, 'SELECT * FROM %T %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r));
     return $table->loadAllFromArray($data);
 }
 public static function addPanelToDashboard(PhabricatorUser $actor, PhabricatorContentSource $content_source, PhabricatorDashboardPanel $panel, PhabricatorDashboard $dashboard, $column)
 {
     $xactions = array();
     $xactions[] = id(new PhabricatorDashboardTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST)->setNewValue(array('+' => array($panel->getPHID() => $panel->getPHID())));
     $layout_config = $dashboard->getLayoutConfigObject();
     $layout_config->setPanelLocation($column, $panel->getPHID());
     $dashboard->setLayoutConfigFromObject($layout_config);
     $editor = id(new PhabricatorDashboardTransactionEditor())->setActor($actor)->setContentSource($content_source)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true)->applyTransactions($dashboard, $xactions);
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $dashboard = id(new PhabricatorDashboardQuery())->setViewer($viewer)->withIDs(array($id))->needPanels(true)->executeOne();
     if (!$dashboard) {
         return new Aphront404Response();
     }
     $manage_uri = $this->getApplicationURI('manage/' . $dashboard->getID() . '/');
     if ($request->isFormPost()) {
         $copy = PhabricatorDashboard::initializeNewDashboard($viewer);
         $copy = PhabricatorDashboard::copyDashboard($copy, $dashboard);
         $copy->setName(pht('Copy of %s', $copy->getName()));
         // Set up all the edges for the new dashboard.
         $xactions = array();
         $xactions[] = id(new PhabricatorDashboardTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST)->setNewValue(array('=' => array_fuse($dashboard->getPanelPHIDs())));
         $editor = id(new PhabricatorDashboardTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true)->applyTransactions($copy, $xactions);
         $manage_uri = $this->getApplicationURI('edit/' . $copy->getID() . '/');
         return id(new AphrontRedirectResponse())->setURI($manage_uri);
     }
     return $this->newDialog()->setTitle(pht('Copy Dashboard'))->appendParagraph(pht('Create a copy of the dashboard "%s"?', phutil_tag('strong', array(), $dashboard->getName())))->addCancelButton($manage_uri)->addSubmitButton(pht('Create Copy'));
 }
 private function processBuildTemplateRequest(AphrontRequest $request)
 {
     $viewer = $request->getUser();
     $template = $request->getStr('template');
     $bare_panel = PhabricatorDashboardPanel::initializeNewPanel($viewer);
     $panel_phids = array();
     switch ($template) {
         case 'simple':
             $v_name = pht('New Simple Dashboard');
             $welcome_panel = $this->newPanel($request, $viewer, 'text', pht('Welcome'), array('text' => pht("This is a simple template dashboard. You can edit this panel " . "to change this text and replace it with a welcome message, or " . "leave this placeholder text as-is to give your dashboard a " . "rustic, authentic feel.\n\n" . "You can drag, remove, add, and edit panels to customize the " . "rest of this dashboard to show the information you want.\n\n" . "To install this dashboard on the home page, use the " . "**Install Dashboard** action link above.")));
             $panel_phids[] = $welcome_panel->getPHID();
             $feed_panel = $this->newPanel($request, $viewer, 'query', pht('Recent Activity'), array('class' => 'PhabricatorFeedSearchEngine', 'key' => 'all'));
             $panel_phids[] = $feed_panel->getPHID();
             $task_panel = $this->newPanel($request, $viewer, 'query', pht('Recent Tasks'), array('class' => 'ManiphestTaskSearchEngine', 'key' => 'all'));
             $panel_phids[] = $task_panel->getPHID();
             $commit_panel = $this->newPanel($request, $viewer, 'query', pht('Recent Commits'), array('class' => 'PhabricatorCommitSearchEngine', 'key' => 'all'));
             $panel_phids[] = $commit_panel->getPHID();
             $mode_2_and_1 = PhabricatorDashboardLayoutConfig::MODE_THIRDS_AND_THIRD;
             $layout = id(new PhabricatorDashboardLayoutConfig())->setLayoutMode($mode_2_and_1)->setPanelLocation(0, $welcome_panel->getPHID())->setPanelLocation(0, $task_panel->getPHID())->setPanelLocation(0, $commit_panel->getPHID())->setPanelLocation(1, $feed_panel->getPHID());
             break;
         default:
             throw new Exception(pht('Unknown dashboard template %s!', $template));
     }
     // Create the dashboard.
     $dashboard = PhabricatorDashboard::initializeNewDashboard($viewer)->setLayoutConfigFromObject($layout);
     $xactions = array();
     $xactions[] = id(new PhabricatorDashboardTransaction())->setTransactionType(PhabricatorDashboardTransaction::TYPE_NAME)->setNewValue($v_name);
     $xactions[] = id(new PhabricatorDashboardTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST)->setNewValue(array('+' => array_fuse($panel_phids)));
     $editor = id(new PhabricatorDashboardTransactionEditor())->setActor($viewer)->setContinueOnNoEffect(true)->setContentSourceFromRequest($request)->applyTransactions($dashboard, $xactions);
     $manage_uri = $this->getApplicationURI('manage/' . $dashboard->getID() . '/');
     return id(new AphrontRedirectResponse())->setURI($manage_uri);
 }
 protected function buildCustomSearchFields()
 {
     return array(id(new PhabricatorSearchCheckboxesField())->setKey('statuses')->setLabel(pht('Status'))->setOptions(PhabricatorDashboard::getStatusNameMap()));
 }
 private function copyPanel(AphrontRequest $request, PhabricatorDashboard $dashboard, PhabricatorDashboardPanel $panel)
 {
     $viewer = $request->getUser();
     $copy = PhabricatorDashboardPanel::initializeNewPanel($viewer);
     $copy = PhabricatorDashboardPanel::copyPanel($copy, $panel);
     $copy->openTransaction();
     $copy->save();
     // TODO: This should record a transaction on the panel copy, too.
     $xactions = array();
     $xactions[] = id(new PhabricatorDashboardTransaction())->setTransactionType(PhabricatorTransactions::TYPE_EDGE)->setMetadataValue('edge:type', PhabricatorDashboardDashboardHasPanelEdgeType::EDGECONST)->setNewValue(array('+' => array($copy->getPHID() => $copy->getPHID()), '-' => array($panel->getPHID() => $panel->getPHID())));
     $layout_config = $dashboard->getLayoutConfigObject();
     $layout_config->replacePanel($panel->getPHID(), $copy->getPHID());
     $dashboard->setLayoutConfigFromObject($layout_config);
     $dashboard->save();
     $editor = id(new PhabricatorDashboardTransactionEditor())->setActor($viewer)->setContentSourceFromRequest($request)->setContinueOnMissingFields(true)->setContinueOnNoEffect(true)->applyTransactions($dashboard, $xactions);
     $copy->saveTransaction();
     return $copy;
 }