diff --git a/client/src/app/_models/script.ts b/client/src/app/_models/script.ts index a01285bc..7ac7ed3d 100644 --- a/client/src/app/_models/script.ts +++ b/client/src/app/_models/script.ts @@ -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, diff --git a/client/src/app/_services/script.service.ts b/client/src/app/_services/script.service.ts index 2769a7f6..aa86c101 100644 --- a/client/src/app/_services/script.service.ts +++ b/client/src/app/_services/script.service.ts @@ -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; } @@ -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]); } diff --git a/client/src/assets/i18n/en.json b/client/src/assets/i18n/en.json index e1fc10a7..32824dad 100644 --- a/client/src/assets/i18n/en.json +++ b/client/src/assets/i18n/en.json @@ -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'", diff --git a/server/runtime/scripts/index.js b/server/runtime/scripts/index.js index 7ac004fa..a90902f3 100644 --- a/server/runtime/scripts/index.js +++ b/server/runtime/scripts/index.js @@ -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; @@ -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)) {