-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
135 lines (124 loc) · 5.92 KB
/
index.html
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style>
html,
body,
main {
/* Ensure the body fills the view, so clicks are handled everywhere: */
width: 100%;
height: 100%;
font-family: Monospace;
}
a.button {
background: #ececec;
border-radius: 10px;
padding: 5px 20px;
font-family: Lato;
font-weight: bold;
color: #3f3f3f;
text-decoration: none;
text-shadow: 0px 1px 0px #fff;
border: 1px solid #a7a7a7;
margin: 0px auto;
box-shadow: 0px 2px 1px white inset, 0px -2px 8px white, 0px 2px 5px rgba(0, 0, 0, 0.1), 0px 8px 10px rgba(0, 0, 0, 0.1);
-webkit-transition: box-shadow 0.5s;
}
a.button i {
float: right;
margin: 2px;
}
a.button:hover {
box-shadow: 0px 2px 1px lightgrey inset, 0px -2px 20px lightgrey, 0px 2px 5px rgba(0, 0, 0, 0.1), 0px 8px 10px rgba(0, 0, 0, 0.1);
}
a.button:active {
box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.5) inset, 0px -2px 20px white, 0px 1px 5px rgba(0, 0, 0, 0.1), 0px 2px 10px rgba(0, 0, 0, 0.1);
background: -webkit-linear-gradient(top, #d1d1d1 0%, #ececec 100%);
}
</style>
<!-- Put SCRIPT tags to load 3rd party libraries here -->
</head>
<body>
<div>
<a href="#" class="button" id="btnid" onclick="startWorkflow()">Refresh Workflow</a><br />
<br />
<div id="jobState"></div>
</div>
<script src="/_global_/customview/v1/omniscope.js"></script>
<!-- Add the Omniscope custom view API -->
<script>
var _jobId = "NA";
var _blocksToExecute;
var _showJobState;
var _projEndpoint;
var _check;
if (!omniscope || !omniscope.view) throw new Error("Omniscope chart API is not loaded");
function startWorkflow() {
var options = omniscope.view.context().options;
var xhr = new XMLHttpRequest();
xhr.open("POST", _projEndpoint + "w/execute", true);
xhr.onreadystatechange = function () {
if (xhr.readyState == XMLHttpRequest.DONE) {
if (this.status == 200) {
_jobId = JSON.parse(xhr.responseText).jobId;
document.getElementById("jobState").innerHTML = "Job state = STARTED";
} else if (this.status == 403) {
document.getElementById("jobState").innerHTML = xhr.responseText;
} else {
document.getElementById("jobState").innerHTML = JSON.parse(xhr.responseText).errorMessage;
}
}
};
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send('{"blocks": ["' + _blocksToExecute.join('","') + '"], "refreshFromSource": ' + options.items.refreshFromSource + ', "cancelExisting": false}');
_check = setInterval(checkWorkflowState, 1000);
}
function checkWorkflowState() {
var xhr = new XMLHttpRequest();
xhr.open("GET", _projEndpoint + "w/job/" + _jobId + "/state", true);
xhr.onreadystatechange = function () {
if (xhr.readyState == XMLHttpRequest.DONE) {
if (this.status == 200) {
var _jobState = JSON.parse(xhr.responseText).jobState;
document.getElementById("jobState").innerHTML = "Job state = " + _jobState;
if (_jobState === "COMPLETED") {
clearInterval(_check);
}
} else if (this.status == 403) {
document.getElementById("jobState").innerHTML = xhr.responseText;
clearInterval(_check);
} else {
document.getElementById("jobState").innerHTML = JSON.parse(xhr.responseText).errorMessage;
clearInterval(_check);
}
}
};
xhr.send();
}
omniscope.view.on("load", function () {
window.onerror = function (msg) {
omniscope.view.error(msg);
};
});
// Ensure clicks on unoccupied space clear the selection in Omniscope, and close menus:
document.body.addEventListener("click", function () {
omniscope.view.whitespaceClick();
});
// Naively redraw on any of these events
// (load = first init, update = external settings/state change, resize = browser window resized)
omniscope.view.on(["load", "update", "resize"], function () {
var options = omniscope.view.context().options;
_blocksToExecute = options.items.block.split(",");
document.getElementById("btnid").textContent = options.items.buttonText ? options.items.buttonText : "Refresh Workflow";
if (options.items.showJobState) {
document.getElementById("jobState").style.display = "block";
} else {
document.getElementById("jobState").style.display = "none";
}
_projEndpoint = omniscope.view.context().baseUrl + "../../../../";
//console.log(_projEndpoint + " -> " +_blocksToExecute);
});
</script>
</body>
</html>