toaster: Don't add new history entries when table data loads
PATCH 1/2 toaster: Don't add new history entries when table data loads
From: Elliot Smith <[email protected]>
When ToasterTable data is loaded into the UI, a new entry is added to the browser history. This means that pressing the back button appears to have no effect, as you end up at the same page, possibly with slightly different data.
Instead, use replaceState(), so that the browser history doesn't grow, but the page context still gets updated.
[YOCTO #7660]
--- lib/toaster/toastergui/static/js/table.js | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
lib/toaster/toastergui/static/js/table.js +2 -12
@@ -33,14 +33,6 @@ function tableInit(ctx){ loadData(tableParams); - window.onpopstate = function(event){ - if (event.state){ - tableParams = event.state.tableParams; - /* We skip loadData and just update the table */ - updateTable(event.state.tableData); - } - }; - function loadData(tableParams){ $.ajax({ type: "GET",
@@ -49,10 +41,8 @@ function tableInit(ctx){ headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, success: function(tableData) { updateTable(tableData); - window.history.pushState({ - tableData: tableData, - tableParams: tableParams - }, null, libtoaster.dumpsUrlParams(tableParams)); + window.history.replaceState(null, null, + libtoaster.dumpsUrlParams(tableParams)); } }); }
Signature · 1 line
2.1.4
PATCH 2/2 toaster: Don't HTTP cache ToasterTable responses
From: Elliot Smith <[email protected]>
Django allows generated pages to be cached by default by the browser. This can result in stale data displaying for some pages.
Instead, disable HTTP caching of ToasterTable responses, so that each time a ToasterTable view is displayed, its data is refreshed. This carries a performance penalty, but ensures that ToasterTable views (e.g. compatible layers) are correctly refreshed if the user navigates their history with forward/back.
[YOCTO #7660]
--- lib/toaster/toastergui/widgets.py | 6 ++++++ 1 file changed, 6 insertions(+)
lib/toaster/toastergui/widgets.py +6 -0
@@ -20,6 +20,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. from django.views.generic import View, TemplateView +from django.views.decorators.cache import cache_control from django.shortcuts import HttpResponse from django.http import HttpResponseBadRequest from django.core import serializers
@@ -64,6 +65,11 @@ class ToasterTable(TemplateView): orderable=True, field_name="id") + # prevent HTTP caching of table data + @cache_control(must_revalidate=True, max_age=0, no_store=True, no_cache=True) + def dispatch(self, *args, **kwargs): + return super(ToasterTable, self).dispatch(*args, **kwargs) + def get_context_data(self, **kwargs): context = super(ToasterTable, self).get_context_data(**kwargs) context['title'] = self.title
Signature · 1 line
2.1.4