From 9cd8e3b7acc0d8cf5d0794adb3e49dff9e636258 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Wed, 16 Sep 2020 09:48:06 +0200 Subject: [PATCH] Change default status values, add project and experiment to saved state and fix parsing error handeling --- .../javascripts/dashboard/current_tasks.js | 41 +++++++++++++------ .../javascripts/sitewide/dropdown_selector.js | 3 ++ app/views/dashboards/_current_tasks.html.erb | 3 +- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/dashboard/current_tasks.js b/app/assets/javascripts/dashboard/current_tasks.js index ce0580512..7c2f1aea9 100644 --- a/app/assets/javascripts/dashboard/current_tasks.js +++ b/app/assets/javascripts/dashboard/current_tasks.js @@ -26,9 +26,16 @@ var DasboardCurrentTasksWidget = (function() { } function getDefaultStatusValues() { - return $.map($(statusFilter).find("option[data-final-status='false']"), function(option) { - return option.value; + // Select uncompleted status values + var values = []; + $(statusFilter).find('option').each(function(_, option) { + if ($(option).data('completionConsequence')) { + return false; + } + values.push(option.value); + return this; }); + return values; } function initInfiniteScroll() { @@ -60,6 +67,8 @@ var DasboardCurrentTasksWidget = (function() { var filterState = { sort: dropdownSelector.getValues(sortFilter), statuses: dropdownSelector.getValues(statusFilter), + project_id: dropdownSelector.getData(projectFilter), + experiment_id: dropdownSelector.getData(experimentFilter), mode: $('.current-tasks-navbar .active').data('mode') }; @@ -76,18 +85,26 @@ var DasboardCurrentTasksWidget = (function() { return option.value; }); - if (filterState !== null) { - parsedFilterState = JSON.parse(filterState); - dropdownSelector.selectValues(sortFilter, parsedFilterState.sort); - // Check if saved statuses are valid - if (parsedFilterState.statuses.every(savedStatus => allStatusValues.includes(savedStatus))) { - dropdownSelector.selectValues(statusFilter, parsedFilterState.statuses); - } else { + if (filterState) { + try { + parsedFilterState = JSON.parse(filterState); + dropdownSelector.selectValues(sortFilter, parsedFilterState.sort); + // Check if saved statuses are valid + if (parsedFilterState.statuses.every(status => allStatusValues.includes(status))) { + dropdownSelector.selectValues(statusFilter, parsedFilterState.statuses); + } else { + dropdownSelector.selectValues(statusFilter, getDefaultStatusValues()); + } + dropdownSelector.setData(projectFilter, parsedFilterState.project_id); + dropdownSelector.setData(experimentFilter, parsedFilterState.experiment_id); + // Select saved navbar state + $('.current-tasks-navbar .navbar-link').removeClass('active'); + $('.current-tasks-navbar').find(`[data-mode='${parsedFilterState.mode}']`).addClass('active'); + } catch (e) { dropdownSelector.selectValues(statusFilter, getDefaultStatusValues()); } - // Select saved navbar state - $('.current-tasks-navbar .navbar-link').removeClass('active'); - $('.current-tasks-navbar').find(`[data-mode='${parsedFilterState.mode}']`).addClass('active'); + } else { + dropdownSelector.selectValues(statusFilter, getDefaultStatusValues()); } } diff --git a/app/assets/javascripts/sitewide/dropdown_selector.js b/app/assets/javascripts/sitewide/dropdown_selector.js index ade695a7a..2660b50c2 100644 --- a/app/assets/javascripts/sitewide/dropdown_selector.js +++ b/app/assets/javascripts/sitewide/dropdown_selector.js @@ -91,6 +91,9 @@ var dropdownSelector = (function() { // Get data in JSON from field function getCurrentData(container) { + if (!container.find('.data-field').val()) { + return ''; + } return JSON.parse(container.find('.data-field').val()); } diff --git a/app/views/dashboards/_current_tasks.html.erb b/app/views/dashboards/_current_tasks.html.erb index 73f7faf31..7a0cf0a27 100644 --- a/app/views/dashboards/_current_tasks.html.erb +++ b/app/views/dashboards/_current_tasks.html.erb @@ -30,8 +30,7 @@ <% MyModuleStatusFlow.find_each do |status_flow| %> <% status_flow.my_module_statuses.each do |status| %> <% end %>