Skip to content

Commit

Permalink
feat: add system functions $getAlarmsHistory to use in script #1512 #…
Browse files Browse the repository at this point in the history
  • Loading branch information
unocelli committed Dec 7, 2024
1 parent e3300ef commit 9e07244
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client/src/app/_models/script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ export class SystemFunctions {
params: [],
paramsText: 'script.sys-fnc-getAlarms-params'
},
{
name: '$getAlarmsHistory',
mode: null,
text: 'script.sys-fnc-getAlarmsHistory-text',
tooltip: 'script.sys-fnc-getAlarmsHistory-tooltip',
params: [false, false],
paramsText: 'script.sys-fnc-getAlarmsHistory-params'
},
{
name: '$ackAlarm',
mode: null,
Expand Down
5 changes: 5 additions & 0 deletions client/src/app/_services/script.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class ScriptService {
code = code.replace(/\$getHistoricalTags\(/g, 'this.$getHistoricalTags(');
code = code.replace(/\$sendMessage\(/g, 'this.$sendMessage(');
code = code.replace(/\$getAlarms\(/g, 'await this.$getAlarms(');
code = code.replace(/\$getAlarmsHistory\(/g, 'await this.$getAlarmsHistory(');
code = code.replace(/\$ackAlarm\(/g, 'await this.$ackAlarm(');
return code;
}
Expand Down Expand Up @@ -183,6 +184,10 @@ export class ScriptService {
return await this.projectService.runSysFunctionSync('$getAlarms', null);
}

public async $getAlarmsHistory(from: Date, to: Date) {
return await this.projectService.runSysFunctionSync('$getAlarmsHistory', [from, to]);
}

public async $ackAlarm(alarmName: string, types?: AlarmsType[]) {
return await this.projectService.runSysFunctionSync('$ackAlarm', [alarmName, types]);
}
Expand Down
3 changes: 3 additions & 0 deletions client/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,9 @@
"script.sys-fnc-getAlarms-text": "$getAlarms()",
"script.sys-fnc-getAlarms-tooltip": "System function to get alarms list (): $getAlarms()",
"script.sys-fnc-getAlarms-params": "",
"script.sys-fnc-getAlarmsHistory-text": "$getAlarmsHistory(from msec., to msec.)",
"script.sys-fnc-getAlarmsHistory-tooltip": "System function to get historical alarms list (): $getAlarmsHistory(from as number, to as number)",
"script.sys-fnc-getAlarmsHistory-params": "'From msec.', 'To msec.'",
"script.sys-fnc-ackAlarms-text": "$ackAlarm(Alarm name, types)",
"script.sys-fnc-ackAlarms-tooltip": "System function to ACK alarm (): $ackAlarm(Alarm name as string, [types] 'highhigh|high|low')",
"script.sys-fnc-ackAlarms-params": "'Alarm name', 'types'",
Expand Down
6 changes: 6 additions & 0 deletions server/runtime/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ function ScriptsManager(_runtime) {
sysFncs['$getHistoricalTags'] = runtime.devices.getHistoricalTags;
sysFncs['$sendMessage'] = _sendMessage;
sysFncs['$getAlarms'] = _getAlarms;
sysFncs['$getAlarmsHistory'] = _getAlarmsHistory;
sysFncs['$ackAlarm'] = _ackAlarm;

return sysFncs;
Expand All @@ -250,6 +251,11 @@ function ScriptsManager(_runtime) {
return await runtime.alarmsMgr.getAlarmsValues(null, -1);
}

var _getAlarmsHistory = async function (start, end) {
const query = { start: start, end: end };
return await runtime.alarmsMgr.getAlarmsHistory(query, -1);
}

var _ackAlarm = async function (alarmName, types) {
const separator = runtime.alarmsMgr.getIdSeparator();
if (alarmName.indexOf(separator) === -1 && !utils.isNullOrUndefined(types)) {
Expand Down

0 comments on commit 9e07244

Please sign in to comment.