1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 11:30:55 +01:00

Allow Dashboards to set an icon

Summary: Allows users set an icon (for reuse on upcoming home) for their dashboard based on 16 descriminating choices.

Test Plan: Create a new dashboard, set new icon. Edit an existing dashboard, set icon.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D17042
This commit is contained in:
Chad Little 2016-12-13 10:52:19 -08:00
parent c03a412d5c
commit 26127b9c5f
8 changed files with 108 additions and 1 deletions

View file

@ -0,0 +1,5 @@
ALTER TABLE {$NAMESPACE}_dashboard.dashboard
ADD icon VARCHAR(32) NOT NULL;
UPDATE {$NAMESPACE}_dashboard.dashboard
SET icon = 'fa-dashboard';

View file

@ -2426,6 +2426,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardDashboardHasPanelEdgeType' => 'applications/dashboard/edge/PhabricatorDashboardDashboardHasPanelEdgeType.php',
'PhabricatorDashboardDashboardPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardDashboardPHIDType.php',
'PhabricatorDashboardEditController' => 'applications/dashboard/controller/PhabricatorDashboardEditController.php',
'PhabricatorDashboardIconSet' => 'applications/dashboard/icon/PhabricatorDashboardIconSet.php',
'PhabricatorDashboardInstall' => 'applications/dashboard/storage/PhabricatorDashboardInstall.php',
'PhabricatorDashboardInstallController' => 'applications/dashboard/controller/PhabricatorDashboardInstallController.php',
'PhabricatorDashboardLayoutConfig' => 'applications/dashboard/layoutconfig/PhabricatorDashboardLayoutConfig.php',
@ -7364,6 +7365,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardDashboardHasPanelEdgeType' => 'PhabricatorEdgeType',
'PhabricatorDashboardDashboardPHIDType' => 'PhabricatorPHIDType',
'PhabricatorDashboardEditController' => 'PhabricatorDashboardController',
'PhabricatorDashboardIconSet' => 'PhabricatorIconSet',
'PhabricatorDashboardInstall' => 'PhabricatorDashboardDAO',
'PhabricatorDashboardInstallController' => 'PhabricatorDashboardController',
'PhabricatorDashboardLayoutConfig' => 'Phobject',

View file

@ -67,12 +67,14 @@ final class PhabricatorDashboardEditController
}
$v_name = $dashboard->getName();
$v_icon = $dashboard->getIcon();
$v_layout_mode = $dashboard->getLayoutConfigObject()->getLayoutMode();
$e_name = true;
$validation_exception = null;
if ($request->isFormPost() && $request->getStr('edit')) {
$v_name = $request->getStr('name');
$v_icon = $request->getStr('icon');
$v_layout_mode = $request->getStr('layout_mode');
$v_view_policy = $request->getStr('viewPolicy');
$v_edit_policy = $request->getStr('editPolicy');
@ -81,6 +83,7 @@ final class PhabricatorDashboardEditController
$xactions = array();
$type_name = PhabricatorDashboardTransaction::TYPE_NAME;
$type_icon = PhabricatorDashboardTransaction::TYPE_ICON;
$type_layout_mode = PhabricatorDashboardTransaction::TYPE_LAYOUT_MODE;
$type_view_policy = PhabricatorTransactions::TYPE_VIEW_POLICY;
$type_edit_policy = PhabricatorTransactions::TYPE_EDIT_POLICY;
@ -91,6 +94,9 @@ final class PhabricatorDashboardEditController
$xactions[] = id(new PhabricatorDashboardTransaction())
->setTransactionType($type_layout_mode)
->setNewValue($v_layout_mode);
$xactions[] = id(new PhabricatorDashboardTransaction())
->setTransactionType($type_icon)
->setNewValue($v_icon);
$xactions[] = id(new PhabricatorDashboardTransaction())
->setTransactionType($type_view_policy)
->setNewValue($v_view_policy);
@ -146,6 +152,12 @@ final class PhabricatorDashboardEditController
->setName('layout_mode')
->setValue($v_layout_mode)
->setOptions($layout_mode_options))
->appendChild(
id(new PHUIFormIconSetControl())
->setLabel(pht('Icon'))
->setName('icon')
->setIconSet(new PhabricatorDashboardIconSet())
->setValue($v_icon))
->appendChild(
id(new AphrontFormPolicyControl())
->setName('viewPolicy')

View file

@ -109,7 +109,7 @@ final class PhabricatorDashboardManageController
->setHeader($dashboard->getName())
->setPolicyObject($dashboard)
->setStatus($status_icon, $status_color, $status_name)
->setHeaderIcon('fa-dashboard')
->setHeaderIcon($dashboard->getIcon())
->addActionLink($button);
}

View file

