Use Web Notifications API in front-end to notify active users of build changes #156#167
Use Web Notifications API in front-end to notify active users of build changes #156#167prezire wants to merge 8 commits intophp-censor:masterphp-censor/php-censor:masterfrom prezire:features/156/notificationsprezire/php-censor:features/156/notificationsCopy head branch name to clipboard
Conversation
|
|
||
| $sPending => $this->formatBuilds($pending), | ||
| $sRunning => $this->formatBuilds($running), | ||
|
|
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Service\BuildService' in method 'ajaxQueue'.
| $sPending => $this->formatBuilds($pending), | ||
| $sRunning => $this->formatBuilds($running), | ||
|
|
||
| 'web_notifications' => [ |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Service\BuildService' in method 'ajaxQueue'.
| $success = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_SUCCESS); | ||
| $failed = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_FAILED); | ||
|
|
||
| $oSuccess = BuildService::formatWebNotificationBuild($success); |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Service\BuildService' in method 'webNotificationUpdate'.
| $failed = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_FAILED); | ||
|
|
||
| $oSuccess = BuildService::formatWebNotificationBuild($success); | ||
| $oFailed = BuildService::formatWebNotificationBuild($failed); |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Service\BuildService' in method 'webNotificationUpdate'.
| $oSuccess = BuildService::formatWebNotificationBuild($success); | ||
| $oFailed = BuildService::formatWebNotificationBuild($failed); | ||
|
|
||
| //@keys count and items Follow the for-loop structure |
There was a problem hiding this comment.
PHPCS: Whitespace found at end of line
| //@keys count and items Follow the for-loop structure | ||
| //found in \PHPCensor\Service\BuildService::formatWebNotificationBuilds() | ||
| $aSuccess = [ | ||
| 'count' => count($oSuccess), |
There was a problem hiding this comment.
PHPCS: Whitespace found at end of line
| 'items' => [$projectId => ['build' => $oSuccess]] | ||
| ]; | ||
| $aFailed = [ | ||
| 'count' => count($oFailed), |
There was a problem hiding this comment.
PHPCS: Whitespace found at end of line
| } | ||
|
|
||
| /** | ||
| * A similar function as \PHPCensor\Controller\BuildController::formatBuilds() |
There was a problem hiding this comment.
PHPCS: Whitespace found at end of line
|
|
||
| /** | ||
| * A similar function as \PHPCensor\Controller\BuildController::formatBuilds() | ||
| * but uses pure object to be used for rendering UI notifications |
There was a problem hiding this comment.
PHPCS: Whitespace found at end of line
| $rtn = ['count' => $builds['count'], 'items' => []]; | ||
|
|
||
| foreach ($builds['items'] as $buildItem) { | ||
| $build = self::formatWebNotificationBuild($buildItem); |
There was a problem hiding this comment.
PHPCS: Whitespace found at end of line
| */ | ||
| public static function formatWebNotificationBuild($build) | ||
| { | ||
| if(empty($build) || is_null($build)) return []; |
There was a problem hiding this comment.
PHPCS: Expected 1 space after IF keyword; 0 found
| */ | ||
| public static function formatWebNotificationBuild($build) | ||
| { | ||
| if(empty($build) || is_null($build)) return []; |
There was a problem hiding this comment.
PHPCS: Inline control structures are not allowed
| either 'created_x' or 'started_x' instead of just | ||
| returning them. | ||
| */ | ||
| if($status === Build::STATUS_PENDING) |
There was a problem hiding this comment.
PHPCS: Expected 1 space after IF keyword; 0 found
| either 'created_x' or 'started_x' instead of just | ||
| returning them. | ||
| */ | ||
| if($status === Build::STATUS_PENDING) |
There was a problem hiding this comment.
PHPCS: Inline control structures are not allowed
| */ | ||
| if($status === Build::STATUS_PENDING) | ||
| $statusDetails = 'Created: ' . $build->getCreateDate()->format('H:i'); | ||
| else if($status === Build::STATUS_RUNNING) |
There was a problem hiding this comment.
PHPCS: Usage of ELSE IF is discouraged; use ELSEIF instead
| */ | ||
| if($status === Build::STATUS_PENDING) | ||
| $statusDetails = 'Created: ' . $build->getCreateDate()->format('H:i'); | ||
| else if($status === Build::STATUS_RUNNING) |
There was a problem hiding this comment.
PHPCS: Expected 1 space after IF keyword; 0 found
| */ | ||
| if($status === Build::STATUS_PENDING) | ||
| $statusDetails = 'Created: ' . $build->getCreateDate()->format('H:i'); | ||
| else if($status === Build::STATUS_RUNNING) |
There was a problem hiding this comment.
PHPCS: Inline control structures are not allowed
| return $response; | ||
| } | ||
|
|
||
| public function webNotificationUpdate($projectId) |
There was a problem hiding this comment.
PHPCensor\Controller\WidgetAllProjectsController::webNotificationUpdate::PHPCensor\Controller\WidgetAllProjectsController::webNotificationUpdate is missing a docblock.
|
|
||
|
|
||
|
|
||
| public function ajaxData($buildId) |
There was a problem hiding this comment.
PHPCensor\Controller\BuildController::ajaxData::PHPCensor\Controller\BuildController::ajaxData is missing a docblock.
| @@ -365,9 +367,21 @@ public function ajaxMeta($buildId) | ||
|
|
||
| public function ajaxQueue() |
There was a problem hiding this comment.
PHPCensor\Controller\BuildController::ajaxQueue::PHPCensor\Controller\BuildController::ajaxQueue is missing a docblock.
| return $response; | ||
| } | ||
|
|
||
| public function webNotificationUpdate($projectId) |
There was a problem hiding this comment.
Class PHPCensor\Controller\WidgetAllProjectsController::webNotificationUpdate is missing a docblock.
|
|
||
|
|
||
|
|
||
| public function ajaxData($buildId) |
There was a problem hiding this comment.
Class PHPCensor\Controller\BuildController::ajaxData is missing a docblock.
|
|
||
| /public/artifacts | ||
| !/public/artifacts/.gitkeep | ||
|
|
There was a problem hiding this comment.
You should move this stuff to your global (in your homedir) .gitignore file.
There was a problem hiding this comment.
The files you uploaded are not relevant to the project. It is files of your environment. See detailed explanation.
There was a problem hiding this comment.
Very nice. Thanks for this.
| @@ -365,9 +365,17 @@ public function ajaxMeta($buildId) | ||
|
|
||
| public function ajaxQueue() |
There was a problem hiding this comment.
PHPCensor\Controller\BuildController::ajaxQueue::PHPCensor\Controller\BuildController::ajaxQueue is missing a docblock.
| { | ||
| parent::init(); | ||
|
|
||
| $this->buildStore = Factory::getStore('Build'); |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Store\Factory' in method 'init'.
| parent::init(); | ||
|
|
||
| $this->buildStore = Factory::getStore('Build'); | ||
| $this->projectStore = Factory::getStore('Project'); |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Store\Factory' in method 'init'.
|
|
||
| $this->buildStore = Factory::getStore('Build'); | ||
| $this->projectStore = Factory::getStore('Project'); | ||
| $this->groupStore = Factory::getStore('ProjectGroup'); |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Store\Factory' in method 'init'.
| $success = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_SUCCESS); | ||
| $failed = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_FAILED); | ||
|
|
||
| $oSuccess = WebNotificationService::formatBuild($success); |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'widgetsAllProjectsUpdate'.
| $failed = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_FAILED); | ||
|
|
||
| $oSuccess = WebNotificationService::formatBuild($success); | ||
| $oFailed = WebNotificationService::formatBuild($failed); |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'widgetsAllProjectsUpdate'.
| $running = $this->buildStore->getByStatus(Build::STATUS_RUNNING); | ||
|
|
||
| $rtn = [ | ||
| 'pending' => WebNotificationService::formatBuilds($pending), |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'buildsUpdated'.
|
|
||
| $rtn = [ | ||
| 'pending' => WebNotificationService::formatBuilds($pending), | ||
| 'running' => WebNotificationService::formatBuilds($running) |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'buildsUpdated'.
| */ | ||
| if ($status === Build::STATUS_PENDING) { | ||
| $datePerformed = 'Created: ' . $build->getCreateDate()->format('H:i'); | ||
| } |
There was a problem hiding this comment.
PHPCS: Expected 1 space after closing brace; newline found
| @@ -365,9 +365,17 @@ public function ajaxMeta($buildId) | ||
|
|
||
| public function ajaxQueue() |
There was a problem hiding this comment.
PHPCensor\Controller\BuildController::ajaxQueue::PHPCensor\Controller\BuildController::ajaxQueue is missing a docblock.
| { | ||
| parent::init(); | ||
|
|
||
| $this->buildStore = Factory::getStore('Build'); |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Store\Factory' in method 'init'.
| parent::init(); | ||
|
|
||
| $this->buildStore = Factory::getStore('Build'); | ||
| $this->projectStore = Factory::getStore('Project'); |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Store\Factory' in method 'init'.
|
|
||
| $this->buildStore = Factory::getStore('Build'); | ||
| $this->projectStore = Factory::getStore('Project'); | ||
| $this->groupStore = Factory::getStore('ProjectGroup'); |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Store\Factory' in method 'init'.
| $success = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_SUCCESS); | ||
| $failed = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_FAILED); | ||
|
|
||
| $oSuccess = WebNotificationService::formatBuild($success); |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'widgetsAllProjectsUpdate'.
| $failed = $this->buildStore->getLastBuildByStatus($projectId, Build::STATUS_FAILED); | ||
|
|
||
| $oSuccess = WebNotificationService::formatBuild($success); | ||
| $oFailed = WebNotificationService::formatBuild($failed); |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'widgetsAllProjectsUpdate'.
| $running = $this->buildStore->getByStatus(Build::STATUS_RUNNING); | ||
|
|
||
| $rtn = [ | ||
| 'pending' => WebNotificationService::formatBuilds($pending), |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'buildsUpdated'.
|
|
||
| $rtn = [ | ||
| 'pending' => WebNotificationService::formatBuilds($pending), | ||
| 'running' => WebNotificationService::formatBuilds($running) |
There was a problem hiding this comment.
Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'buildsUpdated'.
| @@ -365,9 +365,17 @@ public function ajaxMeta($buildId) | ||
|
|
||
| public function ajaxQueue() |
There was a problem hiding this comment.
PHPCensor\Controller\BuildController::ajaxQueue::PHPCensor\Controller\BuildController::ajaxQueue is missing a docblock.
|
How about now? |
|
I will test the feature soon. Thank you @prezire! |
|
Cheers. |
|
I squashed your commits into one, did small fixes and merged into |
Contribution type
*Feature
Description of change
*Added a new UI feature to use Web Notifications API in front-end to notify active users of build changes
*Chrome is very strict with web notifications in an insecure HTTP location or localhost. Use Firefox instead when testing especially localhost
*Allow Notification Permission in the browser to see the notification popups