forked from jenkinsci/jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin-manager-ui.js
More file actions
110 lines (96 loc) · 3.3 KB
/
plugin-manager-ui.js
File metadata and controls
110 lines (96 loc) · 3.3 KB
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
import debounce from "lodash/debounce";
import pluginManagerAvailable from "./templates/plugin-manager/available.hbs";
import pluginManager from "./api/pluginManager";
function applyFilter(searchQuery) {
// debounce reduces number of server side calls while typing
pluginManager.availablePluginsSearch(
searchQuery.toLowerCase().trim(),
50,
function (plugins) {
var pluginsTable = document.getElementById("plugins");
var tbody = pluginsTable.querySelector("tbody");
var admin = pluginsTable.dataset.hasadmin === "true";
var includeHealthScores = pluginsTable.dataset.health === "true";
var selectedPlugins = [];
var filterInput = document.getElementById("filter-box");
filterInput.parentElement.classList.remove("jenkins-search--loading");
function clearOldResults() {
if (!admin) {
tbody.innerHTML = "";
} else {
var rows = tbody.querySelectorAll("tr");
if (rows) {
selectedPlugins = [];
rows.forEach(function (row) {
var input = row.querySelector("input");
if (input.checked === true) {
var pluginName = input.name.split(".")[1];
selectedPlugins.push(pluginName);
} else {
row.remove();
}
});
}
}
}
clearOldResults();
var rows = pluginManagerAvailable({
plugins: plugins.filter(
(plugin) => selectedPlugins.indexOf(plugin.name) === -1,
),
admin,
includeHealthScores,
});
tbody.insertAdjacentHTML("beforeend", rows);
updateInstallButtonState();
},
);
}
var handleFilter = function (e) {
applyFilter(e.target.value);
};
var debouncedFilter = debounce(handleFilter, 150);
document.addEventListener("DOMContentLoaded", function () {
var filterInput = document.getElementById("filter-box");
filterInput.addEventListener("input", function (e) {
debouncedFilter(e);
filterInput.parentElement.classList.add("jenkins-search--loading");
});
applyFilter(filterInput.value);
setTimeout(function () {
layoutUpdateCallback.call();
}, 350);
// Show update center error if element exists
const updateCenterError = document.querySelector("#update-center-error");
if (updateCenterError) {
notificationBar.show(
updateCenterError.content.textContent,
notificationBar.ERROR,
);
}
});
function updateInstallButtonState() {
// Enable/disable the 'Install' button depending on if any plugins are checked
const anyCheckboxesSelected = () => {
return (
document.querySelectorAll("input[type='checkbox']:checked").length > 0
);
};
const installButton = document.querySelector("#button-install");
const installAfterRestartButton = document.querySelector(
"#button-install-after-restart",
);
if (!anyCheckboxesSelected()) {
installButton.disabled = true;
installAfterRestartButton.disabled = true;
}
const checkboxes = document.querySelectorAll("input[type='checkbox']");
checkboxes.forEach((checkbox) => {
checkbox.addEventListener("click", () => {
setTimeout(() => {
installButton.disabled = !anyCheckboxesSelected();
installAfterRestartButton.disabled = !anyCheckboxesSelected();
});
});
});
}