-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70001fe
commit b8d12e7
Showing
86 changed files
with
1,705 additions
and
1,791 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
var Promise = require('bluebird'); | ||
var shared = require('./alarm.shared.js'); | ||
|
||
module.exports = function cancel(alarm){ | ||
if(shared.tabAlarmScheduled.hasOwnProperty(alarm.id)){ | ||
module.exports = function cancel(alarm) { | ||
if (shared.tabAlarmScheduled.hasOwnProperty(alarm.id)) { | ||
sails.log.info(`Cancelling alarm ID n° ${alarm.id}`); | ||
|
||
return gladys.scheduler.delete({index: shared.tabAlarmScheduled[alarm.id]}) | ||
.then(function(){ | ||
return Promise.resolve(alarm); | ||
}); | ||
|
||
return gladys.scheduler.delete({ | ||
index: shared.tabAlarmScheduled[alarm.id] | ||
}) | ||
.then(function() { | ||
return Promise.resolve(alarm); | ||
}); | ||
} | ||
return Promise.resolve(alarm); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
module.exports = function create(alarm) { | ||
|
||
module.exports = function create (alarm) { | ||
|
||
if(!alarm || (!alarm.dayofweek && !alarm.datetime) || (alarm.dayofweek && !alarm.time)){ | ||
if (!alarm || (!alarm.dayofweek && !alarm.datetime) || (alarm.dayofweek && !alarm.time)) { | ||
return Promise.reject(new Error('Wrong parameters, missing arguments.')); | ||
} | ||
|
||
// create alarm in db | ||
return Alarm.create(alarm) | ||
.then(function(alarm){ | ||
.then(function(alarm) { | ||
|
||
// if alarm is in the future and active, we schedule the alarm | ||
if(alarm.active && (new Date(alarm.datetime) > new Date() || alarm.dayofweek !== -1)){ | ||
if (alarm.active && (new Date(alarm.datetime) > new Date() || alarm.dayofweek !== -1)) { | ||
|
||
// schedule the alarm with gladys.schedule | ||
return gladys.alarm.schedule(alarm); | ||
} else { | ||
return gladys.alarm.schedule(alarm); | ||
} else { | ||
return Promise.resolve(alarm); | ||
} | ||
}); | ||
}; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
var queries = require('./alarm.queries.js'); | ||
|
||
module.exports = function(alarm){ | ||
if(!alarm.id){ | ||
module.exports = function(alarm) { | ||
|
||
if (!alarm.id) { | ||
return Promise.reject(new Error('You should provide an id to delete an alarm')); | ||
} | ||
|
||
// deleting alarm from database | ||
return gladys.utils.sql(queries.deleteAlarm, [alarm.id]) | ||
.then(function(alarm){ | ||
// cancelling alarm | ||
return gladys.alarm.cancel(alarm); | ||
}); | ||
}; | ||
.then(function(alarm) { | ||
|
||
// cancelling alarm | ||
return gladys.alarm.cancel(alarm); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
|
||
module.exports = { | ||
getAlarms: `SELECT * FROM alarm | ||
|
||
getAlarms: `SELECT * FROM alarm | ||
WHERE active = 1 | ||
AND ((dayofweek = -1 AND datetime > SYSDATE()) OR dayofweek <> -1 )`, | ||
|
||
deleteAlarm: `DELETE FROM alarm WHERE id = ?` | ||
|
||
}; | ||
deleteAlarm: `DELETE FROM alarm WHERE id = ?` | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
var shared = require('./alarm.shared.js'); | ||
|
||
module.exports = function schedule(alarm){ | ||
module.exports = function schedule(alarm) { | ||
var rule; | ||
|
||
// if the alarm is reccuring | ||
if(alarm.dayofweek === -1){ | ||
if (alarm.dayofweek === -1) { | ||
rule = new Date(alarm.datetime); | ||
}else{ | ||
} else { | ||
rule = { | ||
hour: parseInt(alarm.time.slice(0,2)), | ||
minute: parseInt(alarm.time.slice(3)), | ||
hour: parseInt(alarm.time.slice(0, 2)), | ||
minute: parseInt(alarm.time.slice(3)), | ||
dayOfWeek: alarm.dayofweek | ||
}; | ||
} | ||
|
||
var options = { | ||
rule: rule, | ||
eventName: 'alarmRing', | ||
value: alarm.id | ||
rule: rule, | ||
eventName: 'alarmRing', | ||
value: alarm.id | ||
}; | ||
|
||
return gladys.scheduler.create(options) | ||
.then(function(index){ | ||
shared.tabAlarmScheduled[alarm.id] = index; | ||
return Promise.resolve(alarm); | ||
}); | ||
}; | ||
.then(function(index) { | ||
shared.tabAlarmScheduled[alarm.id] = index; | ||
return Promise.resolve(alarm); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
|
||
// we saved here scheduled alarm to cancel them in the future | ||
module.exports = { | ||
tabAlarmScheduled: {} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
// update an alarm | ||
module.exports = function(params) { | ||
return Alarm.update({ | ||
id: params.id | ||
}, params.alarm) | ||
.then(function(alarms) { | ||
|
||
if (alarms.length === 0) { | ||
return Promise.reject(new Error('Alarm not found')); | ||
} | ||
|
||
// update an alarm | ||
module.exports = function (params){ | ||
return Alarm.update({id:params.id}, params.alarm) | ||
.then(function(alarms){ | ||
|
||
if(alarms.length === 0){ | ||
return Promise.reject(new Error('Alarm not found')); | ||
} | ||
|
||
if(!alarms[0].active){ | ||
return gladys.alarm.cancel(alarms[0]); | ||
} else { | ||
return Promise.resolve(alarms[0]); | ||
} | ||
}); | ||
}; | ||
if (!alarms[0].active) { | ||
return gladys.alarm.cancel(alarms[0]); | ||
} else { | ||
return Promise.resolve(alarms[0]); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
|
||
|
||
module.exports.cancel = require('./alarm.cancel.js'); | ||
module.exports.create = require('./alarm.create.js'); | ||
module.exports.delete = require('./alarm.delete.js'); | ||
module.exports.init = require('./alarm.init.js'); | ||
module.exports.update = require('./alarm.update.js'); | ||
|
||
module.exports.schedule = require('./alarm.schedule.js'); | ||
module.exports.schedule = require('./alarm.schedule.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.