2021-01-28 04:53:39 +08:00
|
|
|
/* global animateSpinner filterDropdown Sidebar Turbolinks HelperModule */
|
2020-10-16 20:21:25 +08:00
|
|
|
(function() {
|
2021-02-12 14:12:26 +08:00
|
|
|
const PERMISSIONS = ['editable', 'archivable', 'restorable', 'moveable', 'duplicable'];
|
2021-02-03 21:23:38 +08:00
|
|
|
var cardsWrapper = '#cardsWrapper';
|
|
|
|
var experimentsPage = '#projectShowWrapper';
|
2021-02-02 18:17:29 +08:00
|
|
|
|
|
|
|
var selectedExperiments = [];
|
|
|
|
|
2021-01-29 20:24:02 +08:00
|
|
|
let experimentsCurrentSort;
|
|
|
|
let experimentsViewSearch;
|
|
|
|
let startedOnFromFilter;
|
|
|
|
let startedOnToFilter;
|
|
|
|
let modifiedOnFromFilter;
|
|
|
|
let modifiedOnToFilter;
|
|
|
|
let archivedOnFromFilter;
|
|
|
|
let archivedOnToFilter;
|
|
|
|
|
2021-02-03 21:23:38 +08:00
|
|
|
|
|
|
|
function checkActionPermission(permission) {
|
|
|
|
return selectedExperiments.every(function(experimentId) {
|
|
|
|
return $(`.experiment-card[data-id="${experimentId}"]`).data(permission);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateExperimentsToolbar() {
|
|
|
|
let experimentsToolbar = $('#projectShowToolbar');
|
2021-02-12 21:45:09 +08:00
|
|
|
let toolbarVisible = false;
|
2021-02-03 21:23:38 +08:00
|
|
|
|
|
|
|
if (selectedExperiments.length === 0) {
|
|
|
|
experimentsToolbar.find('.single-object-action, .multiple-object-action').addClass('hidden');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (selectedExperiments.length === 1) {
|
|
|
|
experimentsToolbar.find('.single-object-action, .multiple-object-action').removeClass('hidden');
|
2021-02-12 21:45:09 +08:00
|
|
|
} else if (selectedExperiments.length > 1) {
|
2021-02-03 21:23:38 +08:00
|
|
|
experimentsToolbar.find('.single-object-action').addClass('hidden');
|
|
|
|
experimentsToolbar.find('.multiple-object-action').removeClass('hidden');
|
|
|
|
}
|
|
|
|
PERMISSIONS.forEach((permission) => {
|
|
|
|
if (!checkActionPermission(permission)) {
|
|
|
|
experimentsToolbar.find(`.btn[data-for="${permission}"]`).addClass('hidden');
|
|
|
|
}
|
|
|
|
});
|
2021-02-12 21:45:09 +08:00
|
|
|
|
|
|
|
$.each($('#projectShowToolbar').find('.btn'), (i, btn) => {
|
|
|
|
if (window.getComputedStyle(btn).display !== 'none') {
|
|
|
|
toolbarVisible = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$(experimentsPage).attr('data-toolbar-visible', toolbarVisible);
|
2021-02-03 21:23:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function initProjectsViewModeSwitch() {
|
2021-02-11 18:50:59 +08:00
|
|
|
$(experimentsPage)
|
|
|
|
.on('ajax:success', '.change-experiments-view-type-form', function(ev, data) {
|
|
|
|
$(cardsWrapper).removeClass('list').addClass(data.cards_view_type_class);
|
|
|
|
$(experimentsPage).find('.cards-switch .button-to').removeClass('selected');
|
|
|
|
$(ev.target).find('.button-to').addClass('selected');
|
|
|
|
$(ev.target).parents('.dropdown.view-switch').removeClass('open');
|
|
|
|
})
|
|
|
|
.on('ajax:error', '.change-projects-view-type-form', function(ev, data) {
|
|
|
|
HelperModule.flashAlertMsg(data.responseJSON.flash, 'danger');
|
|
|
|
});
|
2021-02-04 23:39:29 +08:00
|
|
|
|
2021-02-03 21:23:38 +08:00
|
|
|
$(experimentsPage).on('click', '.archive-switch', function() {
|
|
|
|
Turbolinks.visit($(this).data('url'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadCardsView() {
|
|
|
|
var viewContainer = $(cardsWrapper);
|
|
|
|
$.ajax({
|
|
|
|
url: viewContainer.data('experiments-cards-url'),
|
|
|
|
type: 'GET',
|
|
|
|
dataType: 'json',
|
|
|
|
data: {
|
|
|
|
view_mode: $(experimentsPage).data('view-mode'),
|
|
|
|
sort: experimentsCurrentSort,
|
|
|
|
search: experimentsViewSearch,
|
|
|
|
created_on_from: startedOnFromFilter,
|
|
|
|
created_on_to: startedOnToFilter,
|
|
|
|
updated_on_from: modifiedOnFromFilter,
|
|
|
|
updated_on_to: modifiedOnToFilter,
|
|
|
|
archived_on_from: archivedOnFromFilter,
|
|
|
|
archived_on_to: archivedOnToFilter
|
|
|
|
},
|
|
|
|
success: function(data) {
|
2021-02-12 19:12:26 +08:00
|
|
|
viewContainer.find('.card, .no-results-container').remove();
|
|
|
|
viewContainer.removeClass('no-results');
|
2021-02-03 21:23:38 +08:00
|
|
|
viewContainer.append(data.cards_html);
|
2021-02-12 19:12:26 +08:00
|
|
|
if (viewContainer.find('.no-results-container').length) {
|
|
|
|
viewContainer.addClass('no-results');
|
|
|
|
}
|
2021-02-03 21:23:38 +08:00
|
|
|
selectedExperiments.length = 0;
|
|
|
|
updateExperimentsToolbar();
|
2021-02-16 22:26:51 +08:00
|
|
|
loadExperimentWorkflowImages();
|
2021-02-03 21:23:38 +08:00
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
viewContainer.html('Error loading project list');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshCurrentView() {
|
|
|
|
loadCardsView();
|
|
|
|
Sidebar.reload({
|
|
|
|
sort: experimentsCurrentSort,
|
|
|
|
view_mode: $(experimentsPage).data('view-mode')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-22 19:51:04 +08:00
|
|
|
function selectDate($field) {
|
|
|
|
var datePicker = $field.data('DateTimePicker');
|
|
|
|
if (datePicker && datePicker.date()) {
|
|
|
|
return datePicker.date()._d.toUTCString();
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-01-29 20:24:02 +08:00
|
|
|
function initExperimentsFilters() {
|
|
|
|
var $filterDropdown = filterDropdown.init();
|
|
|
|
|
|
|
|
let $experimentsFilter = $('.experiments-filters');
|
|
|
|
let $startedOnFromFilter = $('.started-on-filter .from-date', $experimentsFilter);
|
|
|
|
let $startedOnToFilter = $('.started-on-filter .to-date', $experimentsFilter);
|
|
|
|
let $modifiedOnFromFilter = $('.modified-on-filter .from-date', $experimentsFilter);
|
|
|
|
let $modifiedOnToFilter = $('.modified-on-filter .to-date', $experimentsFilter);
|
|
|
|
let $archivedOnFromFilter = $('.archived-on-filter .from-date', $experimentsFilter);
|
|
|
|
let $archivedOnToFilter = $('.archived-on-filter .to-date', $experimentsFilter);
|
|
|
|
let $textFilter = $('#textSearchFilterInput', $experimentsFilter);
|
|
|
|
|
|
|
|
function appliedFiltersMark() {
|
|
|
|
let filtersEnabled = experimentsViewSearch
|
|
|
|
|| startedOnFromFilter
|
|
|
|
|| startedOnToFilter
|
|
|
|
|| modifiedOnFromFilter
|
|
|
|
|| modifiedOnToFilter
|
|
|
|
|| archivedOnFromFilter
|
|
|
|
|| archivedOnToFilter;
|
|
|
|
filterDropdown.toggleFilterMark($filterDropdown, filtersEnabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
$filterDropdown.on('filter:apply', function() {
|
2021-02-22 19:51:04 +08:00
|
|
|
startedOnFromFilter = selectDate($startedOnFromFilter);
|
|
|
|
startedOnToFilter = selectDate($startedOnToFilter);
|
|
|
|
modifiedOnFromFilter = selectDate($modifiedOnFromFilter);
|
|
|
|
modifiedOnToFilter = selectDate($modifiedOnToFilter);
|
|
|
|
archivedOnFromFilter = selectDate($archivedOnFromFilter);
|
|
|
|
archivedOnToFilter = selectDate($archivedOnToFilter);
|
2021-01-29 20:24:02 +08:00
|
|
|
experimentsViewSearch = $textFilter.val();
|
|
|
|
appliedFiltersMark();
|
2021-02-02 18:17:29 +08:00
|
|
|
refreshCurrentView();
|
2021-01-29 20:24:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Clear filters
|
|
|
|
$filterDropdown.on('filter:clear', function() {
|
|
|
|
if ($startedOnFromFilter.data('DateTimePicker')) $startedOnFromFilter.data('DateTimePicker').clear();
|
|
|
|
if ($startedOnToFilter.data('DateTimePicker')) $startedOnToFilter.data('DateTimePicker').clear();
|
|
|
|
if ($modifiedOnFromFilter.data('DateTimePicker')) $modifiedOnFromFilter.data('DateTimePicker').clear();
|
|
|
|
if ($modifiedOnToFilter.data('DateTimePicker')) $modifiedOnToFilter.data('DateTimePicker').clear();
|
|
|
|
if ($archivedOnFromFilter.data('DateTimePicker')) $archivedOnFromFilter.data('DateTimePicker').clear();
|
|
|
|
if ($archivedOnToFilter.data('DateTimePicker')) $archivedOnToFilter.data('DateTimePicker').clear();
|
|
|
|
$textFilter.val('');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-02 18:17:29 +08:00
|
|
|
function initSorting() {
|
|
|
|
$('#sortMenuDropdown a').click(function() {
|
|
|
|
if (experimentsCurrentSort !== $(this).data('sort')) {
|
|
|
|
$('#sortMenuDropdown a').removeClass('selected');
|
|
|
|
experimentsCurrentSort = $(this).data('sort');
|
|
|
|
refreshCurrentView();
|
|
|
|
$(this).addClass('selected');
|
|
|
|
$('#sortMenu').dropdown('toggle');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-03 21:23:38 +08:00
|
|
|
function initExperimentsSelector() {
|
|
|
|
$(cardsWrapper).on('click', '.experiment-card-selector', function() {
|
|
|
|
let card = $(this).closest('.experiment-card');
|
|
|
|
let experimentId = card.data('id');
|
|
|
|
// Determine whether ID is in the list of selected project IDs
|
|
|
|
let index = $.inArray(experimentId, selectedExperiments);
|
2021-02-02 18:17:29 +08:00
|
|
|
|
2021-02-03 21:23:38 +08:00
|
|
|
// If checkbox is checked and row ID is not in list of selected project IDs
|
|
|
|
if (this.checked && index === -1) {
|
|
|
|
$(this).closest('.experiment-card').addClass('selected');
|
|
|
|
selectedExperiments.push(experimentId);
|
|
|
|
// Otherwise, if checkbox is not checked and ID is in list of selected IDs
|
|
|
|
} else if (!this.checked && index !== -1) {
|
|
|
|
$(this).closest('.experiment-card').removeClass('selected');
|
|
|
|
selectedExperiments.splice(index, 1);
|
2021-02-02 18:17:29 +08:00
|
|
|
}
|
2021-02-03 21:23:38 +08:00
|
|
|
updateExperimentsToolbar();
|
2021-02-02 18:17:29 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-04 23:39:29 +08:00
|
|
|
function initSelectAllCheckbox() {
|
|
|
|
$(experimentsPage).on('click', '.sci-checkbox.select-all', function() {
|
|
|
|
var selectAll = this.checked;
|
|
|
|
$.each($('.experiment-card-selector'), function() {
|
|
|
|
if (this.checked !== selectAll) this.click();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-03 21:23:38 +08:00
|
|
|
function initArchiveRestoreToolbarButtons() {
|
|
|
|
$(experimentsPage)
|
|
|
|
.on('ajax:before', '.archive-experiments-form, .restore-experiments-form', function() {
|
|
|
|
let buttonForm = $(this);
|
|
|
|
buttonForm.find('input[name="experiments_ids[]"]').remove();
|
|
|
|
selectedExperiments.forEach(function(id) {
|
|
|
|
$('<input>').attr({
|
|
|
|
type: 'hidden',
|
|
|
|
name: 'experiments_ids[]',
|
|
|
|
value: id
|
|
|
|
}).appendTo(buttonForm);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.on('ajax:success', '.archive-experiments-form, .restore-experiments-form', function(ev, data) {
|
|
|
|
HelperModule.flashAlertMsg(data.message, 'success');
|
|
|
|
// Project saved, reload view
|
|
|
|
refreshCurrentView();
|
|
|
|
})
|
|
|
|
.on('ajax:error', '.archive-experiments-form, .restore-experiments-form', function(ev, data) {
|
|
|
|
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-09 22:47:15 +08:00
|
|
|
function appendActionModal(modal) {
|
|
|
|
$('#content-wrapper').append(modal);
|
|
|
|
modal.modal('show');
|
|
|
|
modal.find('.selectpicker').selectpicker();
|
|
|
|
// Remove modal when it gets closed
|
|
|
|
modal.on('hidden.bs.modal', function() {
|
|
|
|
$(this).remove();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function initEditMoveDuplicateToolbarButton() {
|
|
|
|
let forms = '.edit-experiments-form, .move-experiments-form, .clone-experiments-form';
|
|
|
|
$(experimentsPage)
|
|
|
|
.on('ajax:before', forms, function() {
|
|
|
|
let buttonForm = $(this);
|
|
|
|
buttonForm.find('input[name="id"]').remove();
|
|
|
|
$('<input>').attr({
|
|
|
|
type: 'hidden',
|
|
|
|
name: 'id',
|
|
|
|
value: selectedExperiments[0]
|
|
|
|
}).appendTo(buttonForm);
|
|
|
|
})
|
|
|
|
.on('ajax:success', forms, function(ev, data) {
|
|
|
|
appendActionModal($(data.html));
|
|
|
|
})
|
|
|
|
.on('ajax:error', forms, function(ev, data) {
|
|
|
|
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-11 19:36:39 +08:00
|
|
|
function initNewExperimentToolbarButton() {
|
|
|
|
let forms = '.new-experiment-form';
|
|
|
|
$(experimentsPage)
|
|
|
|
.on('ajax:success', forms, function(ev, data) {
|
|
|
|
appendActionModal($(data.html));
|
|
|
|
})
|
|
|
|
.on('ajax:error', forms, function(ev, data) {
|
|
|
|
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-16 22:26:51 +08:00
|
|
|
function loadExperimentWorkflowImages() {
|
2021-03-24 06:13:26 +08:00
|
|
|
$('.experiment-card').each(function() {
|
|
|
|
let card = $(this);
|
|
|
|
let container = $(this).find('.workflowimg-container').first();
|
2020-10-16 20:21:25 +08:00
|
|
|
if (container.data('workflowimg-present') === false) {
|
|
|
|
let imgUrl = container.data('workflowimg-url');
|
2021-03-24 06:13:26 +08:00
|
|
|
card.find('.workflowimg-spinner').removeClass('hidden');
|
2020-10-16 20:21:25 +08:00
|
|
|
$.ajax({
|
|
|
|
url: imgUrl,
|
|
|
|
type: 'GET',
|
|
|
|
dataType: 'json',
|
|
|
|
success: function(data) {
|
2021-03-24 06:13:26 +08:00
|
|
|
card.find('.workflowimg-container').html(data.workflowimg);
|
2020-10-16 20:21:25 +08:00
|
|
|
},
|
|
|
|
error: function() {
|
2021-03-24 06:13:26 +08:00
|
|
|
card.find('.workflowimg-spinner').addClass('hidden');
|
2016-08-19 22:38:34 +08:00
|
|
|
}
|
2020-10-16 20:21:25 +08:00
|
|
|
});
|
2016-08-19 21:36:12 +08:00
|
|
|
}
|
|
|
|
});
|
2021-02-16 22:26:51 +08:00
|
|
|
}
|
2021-01-29 20:24:02 +08:00
|
|
|
|
2021-02-16 22:26:51 +08:00
|
|
|
function init() {
|
2021-01-28 04:53:39 +08:00
|
|
|
$('#content-wrapper').on('ajax:success', '.experiment-action-link', function(ev, data) {
|
2021-02-09 22:47:15 +08:00
|
|
|
appendActionModal($(data.html));
|
2021-01-28 04:53:39 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#content-wrapper')
|
|
|
|
.on('ajax:beforeSend', '.experiment-action-form', function() {
|
|
|
|
animateSpinner();
|
|
|
|
})
|
|
|
|
.on('ajax:success', '.experiment-action-form', function() {
|
2021-02-09 22:47:15 +08:00
|
|
|
$(this).closest('.modal').modal('hide');
|
|
|
|
refreshCurrentView();
|
|
|
|
animateSpinner(null, false);
|
2021-01-28 04:53:39 +08:00
|
|
|
})
|
|
|
|
.on('ajax:error', '.experiment-action-form', function(ev, data) {
|
|
|
|
animateSpinner(null, false);
|
|
|
|
$(this).renderFormErrors('experiment', data.responseJSON);
|
|
|
|
});
|
|
|
|
|
2021-01-29 20:24:02 +08:00
|
|
|
initExperimentsFilters();
|
2021-02-03 21:23:38 +08:00
|
|
|
initSorting();
|
2021-02-02 18:17:29 +08:00
|
|
|
loadCardsView();
|
2021-02-03 21:23:38 +08:00
|
|
|
initProjectsViewModeSwitch();
|
|
|
|
initExperimentsSelector();
|
|
|
|
initArchiveRestoreToolbarButtons();
|
2021-02-09 22:47:15 +08:00
|
|
|
initEditMoveDuplicateToolbarButton();
|
2021-02-11 19:36:39 +08:00
|
|
|
initNewExperimentToolbarButton();
|
2021-02-04 23:39:29 +08:00
|
|
|
initSelectAllCheckbox();
|
2016-08-19 21:36:12 +08:00
|
|
|
}
|
2016-08-25 01:03:58 +08:00
|
|
|
|
2016-11-14 21:27:35 +08:00
|
|
|
init();
|
2020-10-16 20:21:25 +08:00
|
|
|
}());
|