-
Notifications
You must be signed in to change notification settings - Fork 0
/
namespace_category_search.js
354 lines (296 loc) · 12.1 KB
/
namespace_category_search.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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
// Namespace Category search
console.log("Namespace Category Search");
let activeNamespaces = [];
let mainCategoryList = [];
let currentPageCategoryList = [];
let namespaceTotal = 0;
let namespaceCount = 0;
let currentNamespace = currentUrl.split("/")[5];
let zen1;
let zen1Height;
let propertyPane;
let propertyPaneHeight
let body_62;
let body_62Height
let settingsForm;
let settingsFormHeight;
currentNamespace = currentNamespace.toUpperCase();
console.log("currentNamespace", currentNamespace);
createNamespaceCategorySearchBar(document);
namespaceCategorySearchButton(document);
function minimiseiFrame(Document, iframeDiv) {
let minimiseBtn = Document.createElement('btn');
minimiseBtn.classList.add("minimiseiFrameBtn");
minimiseBtn.title = "Close";
minimiseBtn.innerText = "x";
minimiseBtn.addEventListener('click', () => {
minimiseBtn.parentElement.style.display = "none";
})
//console.log("buttonBar", messageBtnBar, messageDiv.id);
iframeDiv.appendChild(minimiseBtn);
}
window.addEventListener("load", function() {
reorderDropdownAlphabetically("id_Category");
// Get category list for this page
let categorySelect = document.getElementById("id_Category");
for (let i = 0; i < categorySelect.options.length; i++ ) {
currentPageCategoryList.push(categorySelect.options[i].textContent);
}
zen1 = document.getElementById("zen1");
zen1Height = zen1.style.height;
propertyPane = document.getElementById("propertyPane");
propertyPaneHeight = propertyPane.style.height;
propertyPane.style.resize = "both";
body_62 = document.getElementById("body_62");
if (body_62 == undefined) {
// Ensemble
body_62 = document.getElementById("body_59");
}
body_62Height = body_62.style.height;
settingsForm = document.getElementById("settingsForm");
settingsFormHeight = settingsForm.style.height;
let zenLayoutTableCell_60 = document.getElementById("zenLayoutTableCell_60");
if (zenLayoutTableCell_60 == undefined) {
// Ensemble
zenLayoutTableCell_60 = document.getElementById("zenLayoutTableCell_57");
}
zenLayoutTableCell_60.style.overflow = "auto";
});
let frameLoadedEvent; // The custom event that will be created
frameLoadedEvent = document.createEvent("HTMLEvents");
frameLoadedEvent.initEvent("frameLoaded", true, true);
frameLoadedEvent.eventName = "frameLoaded";
var click = new CustomEvent('click');
var change = new CustomEvent('change');
// When category list is chosen
document.addEventListener("categoryListSelection", function(e) {
let eventValue
if (e.optionValue.includes("*")) {
eventValue = e.optionValue.split("*")[1]
} else {
eventValue = e.optionValue
}
let currentPageCategoryDropDown = document.getElementById("id_Category");
updateCategoryList(currentPageCategoryDropDown, eventValue);
//e.target.value // our option value
//console.log(e.optionValue);
//console.log("categoryListSelectionEvent",e);
let matchingNamespaces = 0;
for (let i = 0; i < activeNamespaces.length; i++ ) {
let iframe = activeNamespaces[i].iframe;
if (activeNamespaces[i].hostname == currentNamespace) {
// Hide current production
iframe.parentElement.style.display = "none";
} else {
let categoryList = activeNamespaces[i].categoryList;
if ((categoryList != undefined) && (categoryList.includes(eventValue))) {
matchingNamespaces++
let iframeCategoryDropDown = iframe.contentDocument.getElementById("id_Category");
//console.log("iframeCategoryDropDown", iframeCategoryDropDown);
iframe.parentElement.style.display = "";
updateCategoryList(iframeCategoryDropDown, eventValue);
} else {
iframe.parentElement.style.display = "none";
}
}
}
//console.log("matchingNamespaces", matchingNamespaces);
if (matchingNamespaces > 0) {
// Resize window to 50% for ease of viewing all productions
zen1.style.height = "525px";
propertyPane.style.height = "325px";
propertyPane.style.overflow = "auto";
body_62.style.height = "325px";
settingsForm.style.height = "325px";
let zenLayoutTableCell_60 = document.getElementById("zenLayoutTableCell_60");
if (zenLayoutTableCell_60 == undefined) {
// Ensemble
zenLayoutTableCell_60 = document.getElementById("zenLayoutTableCell_57");
}
zenLayoutTableCell_60.style.overflow = "auto";
} else {
zen1.style.height = zen1Height;
propertyPane.style.height = propertyPaneHeight;
body_62.style.height = body_62Height;
settingsForm.style.height = settingsFormHeight;
let zenLayoutTableCell_60 = document.getElementById("zenLayoutTableCell_60");
if (zenLayoutTableCell_60 == undefined) {
// Ensemble
zenLayoutTableCell_60 = document.getElementById("zenLayoutTableCell_57");
}
zenLayoutTableCell_60.style.overflow = "auto";
}
})
function updateCategoryList(categoryListObject, category) {
if (category == "All") {
category = "";
}
for (let x = 0; x < categoryListObject.options.length; x++) {
if (categoryListObject.options[x].value == category) {
categoryListObject.click();
categoryListObject.value = category
categoryListObject[x].selected = true;
categoryListObject.dispatchEvent(change);
categoryListObject.parentElement.click();
delay(200).then(() => {
categoryListObject.click();
categoryListObject.value = category;
categoryListObject[x].selected = true;
categoryListObject.dispatchEvent(change);
categoryListObject.parentElement.click();
});
break
}
}
}
// Remove loading message
let loaded = 0;
document.addEventListener("frameLoaded", function(e) {
loaded ++
let namespaceCategoryDropDown = document.getElementById("namespaceCategoryDropDown");
for (let i = 0; i < activeNamespaces.length; i++) {
if ((activeNamespaces[i].loaded == undefined) || activeNamespaces[i].loaded == false) {
namespaceCategoryDropDown.options[0].textContent = "Fetching active productions: " + loaded + "/" + activeNamespaces.length;
return
}
}
for (let x = 0; x < mainCategoryList.length; x++) {
if (currentPageCategoryList.includes(mainCategoryList[x])) {
mainCategoryList[x] = "*" + mainCategoryList[x]
}
}
let sortedCategoryList = mainCategoryList.sort();
for (let x = 0; x < sortedCategoryList.length; x++) {
createOption(sortedCategoryList[x]);
}
if (namespaceCategoryDropDown.options[0].textContent.includes("Fetching active productions:")) {
namespaceCategoryDropDown.remove(0);
}
});
// When categoryList button clicked
document.addEventListener("categoryList", function(e) {
//optionsLoading();
let homepageIframe = document.createElement("iframe");
homepageIframe.src = currentURLBeforeCSP + "/csp/sys/%25CSP.Portal.Home.zen?disableComponentReport=true"
homepageIframe.style.display = "none";
document.body.appendChild(homepageIframe);
homepageIframe.addEventListener("load", function() {
let ndDidYou = homepageIframe.contentDocument.getElementsByClassName("ndDidYou");
linksContainer = homepageIframe.contentDocument.getElementById("messagePanel");
let links = linksContainer.getElementsByClassName("ndLink");
console.log("LINKS:", links);
let linksLength = links.length;
for (let x = 0; x < linksLength; x ++) {
let isRunning
if (ndDidYou.length != 0) {
//ensemble
isRunning = links[x].parentNode.previousSibling.previousSibling.innerText.includes("Running")
} else {
//iris
isRunning = links[x].parentNode.previousElementSibling.innerText.includes("Running")
}
if (links[x].href.includes("EnsPortal.ProductionConfig.zen") && (isRunning)) {
namespaceTotal ++
activeNamespaces.push({
href: String(links[x].href),
hostname: links[x].parentNode.previousSibling.previousSibling.previousElementSibling.outerText.split(" in ")[1],
status: links[x].parentNode.previousSibling.previousSibling.innerText.includes("Running")}
);
}
}
let namespacesLength = activeNamespaces.length;
console.log("activeNamespaces", activeNamespaces);
for (let i = 0; i < namespacesLength; i ++) {
//console.log("compare namespace names", activeNamespaces[i].hostname, currentNamespace);
/*if (activeNamespaces[i].hostname == currentNamespace) {
activeNamespaces[i].loaded = true;
continue
}*/
namespaceCount ++
let iframe = document.createElement("iframe");
iframe.src = String(activeNamespaces[i].href) + "&disableNamespaceCategorySearch=true"
iframe.namespace = String(activeNamespaces[i].hostname)
activeNamespaces[i].iframe = iframe;
activeNamespaces[i].loaded = false;
iframe.style.width = "100%";
iframe.style.height = "500px";
//iframe.style.display = "none";
iframe.style.resize = "both";
iframe.style.overflow = "auto";
activeNamespaces[i].categoryList = [];
let iframeDiv = document.createElement("div");
minimiseiFrame(document, iframeDiv);
iframeDiv.appendChild(iframe);
document.body.appendChild(iframeDiv);
iframe.addEventListener("load", function() {
// this is where we need to hide the headers, grab the categories and
// Hide header
let iframeTable = iframe.contentDocument.getElementById("group_1");
iframeTable.rows[0].style.display = "none";
//iframeTable.rows[4].style.display = "none";
// Update title to be namespace
//let nametoolRibbon = iframeTable.getElementById("nametoolRibbon");
let ribbonTitle =iframe.contentDocument.getElementsByClassName("ribbonTitle");
ribbonTitle[0].innerText = iframe.namespace;
let iframeCategoryList = iframe.contentDocument.getElementById("id_Category");
for (let x = 0; x < iframeCategoryList.options.length; x++ ) {
let iterationOption = iframeCategoryList.options[x].textContent
if (mainCategoryList.includes(iterationOption)) {
//Already includes this category list, skip
activeNamespaces[i].categoryList.push(iterationOption);
} else {
mainCategoryList.push(iterationOption);
activeNamespaces[i].categoryList.push(iterationOption);
}
}
activeNamespaces[i].loaded = true;
document.dispatchEvent(frameLoadedEvent);
});
}
});
});
// Get namespace homepage
function createOption(optionText) {
let namespaceCategoryDropDown = document.getElementById("namespaceCategoryDropDown");
let thisOption = document.createElement('option');
let thisOptiontext = document.createTextNode(optionText);
thisOption.appendChild(thisOptiontext);
namespaceCategoryDropDown.appendChild(thisOption);
}
function optionsLoading() {
delay(500).then(() => {
let namespaceCategoryDropDown = document.getElementById("namespaceCategoryDropDown");
let loadingstring = namespaceCategoryDropDown.options[0].textContent
if (loadingstring.includes("Loading")) {
let count = (loadingstring.match(/\./g) || []).length
if (count > 3) {
loadingstring = "Loading"
} else {
loadingstring = loadingstring + "."
}
namespaceCategoryDropDown.options[0].textContent = loadingstring
optionsLoading();
}
});
}
function reorderDropdownAlphabetically(dropdownId) {
// Find the dropdown element by its ID
const dropdown = document.getElementById(dropdownId);
if (!dropdown) {
console.error(`Dropdown with ID "${dropdownId}" not found.`);
return;
}
// Extract all option elements into an array
const options = Array.from(dropdown.options);
// Separate the first option if it is selected by default (e.g., "All")
const defaultOption = options.find(option => option.selected && option.value === "");
const otherOptions = options.filter(option => option !== defaultOption);
// Sort the options alphabetically, ignoring case
otherOptions.sort((a, b) => a.text.toLowerCase().localeCompare(b.text.toLowerCase()));
// Clear the dropdown and append the options in order
dropdown.innerHTML = ""; // Clear all options
if (defaultOption) {
dropdown.appendChild(defaultOption); // Re-add the default option if it exists
}
otherOptions.forEach(option => dropdown.appendChild(option)); // Append sorted options
}