Skip to content
This repository has been archived by the owner on Feb 15, 2025. It is now read-only.

Commit

Permalink
Front-End Upgrade: New UI Based on Admin LTE.
Browse files Browse the repository at this point in the history
Closes #673
  • Loading branch information
Dan Cryer committed Dec 3, 2014
1 parent 4870dc0 commit 9eeaabc
Show file tree
Hide file tree
Showing 364 changed files with 51,722 additions and 987 deletions.
31 changes: 22 additions & 9 deletions PHPCI/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use b8\Http\Response;
use b8\Http\Response\RedirectResponse;
use b8\View;
use PHPCI\Model\Build;

/**
* PHPCI Front Controller
Expand Down Expand Up @@ -91,18 +92,30 @@ public function handleRequest()
$this->response->setContent($view->render());
}

if (View::exists('layout') && $this->response->hasLayout()) {
$view = new View('layout');
$pageTitle = $this->config->get('page_title', null);
if ($this->response->hasLayout()) {
$this->setLayoutVariables($this->controller->layout);

if (!is_null($pageTitle)) {
$view->title = $pageTitle;
}

$view->content = $this->response->getContent();
$this->response->setContent($view->render());
$this->controller->layout->content = $this->response->getContent();
$this->response->setContent($this->controller->layout->render());
}

return $this->response;
}

protected function loadController($class)
{
$controller = parent::loadController($class);
$controller->layout = new View('layout');
$controller->layout->title = 'PHPCI';
$controller->layout->breadcrumb = array();

return $controller;
}

protected function setLayoutVariables(View &$layout)
{
/** @var \PHPCI\Store\ProjectStore $projectStore */
$projectStore = b8\Store\Factory::getStore('Project');
$layout->projects = $projectStore->getAll();
}
}
1 change: 1 addition & 0 deletions PHPCI/Command/DaemoniseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->sleep = 0;
$runner = new RunCommand($this->logger);
$runner->setMaxBuilds(1);
$runner->setIsDaemon(true);

$emptyInput = new ArgvInput(array());

Expand Down
27 changes: 21 additions & 6 deletions PHPCI/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ class RunCommand extends Command
*/
protected $maxBuilds = null;

/**
* @var bool
*/
protected $isFromDaemon = false;

/**
* @param \Monolog\Logger $logger
* @param string $name
Expand All @@ -62,8 +67,7 @@ protected function configure()
{
$this
->setName('phpci:run-builds')
->setDescription('Run all pending PHPCI builds.')
->addOption('verbose', 'v', InputOption::VALUE_NONE);
->setDescription('Run all pending PHPCI builds.');
}

/**
Expand All @@ -75,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

// For verbose mode we want to output all informational and above
// messages to the symphony output interface.
if ($input->getOption('verbose')) {
if ($input->hasOption('verbose') && $input->getOption('verbose')) {
$this->logger->pushHandler(
new OutputLogHandler($this->output, Logger::INFO)
);
Expand All @@ -91,13 +95,17 @@ protected function execute(InputInterface $input, OutputInterface $output)

$builds = 0;

foreach ($result['items'] as $build) {

while (count($result['items'])) {
$build = array_shift($result['items']);
$build = BuildFactory::getBuild($build);

// Skip build (for now) if there's already a build running in that project:
if (in_array($build->getProjectId(), $running)) {
if (!$this->isFromDaemon && in_array($build->getProjectId(), $running)) {
$this->logger->addInfo('Skipping Build #'.$build->getId() . ' - Project build already in progress.');
$result['items'][] = $build;

// Re-run build validator:
$running = $this->validateRunningBuilds();
continue;
}

Expand All @@ -117,6 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->logger->popHandler($buildDbLog);
} catch (\Exception $ex) {
$build->setStatus(Build::STATUS_FAILED);
$build->setFinished(new \DateTime());
$build->setLog($build->getLog() . PHP_EOL . PHP_EOL . $ex->getMessage());
$store->save($build);
}
Expand All @@ -133,6 +142,11 @@ public function setMaxBuilds($numBuilds)
$this->maxBuilds = (int)$numBuilds;
}

public function setIsDaemon($fromDaemon)
{
$this->isFromDaemon = (bool)$fromDaemon;
}

protected function validateRunningBuilds()
{
/** @var \PHPCI\Store\BuildStore $store */
Expand All @@ -152,6 +166,7 @@ protected function validateRunningBuilds()
if (($now - $start) > $timeout) {
$this->logger->addInfo('Build #'.$build->getId().' marked as failed due to timeout.');
$build->setStatus(Build::STATUS_FAILED);
$build->setFinished(new \DateTime());
$store->save($build);
$this->removeBuildDirectory($build);
continue;
Expand Down
15 changes: 14 additions & 1 deletion PHPCI/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,23 @@ public function handleAction($action, $actionParams)
return $this->response;
}

/**
* Require that the currently logged in user is an administrator.
* @throws ForbiddenException
*/
protected function requireAdmin()
{
if (!$_SESSION['phpci_user']->getIsAdmin()) {
if (!$this->currentUserIsAdmin()) {
throw new ForbiddenException('You do not have permission to do that.');
}
}

/**
* Check if the currently logged in user is an administrator.
* @return bool
*/
protected function currentUserIsAdmin()
{
return $_SESSION['phpci_user']->getIsAdmin();
}
}
55 changes: 50 additions & 5 deletions PHPCI/Controller/BuildController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use b8\Exception\HttpException\NotFoundException;
use PHPCI\BuildFactory;
use PHPCI\Model\Build;
use PHPCI\Model\Project;
use PHPCI\Service\BuildService;

