e7ca85de382b6acb06611d6ea80a4b5dba261ccc
[nonrtric/plt/sme.git] / invoker / view / js / script.js
1 /*
2    ========================LICENSE_START=================================
3    O-RAN-SC
4    %%
5    Copyright (C) 2023: Nordix Foundation
6    %%
7    Licensed under the Apache License, Version 2.0 (the "License");
8    you may not use this file except in compliance with the License.
9    You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13    Unless required by applicable law or agreed to in writing, software
14    distributed under the License is distributed on an "AS IS" BASIS,
15    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16    See the License for the specific language governing permissions and
17    limitations under the License.
18    ========================LICENSE_END===================================
19 */
20 const isObject = (value) => typeof value === "object" && value !== null
21
22 function checkValue(value){
23     return (isObject(value) ? value : "");
24 }
25
26 function printResources(resources) {
27     let res = Object.values(checkValue(resources));
28     let out = `<p class="lead">Resources:</p><ul>`;
29     res.forEach((r) => {
30         out += `<li>
31             <p>
32             <strong>CommType:</strong> ${r.commType}
33             <strong>CustOpName:</strong> ${r.custOpName} 
34             <strong>ResourceName:</strong> ${r.resourceName}
35             <strong>Uri:</strong> ${r.uri} 
36             <strong>Description:</strong> ${r.description}
37             <strong>Operations:</strong> ${Object.values(checkValue(r.operations))}
38             </p>
39             </li>`;
40     });
41     out += `</ul>`;
42     return out;
43 }
44
45 function printCustomOperations(custOperations) {
46     let operations = Object.values(checkValue(custOperations));
47     let out = `<p class="lead"> Custom Operations:</p><ul>`;
48     operations.forEach((o) => {
49         out += `<li>
50             <p>
51             <strong>CommType:</strong> ${o.commType}
52             <strong>CustOpName:</strong> ${o.custOpName} 
53             <strong>Description:</strong> ${o.description}
54             <strong>Operations:</strong> ${Object.values(checkValue(o.operations))}
55             </p>
56             </li>`;
57     });
58     out += `</ul>`;
59     return out;
60 }
61
62 function printVersions(versions) {
63     let vers = Object.values(checkValue(versions));
64     let out = `<p class="lead">Versions:</p><ul>`;
65     vers.forEach((v) => {
66         out += `<li>
67             <p>
68             <strong>ApiVersion:</strong> ${v.apiVersion} 
69             ${printCustomOperations(v.custOperations)}
70             ${printResources(v.resources)}
71             </p>
72             </li>`;
73     });
74     out += `</ul>`;
75     return out;
76 }
77
78 function printInterfaceDescription(description) {
79     let interfaceDescriptions = Object.values(checkValue(description));
80     let out = `<p class="lead">Interface Description:</p><ul>`;
81     interfaceDescriptions.forEach((d) => {
82         out += `<li>
83             <p>
84             <strong>Ipv4Addr:</strong> ${d.ipv4Addr} 
85             <strong>Ipv6Addr:</strong> ${d.ipv6Addr} 
86             <strong>Port:</strong> ${d.port} 
87             <strong>SecurityMethods:</strong> ${Object.values(checkValue(d.securityMethods))}
88             </p>
89             </li>`;
90     });
91     out += `</ul>`;
92     return out;
93 }
94
95 function printAefProfiles(aefProfiles, k){
96     let out = "";
97     let index = 0;
98     aefProfiles.forEach((aef) => {
99       out += `
100          <tr data-bs-toggle="collapse"  data-bs-target="#r${k}${index}">
101             <td>${aef.aefId}</td>
102             <td>${aef.aefLocation}</td>
103             <td>${aef.domainName}</td>
104             <td>${aef.protocol}</td>
105             <td>${Object.values(checkValue(aef.securityMethods))}</td>
106          </tr>
107          <tr class="collapse accordion-collapse" id="r${k}${index}" data-bs-parent=".table">
108             <td colspan="5"> 
109                 <div id="demo1">
110                     ${printInterfaceDescription(aef.interfaceDescriptions)} 
111                     ${printVersions(aef.versions)}
112                 </div> 
113             </td>
114         </tr>
115       `;
116       index++;
117     }); 
118     return out;
119 }
120
121 function printSecInfo(secInfo){
122     let out = "";
123     let index = 0;
124     secInfo.forEach((info) => {
125       out += `
126          <tr>
127             <td>${info.aefId}</td>
128             <td>${info.apiId}</td>
129             <td>${Object.values(checkValue(info.prefSecurityMethods))}</td>
130             <td>${info.selSecurityMethod}</td>
131          </tr>
132       `;
133       index++;
134     }); 
135     return out;
136 }