/*
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020-2022 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
import {ajax_get} from "./ApexAjax";
import {rightClickMenu_scopePreserver} from "./contextMenu";
import {createTable} from "./ApexTable";
import {apexUtils_removeElement} from "./ApexUtils";
function eventTab_reset() {
eventTab_deactivate();
eventTab_activate();
}
function eventTab_activate() {
eventTab_create();
var requestURL = window.restRootURL + "/Event/Get?name=&version=";
ajax_get(requestURL, function(data) {
$("#eventTableBody").find("tr:gt(0)").remove();
for (let value of data.messages) {
var event = JSON.parse(value);
var eventTableRow_tr = document.createElement("tr");
var eventid = event.key.name + ":" + event.key.version;
var eventTableRow =
"
" +
eventid +
" | " +
"" +
event.nameSpace +
" | " +
"" +
event.source +
" | " +
"" +
event.target +
" | ";
eventTableRow += "Parameter | Parameter Type/Schema | Optional | ";
for (let fieldEntry of event.parameter.entry) {
eventTableRow +=
"" +
fieldEntry.key +
" | " +
"" +
fieldEntry.value.fieldSchemaKey.name + ":" + fieldEntry.value.fieldSchemaKey.version +
" | " +
fieldEntry.value.optional +
" | ";
}
eventTableRow += "
| ";
eventTableRow_tr.innerHTML = eventTableRow;
eventTableRow_tr.addEventListener('contextmenu', rightClickMenu_scopePreserver("eventTabContent", "Event", event.key.name, event.key.version));
$("#eventTableBody").append(eventTableRow_tr);
}
});
}
function eventTab_deactivate() {
apexUtils_removeElement("eventTabContent");
}
function eventTab_create() {
var eventTab = document.getElementById("eventsTab");
//Testing purposes
if(eventTab === null){
eventTab = document.createElement('eventsTab');
}
var eventTabContent = document.getElementById("eventTabContent");
if (eventTabContent != null) {
return
}
eventTabContent = document.createElement("eventTabContent");
eventTab.appendChild(eventTabContent);
eventTabContent.setAttribute("id", "eventTabContent");
eventTabContent.addEventListener('contextmenu', rightClickMenu_scopePreserver("eventTabContent", "Event", null, null));
var eventTable = createTable("eventTable");
eventTabContent.appendChild(eventTable);
var eventTableHeader = document.createElement("thead");
eventTable.appendChild(eventTableHeader);
eventTableHeader.setAttribute("id", "eventTableHeader");
var eventTableHeaderRow = document.createElement("tr");
eventTableHeader.appendChild(eventTableHeaderRow);
eventTableHeaderRow.setAttribute("id", "eventTableHeaderRow");
var eventTableKeyHeader = document.createElement("th");
eventTableHeaderRow.appendChild(eventTableKeyHeader);
eventTableKeyHeader.setAttribute("id", "eventTableKeyHeader");
eventTableKeyHeader.appendChild(document.createTextNode("Event"));
var eventTableNamespaceHeader = document.createElement("th");
eventTableHeaderRow.appendChild(eventTableNamespaceHeader);
eventTableNamespaceHeader.setAttribute("id", "eventTableNamespaceHeader");
eventTableNamespaceHeader.appendChild(document.createTextNode("Name Space"));
var eventTableSourceHeader = document.createElement("th");
eventTableHeaderRow.appendChild(eventTableSourceHeader);
eventTableSourceHeader.setAttribute("id", "eventTableSourceHeader");
eventTableSourceHeader.appendChild(document.createTextNode("Source"));
var eventTableTargetHeader = document.createElement("th");
eventTableHeaderRow.appendChild(eventTableTargetHeader);
eventTableTargetHeader.setAttribute("id", "eventTableTargetHeader");
eventTableTargetHeader.appendChild(document.createTextNode("Target"));
var eventTableParameterHeader = document.createElement("th");
eventTableHeaderRow.appendChild(eventTableParameterHeader);
eventTableParameterHeader.setAttribute("id", "eventTableParameterHeader");
eventTableParameterHeader.appendChild(document.createTextNode("Parameters"));
var eventTableBody = document.createElement("tbody");
eventTable.appendChild(eventTableBody);
eventTable.setAttribute("id", "eventTableBody");
}
export {
eventTab_reset,
eventTab_activate,
eventTab_deactivate,
eventTab_create
}