1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Add a "Reports" menu item to Projects

Summary:
Ref T13279. Since the use cases that have made it upstream are all for relatively complex charts (e.g., requiring aggregation and composition of multiple data series in nontrivial ways) I'm currently looking at an overall approach like this:

  - At least for now, Charts provides a low-level internal-only API for composing charts from raw datasets.
  - This is exposed to users through pre-built `SearchEngine`-like interfaces that provide a small number of more manageable controls (show chart from date X to date Y, show projects A, B, C), but not the full set of composition features (`compose(scale(2), cos())` and such).
  - Eventually, we may put more UI on the raw chart composition stuff and let you build your own fully custom charts by gluing together datasets and functions.
  - Or we may add this stuff in piecemeal to the higher-level UI as tools like "add goal line" or "add trend line" or whatever.

This will let the low-level API mature/evolve a bit before users get hold of it directly, if they ever do. Most requests today are likely satisfiable with a small number of chart engines plus raw API data access, so maybe UI access to flexible charting is far away.

Step toward this by adding a "Reports" section to projects. For now, this just renders a basic burnup for the current project. Followups will add an "Engine" layer above this and make the chart it produces more useful.

Test Plan: {F6426984}

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13279

Differential Revision: https://secure.phabricator.com/D20495
This commit is contained in:
epriestley 2019-05-03 11:44:05 -07:00
parent f87c1ac362
commit 0aee3da19e
6 changed files with 191 additions and 0 deletions

View file

