Skip to content

Use Web Notifications API in front-end to notify active users of build changes #156#167

Closed
prezire wants to merge 8 commits into
php-censor:masterfrom
prezire:features/156/notifications
Closed

Use Web Notifications API in front-end to notify active users of build changes #156#167
prezire wants to merge 8 commits into
php-censor:masterfrom
prezire:features/156/notifications

Conversation

@prezire

@prezire prezire commented Apr 5, 2018

Copy link
Copy Markdown
Contributor

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


$sPending => $this->formatBuilds($pending),
$sRunning => $this->formatBuilds($running),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  Avoid using static access to class '\PHPCensor\Service\BuildService' in method 'ajaxQueue'.

Comment thread src/Controller/BuildController.php Outdated
$sPending => $this->formatBuilds($pending),
$sRunning => $this->formatBuilds($running),

'web_notifications' => [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS: Whitespace found at end of line

'items' => [$projectId => ['build' => $oSuccess]]
];
$aFailed = [
'count' => count($oFailed),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS: Whitespace found at end of line

Comment thread src/Service/BuildService.php Outdated
}

/**
* A similar function as \PHPCensor\Controller\BuildController::formatBuilds()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS: Whitespace found at end of line

Comment thread src/Service/BuildService.php Outdated

/**
* A similar function as \PHPCensor\Controller\BuildController::formatBuilds()
* but uses pure object to be used for rendering UI notifications

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS: Whitespace found at end of line

Comment thread src/Service/BuildService.php Outdated
$rtn = ['count' => $builds['count'], 'items' => []];

foreach ($builds['items'] as $buildItem) {
$build = self::formatWebNotificationBuild($buildItem);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS: Whitespace found at end of line

Comment thread src/Service/BuildService.php Outdated
*/
public static function formatWebNotificationBuild($build)
{
if(empty($build) || is_null($build)) return [];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS: Expected 1 space after IF keyword; 0 found

Comment thread src/Service/BuildService.php Outdated
*/
public static function formatWebNotificationBuild($build)
{
if(empty($build) || is_null($build)) return [];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS: Inline control structures are not allowed

Comment thread src/Service/BuildService.php Outdated
either 'created_x' or 'started_x' instead of just
returning them.
*/
if($status === Build::STATUS_PENDING)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS: Expected 1 space after IF keyword; 0 found

Comment thread src/Service/BuildService.php Outdated
either 'created_x' or 'started_x' instead of just
returning them.
*/
if($status === Build::STATUS_PENDING)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS: Inline control structures are not allowed

Comment thread src/Service/BuildService.php Outdated
*/
if($status === Build::STATUS_PENDING)
$statusDetails = 'Created: ' . $build->getCreateDate()->format('H:i');
else if($status === Build::STATUS_RUNNING)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS: Usage of ELSE IF is discouraged; use ELSEIF instead

Comment thread src/Service/BuildService.php Outdated
*/
if($status === Build::STATUS_PENDING)
$statusDetails = 'Created: ' . $build->getCreateDate()->format('H:i');
else if($status === Build::STATUS_RUNNING)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS: Expected 1 space after IF keyword; 0 found

Comment thread src/Service/BuildService.php Outdated
*/
if($status === Build::STATUS_PENDING)
$statusDetails = 'Created: ' . $build->getCreateDate()->format('H:i');
else if($status === Build::STATUS_RUNNING)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS: Inline control structures are not allowed

return $response;
}

public function webNotificationUpdate($projectId)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCensor\Controller\WidgetAllProjectsController::webNotificationUpdate::PHPCensor\Controller\WidgetAllProjectsController::webNotificationUpdate is missing a docblock.




public function ajaxData($buildId)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCensor\Controller\BuildController::ajaxData::PHPCensor\Controller\BuildController::ajaxData is missing a docblock.

@@ -365,9 +367,21 @@ public function ajaxMeta($buildId)

public function ajaxQueue()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCensor\Controller\BuildController::ajaxQueue::PHPCensor\Controller\BuildController::ajaxQueue is missing a docblock.

return $response;
}

