Skip to content

Commit

Permalink
feat: send message (mail) script #1305
Browse files Browse the repository at this point in the history
  • Loading branch information
unocelli committed Nov 17, 2024
1 parent d08c6c1 commit 202d470
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 @@ -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'
}
];
}
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 @@ -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;
}

Expand Down Expand Up @@ -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]);
}
}
3 changes: 3 additions & 0 deletions client/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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 @@ -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;
}
Expand All @@ -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 = {
Expand Down

0 comments on commit 202d470

Please sign in to comment.