diff --git a/PHPCI/Controller/IndexController.php b/PHPCI/Controller/IndexController.php index c185d2f3..2404a047 100644 --- a/PHPCI/Controller/IndexController.php +++ b/PHPCI/Controller/IndexController.php @@ -33,7 +33,7 @@ class IndexController extends \PHPCI\Controller $projects = $this->_projectStore->getWhere(array(), 50, 0, array(), array('title' => 'ASC')); $summary = $this->_buildStore->getBuildSummary(); - $summaryView = new b8\View('BuildsTable'); + $summaryView = new b8\View('SummaryTable'); $summaryView->builds = $summary['items']; $this->view->builds = $this->getLatestBuildsHtml(); diff --git a/PHPCI/Store/BuildStore.php b/PHPCI/Store/BuildStore.php index 6b26c3c7..fca490f2 100644 --- a/PHPCI/Store/BuildStore.php +++ b/PHPCI/Store/BuildStore.php @@ -31,7 +31,7 @@ class BuildStore extends BuildStoreBase $count = 0; } - $query = 'SELECT b.* FROM build b LEFT JOIN project p on p.id = b.project_id GROUP BY b.project_id ORDER BY p.title ASC, b.id DESC'; + $query = 'SELECT b.* FROM build b LEFT JOIN project p on p.id = b.project_id ORDER BY p.title ASC, b.id DESC'; $stmt = \b8\Database::getConnection('read')->prepare($query); if ($stmt->execute()) { diff --git a/PHPCI/View/Index/index.phtml b/PHPCI/View/Index/index.phtml index 887b46d3..903b0bc2 100644 --- a/PHPCI/View/Index/index.phtml +++ b/PHPCI/View/Index/index.phtml @@ -44,11 +44,11 @@ - + - - - + + + diff --git a/PHPCI/View/SummaryTable.phtml b/PHPCI/View/SummaryTable.phtml new file mode 100644 index 00000000..6a81de0d --- /dev/null +++ b/PHPCI/View/SummaryTable.phtml @@ -0,0 +1,114 @@ +"; +// var_dump($builds); +// echo ""; + +$maxbuildcount = 5; +$projects = array(); +$prevBuild = null; +$health = false; + +foreach($builds as $build): + + if ($build->getStatus() < 2) { + continue; + } + + if ( is_null($prevBuild) || $build->getProjectId() !== $prevBuild->getProjectId() ) { + $health = false; + $projects[$build->getProjectId()]['count'] = 0; + $projects[$build->getProjectId()]['health'] = 0; + $projects[$build->getProjectId()]['successes'] = 0; + $projects[$build->getProjectId()]['failures'] = 0; + $projects[$build->getProjectId()]['lastbuildstatus'] = (int)$build->getStatus(); + } + + if ( + !is_null($prevBuild) && + $projects[$build->getProjectId()]['count'] >= $maxbuildcount && + $build->getProjectId() === $prevBuild->getProjectId() + ) { + $projects[$build->getProjectId()]['count']++; + continue; + } + + switch ((int)$build->getStatus()) { + case 2: + $projects[$build->getProjectId()]['health']++; + $projects[$build->getProjectId()]['successes']++; + + if ( empty($projects[$build->getProjectId()]['lastsuccess']) ) { + $projects[$build->getProjectId()]['lastsuccess'] = $build; + } + break; + case 3: + $projects[$build->getProjectId()]['health']--; + $projects[$build->getProjectId()]['failures']++; + + if ( empty($projects[$build->getProjectId()]['lastfailure']) ) { + $projects[$build->getProjectId()]['lastfailure'] = $build; + } + break; + } + + $projects[$build->getProjectId()]['count']++; + $projects[$build->getProjectId()]['projectname'] = $build->getProject()->getTitle(); + $prevBuild = $build; +endforeach; + +foreach($projects as $projectId => $project): + switch($project['lastbuildstatus']) + { + case 0: + $cls = 'info'; + $status = 'Pending'; + break; + + case 1: + $cls = 'warning'; + $status = 'Running'; + break; + + case 2: + $cls = 'success'; + $status = 'Success'; + break; + + case 3: + $cls = 'error'; + $status = 'Failed'; + break; + } + + $health = ($project['health'] < 0 ? 'Stormy': ($project['health'] < 5? 'Overcast': 'Sunny')); + $subcls = ($project['health'] < 0 ? 'important': ($project['health'] < 5? 'warning': 'success')); +?> + + + + + + + + + \ No newline at end of file
IDHealth ProjectCommitBranchStatusLast SuccessLast FailureSuccess/Failures
+ + + + + + getId() ?>'> + getStarted()->format("Y-m-d H:i:s") ?> + + + + + getId() ?>'> + getStarted()->format("Y-m-d H:i:s") ?> + + + /build