@ -4245,6 +4245,8 @@ phutil_register_library_map(array(
'PhabricatorProjectProjectPHIDType' => 'applications/project/phid/PhabricatorProjectProjectPHIDType.php',
'PhabricatorProjectQuery' => 'applications/project/query/PhabricatorProjectQuery.php',
'PhabricatorProjectRemoveHeraldAction' => 'applications/project/herald/PhabricatorProjectRemoveHeraldAction.php',
'PhabricatorProjectReportsController' => 'applications/project/controller/PhabricatorProjectReportsController.php',
'PhabricatorProjectReportsProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectReportsProfileMenuItem.php',
'PhabricatorProjectSchemaSpec' => 'applications/project/storage/PhabricatorProjectSchemaSpec.php',
'PhabricatorProjectSearchEngine' => 'applications/project/query/PhabricatorProjectSearchEngine.php',
'PhabricatorProjectSearchField' => 'applications/project/searchfield/PhabricatorProjectSearchField.php',
@ -10496,6 +10498,8 @@ phutil_register_library_map(array(
'PhabricatorProjectProjectPHIDType' => 'PhabricatorPHIDType',
'PhabricatorProjectQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorProjectRemoveHeraldAction' => 'PhabricatorProjectHeraldAction',
'PhabricatorProjectReportsController' => 'PhabricatorProjectController',
'PhabricatorProjectReportsProfileMenuItem' => 'PhabricatorProfileMenuItem',
'PhabricatorProjectSchemaSpec' => 'PhabricatorConfigSchemaSpec',
'PhabricatorProjectSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhabricatorProjectSearchField' => 'PhabricatorSearchTokenizerField',

View file

@ -71,6 +71,8 @@ final class PhabricatorProjectApplication extends PhabricatorApplication {
=> 'PhabricatorProjectBoardViewController',
'move/(?P<id>[1-9]\d*)/' => 'PhabricatorProjectMoveController',
'cover/' => 'PhabricatorProjectCoverController',
'reports/(?P<projectID>[1-9]\d*)/' =>
'PhabricatorProjectReportsController',
'board/(?P<projectID>[1-9]\d*)/' => array(
'edit/(?:(?P<id>\d+)/)?'
=> 'PhabricatorProjectColumnEditController',

View file

@ -0,0 +1,96 @@
<?php
final class PhabricatorProjectReportsController
extends PhabricatorProjectController {
public function shouldAllowPublic() {
return true;
}
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$response = $this->loadProject();
if ($response) {
return $response;
}
$project = $this->getProject();
$id = $project->getID();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$project,
PhabricatorPolicyCapability::CAN_EDIT);
$nav = $this->newNavigation(
$project,
PhabricatorProject::ITEM_REPORTS);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Reports'));
$crumbs->setBorder(true);
$project_phid = $project->getPHID();
$argv = array(
'sum',
array(
'accumulate',
array('fact', 'tasks.open-count.create.project', $project_phid),
),
array(
'accumulate',
array('fact', 'tasks.open-count.status.project', $project_phid),
),
array(
'accumulate',
array('fact', 'tasks.open-count.assign.project', $project_phid),
),
);
$function = id(new PhabricatorComposeChartFunction())
->setArguments(array($argv));
$datasets = array(
id(new PhabricatorChartDataset())
->setFunction($function),
);
$chart = id(new PhabricatorFactChart())
->setDatasets($datasets);
$engine = id(new PhabricatorChartEngine())
->setViewer($viewer)
->setChart($chart);
$chart = $engine->getStoredChart();
$panel_type = id(new PhabricatorDashboardChartPanelType())
->getPanelTypeKey();
$chart_panel = id(new PhabricatorDashboardPanel())
->setPanelType($panel_type)
->setName(pht('%s: Burndown', $project->getName()))
->setProperty('chartKey', $chart->getChartKey());
$chart_view = id(new PhabricatorDashboardPanelRenderingEngine())
->setViewer($viewer)
->setPanel($chart_panel)
->setParentPanelPHIDs(array())
->renderPanel();
$view = id(new PHUITwoColumnView())
->setFooter(
array(
$chart_view,
));
return $this->newPage()
->setNavigation($nav)
->setCrumbs($crumbs)
->setTitle(array($project->getName(), pht('Reports')))
->appendChild($view);
}
}

View file

@ -37,6 +37,10 @@ final class PhabricatorProjectProfileMenuEngine
->setBuiltinKey(PhabricatorProject::ITEM_WORKBOARD)
->setMenuItemKey(PhabricatorProjectWorkboardProfileMenuItem::MENUITEMKEY);
$items[] = $this->newItem()
->setBuiltinKey(PhabricatorProject::ITEM_REPORTS)
->setMenuItemKey(PhabricatorProjectReportsProfileMenuItem::MENUITEMKEY);
$items[] = $this->newItem()
->setBuiltinKey(PhabricatorProject::ITEM_MEMBERS)
->setMenuItemKey(PhabricatorProjectMembersProfileMenuItem::MENUITEMKEY);

View file

@ -0,0 +1,80 @@
<?php
final class PhabricatorProjectReportsProfileMenuItem
extends PhabricatorProfileMenuItem {
const MENUITEMKEY = 'project.reports';
public function getMenuItemTypeName() {
return pht('Project Reports');
}
private function getDefaultName() {
return pht('Reports (Prototype)');
}
public function getMenuItemTypeIcon() {
return 'fa-area-chart';
}
public function canMakeDefault(
PhabricatorProfileMenuItemConfiguration $config) {
return true;
}
public function shouldEnableForObject($object) {
$viewer = $this->getViewer();
if (!PhabricatorEnv::getEnvConfig('phabricator.show-prototypes')) {
return false;
}
$class = 'PhabricatorManiphestApplication';
if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) {
return false;
}
return true;
}
public function getDisplayName(
PhabricatorProfileMenuItemConfiguration $config) {
$name = $config->getMenuItemProperty('name');
if (strlen($name)) {
return $name;
}
return $this->getDefaultName();
}
public function buildEditEngineFields(
PhabricatorProfileMenuItemConfiguration $config) {
return array(
id(new PhabricatorTextEditField())
->setKey('name')
->setLabel(pht('Name'))
->setPlaceholder($this->getDefaultName())
->setValue($config->getMenuItemProperty('name')),
);
}
protected function newMenuItemViewList(
PhabricatorProfileMenuItemConfiguration $config) {
$project = $config->getProfileObject();
$id = $project->getID();
$uri = $project->getReportsURI();
$name = $this->getDisplayName($config);
$item = $this->newItemView()
->setURI($uri)
->setName($name)
->setIcon('fa-area-chart');
return array(
$item,
);
}
}

View file

@ -58,6 +58,7 @@ final class PhabricatorProject extends PhabricatorProjectDAO
const ITEM_PROFILE = 'project.profile';
const ITEM_POINTS = 'project.points';
const ITEM_WORKBOARD = 'project.workboard';
const ITEM_REPORTS = 'project.reports';
const ITEM_MEMBERS = 'project.members';
const ITEM_MANAGE = 'project.manage';
const ITEM_MILESTONES = 'project.milestones';
@ -396,6 +397,10 @@ final class PhabricatorProject extends PhabricatorProjectDAO
return urisprintf('/project/board/%d/', $this->getID());
}
public function getReportsURI() {
return urisprintf('/project/reports/%d/', $this->getID());
}
public function save() {
if (!$this->getMailKey()) {
$this->setMailKey(Filesystem::readRandomCharacters(20));