Skip to content

Commit

Permalink
use browser history
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide Arcuri committed Sep 25, 2024
1 parent 5b3d9a1 commit 946253a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 21 deletions.
39 changes: 29 additions & 10 deletions orochi/templates/website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ <h5 class="offcanvas-title" id="leftNoteLabel">History Log</h5>
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 + '"]');
Expand All @@ -103,7 +112,6 @@ <h5 class="offcanvas-title" id="leftNoteLabel">History Log</h5>
});
update_sidebar();
}
window.history.pushState("", "", '/');

// ADD BOOKMARK FORM
$(document).on("click", "#bookmark", function (e) {
Expand Down Expand Up @@ -150,7 +158,6 @@ <h5 class="offcanvas-title" id="leftNoteLabel">History Log</h5>
type: form.attr("method"),
dataType: 'json',
success: function (data) {

$.toast({
title: 'Bookmark saved!',
content: 'Bookmark saved.',
Expand Down Expand Up @@ -257,9 +264,15 @@ <h5 class="offcanvas-title" id="leftNoteLabel">History Log</h5>
// 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('<div class="alert alert-primary" role="alert">Select index(es) and plugin!</div>');
}
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) {

Expand Down Expand Up @@ -380,17 +393,20 @@ <h5 class="offcanvas-title" id="leftNoteLabel">History Log</h5>
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();
Expand Down Expand Up @@ -547,6 +563,7 @@ <h5 class="offcanvas-title" id="leftNoteLabel">History Log</h5>
});
});

// OPEN/CLOSE FOLDER TO HIDE ELEMENTS INSIDE
$(document).on("change", "#id_local_folder", function () {
var value = $(this).val();
if (value != "") {
Expand Down Expand Up @@ -576,7 +593,8 @@ <h5 class="offcanvas-title" id="leftNoteLabel">History Log</h5>
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();
Expand Down Expand Up @@ -649,7 +667,6 @@ <h5 class="offcanvas-title" id="leftNoteLabel">History Log</h5>
});
});


// RESTART INDEX FORM SUBMIT
$(document).on("click", ".restart-index", function (e) {
var btn = $(this);
Expand Down Expand Up @@ -691,7 +708,8 @@ <h5 class="offcanvas-title" id="leftNoteLabel">History Log</h5>
type: 'get',
dataType: 'json',
success: function (data) {
console.log(data);
selected_plugin = null;
update_sidebar();
}
});
});
Expand Down Expand Up @@ -731,7 +749,8 @@ <h5 class="offcanvas-title" id="leftNoteLabel">History Log</h5>
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);
}
Expand Down Expand Up @@ -792,7 +811,8 @@ <h5 class="offcanvas-title" id="leftNoteLabel">History Log</h5>
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);
}
Expand All @@ -819,7 +839,6 @@ <h5 class="offcanvas-title" id="leftNoteLabel">History Log</h5>
});
selected_plugin = null;
update_sidebar();
update_main_stage();
$.toast({
title: 'Index delete!',
content: 'Index has been deleted successfully.',
Expand Down
17 changes: 7 additions & 10 deletions orochi/utils/timeliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion orochi/website/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions orochi/website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 946253a

Please sign in to comment.