summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-09-16 12:34:32 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-09-16 12:34:32 +0200
commit233156b19ab2b3d490a8bb450bbb22fdff4caaec (patch)
tree2dd00b9811e854fcbf07588dbf68d23bfb2b5d31
parentf85c61df993dddee233ead7b6c9e136d9d9fa742 (diff)
js: consolidate sidebar collapse persistence logic
Consolidate all the sidebar collapse persistence logic. Implement a single function to handle all the views.
-rw-r--r--ogcp/static/js/ogcp.js51
-rw-r--r--ogcp/templates/base.html2
-rw-r--r--ogcp/templates/images.html2
-rw-r--r--ogcp/templates/macros.html2
-rw-r--r--ogcp/templates/repos.html2
5 files changed, 9 insertions, 50 deletions
diff --git a/ogcp/static/js/ogcp.js b/ogcp/static/js/ogcp.js
index 362aed1..658748f 100644
--- a/ogcp/static/js/ogcp.js
+++ b/ogcp/static/js/ogcp.js
@@ -152,60 +152,19 @@ function keepSelectedClients(context) {
});
}
-function keepImagesTreeState() {
- const images_tree = $('#servers .collapse')
- images_tree.on('hidden.bs.collapse', function (event) {
- event.stopPropagation();
- localStorage.removeItem(this.id);
- });
- images_tree.on('shown.bs.collapse', function (event) {
- event.stopPropagation();
- localStorage.setItem(this.id, 'show');
- });
-
- images_tree.each(function () {
- if (localStorage.getItem(this.id) == 'show') {
- $(this).collapse('show');
- } else {
- $(this).siblings('a').addClass('collapsed');
- }
- });
-}
-
-function keepReposTreeState() {
- const repos_tree = $('#repos-list .collapse')
-
- repos_tree.on('hidden.bs.collapse', function (event) {
- event.stopPropagation();
- localStorage.removeItem(this.id);
- });
- repos_tree.on('shown.bs.collapse', function (event) {
- event.stopPropagation();
- localStorage.setItem(this.id, 'show');
- });
-
- repos_tree.each(function () {
- if (localStorage.getItem(this.id) == 'show') {
- $(this).collapse('show');
- } else {
- $(this).siblings('a').addClass('collapsed');
- }
- });
-}
-
-function keepScopesTreeState() {
- const scopes_tree = $('#scopes .collapse')
+function keepTreeState(selector) {
+ const tree = $(selector + ' .collapse');
- scopes_tree.on('hidden.bs.collapse', function (event) {
+ tree.on('hidden.bs.collapse', function (event) {
event.stopPropagation();
localStorage.removeItem(this.id);
});
- scopes_tree.on('shown.bs.collapse', function (event) {
+ tree.on('shown.bs.collapse', function (event) {
event.stopPropagation();
localStorage.setItem(this.id, 'show');
});
- scopes_tree.each(function () {
+ tree.each(function () {
if (localStorage.getItem(this.id) == 'show') {
$(this).collapse('show');
} else {
diff --git a/ogcp/templates/base.html b/ogcp/templates/base.html
index b9042fd..c9b2d63 100644
--- a/ogcp/templates/base.html
+++ b/ogcp/templates/base.html
@@ -111,7 +111,7 @@
<!-- ChartJS -->
<script src="{{ url_for('static', filename='AdminLTE/plugins/chart.js/Chart.min.js') }}"></script>
- <script src="{{ url_for('static', filename='js/ogcp.js') }}?v=17"></script>
+ <script src="{{ url_for('static', filename='js/ogcp.js') }}?v=18"></script>
<script>
// error messages
diff --git a/ogcp/templates/images.html b/ogcp/templates/images.html
index 462e68d..34d8a87 100644
--- a/ogcp/templates/images.html
+++ b/ogcp/templates/images.html
@@ -14,7 +14,7 @@
// in the scope
document.addEventListener('readystatechange', () => {
if (document.readyState === 'complete') {
- keepImagesTreeState();
+ keepTreeState('#servers');
checkImageServer();
}
});
diff --git a/ogcp/templates/macros.html b/ogcp/templates/macros.html
index 7583c59..16b3017 100644
--- a/ogcp/templates/macros.html
+++ b/ogcp/templates/macros.html
@@ -10,7 +10,7 @@
if (document.readyState === 'complete') {
showSelectedClientsOnEvents();
updateScopeState();
- keepScopesTreeState();
+ keepTreeState('#scopes');
let context = {{ selection_mode | tojson | safe }};
{% if selection_mode == 'commands' %}
configureCommandCheckboxes(context);
diff --git a/ogcp/templates/repos.html b/ogcp/templates/repos.html
index 06bee58..9f15391 100644
--- a/ogcp/templates/repos.html
+++ b/ogcp/templates/repos.html
@@ -42,7 +42,7 @@
// in the scope
document.addEventListener('readystatechange', () => {
if (document.readyState === 'complete') {
- keepReposTreeState()
+ keepTreeState('#repos-list')
checkRepoServer()
}
});