Web notifications small fixes. Issue #156.
This commit is contained in:
parent
3f56e4cc54
commit
56fc76d4e5
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -16,4 +16,4 @@
|
||||||
/public/assets/vendor
|
/public/assets/vendor
|
||||||
|
|
||||||
/public/artifacts
|
/public/artifacts
|
||||||
!/public/artifacts/.gitkeep
|
!/public/artifacts/.gitkeep
|
||||||
|
|
|
@ -34,8 +34,6 @@ PHPCensor.widgets.allProjects = {
|
||||||
error: PHPCensor.handleFailedAjax
|
error: PHPCensor.handleFailedAjax
|
||||||
});
|
});
|
||||||
|
|
||||||
//Let's build another mechanism for web notification
|
|
||||||
//since the above feature is tightly coupled to the view.
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: APP_URL +
|
url: APP_URL +
|
||||||
'web-notifications/widgets-all-projects-update/' +
|
'web-notifications/widgets-all-projects-update/' +
|
||||||
|
|
|
@ -365,17 +365,9 @@ class BuildController extends WebController
|
||||||
|
|
||||||
public function ajaxQueue()
|
public function ajaxQueue()
|
||||||
{
|
{
|
||||||
$sPending = 'pending';
|
|
||||||
$sRunning = 'running';
|
|
||||||
|
|
||||||
$pending = $this->buildStore->getByStatus(Build::STATUS_PENDING);
|
|
||||||
$running = $this->buildStore->getByStatus(Build::STATUS_RUNNING);
|
|
||||||
|
|
||||||
$rtn = [
|
$rtn = [
|
||||||
|
'pending' => $this->formatBuilds($this->buildStore->getByStatus(Build::STATUS_PENDING)),
|
||||||
$sPending => $this->formatBuilds($pending),
|
'running' => $this->formatBuilds($this->buildStore->getByStatus(Build::STATUS_RUNNING)),
|
||||||
$sRunning => $this->formatBuilds($running),
|
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = new JsonResponse();
|
$response = new JsonResponse();
|
||||||
|
|
|
@ -3,16 +3,9 @@
|
||||||
namespace PHPCensor\Controller;
|
namespace PHPCensor\Controller;
|
||||||
|
|
||||||
use PHPCensor\Model\Build;
|
use PHPCensor\Model\Build;
|
||||||
|
use PHPCensor\Store\BuildStore;
|
||||||
use PHPCensor\WebController;
|
use PHPCensor\WebController;
|
||||||
use PHPCensor\Store\Factory;
|
use PHPCensor\Store\Factory;
|
||||||
//use PHPCensor\View;
|
|
||||||
//use PHPCensor\Model\Project;
|
|
||||||
//use PHPCensor\Http\Response;
|
|
||||||
//use PHPCensor\Store\BuildStore;
|
|
||||||
//use PHPCensor\Store\ProjectStore;
|
|
||||||
//use PHPCensor\Store\ProjectGroupStore;
|
|
||||||
//use PHPCensor\Service\BuildService;
|
|
||||||
//use b8\Http\Response\JsonResponse;
|
|
||||||
use PHPCensor\Http\Response\JsonResponse;
|
use PHPCensor\Http\Response\JsonResponse;
|
||||||
use PHPCensor\Service\WebNotificationService;
|
use PHPCensor\Service\WebNotificationService;
|
||||||
|
|
||||||
|
@ -26,16 +19,6 @@ class WebNotificationsController extends WebController
|
||||||
*/
|
*/
|
||||||
protected $buildStore;
|
protected $buildStore;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var ProjectStore
|
|
||||||
*/
|
|
||||||
protected $projectStore;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var ProjectGroupStore
|
|
||||||
*/
|
|
||||||
protected $groupStore;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialise the controller, set up stores and services.
|
* Initialise the controller, set up stores and services.
|
||||||
*/
|
*/
|
||||||
|
@ -43,18 +26,17 @@ class WebNotificationsController extends WebController
|
||||||
{
|
{
|
||||||
parent::init();
|
parent::init();
|
||||||
|
|
||||||
$this->buildStore = Factory::getStore('Build');
|
$this->buildStore = Factory::getStore('Build');
|
||||||
$this->projectStore = Factory::getStore('Project');
|
|
||||||
$this->groupStore = Factory::getStore('ProjectGroup');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides JSON format for web notification UI of all last
|
* Provides JSON format for web notification UI of all last builds that have success and failed status.
|
||||||
* builds that have success and failed status.
|
* This is similar to WidgetAllProjectsController::update() but instead, this only returns JSON.
|
||||||
* This is similar to WidgetAllProjectsController::update()
|
*
|
||||||
* but instead, this only returns JSON.
|
|
||||||
* @param int $projectId
|
* @param int $projectId
|
||||||
|
*
|
||||||
* @return \PHPCensor\Http\Response\JsonResponse
|
* @return \PHPCensor\Http\Response\JsonResponse
|
||||||
|
*
|
||||||
* @see \PHPCensor\Controller\WidgetAllProjectsController
|
* @see \PHPCensor\Controller\WidgetAllProjectsController
|
||||||
*/
|
*/
|
||||||
public function widgetsAllProjectsUpdate($projectId)
|
public function widgetsAllProjectsUpdate($projectId)
|
||||||
|
@ -65,9 +47,6 @@ class WebNotificationsController extends WebController
|
||||||
$oSuccess = WebNotificationService::formatBuild($success);
|
$oSuccess = WebNotificationService::formatBuild($success);
|
||||||
$oFailed = WebNotificationService::formatBuild($failed);
|
$oFailed = WebNotificationService::formatBuild($failed);
|
||||||
|
|
||||||
//@keys count and items Follow the for-loop structure
|
|
||||||
//found in
|
|
||||||
//\PHPCensor\Service\WebNotificationService::formatBuilds()
|
|
||||||
$aSuccess = [
|
$aSuccess = [
|
||||||
'count' => count($oSuccess),
|
'count' => count($oSuccess),
|
||||||
'items' => [$projectId => ['build' => $oSuccess]]
|
'items' => [$projectId => ['build' => $oSuccess]]
|
||||||
|
@ -90,24 +69,25 @@ class WebNotificationsController extends WebController
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides JSON format for web notification UI of all last
|
* Provides JSON format for web notification UI of all last builds that have pending and running status.
|
||||||
* builds that have pending and running status.
|
* This is similar to WidgetAllProjectsController::update() but instead, this only returns JSON.
|
||||||
* This is similar to WidgetAllProjectsController::update()
|
*
|
||||||
* but instead, this only returns JSON.
|
* @return JsonResponse
|
||||||
* @return \PHPCensor\Http\Response\JsonResponse
|
*
|
||||||
|
* @throws \PHPCensor\Exception\HttpException
|
||||||
*/
|
*/
|
||||||
public function buildsUpdated()
|
public function buildsUpdated()
|
||||||
{
|
{
|
||||||
$pending = $this->buildStore->getByStatus(Build::STATUS_PENDING);
|
$pending = $this->buildStore->getByStatus(Build::STATUS_PENDING);
|
||||||
$running = $this->buildStore->getByStatus(Build::STATUS_RUNNING);
|
$running = $this->buildStore->getByStatus(Build::STATUS_RUNNING);
|
||||||
|
|
||||||
$rtn = [
|
$result = [
|
||||||
'pending' => WebNotificationService::formatBuilds($pending),
|
'pending' => WebNotificationService::formatBuilds($pending),
|
||||||
'running' => WebNotificationService::formatBuilds($running)
|
'running' => WebNotificationService::formatBuilds($running)
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = new JsonResponse();
|
$response = new JsonResponse();
|
||||||
$response->setContent($rtn);
|
$response->setContent($result);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,6 @@ use PHPCensor\Http\Response;
|
||||||
use PHPCensor\Store\BuildStore;
|
use PHPCensor\Store\BuildStore;
|
||||||
use PHPCensor\Store\ProjectStore;
|
use PHPCensor\Store\ProjectStore;
|
||||||
use PHPCensor\Store\ProjectGroupStore;
|
use PHPCensor\Store\ProjectGroupStore;
|
||||||
use PHPCensor\Service\BuildService;
|
|
||||||
use b8\Http\Response\JsonResponse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Widget All Projects Controller
|
* Widget All Projects Controller
|
||||||
|
@ -106,6 +104,8 @@ class WidgetAllProjectsController extends WebController
|
||||||
* Get a summary of the project groups we have, and what projects they have in them.
|
* Get a summary of the project groups we have, and what projects they have in them.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
protected function getGroupInfo()
|
protected function getGroupInfo()
|
||||||
{
|
{
|
||||||
|
@ -129,6 +129,8 @@ class WidgetAllProjectsController extends WebController
|
||||||
* @param integer $projectId
|
* @param integer $projectId
|
||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
|
*
|
||||||
|
* @throws \PHPCensor\Exception\HttpException
|
||||||
*/
|
*/
|
||||||
public function update($projectId)
|
public function update($projectId)
|
||||||
{
|
{
|
||||||
|
|
|
@ -52,6 +52,8 @@ class WidgetBuildErrorsController extends WebController
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Response
|
* @return Response
|
||||||
|
*
|
||||||
|
* @throws \PHPCensor\Exception\HttpException
|
||||||
*/
|
*/
|
||||||
public function update()
|
public function update()
|
||||||
{
|
{
|
||||||
|
@ -65,6 +67,8 @@ class WidgetBuildErrorsController extends WebController
|
||||||
* @param View $view
|
* @param View $view
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
|
*
|
||||||
|
* @throws \PHPCensor\Exception\HttpException
|
||||||
*/
|
*/
|
||||||
protected function renderAllProjectsLatestBuilds($view)
|
protected function renderAllProjectsLatestBuilds($view)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,13 +2,7 @@
|
||||||
|
|
||||||
namespace PHPCensor\Service;
|
namespace PHPCensor\Service;
|
||||||
|
|
||||||
use PHPCensor\Config;
|
|
||||||
use Pheanstalk\Pheanstalk;
|
|
||||||
use Pheanstalk\PheanstalkInterface;
|
|
||||||
use PHPCensor\BuildFactory;
|
|
||||||
use PHPCensor\Model\Build;
|
use PHPCensor\Model\Build;
|
||||||
use PHPCensor\Model\Project;
|
|
||||||
use PHPCensor\Store\BuildStore;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A service that listens for creation, duplication and deletion of builds for web notification UI.
|
* A service that listens for creation, duplication and deletion of builds for web notification UI.
|
||||||
|
@ -18,8 +12,11 @@ class WebNotificationService
|
||||||
/**
|
/**
|
||||||
* Similar to BuildController::formatBuilds() but uses
|
* Similar to BuildController::formatBuilds() but uses
|
||||||
* pure object to be used for rendering web notifications.
|
* pure object to be used for rendering web notifications.
|
||||||
|
*
|
||||||
* @param array $builds
|
* @param array $builds
|
||||||
|
*
|
||||||
* @return array Formatted builds
|
* @return array Formatted builds
|
||||||
|
*
|
||||||
* @see \PHPCensor\Controller\WidgetLastBuildsController::webNotificationUpdate().
|
* @see \PHPCensor\Controller\WidgetLastBuildsController::webNotificationUpdate().
|
||||||
*/
|
*/
|
||||||
public static function formatBuilds($builds)
|
public static function formatBuilds($builds)
|
||||||
|
@ -37,7 +34,9 @@ class WebNotificationService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides structured keys for web notification.
|
* Provides structured keys for web notification.
|
||||||
|
*
|
||||||
* @param Build $build
|
* @param Build $build
|
||||||
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function formatBuild($build)
|
public static function formatBuild($build)
|
||||||
|
@ -45,15 +44,11 @@ class WebNotificationService
|
||||||
if (empty($build) || is_null($build)) {
|
if (empty($build) || is_null($build)) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
$status = $build->getStatus();
|
|
||||||
$datePerformed = '';
|
|
||||||
$dateFinished = '';
|
|
||||||
|
|
||||||
/*
|
$status = $build->getStatus();
|
||||||
BUG: Lang::out() automatically renders the values for
|
$datePerformed = '';
|
||||||
either 'created_x' or 'started_x' instead of just
|
$dateFinished = '';
|
||||||
returning them.
|
|
||||||
*/
|
|
||||||
if ($status === Build::STATUS_PENDING) {
|
if ($status === Build::STATUS_PENDING) {
|
||||||
$datePerformed = 'Created: ' . $build->getCreateDate()->format('H:i');
|
$datePerformed = 'Created: ' . $build->getCreateDate()->format('H:i');
|
||||||
} elseif ($status === Build::STATUS_RUNNING) {
|
} elseif ($status === Build::STATUS_RUNNING) {
|
||||||
|
@ -66,13 +61,9 @@ class WebNotificationService
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'branch' => $build->getBranch(),
|
'branch' => $build->getBranch(),
|
||||||
'url' => APP_URL .
|
'url' => APP_URL . 'build/view/' . $build->getId(),
|
||||||
'build/view/' .
|
|
||||||
$build->getId(),
|
|
||||||
'committer_email' => $build->getCommitterEmail(),
|
'committer_email' => $build->getCommitterEmail(),
|
||||||
'img_src' => 'https://www.gravatar.com/avatar/' .
|
'img_src' => 'https://www.gravatar.com/avatar/' . md5($build->getCommitterEmail()) . '?d=mm&s=40',
|
||||||
md5($build->getCommitterEmail()) .
|
|
||||||
'?d=mm&s=40',
|
|
||||||
'project_title' => $build->getProject()->getTitle(),
|
'project_title' => $build->getProject()->getTitle(),
|
||||||
'status' => $status,
|
'status' => $status,
|
||||||
'date_performed' => $datePerformed,
|
'date_performed' => $datePerformed,
|
||||||
|
|
Loading…
Reference in a new issue