@ -51,6 +51,7 @@ final class PhabricatorDashboardTransactionEditor
$types[] = PhabricatorTransactions::TYPE_EDGE;
$types[] = PhabricatorDashboardTransaction::TYPE_NAME;
$types[] = PhabricatorDashboardTransaction::TYPE_ICON;
$types[] = PhabricatorDashboardTransaction::TYPE_STATUS;
$types[] = PhabricatorDashboardTransaction::TYPE_LAYOUT_MODE;
@ -66,6 +67,11 @@ final class PhabricatorDashboardTransactionEditor
return null;
}
return $object->getName();
case PhabricatorDashboardTransaction::TYPE_ICON:
if ($this->getIsNewObject()) {
return null;
}
return $object->getIcon();
case PhabricatorDashboardTransaction::TYPE_STATUS:
if ($this->getIsNewObject()) {
return null;
@ -87,6 +93,7 @@ final class PhabricatorDashboardTransactionEditor
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorDashboardTransaction::TYPE_NAME:
case PhabricatorDashboardTransaction::TYPE_ICON:
case PhabricatorDashboardTransaction::TYPE_STATUS:
case PhabricatorDashboardTransaction::TYPE_LAYOUT_MODE:
return $xaction->getNewValue();
@ -101,6 +108,9 @@ final class PhabricatorDashboardTransactionEditor
case PhabricatorDashboardTransaction::TYPE_NAME:
$object->setName($xaction->getNewValue());
return;
case PhabricatorDashboardTransaction::TYPE_ICON:
$object->setIcon($xaction->getNewValue());
return;
case PhabricatorDashboardTransaction::TYPE_STATUS:
$object->setStatus($xaction->getNewValue());
return;
@ -130,6 +140,7 @@ final class PhabricatorDashboardTransactionEditor
switch ($xaction->getTransactionType()) {
case PhabricatorDashboardTransaction::TYPE_NAME:
case PhabricatorDashboardTransaction::TYPE_ICON:
case PhabricatorDashboardTransaction::TYPE_STATUS:
case PhabricatorDashboardTransaction::TYPE_LAYOUT_MODE:
return;

View file

@ -0,0 +1,45 @@
<?php
final class PhabricatorDashboardIconSet
extends PhabricatorIconSet {
const ICONSETKEY = 'dashboards';
public function getSelectIconTitleText() {
return pht('Choose Dashboard Icon');
}
protected function newIcons() {
$map = array(
'fa-home' => pht('Home'),
'fa-th-large' => pht('Blocks'),
'fa-columns' => pht('Columns'),
'fa-bookmark' => pht('Page Saver'),
'fa-book' => pht('Knowledge'),
'fa-bomb' => pht('Kaboom'),
'fa-pie-chart' => pht('Apple Blueberry'),
'fa-bar-chart' => pht('Serious Business'),
'fa-bell' => pht('Ding Ding'),
'fa-credit-card' => pht('Plastic Debt'),
'fa-code' => pht('PHP is Life'),
'fa-sticky-note' => pht('To Self'),
'fa-newspaper-o' => pht('Stay Woke'),
'fa-server' => pht('Metallica'),
'fa-hashtag' => pht('Corned Beef'),
'fa-group' => pht('Triplets'),
);
$icons = array();
foreach ($map as $key => $label) {
$icons[] = id(new PhabricatorIconSetIcon())
->setKey($key)
->setLabel($label);
}
return $icons;
}
}

View file

@ -16,6 +16,7 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO
protected $viewPolicy;
protected $editPolicy;
protected $status;
protected $icon;
protected $layoutConfig = array();
const STATUS_ACTIVE = 'active';
@ -29,6 +30,7 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO
public static function initializeNewDashboard(PhabricatorUser $actor) {
return id(new PhabricatorDashboard())
->setName('')
->setIcon('fa-dashboard')
->setViewPolicy(PhabricatorPolicies::POLICY_USER)
->setEditPolicy($actor->getPHID())
->setStatus(self::STATUS_ACTIVE)
@ -63,6 +65,7 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text255',
'status' => 'text32',
'icon' => 'text32',
'authorPHID' => 'phid',
),
) + parent::getConfiguration();

View file

@ -4,6 +4,7 @@ final class PhabricatorDashboardTransaction
extends PhabricatorApplicationTransaction {
const TYPE_NAME = 'dashboard:name';
const TYPE_ICON = 'dashboard:icon';
const TYPE_STATUS = 'dashboard:status';
const TYPE_LAYOUT_MODE = 'dashboard:layoutmode';
@ -39,6 +40,19 @@ final class PhabricatorDashboardTransaction
$new);
}
break;
case self::TYPE_ICON:
if (!strlen($old)) {
return pht(
'%s set the dashboard icon.',
$author_link);
} else {
return pht(
'%s changed this dashboard icon from "%s" to "%s".',
$author_link,
$old,
$new);
}
break;
case self::TYPE_STATUS:
if ($new == PhabricatorDashboard::STATUS_ACTIVE) {
return pht(
@ -82,6 +96,21 @@ final class PhabricatorDashboardTransaction
$new);
}
break;
case self::TYPE_ICON:
if (!strlen($old)) {
return pht(
'%s set dashboard icon for %s.',
$author_link,
$object_link);
} else {
return pht(
'%s set the dashboard icon on %s from "%s" to "%s".',
$author_link,
$object_link,
$old,
$new);
}
break;
case self::TYPE_STATUS:
if ($new == PhabricatorDashboard::STATUS_ACTIVE) {
return pht(