f47c98f072b4bc4f2a95fb1028c73f231ed7bd0e
[policy/apex-pdp.git] / client / client-monitoring / src / main / resources / webapp / js / ApexEngineService.js
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 /*
22  * Create the Engine Service Table 
23  */
24 function createEngineServiceTable() {
25     var tableId = config.engineService.tableId;
26     var headers = config.engineService.headers;
27     var table = createEngineTable($("." + config.engineService.parent), tableId, headers.map(function(a) {
28         return a.title;
29     }));
30     var tableRow = document.createElement("tr");
31     var tableData = "";
32     for ( var h in headers) {
33         tableData += "<td id=" + tableId + "_" + headers[h].id + "></td>";
34     }
35     tableRow.innerHTML = tableData;
36     var actionTD = $(tableRow).find("#" + tableId + "_periodic_events");
37     actionTD
38             .html('<input type="text" name="period" id="period" style="display:inline-block"><label class="ebSwitcher"><input type="checkbox" class="ebSwitcher-checkbox" /><div class="ebSwitcher-body"><div class="ebSwitcher-onLabel">Stopped</div><div class="ebSwitcher-switch"></div><div class="ebSwitcher-offLabel">Started</div></div></label>');
39     var period = actionTD.find("#period");
40     var switcher = actionTD.find(".ebSwitcher");
41     switcher.css('display', 'inline-block');
42     switcher.css('margin-left', '5px');
43     switcher.css('vertical-align', 'middle');
44     var checkbox = $(actionTD).find('input:checkbox:first');
45     checkbox.change(function(event) {
46         var startstop;
47         if (checkbox.prop('checked')) {
48             startstop = "Stop";
49         } else {
50             startstop = "Start";
51         }
52         this.servicesCall.abort();
53         ajax_get(restRootURL + "periodiceventstartstop", startStopCallback, this.engineURL.hostname,
54                 this.engineURL.port, {
55                     engineId : this.engineId,
56                     startstop : startstop,
57                     period : period.val()
58                 }, resetPeriodicEvents);
59     }.bind(this));
60     $(table).children("#engineTableBody").append(tableRow);
61 }
62
63 /*
64  * Check for any changes in the Engine Service Table data and update only where
65  * necessary
66  */
67 function setEngineServiceData(engineId, modelId, server, port, periodicEvents) {
68     this.engineId = engineId;
69     var tableId = config.engineService.tableId;
70     var headers = config.engineService.headers.map(function(a) {
71         return a.id;
72     });
73     var data = [ engineId, server + ":" + port, modelId ];
74
75     var engineServiceTable = $("#engineServicesTable");
76
77     for ( var h in headers) {
78         var td = engineServiceTable.find("#" + tableId + "_" + headers[h]);
79         if (td.html() !== data[h]) {
80             engineServiceTable.find("#" + tableId + "_" + headers[h]).html(data[h]);
81         }
82     }
83
84     var actionTD = engineServiceTable.find("#" + tableId + "_periodic_events");
85     var checkbox = $(actionTD).find('input:checkbox:first');
86     if (checkbox.is(":checked") === periodicEvents) {
87         checkbox.prop("checked", !checkbox.prop("checked"));
88     }
89 }
90
91 /*
92  * Resets the switcher for Periodic Events in the Engine Service Table
93  */
94 function resetPeriodicEvents() {
95     var engineServiceTable = $("#engineServicesTable");
96     var periodicEventsTD = $(engineServiceTable).find("#engineServicesTable_periodic_events");
97     var checkbox = $(periodicEventsTD).find('input:checkbox:first');
98     if (checkbox.is(":checked")) {
99         checkbox.prop("checked", false);
100     }
101 }