/**
Expand Down Expand Up @@ -58,8 +59,22 @@ public function view($buildId)
$this->view->build = $build;
$this->view->data = $this->getBuildData($build);

$title = 'Build #' . $build->getId() . ' - ' . $build->getProjectTitle();
$this->config->set('page_title', $title);
$this->layout->title = 'Build #' . $build->getId();
$this->layout->subtitle = $build->getProjectTitle();

$nav = array(
'title' => 'Build '.$build->getId(),
'icon' => 'cog',
'links' => array(
'build/rebuild/' . $build->getId() => 'Rebuild Now',
),
);

if ($this->currentUserIsAdmin()) {
$nav['links']['build/delete/' . $build->getId()] = 'Delete Build';
}

$this->layout->nav = $nav;
}

protected function getUiPlugins()
Expand Down Expand Up @@ -141,9 +156,7 @@ public function rebuild($buildId)
*/
public function delete($buildId)
{
if (empty($_SESSION['phpci_user']) || !$_SESSION['phpci_user']->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.');
}
$this->requireAdmin();

$build = BuildFactory::getBuildById($buildId);

Expand All @@ -168,4 +181,36 @@ protected function cleanLog($log)

return $log;
}

public function latest()
{
$rtn = array(
'pending' => $this->formatBuilds($this->buildStore->getByStatus(Build::STATUS_NEW)),
'running' => $this->formatBuilds($this->buildStore->getByStatus(Build::STATUS_RUNNING)),
);

if ($this->request->isAjax()) {
die(json_encode($rtn));
}
}

protected function formatBuilds($builds)
{
Project::$sleepable = array('id', 'title', 'reference', 'type');

$rtn = array('count' => $builds['count'], 'items' => array());

foreach ($builds['items'] as $build) {
$item = $build->toArray(1);

$header = new b8\View('Build/header-row');
$header->build = $build;

$item['header_row'] = $header->render();
$rtn['items'][$item['id']] = $item;
}

ksort($rtn['items']);
return $rtn;
}
}
24 changes: 21 additions & 3 deletions PHPCI/Controller/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use b8;
use PHPCI\BuildFactory;
use PHPCI\Model\Build;

/**
* Home Controller - Displays the PHPCI Dashboard.
Expand Down Expand Up @@ -41,14 +42,20 @@ public function init()
*/
public function index()
{
$this->layout->title = 'Dashboard';

$projects = $this->projectStore->getWhere(array(), 50, 0, array(), array('title' => 'ASC'));

$this->view->builds = $this->getLatestBuildsHtml();
$builds = $this->buildStore->getLatestBuilds(null, 10);

foreach ($builds as &$build) {
$build = BuildFactory::getBuild($build);
}

$this->view->builds = $builds;
$this->view->projects = $projects['items'];
$this->view->summary = $this->getSummaryHtml($projects);

$this->config->set('page_title', 'Dashboard');

return $this->view->render();
}

Expand All @@ -69,13 +76,24 @@ public function summary()
protected function getSummaryHtml($projects)
{
$summaryBuilds = array();
$successes = array();
$failures = array();

foreach ($projects['items'] as $project) {
$summaryBuilds[$project->getId()] = $this->buildStore->getLatestBuilds($project->getId());

$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;
}

$summaryView = new b8\View('SummaryTable');
$summaryView->projects = $projects['items'];
$summaryView->builds = $summaryBuilds;
$summaryView->successful = $successes;
$summaryView->failed = $failures;

return $summaryView->render();
}
Expand Down
21 changes: 10 additions & 11 deletions PHPCI/Controller/PluginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,27 @@
class PluginController extends \PHPCI\Controller
{
protected $required = array(
'php',
'ext-mcrypt',
'ext-pdo',
'ext-pdo_mysql',
'block8/b8framework',
'ircmaxell/password-compat',
'swiftmailer/swiftmailer',
'symfony/yaml',
'symfony/console',
'psr/log',
'monolog/monolog',
'pimple/pimple'
'pimple/pimple',
'robmorgan/phinx',
);

protected $canInstall;
protected $composerPath;

public function index()
{
if (!$_SESSION['phpci_user']->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.');
}
$this->requireAdmin();

$this->view->canWrite = is_writable(APPLICATION_PATH . 'composer.json');
$this->view->required = $this->required;
Expand All @@ -60,16 +63,14 @@ public function index()

$this->view->plugins = $pluginInfo->getInstalledPlugins();

$this->config->set('page_title', 'Plugins');
$this->layout->title = 'Plugins';

return $this->view->render();
}

public function remove()
{
if (!$_SESSION['phpci_user']->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.');
}
$this->requireAdmin();

$package = $this->getParam('package', null);
$json = $this->getComposerJson();
Expand All @@ -88,9 +89,7 @@ public function remove()

public function install()
{
if (!$_SESSION['phpci_user']->getIsAdmin()) {
throw new \Exception('You do not have permission to do that.');
}
$this->requireAdmin();

$package = $this->getParam('package', null);
$version = $this->getParam('version', '*');
Expand Down
Loading

0 comments on commit 9eeaabc

Please sign in to comment.