scinote-web/app/javascript/vue/experiments/list.vue

274 lines
7.6 KiB
Vue
Raw Normal View History

2023-12-07 03:53:11 +08:00
<template>
<DataTable
:columnDefs="columnDefs"
tableId="ExperimentList"
2023-12-07 03:53:11 +08:00
:dataUrl="dataSource"
:reloadingTable="reloadingTable"
:toolbarActions="toolbarActions"
:actionsUrl="actionsUrl"
:activePageUrl="activePageUrl"
:archivedPageUrl="archivedPageUrl"
:currentViewMode="currentViewMode"
:filters="filters"
:viewRenders="viewRenders"
:objectArchived="archived"
:hiddenDataMessage="i18n.t('projects.show.empty_state.no_active_experiment_archived_project')"
2024-01-23 18:08:42 +08:00
scrollMode="infinite"
2023-12-07 03:53:11 +08:00
@tableReloaded="reloadingTable = false"
2023-12-11 16:18:22 +08:00
@archive="archive"
@restore="restore"
@showDescription="showDescription"
@duplicate="duplicate"
@move="move"
@edit="edit"
2023-12-11 22:41:03 +08:00
@create="create"
@access="access"
2023-12-07 03:53:11 +08:00
>
2023-12-11 22:41:03 +08:00
<template #card="data">
<ExperimentCard :params="data.params" :dtComponent="data.dtComponent" ></ExperimentCard>
</template>
2023-12-07 03:53:11 +08:00
</DataTable>
2023-12-11 16:18:22 +08:00
<DescriptionModal
v-if="descriptionModalObject"
:experiment="descriptionModalObject"
@close="descriptionModalObject = null"/>
<DuplicateModal
v-if="duplicateModalObject"
:experiment="duplicateModalObject"
@close="duplicateModalObject = null"/>
<MoveModal
v-if="moveModalObject"
:experiment="moveModalObject"
@close="moveModalObject = null"
@move="updateTable"/>
<EditModal
v-if="editModalObject"
:experiment="editModalObject"
@close="editModalObject = null"
@update="updateTable"/>
2023-12-11 22:41:03 +08:00
<NewModal
v-if="newModalOpen"
:createUrl="createUrl"
@close="newModalOpen = false"
@create="updateTable"/>
<AccessModal v-if="accessModalParams" :params="accessModalParams"
@close="accessModalParams = null" @refresh="this.reloadingTable = true" />
2023-12-07 03:53:11 +08:00
</template>
<script>
2023-12-11 16:18:22 +08:00
/* global HelperModule */
2023-12-07 03:53:11 +08:00
2023-12-11 16:18:22 +08:00
import axios from '../../packs/custom_axios.js';
2023-12-07 03:53:11 +08:00
import DataTable from '../shared/datatable/table.vue';
import DescriptionRenderer from './renderers/description.vue';
2023-12-11 16:18:22 +08:00
import ConfirmationModal from '../shared/confirmation_modal.vue';
2023-12-07 03:53:11 +08:00
import CompletedTasksRenderer from './renderers/completed_tasks.vue';
import NameRenderer from './renderers/name.vue';
2023-12-11 16:18:22 +08:00
import DescriptionModal from './modals/description.vue';
import DuplicateModal from './modals/duplicate.vue';
import MoveModal from './modals/move.vue';
import EditModal from './modals/edit.vue';
2023-12-11 22:41:03 +08:00
import NewModal from './modals/new.vue';
import AccessModal from '../shared/access_modal/modal.vue';
import ExperimentCard from './card.vue';
2023-12-07 03:53:11 +08:00
export default {
name: 'ExperimentsList',
components: {
DataTable,
2023-12-11 16:18:22 +08:00
ConfirmationModal,
DescriptionModal,
DuplicateModal,
MoveModal,
EditModal,
2023-12-11 22:41:03 +08:00
NewModal,
AccessModal,
2023-12-12 19:17:38 +08:00
ExperimentCard
2023-12-07 03:53:11 +08:00
},
props: {
dataSource: { type: String, required: true },
actionsUrl: { type: String, required: true },
activePageUrl: { type: String },
archivedPageUrl: { type: String },
currentViewMode: { type: String, required: true },
2023-12-11 22:41:03 +08:00
createUrl: { type: String, required: true },
userRolesUrl: { type: String, required: true },
archived: { type: Boolean }
2023-12-07 03:53:11 +08:00
},
data() {
return {
2023-12-11 22:41:03 +08:00
accessModalParams: null,
newModalOpen: false,
editModalObject: null,
2023-12-11 16:18:22 +08:00
moveModalObject: null,
duplicateModalObject: null,
descriptionModalObject: null,
2023-12-12 19:17:38 +08:00
reloadingTable: false
2023-12-07 03:53:11 +08:00
};
},
computed: {
columnDefs() {
const columns = [
{
field: 'name',
flex: 1,
headerName: this.i18n.t('experiments.card.name'),
sortable: true,
cellRenderer: NameRenderer,
minWidth: 150
2023-12-07 03:53:11 +08:00
},
{
field: 'code',
headerName: this.i18n.t('experiments.id'),
sortable: true,
minWidth: 80
2023-12-07 03:53:11 +08:00
},
{
field: 'created_at',
headerName: this.i18n.t('experiments.card.start_date'),
2024-02-19 20:01:37 +08:00
sortable: true,
minWidth: 110
2023-12-07 03:53:11 +08:00
},
{
field: 'updated_at',
headerName: this.i18n.t('experiments.card.modified_date'),
sortable: true,
minWidth: 110
2023-12-12 19:17:38 +08:00
}
2023-12-07 03:53:11 +08:00
];
if (this.currentViewMode === 'archived') {
columns.push({
field: 'archived_on',
headerName: this.i18n.t('experiments.card.archived_date'),
2023-12-12 19:17:38 +08:00
sortable: true
2023-12-07 03:53:11 +08:00
});
}
columns.push({
field: 'completed_tasks',
2023-12-07 03:53:11 +08:00
headerName: this.i18n.t('experiments.card.completed_task'),
cellRenderer: CompletedTasksRenderer,
sortable: true,
minWidth: 110
2023-12-07 03:53:11 +08:00
});
columns.push({
field: 'description',
headerName: this.i18n.t('experiments.card.description'),
sortable: true,
2023-12-07 03:53:11 +08:00
cellStyle: { 'white-space': 'normal' },
cellRenderer: DescriptionRenderer,
autoHeight: true,
minWidth: 110
2023-12-07 03:53:11 +08:00
});
return columns;
},
viewRenders() {
return [{ type: 'table' }, { type: 'cards' }];
},
toolbarActions() {
const left = [];
2023-12-12 19:17:38 +08:00
if (this.createUrl) {
left.push({
name: 'create',
icon: 'sn-icon sn-icon-new-task',
label: this.i18n.t('experiments.toolbar.new_button'),
type: 'emit',
path: this.createUrl,
buttonStyle: 'btn btn-primary'
});
}
2023-12-07 03:53:11 +08:00
return {
left,
2023-12-12 19:17:38 +08:00
right: []
2023-12-07 03:53:11 +08:00
};
},
filters() {
const filters = [
{
key: 'query',
2023-12-12 19:17:38 +08:00
type: 'Text'
2023-12-07 03:53:11 +08:00
},
{
key: 'created_at',
type: 'DateRange',
2023-12-12 19:17:38 +08:00
label: this.i18n.t('filters_modal.created_on.label')
2023-12-07 03:53:11 +08:00
},
2023-12-11 22:41:03 +08:00
{
key: 'created_at',
type: 'DateRange',
2023-12-12 19:17:38 +08:00
label: this.i18n.t('filters_modal.updated_on.label')
}
2023-12-07 03:53:11 +08:00
];
2023-12-11 22:41:03 +08:00
if (this.currentViewMode === 'archived') {
filters.push({
key: 'archived_on',
type: 'DateRange',
2023-12-12 19:17:38 +08:00
label: this.i18n.t('filters_modal.archived_on.label')
2023-12-11 22:41:03 +08:00
});
}
2023-12-07 03:53:11 +08:00
return filters;
2023-12-12 19:17:38 +08:00
}
2023-12-07 03:53:11 +08:00
},
2023-12-11 16:18:22 +08:00
methods: {
updateTable() {
2023-12-11 22:41:03 +08:00
this.newModalOpen = false;
this.editModalObject = null;
2023-12-11 16:18:22 +08:00
this.moveModalObject = null;
this.duplicateModalObject = null;
this.descriptionModalObject = null;
this.reloadingTable = true;
},
updateNavigator(withExpanedChildren = false) {
window.navigatorContainer.reloadNavigator(withExpanedChildren);
},
2023-12-11 16:18:22 +08:00
async archive(event, rows) {
axios.post(event.path, { experiment_ids: rows.map((row) => row.id) }).then((response) => {
this.reloadingTable = true;
HelperModule.flashAlertMsg(response.data.message, 'success');
this.updateNavigator(false);
}).catch((error) => {
HelperModule.flashAlertMsg(error.response.data.error, 'danger');
});
2023-12-11 16:18:22 +08:00
},
restore(event, rows) {
axios.post(event.path, { experiment_ids: rows.map((row) => row.id) }).then((response) => {
this.reloadingTable = true;
HelperModule.flashAlertMsg(response.data.message, 'success');
this.updateNavigator(false);
2023-12-11 16:18:22 +08:00
}).catch((error) => {
HelperModule.flashAlertMsg(error.response.data.error, 'danger');
});
},
showDescription(_e, experiment) {
[this.descriptionModalObject] = experiment;
},
duplicate(_e, experiment) {
[this.duplicateModalObject] = experiment;
},
2024-02-29 20:18:58 +08:00
move(event, rows) {
[this.moveModalObject] = rows;
2024-02-29 20:18:58 +08:00
this.moveModalObject.movePath = event.path;
2023-12-11 16:18:22 +08:00
},
edit(_e, experiment) {
[this.editModalObject] = experiment;
},
2023-12-11 22:41:03 +08:00
create() {
this.newModalOpen = true;
},
access(event, rows) {
this.accessModalParams = {
object: rows[0],
2023-12-12 19:17:38 +08:00
roles_path: this.userRolesUrl
2023-12-11 22:41:03 +08:00
};
2023-12-12 19:17:38 +08:00
}
}
2023-12-07 03:53:11 +08:00
};
</script>