-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathalert-template.js
41 lines (37 loc) · 1.11 KB
/
alert-template.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// import { $http } from '@/services/ng';
import Mustache from 'mustache';
export default class AlertTemplate {
render(alert, queryResult) {
const view = {
state: alert.state,
rows: queryResult.rows,
cols: queryResult.columns,
};
const result = Mustache.render(alert.options.template, view);
const escaped = result
.replace(/"/g, '"')
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/\n|\r/g, '<br>');
return { escaped, raw: result };
}
constructor() {
this.helpMessage = `using template engine "mustache".
you can build message with latest query result.
variable name "rows" is assigned as result rows. "cols" as result columns, "state" as alert state.`;
this.editorOptions = {
useWrapMode: true,
showPrintMargin: false,
advanced: {
behavioursEnabled: true,
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
autoScrollEditorIntoView: true,
},
onLoad(editor) {
editor.$blockScrolling = Infinity;
},
};
}
}