forked from DevoInc/browser-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowserify-task.js
101 lines (84 loc) · 2.23 KB
/
browserify-task.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
'use strict';
const devo = require('@devo/browser-sdk')
const credentials = require('./credentials.json')
const options = {
"dateFrom": "2018-07-02T11:00:00Z",
"dateTo": "2018-07-02T11:30:30Z",
"query": "from demo.ecommerce.data select eventdate,protocol,statusCode,method",
"destination": {
type: 'donothing',
params: {
topic: 'any'
}
},
};
const client = devo.client(credentials)
$( document ).ready(function() {
$("#btn_all").on( "click", function() {
loadTasks();
});
$("#btn_new").on( "click", function() {
client.query(options)
.then(loadTasks)
.catch(console.error)
});
});
function loadTasks() {
client.getTasks()
.then(addTasks)
.catch(console.error)
}
function addTasks(tasks) {
$("#divTableBody").html("");
addHead();
for (let i=0; i < tasks.object.length; i++) {
addRow(tasks.object[i]);
}
}
function addHead() {
const body = $('#divTableBody');
const tbh = $('<div></div>').addClass('divTableRow divTableHeading');
const td = $('<div></div>').addClass('divTableHead');
tbh.append(td.clone().text("ID"));
tbh.append(td.clone().text("Status"));
tbh.append(td.clone().text("LastDatetime"));
tbh.append(td.text("Options"));
body.append(tbh);
}
function addRow(event) {
const body = $('#divTableBody');
const tbh = $('<div></div>').addClass('divTableRow');
const td = $('<div></div>').addClass('divTableCell');
tbh.append(td.clone().text(event.id));
tbh.append(td.clone().text(event.status));
tbh.append(td.clone().text(event.lastDatetime));
td.append(
$('<button>Start</button>').click(function () {
client.startTask(event.id)
.then(data => {
alert('Started');
loadTasks();
})
.catch(console.error)
}));
td.append(
$('<button>Stop</button>').click(function () {
client.stopTask(event.id)
.then(data => {
alert('Stopped');
loadTasks();
})
.catch(console.error)
}));
td.append(
$('<button>Remove</button>').click(function () {
client.deleteTask(event.id)
.then(data => {
alert('Removed');
loadTasks();
})
.catch(console.error);
}));
tbh.append(td);
body.append(tbh)
}