(feat) new Alarm service + alarms support in all modules
parent
e8dcc6df37
commit
7365f77dd5
|
@ -1,8 +1,6 @@
|
|||
/* UIxReminderEditor.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009 Inverse inc.
|
||||
*
|
||||
* Author: Francis Lachapelle <flachapelle@inverse.ca>
|
||||
* Copyright (C) 2009-2015 Inverse inc.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
/* UIxReminderEditor.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009 Inverse inc.
|
||||
*
|
||||
* Author: Francis Lachapelle <flachapelle@inverse.ca>
|
||||
* Copyright (C) 2009-2015 Inverse inc.
|
||||
*
|
||||
* This file is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
|
|
@ -0,0 +1,142 @@
|
|||
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @name Alarm
|
||||
* @constructor
|
||||
*/
|
||||
function Alarm() {
|
||||
this.currentAlarm = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name getAlarms
|
||||
* @desc Fetch the list of alarms from the server and use the last one
|
||||
*/
|
||||
Alarm.getAlarms = function() {
|
||||
var _this = this;
|
||||
var now = new Date();
|
||||
var browserTime = Math.floor(now.getTime()/1000);
|
||||
|
||||
this.$$resource.fetch('', 'alarmslist?browserTime=' + browserTime).then(function(data) {
|
||||
|
||||
var alarms = data.alarms.sort(function reverseSortByAlarmTime(a, b) {
|
||||
var x = parseInt(a[2]);
|
||||
var y = parseInt(b[2]);
|
||||
return (y - x);
|
||||
});
|
||||
|
||||
if (alarms.length > 0) {
|
||||
var next = alarms.pop();
|
||||
var now = new Date();
|
||||
var utc = Math.floor(now.getTime()/1000);
|
||||
var url = next[0] + '/' + next[1];
|
||||
var alarmTime = parseInt(next[2]);
|
||||
var delay = alarmTime;
|
||||
if (alarmTime > 0) delay -= utc;
|
||||
var d = new Date(alarmTime*1000);
|
||||
//console.log ("now = " + now.toUTCString());
|
||||
//console.log ("next event " + url + " in " + delay + " seconds (on " + d.toUTCString() + ")");
|
||||
|
||||
var f = angular.bind(_this, Alarm.showAlarm, url);
|
||||
|
||||
if (_this.currentAlarm)
|
||||
_this.$timeout.cancel(_this.currentAlarm);
|
||||
|
||||
_this.currentAlarm = _this.$timeout(f, delay*1000);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @name showAlarm
|
||||
* @desc Show the latest alarm using a toast
|
||||
* @param url The URL of the calendar component for snoozing
|
||||
*/
|
||||
Alarm.showAlarm = function(url) {
|
||||
var _this = this;
|
||||
|
||||
this.$toast.show({
|
||||
position: 'top right',
|
||||
hideDelay: 0,
|
||||
template: [
|
||||
'<md-toast>',
|
||||
' <md-input-container>',
|
||||
' <md-select ng-model="reminder">',
|
||||
' <md-option value=5>',
|
||||
l('5 minutes'),
|
||||
' </md-option>',
|
||||
' <md-option value=10>',
|
||||
l('10 minutes'),
|
||||
' </md-option>',
|
||||
' <md-option value=15>',
|
||||
l('15 minutes'),
|
||||
' </md-option>',
|
||||
' <md-option value=30>',
|
||||
l('30 minutes'),
|
||||
' </md-option>',
|
||||
' <md-option value=45>',
|
||||
l('45 minutes'),
|
||||
' </md-option>',
|
||||
' <md-option value=60>',
|
||||
l('1 hour'),
|
||||
' </md-option>',
|
||||
' <md-option value=1440>',
|
||||
l('1 day'),
|
||||
' </md-option>',
|
||||
' </md-select>',
|
||||
' </md-input-container>',
|
||||
' <md-button ng-click="cancel()">',
|
||||
l('Cancel'),
|
||||
' </md-button>',
|
||||
' <md-button ng-click="ok()">',
|
||||
l('Ok'),
|
||||
' </md-button>',
|
||||
'</md-toast>'
|
||||
].join(''),
|
||||
locals: {
|
||||
url: url
|
||||
},
|
||||
controller: AlarmController
|
||||
});
|
||||
|
||||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
AlarmController.$inject = ['scope', '$mdToast', 'url'];
|
||||
function AlarmController(scope, $mdToast, url) {
|
||||
scope.reminder = '10';
|
||||
scope.cancel = function() {
|
||||
$mdToast.hide();
|
||||
};
|
||||
scope.ok = function() {
|
||||
_this.$$resource.fetch(url, 'view?snoozeAlarm=' + scope.reminder);
|
||||
$mdToast.hide();
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @memberof Alarm
|
||||
* @desc The factory we'll register as Alarm in the Angular module SOGo.Common
|
||||
* @ngInject
|
||||
*/
|
||||
AlarmService.$inject = ['$timeout', 'sgSettings', 'Resource', '$mdToast'];
|
||||
function AlarmService($timeout, Settings, Resource, $mdToast) {
|
||||
angular.extend(Alarm, {
|
||||
$timeout: $timeout,
|
||||
$$resource: new Resource(Settings.activeUser.folderURL + 'Calendar', Settings.activeUser),
|
||||
$toast: $mdToast
|
||||
});
|
||||
|
||||
return Alarm; // return constructor
|
||||
}
|
||||
|
||||
/* Factory registration in Angular module */
|
||||
angular
|
||||
.module('SOGo.Common')
|
||||
.factory('Alarm', AlarmService);
|
||||
|
||||
})();
|
|
@ -9,8 +9,8 @@
|
|||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
navController.$inject = ['$scope', '$timeout', '$interval', '$http', '$mdSidenav', '$mdBottomSheet', '$mdMedia', '$log', 'sgConstant', 'sgSettings'];
|
||||
function navController($scope, $timeout, $interval, $http, $mdSidenav, $mdBottomSheet, $mdMedia, $log, sgConstant, sgSettings) {
|
||||
navController.$inject = ['$scope', '$timeout', '$interval', '$http', '$mdSidenav', '$mdBottomSheet', '$mdMedia', '$log', 'sgConstant', 'sgSettings', 'Alarm'];
|
||||
function navController($scope, $timeout, $interval, $http, $mdSidenav, $mdBottomSheet, $mdMedia, $log, sgConstant, sgSettings, Alarm) {
|
||||
|
||||
$scope.activeUser = sgSettings.activeUser;
|
||||
|
||||
|
@ -52,6 +52,8 @@
|
|||
}, function(newVal) {
|
||||
$scope.isGtMedium = newVal;
|
||||
});
|
||||
|
||||
Alarm.getAlarms();
|
||||
}
|
||||
|
||||
angular.module('SOGo.Common')
|
||||
|
|
|
@ -59,8 +59,8 @@
|
|||
/**
|
||||
* @ngInject
|
||||
*/
|
||||
ComponentEditorController.$inject = ['$rootScope', '$scope', '$log', '$timeout', '$mdDialog', 'User', 'Calendar', 'Component', 'AddressBook', 'Card', 'stateComponent'];
|
||||
function ComponentEditorController($rootScope, $scope, $log, $timeout, $mdDialog, User, Calendar, Component, AddressBook, Card, stateComponent) {
|
||||
ComponentEditorController.$inject = ['$rootScope', '$scope', '$log', '$timeout', '$mdDialog', 'User', 'Calendar', 'Component', 'AddressBook', 'Card', 'Alarm', 'stateComponent'];
|
||||
function ComponentEditorController($rootScope, $scope, $log, $timeout, $mdDialog, User, Calendar, Component, AddressBook, Card, Alarm, stateComponent) {
|
||||
var vm = this, component;
|
||||
|
||||
vm.calendars = Calendar.$calendars;
|
||||
|
@ -163,6 +163,7 @@
|
|||
.then(function(data) {
|
||||
$rootScope.$broadcast('calendars:list');
|
||||
$mdDialog.hide();
|
||||
Alarm.getAlarms();
|
||||
}, function(data, status) {
|
||||
$log.debug('failed');
|
||||
});
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
//@import 'components/swipe/swipe';
|
||||
@import 'components/switch/switch';
|
||||
@import 'components/tabs/tabs';
|
||||
//@import 'components/toast/toast';
|
||||
@import 'components/toast/toast';
|
||||
@import 'components/toolbar/toolbar';
|
||||
@import 'components/tooltip/tooltip';
|
||||
@import 'components/virtualRepeat/virtualRepeat';
|
||||
|
|
Loading…
Reference in New Issue