Permalink
Browse files

Removed useless web notifications. Issue #156.

  • Loading branch information...
corpsee committed Sep 14, 2018
1 parent eef2151 commit 09aa7f782d3ae4e338481d54de238125880573d8
View
@@ -85,6 +85,7 @@
"sebastian/diff": "^1.0 || ^2.0 || ^3.0",
"symfony/debug": "~3.4.0",
"symfony/intl": "~3.4.0",
"doctrine/instantiator": "~1.0.0",
"phpunit/php-token-stream": "~1.4.0",
"phpdocumentor/reflection-docblock": "~2.0.0",
@@ -94,7 +95,6 @@
"npm-asset/sprintf-js": "~1.0.0",
"npm-asset/codemirror": "~5.23.0",
"npm-asset/notifyjs": "~3.0.0",
"bower-asset/admin-lte": "~2.3.0",
"bower-asset/font-awesome": "~4.7.0",
"bower-asset/ionicons": "~2.0.0",
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -39,8 +39,6 @@ php-censor:
log:
rotate: true
max_files: 10
notifications:
enabled: false # notify.js notifications to browser
ssh:
strength: 4096 # SSH keys strength (default: 2048)
comment: admin@php-censor.info # SSH keys comment (default: admin@php-censor)
View
@@ -1,18 +1,6 @@
var PHPCensor = {
intervals: {},
widgets: {},
webNotifiedBuilds: [],
/*
@var STATUS Refer to \PHPCensor\Model\Build.php constants.
TODO: Transfer this variable to Build JS class so
Build JS itself can use it as well.
*/
STATUS: [
'Pending',
'Running',
'Success',
'Failed'
],
init: function () {
$(document).ready(function () {
@@ -31,128 +19,6 @@ var PHPCensor = {
});
},
/**
* Shallow comparison that determines that the build
* has been shown as at least once as a web notification.
* Also adds the build to a list of shown web notifications
* if it's not found in the list.
* @param object build
* @return boolean
*/
isWebNotifiedBuild: function (build) {
var o = PHPCensor.webNotifiedBuilds;
for (var i = 0; i < o.length; i++) {
var webNotifiedBuild = o[i];
var b =
webNotifiedBuild.projectTitle === build.projectTitle &&
webNotifiedBuild.branch === build.branch &&
webNotifiedBuild.status === build.status &&
webNotifiedBuild.datePerformed === build.datePerformed &&
webNotifiedBuild.dateFinished === build.dateFinished;
if (b) {
return true;
}
}
/*
It's impossible to remember or use all previously shown
builds. So let's clear them out once they reach 1000.
@var 1000 Estimated.
*/
if (PHPCensor.webNotifiedBuilds.length > 1000) {
PHPCensor.webNotifiedBuilds = [];
}
PHPCensor.webNotifiedBuilds.push(build);
return false;
},
/**
* Web notification.
* Chrome doesn't allow insecure protocols.
* Enable HTTPS even on localhost in order for
* web notifications to work properly.
* @param object data Contains an array of builds.
* @return void
*/
showWebNotification: function (data) {
var pending = data.pending;
var running = data.running;
var success = data.success;
var failed = data.failed;
var notification = null;
//Determine which notification to show.
//TODO: Refactor. Use foreach.
if (pending && pending.count > 0) {
notification = pending;
}
else if (running && running.count > 0) {
notification = running;
}
else if (success && success.count > 0) {
notification = success;
}
else if (failed && failed.count > 0) {
notification = failed;
}
if (notification) {
var msg = '';
if (!Notify.needsPermission) {
var items = notification.items;
for (var item in items) {
var build = items[item].build;
var projTitle = build.project_title;
var branch = build.branch;
var status = PHPCensor.STATUS[build.status];
var datePerformed = build.date_performed;
var dateFinished = build.date_finished;
var rn = "\r\n";
var build = {
projectTitle: projTitle,
branch: branch,
status: status,
datePerformed: datePerformed,
dateFinished: dateFinished
};
//Ignore if the last displayed notification is
//similar to what we're again about to display.
if (!PHPCensor.isWebNotifiedBuild(build)) {
msg +=
'Project title: ' + projTitle + rn +
'Git branch: ' + branch + rn +
'Status: ' + status + rn;
//Build details is empty during
//widget-all-projects-update.
if (datePerformed.length > 0) {
msg += datePerformed + rn;
}
if (dateFinished.length > 0) {
msg += dateFinished;
}
new Notify(
'PHP Censor Web Notification',
{body: msg}
).show();
}
}
}
else if (Notify.isSupported()) {
Notify.requestPermission(null, function(){
msg = 'Web notifications permission ' +
'has been denied by the user.'
console.warn(msg);
});
}
}
},
getBuilds: function () {
$.ajax({
url: APP_URL + 'build/ajax-queue',
@@ -163,16 +29,6 @@ var PHPCensor = {
error: PHPCensor.handleFailedAjax
});
if (NOTIFICATIONS) {
$.ajax({
url: APP_URL + 'web-notifications/builds-updated',
success: function (data) {
PHPCensor.showWebNotification(data);
},
error: PHPCensor.handleFailedAjax
});
}
},
getProjectBuilds: function () {
@@ -487,7 +343,6 @@ var PHPCensorConfirmDialog = Class.extend({
var Lang = {
get: function () {
var args = Array.prototype.slice.call(arguments);
;
var string = args.shift();
if (STRINGS[string]) {
@@ -33,18 +33,6 @@ PHPCensor.widgets.allProjects = {
error: PHPCensor.handleFailedAjax
});
if (NOTIFICATIONS) {
$.ajax({
url: APP_URL +
'web-notifications/widgets-all-projects-update/' +
projectId,
success: function (data) {
PHPCensor.showWebNotification(data);
},
error: PHPCensor.handleFailedAjax
});
}
});
}
};
@@ -258,9 +258,6 @@ protected function getConfigInformation(InputInterface $input, OutputInterface $
'rotate' => false,
'max_files' => 0,
],
'notifications' => [
'enabled' => false,
],
'email_settings' => [
'from_address' => 'PHP Censor <no-reply@php-censor.local>',
'smtp_address' => null,

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 09aa7f7

Please sign in to comment.