Split dashboard into widgets. Add build errors widget.
This commit is contained in:
parent
257aabc113
commit
11f58d7c2b
24 changed files with 793 additions and 328 deletions
|
|
@ -368,20 +368,4 @@ class BuildController extends Controller
|
|||
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function ajaxTimeline()
|
||||
{
|
||||
$builds = $this->buildStore->getLatestBuilds(null, 10);
|
||||
foreach ($builds as &$build) {
|
||||
$build = BuildFactory::getBuild($build);
|
||||
}
|
||||
|
||||
$view = new b8\View('Home/ajax-timeline');
|
||||
$view->builds = $builds;
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($view->render());
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,120 +3,40 @@
|
|||
namespace PHPCensor\Controller;
|
||||
|
||||
use b8;
|
||||
use PHPCensor\BuildFactory;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Controller;
|
||||
|
||||
/**
|
||||
* Home Controller - Displays the Dashboard.
|
||||
*
|
||||
* @author Dan Cryer <dan@block8.co.uk>
|
||||
*/
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Store\BuildStore
|
||||
*/
|
||||
protected $buildStore;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Store\ProjectStore
|
||||
*/
|
||||
protected $projectStore;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Store\ProjectGroupStore
|
||||
*/
|
||||
protected $groupStore;
|
||||
|
||||
/**
|
||||
* Initialise the controller, set up stores and services.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->buildStore = b8\Store\Factory::getStore('Build');
|
||||
$this->projectStore = b8\Store\Factory::getStore('Project');
|
||||
$this->groupStore = b8\Store\Factory::getStore('ProjectGroup');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display dashboard:
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->layout->title = Lang::get('dashboard');
|
||||
$builds = $this->buildStore->getLatestBuilds(null, 10);
|
||||
|
||||
foreach ($builds as &$build) {
|
||||
$build = BuildFactory::getBuild($build);
|
||||
$widgets = [
|
||||
'left' => [],
|
||||
'right' => [],
|
||||
];
|
||||
$widgets_config = b8\Config::getInstance()->get('php-censor.dashboard_widgets', [
|
||||
'all_projects' => [
|
||||
'side' => 'left',
|
||||
],
|
||||
'last_builds' => [
|
||||
'side' => 'right',
|
||||
],
|
||||
]);
|
||||
foreach($widgets_config as $name => $params) {
|
||||
$side = (isset($params['side']) and ($params['side'] == 'right')) ? 'right' : 'left';
|
||||
$widgets[$side][$name] = $params;
|
||||
}
|
||||
|
||||
$this->view->builds = $builds;
|
||||
$this->view->groups = $this->getGroupInfo();
|
||||
$this->view->widgets = $widgets;
|
||||
|
||||
return $this->view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the HTML for the project overview section of the dashboard.
|
||||
* @param $projects
|
||||
* @return string
|
||||
*/
|
||||
protected function getSummaryHtml($projects)
|
||||
{
|
||||
$summaryBuilds = [];
|
||||
$successes = [];
|
||||
$failures = [];
|
||||
$counts = [];
|
||||
|
||||
foreach ($projects as $project) {
|
||||
$summaryBuilds[$project->getId()] = $this->buildStore->getLatestBuilds($project->getId());
|
||||
|
||||
$count = $this->buildStore->getWhere(
|
||||
['project_id' => $project->getId()],
|
||||
1,
|
||||
0,
|
||||
[],
|
||||
['id' => 'DESC']
|
||||
);
|
||||
$counts[$project->getId()] = $count['count'];
|
||||
|
||||
$success = $this->buildStore->getLastBuildByStatus($project->getId(), Build::STATUS_SUCCESS);
|
||||
$failure = $this->buildStore->getLastBuildByStatus($project->getId(), Build::STATUS_FAILED);
|
||||
|
||||
$successes[$project->getId()] = $success;
|
||||
$failures[$project->getId()] = $failure;
|
||||
}
|
||||
|
||||
$view = new b8\View('Home/dashboard-projects');
|
||||
$view->projects = $projects;
|
||||
$view->builds = $summaryBuilds;
|
||||
$view->successful = $successes;
|
||||
$view->failed = $failures;
|
||||
$view->counts = $counts;
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a summary of the project groups we have, and what projects they have in them.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getGroupInfo()
|
||||
{
|
||||
$rtn = [];
|
||||
$groups = $this->groupStore->getWhere([], 100, 0, [], ['title' => 'ASC']);
|
||||
|
||||
foreach ($groups['items'] as $group) {
|
||||
$thisGroup = ['title' => $group->getTitle()];
|
||||
$projects = $this->projectStore->getByGroupId($group->getId(), false);
|
||||
$thisGroup['projects'] = $projects['items'];
|
||||
$thisGroup['summary'] = $this->getSummaryHtml($thisGroup['projects']);
|
||||
$rtn[] = $thisGroup;
|
||||
}
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -287,35 +287,6 @@ class ProjectController extends PHPCensor\Controller
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Render latest builds for project as HTML table.
|
||||
*
|
||||
* @param int $projectId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getDashboardProjectHtml($projectId)
|
||||
{
|
||||
$count = $this->buildStore->getWhere(
|
||||
['project_id' => $projectId],
|
||||
1,
|
||||
0,
|
||||
[],
|
||||
['id' => 'DESC']
|
||||
);
|
||||
$counts = $count['count'];
|
||||
|
||||
$view = new b8\View('Home/ajax-dashboard-project');
|
||||
|
||||
$view->project = $this->projectStore->getById($projectId);
|
||||
$view->builds = $this->buildStore->getLatestBuilds($projectId);
|
||||
$view->successful = $this->buildStore->getLastBuildByStatus($projectId, PHPCensor\Model\Build::STATUS_SUCCESS);
|
||||
$view->failed = $this->buildStore->getLastBuildByStatus($projectId, PHPCensor\Model\Build::STATUS_FAILED);
|
||||
$view->counts = $counts;
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new project. Handles both the form, and processing.
|
||||
*/
|
||||
|
|
@ -605,21 +576,6 @@ class ProjectController extends PHPCensor\Controller
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $projectId
|
||||
*
|
||||
* @return b8\Http\Response
|
||||
*/
|
||||
public function ajaxDashboardProject($projectId)
|
||||
{
|
||||
$builds = $this->getDashboardProjectHtml($projectId);
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($builds);
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of repositories from Github's API.
|
||||
*/
|
||||
|
|
|
|||
143
src/PHPCensor/Controller/WidgetAllProjectsController.php
Normal file
143
src/PHPCensor/Controller/WidgetAllProjectsController.php
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Controller;
|
||||
|
||||
use b8;
|
||||
use PHPCensor\BuildFactory;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Controller;
|
||||
|
||||
/**
|
||||
* Widget All Projects Controller
|
||||
*/
|
||||
class WidgetAllProjectsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Store\BuildStore
|
||||
*/
|
||||
protected $buildStore;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Store\ProjectStore
|
||||
*/
|
||||
protected $projectStore;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Store\ProjectGroupStore
|
||||
*/
|
||||
protected $groupStore;
|
||||
|
||||
/**
|
||||
* Initialise the controller, set up stores and services.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->buildStore = b8\Store\Factory::getStore('Build');
|
||||
$this->projectStore = b8\Store\Factory::getStore('Project');
|
||||
$this->groupStore = b8\Store\Factory::getStore('ProjectGroup');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display dashboard:
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$this->view->groups = $this->getGroupInfo();
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($this->view->render());
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the HTML for the project overview section of the dashboard.
|
||||
* @param $projects
|
||||
* @return string
|
||||
*/
|
||||
protected function getSummaryHtml($projects)
|
||||
{
|
||||
$summaryBuilds = [];
|
||||
$successes = [];
|
||||
$failures = [];
|
||||
$counts = [];
|
||||
|
||||
foreach ($projects as $project) {
|
||||
$summaryBuilds[$project->getId()] = $this->buildStore->getLatestBuilds($project->getId());
|
||||
|
||||
$count = $this->buildStore->getWhere(
|
||||
['project_id' => $project->getId()],
|
||||
1,
|
||||
0,
|
||||
[],
|
||||
['id' => 'DESC']
|
||||
);
|
||||
$counts[$project->getId()] = $count['count'];
|
||||
|
||||
$success = $this->buildStore->getLastBuildByStatus($project->getId(), Build::STATUS_SUCCESS);
|
||||
$failure = $this->buildStore->getLastBuildByStatus($project->getId(), Build::STATUS_FAILED);
|
||||
|
||||
$successes[$project->getId()] = $success;
|
||||
$failures[$project->getId()] = $failure;
|
||||
}
|
||||
|
||||
$view = new b8\View('WidgetAllProjects/index-projects');
|
||||
$view->projects = $projects;
|
||||
$view->builds = $summaryBuilds;
|
||||
$view->successful = $successes;
|
||||
$view->failed = $failures;
|
||||
$view->counts = $counts;
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a summary of the project groups we have, and what projects they have in them.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getGroupInfo()
|
||||
{
|
||||
$rtn = [];
|
||||
$groups = $this->groupStore->getWhere([], 100, 0, [], ['title' => 'ASC']);
|
||||
|
||||
foreach ($groups['items'] as $group) {
|
||||
$thisGroup = ['title' => $group->getTitle()];
|
||||
$projects = $this->projectStore->getByGroupId($group->getId(), false);
|
||||
$thisGroup['projects'] = $projects['items'];
|
||||
$thisGroup['summary'] = $this->getSummaryHtml($thisGroup['projects']);
|
||||
$rtn[] = $thisGroup;
|
||||
}
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $projectId
|
||||
*
|
||||
* @return b8\Http\Response
|
||||
*/
|
||||
public function update($projectId)
|
||||
{
|
||||
$count = $this->buildStore->getWhere(
|
||||
['project_id' => $projectId],
|
||||
1,
|
||||
0,
|
||||
[],
|
||||
['id' => 'DESC']
|
||||
);
|
||||
$counts = $count['count'];
|
||||
|
||||
$this->view->project = $this->projectStore->getById($projectId);
|
||||
$this->view->builds = $this->buildStore->getLatestBuilds($projectId);
|
||||
$this->view->successful = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_SUCCESS);
|
||||
$this->view->failed = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_FAILED);
|
||||
$this->view->counts = $counts;
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($this->view->render());
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
}
|
||||
83
src/PHPCensor/Controller/WidgetBuildErrorsController.php
Normal file
83
src/PHPCensor/Controller/WidgetBuildErrorsController.php
Normal file
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Controller;
|
||||
|
||||
use b8;
|
||||
use PHPCensor\BuildFactory;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Controller;
|
||||
|
||||
/**
|
||||
* Widget Build Errors Controller
|
||||
*/
|
||||
class WidgetBuildErrorsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Store\BuildStore
|
||||
*/
|
||||
protected $buildStore;
|
||||
|
||||
/**
|
||||
* @var \PHPCensor\Store\ProjectStore
|
||||
*/
|
||||
protected $projectStore;
|
||||
|
||||
/**
|
||||
* Initialise the controller, set up stores and services.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->buildStore = b8\Store\Factory::getStore('Build');
|
||||
$this->projectStore = b8\Store\Factory::getStore('Project');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display dashboard:
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$view = new b8\View('WidgetBuildErrors/update');
|
||||
$this->view->projects = $this->renderAllProjectsLatestBuilds($view);
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($this->view->render());
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return b8\Http\Response
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($this->renderAllProjectsLatestBuilds($this->view));
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b8\View $view
|
||||
* @return string
|
||||
*/
|
||||
protected function renderAllProjectsLatestBuilds($view)
|
||||
{
|
||||
$builds = $this->buildStore->getAllProjectsLatestBuilds();
|
||||
|
||||
$view->builds = $builds['projects'];
|
||||
$projects = $this->projectStore->getByIds(array_keys($builds['projects']));
|
||||
|
||||
$view_projects = [];
|
||||
foreach($projects as $id => $project) {
|
||||
if (!$project->getArchived()) {
|
||||
$view_projects[$id] = $project;
|
||||
} else {
|
||||
unset($builds['projects'][$id]);
|
||||
}
|
||||
}
|
||||
$view->projects = $view_projects;
|
||||
|
||||
return $view->render();
|
||||
}
|
||||
}
|
||||
66
src/PHPCensor/Controller/WidgetLastBuildsController.php
Normal file
66
src/PHPCensor/Controller/WidgetLastBuildsController.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCensor\Controller;
|
||||
|
||||
use b8;
|
||||
use PHPCensor\BuildFactory;
|
||||
use PHPCensor\Helper\Lang;
|
||||
use PHPCensor\Model\Build;
|
||||
use PHPCensor\Controller;
|
||||
|
||||
/**
|
||||
* Widget Last Builds Controller
|
||||
*/
|
||||
class WidgetLastBuildsController extends Controller
|
||||
{
|
||||
/**
|
||||
* @var \PHPCensor\Store\BuildStore
|
||||
*/
|
||||
protected $buildStore;
|
||||
|
||||
/**
|
||||
* Initialise the controller, set up stores and services.
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->buildStore = b8\Store\Factory::getStore('Build');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display dashboard:
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$builds = $this->buildStore->getLatestBuilds(null, 10);
|
||||
|
||||
foreach ($builds as &$build) {
|
||||
$build = BuildFactory::getBuild($build);
|
||||
}
|
||||
|
||||
$view = new b8\View('WidgetLastBuilds/update');
|
||||
$view->builds = $builds;
|
||||
|
||||
$this->view->timeline = $view->render();
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($this->view->render());
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
$builds = $this->buildStore->getLatestBuilds(null, 10);
|
||||
|
||||
foreach ($builds as &$build) {
|
||||
$build = BuildFactory::getBuild($build);
|
||||
}
|
||||
|
||||
$this->view->builds = $builds;
|
||||
|
||||
$this->response->disableLayout();
|
||||
$this->response->setContent($this->view->render());
|
||||
|
||||
return $this->response;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue