frontend: new parameters to setup kind of notifications allowed

This commit is contained in:
nemunaire 2019-01-19 08:04:54 +01:00
parent 24989c4cfa
commit ef35879dde
4 changed files with 141 additions and 15 deletions

View file

@ -77,12 +77,17 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$rootScope.current_tag = undefined;
$rootScope.notify_field = 0;
Notification.requestPermission().then(function(result) {
if (result == "granted")
$rootScope.notify_field = 7;
else
$rootScope.notify_field = 0;
});
if ('Notification' in window)
Notification.requestPermission(function(result) {
if (result == "granted") {
if (localStorage && localStorage.notification)
$rootScope.notify_field = localStorage.notification;
else
$rootScope.notify_field = 63;
}
else
$rootScope.notify_field = 0;
});
})
.component('flagKey', {
bindings: {
@ -259,7 +264,30 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
else if (event.time > maxTimeSeen)
maxTimeSeen = event.time;
if ($rootScope.notify_field != 0) {
// Determine the kind of event
var kind = 1;
if (event.txt.match(/<\/strong> qui vient de nous rejoindre/)) {
kind = 64;
} else {
var res = event.txt.match(/(\w+) le <strong>\d+<sup>e<\/sup><\/strong> défi [^&]+/)
if (res) {
if (res[1] == "résolu")
kind = 8;
else if (res[1] == "pour")
kind = 16;
else if (res[1] == "tente")
kind = 32;
}
}
if (kind != 1) {
if ($scope.my && $scope.my.name && event.txt.indexOf($scope.my.name) >= 0)
kind |= 2;
else
kind |= 4;
}
if ((kind & $rootScope.notify_field) == kind) {
var notification = new Notification("Challenge forensic", {body: event.txt.replace(/&#(\d+);/g, function(match, dec) {return String.fromCharCode(dec);}).replace(/(<([^>]+)>)/ig,""), badge: "/img/icon-" + event.kind + ".ico", icon: "/img/icon-" + event.kind + ".ico"});
notification.onclick = function(ev) {
$location.url("/edit");
@ -542,7 +570,7 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
});
}
})
.controller("MyTeamController", function($scope, $http, $rootScope, $timeout) {
.controller("MyTeamController", function($scope, $http, $rootScope, $timeout, $location) {
$rootScope.current_theme = 0;
$rootScope.current_exercice = 0;
$rootScope.current_tag = undefined;
@ -555,6 +583,32 @@ angular.module("FICApp", ["ngRoute", "ngSanitize"])
$rootScope.message = "";
$rootScope.sberr = "";
$scope.notify = {
info: ($rootScope.notify_field & 1) != 1,
team: ($rootScope.notify_field & 2) != 2,
others: ($rootScope.notify_field & 4) != 4,
solve: ($rootScope.notify_field & 8) != 8,
hint: ($rootScope.notify_field & 16) != 16,
tries: ($rootScope.notify_field & 32) != 32,
rename: ($rootScope.notify_field & 64) != 64,
}
$scope.alternotify = function() {
$rootScope.notify_field =
($scope.notify.info?0:1) |
($scope.notify.team?0:2) |
($scope.notify.others?0:4) |
($scope.notify.solve?0:8) |
($scope.notify.hint?0:16) |
($scope.notify.tries?0:32) |
($scope.notify.rename?0:64);
if ($rootScope.notify_field != 0)
localStorage.notification = $rootScope.notify_field;
else
delete localStorage.notification;
$location.url("/");
}
var cbt;
$scope.tsubmit = function() {