From 946253a7230c0bd4b772685d06117badcda42328 Mon Sep 17 00:00:00 2001 From: Davide Arcuri Date: Wed, 25 Sep 2024 15:13:39 +0200 Subject: [PATCH] use browser history --- orochi/templates/website/index.html | 39 +++++++++++++++++++++-------- orochi/utils/timeliner.py | 17 ++++++------- orochi/website/admin.py | 1 - orochi/website/views.py | 1 + 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/orochi/templates/website/index.html b/orochi/templates/website/index.html index 98ec38c8..08f644e3 100644 --- a/orochi/templates/website/index.html +++ b/orochi/templates/website/index.html @@ -89,6 +89,15 @@
History Log
var selected_indexes = {{ selected_indexes| safe }}; var selected_plugin = {% if not selected_plugin %}null{% else %} "{{selected_plugin}}"{% endif %}; var selected_query = {% if not selected_query %}null{% else %} "{{selected_query}}"{% endif %}; + + window.onpopstate = function(event) { + if(event && event.state) { + selected_plugin = event.state.selected_plugin; + selected_indexes = event.state.selected_indexes; + update_sidebar(); + } + } + if (selected_plugin && selected_indexes.length > 0) { selected_indexes.forEach(element => { var label = $('#index-list li label').filter('[data-index="' + element + '"]'); @@ -103,7 +112,6 @@
History Log
}); update_sidebar(); } - window.history.pushState("", "", '/'); // ADD BOOKMARK FORM $(document).on("click", "#bookmark", function (e) { @@ -150,7 +158,6 @@
History Log
type: form.attr("method"), dataType: 'json', success: function (data) { - $.toast({ title: 'Bookmark saved!', content: 'Bookmark saved.', @@ -257,9 +264,15 @@
History Log
// UPDATE MAIN STAGE AFTER INDEX, PLUGIN CHANGE function update_main_stage() { if (selected_plugin == null || selected_indexes.length == 0) { + window.history.pushState({selected_plugin: null, selected_indexes: null}, "", "/"); $('#main_stage').html(''); } else { + window.history.pushState( + {selected_plugin: selected_plugin, selected_indexes: selected_indexes}, + "", + "/indexes/" + selected_indexes.join(",") + "/plugin/" + selected_plugin + ); $.get("{% url 'website:analysis' %}", { 'indexes': selected_indexes, 'plugin': selected_plugin }) .done(function (data) { @@ -380,17 +393,20 @@
History Log
if (indexes.length > 0) { var template = Handlebars.templates.plugins; var url = "{% url 'api:dumps_plugins' pks=111111111122222222223333333333444444 %}".replace(/111111111122222222223333333333444444/, indexes.join(",")); - $.ajax({ url: url, method: 'get', dataType: 'json', success: function (data) { $("#list_plugin").append(template(data)) + if(selected_plugin){ + var label = $('#list_plugin li label').filter('[data-plugin="' + selected_plugin + '"]'); + checkbox = $(":radio", label.parent()); + checkbox.prop('checked', true); + } } }); } - } selected_indexes = indexes; update_main_stage(); @@ -547,6 +563,7 @@
History Log
}); }); + // OPEN/CLOSE FOLDER TO HIDE ELEMENTS INSIDE $(document).on("change", "#id_local_folder", function () { var value = $(this).val(); if (value != "") { @@ -576,7 +593,8 @@
History Log
if (data.form_is_valid) { $("#index-list").html(data.dumps); $("#modal-update").modal('hide'); - update_main_stage(); + selected_plugin = null; + update_sidebar(); } else { $("#modal-update .modal-content").html(data.html_form); $("#create_loading").hide(); @@ -649,7 +667,6 @@
History Log
}); }); - // RESTART INDEX FORM SUBMIT $(document).on("click", ".restart-index", function (e) { var btn = $(this); @@ -691,7 +708,8 @@
History Log
type: 'get', dataType: 'json', success: function (data) { - console.log(data); + selected_plugin = null; + update_sidebar(); } }); }); @@ -731,7 +749,8 @@
History Log
if (data.form_is_valid) { $("#index-list").html(data.dumps); $("#modal-update").modal('hide'); - update_main_stage(); + selected_plugin = null; + update_sidebar(); } else { $("#modal-update .modal-content").html(data.html_form); } @@ -792,7 +811,8 @@
History Log
if (data.form_is_valid) { $("#index-list").html(data.dumps); $("#modal-update").modal('hide'); - update_main_stage(); + selected_plugin = null; + update_sidebar(); } else { $("#modal-update .modal-content").html(data.html_form); } @@ -819,7 +839,6 @@
History Log
}); selected_plugin = null; update_sidebar(); - update_main_stage(); $.toast({ title: 'Index delete!', content: 'Index has been deleted successfully.', diff --git a/orochi/utils/timeliner.py b/orochi/utils/timeliner.py index c1a4bb45..0092a294 100644 --- a/orochi/utils/timeliner.py +++ b/orochi/utils/timeliner.py @@ -2,7 +2,6 @@ import pandas as pd import plotly.express as px -from django.views.generic.base import TemplateView def parse_body_line(line): @@ -53,15 +52,13 @@ def clean_bodywork(file_path): legend_title="Plugin", xaxis=dict( rangeselector=dict( - buttons=list( - [ - dict(count=1, label="1m", step="month", stepmode="backward"), - dict(count=6, label="6m", step="month", stepmode="backward"), - dict(count=1, label="YTD", step="year", stepmode="todate"), - dict(count=1, label="1y", step="year", stepmode="backward"), - dict(step="all"), - ] - ) + buttons=[ + dict(count=1, label="1m", step="month", stepmode="backward"), + dict(count=6, label="6m", step="month", stepmode="backward"), + dict(count=1, label="YTD", step="year", stepmode="todate"), + dict(count=1, label="1y", step="year", stepmode="backward"), + dict(step="all"), + ] ), rangeslider=dict(visible=True), type="date", diff --git a/orochi/website/admin.py b/orochi/website/admin.py index 8e34eb94..65261344 100644 --- a/orochi/website/admin.py +++ b/orochi/website/admin.py @@ -16,7 +16,6 @@ from guardian.shortcuts import assign_perm, get_perms, remove_perm from import_export import fields, resources from import_export.admin import ExportActionMixin, ImportExportModelAdmin -from import_export.mixins import BaseImportExportMixin from import_export.widgets import ForeignKeyWidget from orochi.website.defaults import RESULT diff --git a/orochi/website/views.py b/orochi/website/views.py index acd61cd6..bb7135ce 100644 --- a/orochi/website/views.py +++ b/orochi/website/views.py @@ -950,6 +950,7 @@ def bookmarks(request, indexes, plugin, query=None): "selected_indexes": indexes, "selected_plugin": plugin, "selected_query": query, + "readonly": is_not_readonly(request.user), } return TemplateResponse(request, "website/index.html", context)