From 202d470bde3e7c147825d3bdc37f832c8c4267ee Mon Sep 17 00:00:00 2001 From: unocelli Date: Sun, 17 Nov 2024 17:52:53 +0100 Subject: [PATCH] feat: send message (mail) script #1305 --- client/src/app/_models/script.ts | 8 ++++++++ client/src/app/_services/script.service.ts | 5 +++++ client/src/assets/i18n/en.json | 3 +++ server/runtime/scripts/index.js | 6 ++++++ 4 files changed, 22 insertions(+) diff --git a/client/src/app/_models/script.ts b/client/src/app/_models/script.ts index 0fa478612..eb1892e16 100644 --- a/client/src/app/_models/script.ts +++ b/client/src/app/_models/script.ts @@ -189,6 +189,14 @@ export class SystemFunctions { params:['array', false, false], paramsText: 'script.sys-fnc-getHistoricalTag-params', paramFilter: ScriptParamFilterType.history + }, + { + name: '$sendMessage', + mode: null, + text: 'script.sys-fnc-sendMessage-text', + tooltip: 'script.sys-fnc-sendMessage-tooltip', + params: [false, false, false], + paramsText: 'script.sys-fnc-sendMessage-params' } ]; } diff --git a/client/src/app/_services/script.service.ts b/client/src/app/_services/script.service.ts index dc4fa182b..b3ff50035 100644 --- a/client/src/app/_services/script.service.ts +++ b/client/src/app/_services/script.service.ts @@ -93,6 +93,7 @@ export class ScriptService { code = code.replace(/\$invokeObject\(/g, 'this.$invokeObject('); code = code.replace(/\$runServerScript\(/g, 'this.$runServerScript('); code = code.replace(/\$getHistoricalTags\(/g, 'this.$getHistoricalTags('); + code = code.replace(/\$sendMessage\(/g, 'this.$sendMessage('); return code; } @@ -167,4 +168,8 @@ export class ScriptService { const query: DaqQuery = { sids: tagIds, from: fromDate, to: toDate }; return await lastValueFrom(this.hmiService.getDaqValues(query)); } + + public async $sendMessage(to: string, subject: string, message: string) { + return await this.projectService.runSysFunctionSync('$sendMessage', [to, subject, message]); + } } diff --git a/client/src/assets/i18n/en.json b/client/src/assets/i18n/en.json index ad9676a02..f3dc0fdc9 100644 --- a/client/src/assets/i18n/en.json +++ b/client/src/assets/i18n/en.json @@ -1268,6 +1268,9 @@ "script.sys-fnc-getHistoricalTag-text": "$getHistoricalTags(TagIds array, from msec., to msec.)", "script.sys-fnc-getHistoricalTag-tooltip":"get historical tags by milliseconds range: $getHistoricalTags([TagIds] as array, from as number, to as number)", "script.sys-fnc-getHistoricalTag-params":"'Tag Ids array', 'From msec.', 'To msec.'", + "script.sys-fnc-sendMessage-text": "$sendMessage(address, subject, message)", + "script.sys-fnc-sendMessage-tooltip": "System function to send Message (Mail): $sendMessage(address as string, subject as string, message as string)", + "script.sys-fnc-sendMessage-params": "'address', 'subject', 'message'", "script.template-chart-data-text": "Customized chart data", "script.template-chart-data-tooltip": "Code template of customized chart data to return", diff --git a/server/runtime/scripts/index.js b/server/runtime/scripts/index.js index cb64f8e1e..42b9d0a70 100644 --- a/server/runtime/scripts/index.js +++ b/server/runtime/scripts/index.js @@ -229,6 +229,7 @@ function ScriptsManager(_runtime) { sysFncs['$getDeviceProperty'] = runtime.devices.getDeviceProperty; sysFncs['$setDeviceProperty'] = runtime.devices.setDeviceProperty; sysFncs['$getHistoricalTags'] = runtime.devices.getHistoricalTags; + sysFncs['$sendMessage'] = _sendMessage; return sysFncs; } @@ -237,6 +238,11 @@ function ScriptsManager(_runtime) { let command = { command: ScriptCommandEnum.SETVIEW, params: [view, force] }; runtime.scriptSendCommand(command); } + + var _sendMessage = async function (address, subject, message) { + var temp = await runtime.notificatorMgr.sendMailMessage(null, address, subject, message, null, null); + return temp; + } } module.exports = {