mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
Change default status values, add project and experiment to saved state and fix parsing error handeling
This commit is contained in:
parent
3c30ee904e
commit
9cd8e3b7ac
3 changed files with 33 additions and 14 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -30,8 +30,7 @@
|
|||
<% MyModuleStatusFlow.find_each do |status_flow| %>
|
||||
<% status_flow.my_module_statuses.each do |status| %>
|
||||
<option value="<%= status.id %>"
|
||||
data-final-status="<%= status.final_status? %>"
|
||||
<%= 'data-selected=true' unless status.final_status? %>>
|
||||
data-completion-consequence="<%= status.my_module_status_consequences.where(type: "MyModuleStatusConsequences::Completion").any? %>">
|
||||
<%= status.name %>
|
||||
</option>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in a new issue