Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15379983
D9651.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D9651.id.diff
View Options
diff --git a/src/applications/dashboard/controller/PhabricatorDashboardEditController.php b/src/applications/dashboard/controller/PhabricatorDashboardEditController.php
--- a/src/applications/dashboard/controller/PhabricatorDashboardEditController.php
+++ b/src/applications/dashboard/controller/PhabricatorDashboardEditController.php
@@ -30,6 +30,19 @@
$is_new = false;
} else {
+ if (!$request->getStr('edit')) {
+ if ($request->isFormPost()) {
+ switch ($request->getStr('template')) {
+ case 'empty':
+ break;
+ default:
+ return $this->processBuildTemplateRequest($request);
+ }
+ } else {
+ return $this->processTemplateRequest($request);
+ }
+ }
+
$dashboard = PhabricatorDashboard::initializeNewDashboard($viewer);
$is_new = true;
@@ -61,7 +74,7 @@
$e_name = true;
$validation_exception = null;
- if ($request->isFormPost()) {
+ if ($request->isFormPost() && $request->getStr('edit')) {
$v_name = $request->getStr('name');
$v_layout_mode = $request->getStr('layout_mode');
$v_view_policy = $request->getStr('viewPolicy');
@@ -116,6 +129,7 @@
PhabricatorDashboardLayoutConfig::getLayoutModeSelectOptions();
$form = id(new AphrontFormView())
->setUser($viewer)
+ ->addHiddenInput('edit', true)
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('Name'))
@@ -161,4 +175,172 @@
));
}
+ private function processTemplateRequest(AphrontRequest $request) {
+ $viewer = $request->getUser();
+
+ $template_control = id(new AphrontFormRadioButtonControl())
+ ->setName(pht('template'))
+ ->setValue($request->getStr('template', 'empty'))
+ ->addButton(
+ 'empty',
+ pht('Empty'),
+ pht('Start with a blank canvas.'))
+ ->addButton(
+ 'simple',
+ pht('Simple Template'),
+ pht(
+ 'Start with a simple dashboard with a welcome message, a feed of '.
+ 'recent events, and a few starter panels.'));
+
+ $form = id(new AphrontFormView())
+ ->setUser($viewer)
+ ->appendRemarkupInstructions(
+ pht('Choose a dashboard template to start with.'))
+ ->appendChild($template_control);
+
+ return $this->newDialog()
+ ->setTitle(pht('Create Dashboard'))
+ ->setWidth(AphrontDialogView::WIDTH_FORM)
+ ->appendChild($form->buildLayoutView())
+ ->addCancelButton('/dashboard/')
+ ->addSubmitButton(pht('Continue'));
+ }
+
+ 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',
+ PhabricatorEdgeConfig::TYPE_DASHBOARD_HAS_PANEL)
+ ->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);
+ }
+
+ private function newPanel(
+ AphrontRequest $request,
+ PhabricatorUser $viewer,
+ $type,
+ $name,
+ array $properties) {
+
+ $panel = PhabricatorDashboardPanel::initializeNewPanel($viewer)
+ ->setPanelType($type)
+ ->setProperties($properties);
+
+ $xactions = array();
+
+ $xactions[] = id(new PhabricatorDashboardPanelTransaction())
+ ->setTransactionType(PhabricatorDashboardPanelTransaction::TYPE_NAME)
+ ->setNewValue($name);
+
+ $editor = id(new PhabricatorDashboardPanelTransactionEditor())
+ ->setActor($viewer)
+ ->setContinueOnNoEffect(true)
+ ->setContentSourceFromRequest($request)
+ ->applyTransactions($panel, $xactions);
+
+ return $panel;
+ }
+
+
}
diff --git a/src/applications/dashboard/controller/PhabricatorDashboardManageController.php b/src/applications/dashboard/controller/PhabricatorDashboardManageController.php
--- a/src/applications/dashboard/controller/PhabricatorDashboardManageController.php
+++ b/src/applications/dashboard/controller/PhabricatorDashboardManageController.php
@@ -103,6 +103,12 @@
$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}/"))
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 15, 12:43 AM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7335096
Default Alt Text
D9651.id.diff (7 KB)
Attached To
Mode
D9651: Add a "start with a template" option when creating dashboards
Attached
Detach File
Event Timeline
Log In to Comment