public function webNotificationUpdate($projectId)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class PHPCensor\Controller\WidgetAllProjectsController::webNotificationUpdate is missing a docblock.




public function ajaxData($buildId)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class PHPCensor\Controller\BuildController::ajaxData is missing a docblock.

@corpsee corpsee added this to the 1.x milestone Apr 5, 2018
Comment thread .gitignore Outdated

/public/artifacts
!/public/artifacts/.gitkeep

@corpsee corpsee Apr 5, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should move this stuff to your global (in your homedir) .gitignore file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files you uploaded are not relevant to the project. It is files of your environment. See detailed explanation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice. Thanks for this.

@@ -365,9 +365,17 @@ public function ajaxMeta($buildId)

public function ajaxQueue()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCensor\Controller\BuildController::ajaxQueue::PHPCensor\Controller\BuildController::ajaxQueue is missing a docblock.

{
parent::init();

$this->buildStore = Factory::getStore('Build');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  Avoid using static access to class '\PHPCensor\Store\Factory' in method 'init'.

parent::init();

$this->buildStore = Factory::getStore('Build');
$this->projectStore = Factory::getStore('Project');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  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');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'widgetsAllProjectsUpdate'.

$running = $this->buildStore->getByStatus(Build::STATUS_RUNNING);

$rtn = [
'pending' => WebNotificationService::formatBuilds($pending),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'buildsUpdated'.


$rtn = [
'pending' => WebNotificationService::formatBuilds($pending),
'running' => WebNotificationService::formatBuilds($running)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'buildsUpdated'.

Comment thread src/Service/WebNotificationService.php Outdated
*/
if ($status === Build::STATUS_PENDING) {
$datePerformed = 'Created: ' . $build->getCreateDate()->format('H:i');
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCS: Expected 1 space after closing brace; newline found

@@ -365,9 +365,17 @@ public function ajaxMeta($buildId)

public function ajaxQueue()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCensor\Controller\BuildController::ajaxQueue::PHPCensor\Controller\BuildController::ajaxQueue is missing a docblock.

{
parent::init();

$this->buildStore = Factory::getStore('Build');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  Avoid using static access to class '\PHPCensor\Store\Factory' in method 'init'.

parent::init();

$this->buildStore = Factory::getStore('Build');
$this->projectStore = Factory::getStore('Project');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  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');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'widgetsAllProjectsUpdate'.

$running = $this->buildStore->getByStatus(Build::STATUS_RUNNING);

$rtn = [
'pending' => WebNotificationService::formatBuilds($pending),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'buildsUpdated'.


$rtn = [
'pending' => WebNotificationService::formatBuilds($pending),
'running' => WebNotificationService::formatBuilds($running)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  Avoid using static access to class '\PHPCensor\Service\WebNotificationService' in method 'buildsUpdated'.

@@ -365,9 +365,17 @@ public function ajaxMeta($buildId)

public function ajaxQueue()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPCensor\Controller\BuildController::ajaxQueue::PHPCensor\Controller\BuildController::ajaxQueue is missing a docblock.

@prezire

prezire commented Apr 9, 2018

Copy link
Copy Markdown
Contributor Author

How about now?

@corpsee

corpsee commented Apr 9, 2018

Copy link
Copy Markdown
Member

I will test the feature soon. Thank you @prezire!

@prezire

prezire commented Apr 9, 2018

Copy link
Copy Markdown
Contributor Author

Cheers.

@corpsee

corpsee commented Apr 9, 2018

Copy link
Copy Markdown
Member

I squashed your commits into one, did small fixes and merged into master branch manually. Thanks @prezire 👍

@corpsee corpsee closed this Apr 9, 2018
@corpsee corpsee modified the milestones: Version 1.1.0 (minor), 1.1.0 May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants