Web notifications. Issue #156.

This commit is contained in:
Mark Amoin 2018-04-03 15:43:11 +08:00 committed by Dmitry Khomutov
commit 3f56e4cc54
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
10 changed files with 512 additions and 135 deletions

View file

@ -365,9 +365,17 @@ class BuildController extends WebController
public function ajaxQueue()
{
$sPending = 'pending';
$sRunning = 'running';
$pending = $this->buildStore->getByStatus(Build::STATUS_PENDING);
$running = $this->buildStore->getByStatus(Build::STATUS_RUNNING);
$rtn = [
'pending' => $this->formatBuilds($this->buildStore->getByStatus(Build::STATUS_PENDING)),
'running' => $this->formatBuilds($this->buildStore->getByStatus(Build::STATUS_RUNNING)),
$sPending => $this->formatBuilds($pending),
$sRunning => $this->formatBuilds($running),
];
$response = new JsonResponse();

View file

@ -0,0 +1,114 @@
<?php
namespace PHPCensor\Controller;
use PHPCensor\Model\Build;
use PHPCensor\WebController;
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\Service\WebNotificationService;
/**
* Web Notifications Controller
*/
class WebNotificationsController extends WebController
{
/**
* @var BuildStore
*/
protected $buildStore;
/**
* @var ProjectStore
*/
protected $projectStore;
/**
* @var ProjectGroupStore
*/
protected $groupStore;
/**
* Initialise the controller, set up stores and services.
*/
public function init()
{
parent::init();
$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
* builds that have success and failed status.
* This is similar to WidgetAllProjectsController::update()
* but instead, this only returns JSON.
* @param int $projectId
* @return \PHPCensor\Http\Response\JsonResponse
* @see \PHPCensor\Controller\WidgetAllProjectsController
*/
public function widgetsAllProjectsUpdate($projectId)
{
$success = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_SUCCESS);
$failed = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_FAILED);
$oSuccess = WebNotificationService::formatBuild($success);
$oFailed = WebNotificationService::formatBuild($failed);
//@keys count and items Follow the for-loop structure
//found in
//\PHPCensor\Service\WebNotificationService::formatBuilds()
$aSuccess = [
'count' => count($oSuccess),
'items' => [$projectId => ['build' => $oSuccess]]
];
$aFailed = [
'count' => count($oFailed),
'items' => [$projectId => ['build' => $oFailed]]
];
$builds = [
'success' => $aSuccess,
'failed' => $aFailed
];
$response = new JsonResponse();
$response->setContent($builds);
return $response;
}
/**
* Provides JSON format for web notification UI of all last
* builds that have pending and running status.
* This is similar to WidgetAllProjectsController::update()
* but instead, this only returns JSON.
* @return \PHPCensor\Http\Response\JsonResponse
*/
public function buildsUpdated()
{
$pending = $this->buildStore->getByStatus(Build::STATUS_PENDING);
$running = $this->buildStore->getByStatus(Build::STATUS_RUNNING);
$rtn = [
'pending' => WebNotificationService::formatBuilds($pending),
'running' => WebNotificationService::formatBuilds($running)
];
$response = new JsonResponse();
$response->setContent($rtn);
return $response;
}
}

View file

@ -11,6 +11,8 @@ 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;
/**
* Widget All Projects Controller