-
Notifications
You must be signed in to change notification settings - Fork 9
/
interactive_script.js
177 lines (155 loc) · 6.96 KB
/
interactive_script.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
/*
* Copyright 2022, Red Hat, Inc.
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
const FILTER_TABLE = {
"result-pass": true,
"result-fail": true,
"result-notchecked": true,
"result-notapplicable": true,
"result-fixed": true,
"result-error": true,
"result-informational": true,
"result-fix-failed": true,
"result-fix-unsuccessful": true,
"result-unknown": true,
"severity-high": true,
"severity-medium": true,
"severity-low": true,
"severity-unknown": true
};
// eslint-disable-next-line no-extend-native
String.prototype.asId = function (prefix) {
return prefix + this.replace(/ /ug, "-").toLowerCase();
};
document.querySelector('main').addEventListener('scroll', () => {
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
show_next_rules();
}
document.getElementById('back-to-top-button').style.visibility = 'visible';
}, false);
function show_next_rules() {
const next_five_rules = get_next_five_rules();
next_five_rules.forEach(rule => {
rule.classList.remove("hidden");
});
}
let FIRST_HIDDEN_ELEMENT = document.querySelector("table[id=rule-table] tbody[rule-id].hidden");
function get_next_five_rules() {
const next_five_rules = [];
var count_five = 5;
for(let i = 0; i <= count_five && FIRST_HIDDEN_ELEMENT !== null; i += 1) {
next_five_rules.push(FIRST_HIDDEN_ELEMENT);
FIRST_HIDDEN_ELEMENT = FIRST_HIDDEN_ELEMENT.nextSibling;
if (!(FIRST_HIDDEN_ELEMENT instanceof HTMLElement) && FIRST_HIDDEN_ELEMENT !== null) {
FIRST_HIDDEN_ELEMENT = FIRST_HIDDEN_ELEMENT.nextSibling;
}
}
return next_five_rules;
}
function get_child_of_element_with_selector(element, selector) {
return element.querySelector(":scope > ".concat(selector));
}
function hide_or_show(element) {
if (element.style.display === "none") {
element.style.display = "block";
} else {
element.style.display = "none";
}
}
// Search engine of rules
function search_rule(self) { // eslint-disable-line no-unused-vars
const value = self.value.toLowerCase();
const rules = document.querySelectorAll("table[id=rule-table] tbody[rule-id]");
rules.forEach(function (rule) {
const is_matched_title = rule.getAttribute("rule-title").toLowerCase().includes(value);
const is_matched_rule_id = rule.getAttribute("rule-id").toLowerCase().includes(value);
const is_matched_rule_reference = rule.getAttribute("rule-references").toLowerCase().includes(value);
const result_of_rule = rule.getAttribute("result").asId('result-');
const severity_of_rule = rule.getAttribute("severity").asId('severity-');
const advance_option = (FILTER_TABLE[result_of_rule]) && (FILTER_TABLE[severity_of_rule]);
if ((is_matched_title || is_matched_rule_id || is_matched_rule_reference) && advance_option) {
rule.style.display = "";
rule.classList.remove("hidden")
} else {
rule.style.display = "none";
}
});
}
// Filter by result, Severity
function toggle_rules(filter_by, result) { // eslint-disable-line no-unused-vars
FILTER_TABLE[filter_by + '-' + result] = !(FILTER_TABLE[filter_by + '-' + result]);
search_rule(document.querySelector("input[id=input-search-rule]"));
}
function show_advanced_options(self) { // eslint-disable-line no-unused-vars
self.classList.toggle('pf-m-expanded');
self.firstChild.className = self.firstChild.className == 'fas fa-caret-right' ? 'fas fa-caret-down' : 'fas fa-caret-right';
const element_to_show = get_child_of_element_with_selector(
self.parentNode.parentNode,
".pf-c-accordion__expanded-content"
);
element_to_show.classList.toggle('pf-m-expanded');
hide_or_show(element_to_show);
}
function show_evaluation_characteristics(self) { // eslint-disable-line no-unused-vars
self.classList.toggle('pf-m-expanded');
const div_to_show = get_child_of_element_with_selector(
self.parentNode.parentNode,
".pf-c-accordion__expanded-content"
);
div_to_show.classList.toggle('pf-m-expanded');
hide_or_show(div_to_show);
}
function show_rule_detail(self) { // eslint-disable-line no-unused-vars
var rule_id = self.parentNode.parentNode.parentNode.getAttribute("rule-id").asJqueryComplaintId();
generate_oval_tree(self, "oval_tree_of_rule_" + rule_id); // eslint-disable-line no-undef
generate_oval_tree(self, "cpe_tree_of_rule_" + rule_id); // eslint-disable-line no-undef
generate_cpe_al(self, "cpe_al_tree_of_rule_profile_platforms_" + rule_id); // eslint-disable-line no-undef
generate_cpe_al(self, "cpe_al_tree_of_rule_group_platforms_" + rule_id); // eslint-disable-line no-undef
generate_cpe_al(self, "cpe_al_tree_of_rule_rule_platforms_" + rule_id); // eslint-disable-line no-undef
self.classList.toggle('pf-m-expanded');
const element_to_show = get_child_of_element_with_selector(
self.parentNode.parentNode.parentNode,
".pf-c-table__expandable-row"
);
element_to_show.classList.toggle('pf-m-expanded');
}
function show_rule_detail_after_click_on_rule_title(self) { // eslint-disable-line no-unused-vars
show_rule_detail(self.parentElement.previousSibling.firstChild);
}
const selector = ".pf-c-clipboard-copy__text";
document.querySelectorAll("#copy").forEach(el => el.addEventListener('click', () => {
const el_with_text = el.parentElement.parentElement.parentElement.querySelector(selector);
navigator.clipboard.writeText(el_with_text.textContent);
}));
function clear_input(self) { // eslint-disable-line no-unused-vars
self.previousSibling.value= "";
search_rule(self.previousSibling);
}
document.querySelectorAll("#copy").forEach(el => el.appendChild(get_tooltip_copy_to_clipboard()));
function get_tooltip_copy_to_clipboard() { // eslint-disable-line no-unused-vars
const div = document.createElement("div");
const tooltip_div = div.cloneNode();
tooltip_div.className = "pf-c-tooltip pf-m-top tooltip-box-top-side";
tooltip_div.setAttribute("role", "tooltip");
const tooltip_arrow_div = div.cloneNode();
tooltip_arrow_div.className = "pf-c-tooltip__arrow";
tooltip_div.appendChild(tooltip_arrow_div);
const tooltip_content_div = div.cloneNode();
tooltip_content_div.className = "pf-c-tooltip__content";
tooltip_content_div.textContent = `Copied to clipboard.`;
tooltip_div.appendChild(tooltip_content_div);
return tooltip_div;
}
function toogle_deselect_button(self) { // eslint-disable-line no-unused-vars
self.parentElement.parentElement.querySelectorAll('input[type="checkbox"]').forEach(e => {
if (self.textContent == 'Deselect all' && e.checked) {
e.onchange();
e.checked = !e.checked;
} else if (self.textContent == 'Select all' && !e.checked) {
e.onchange();
e.checked = !e.checked;
}
});
self.textContent = self.textContent == 'Deselect all' ? 'Select all' : 'Deselect all';
}