2023-05-03 19:39:10 +08:00
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
ref="modal"
|
|
|
|
class="modal fade"
|
|
|
|
id="assign-items-to-task-modal"
|
|
|
|
tabindex="-1"
|
|
|
|
role="dialog"
|
|
|
|
aria-labelledby="assignItemsToTaskModalLabel"
|
|
|
|
>
|
2023-05-05 16:31:35 +08:00
|
|
|
<div class="modal-dialog modal-sm" role="document">
|
2023-05-03 19:39:10 +08:00
|
|
|
<div class="modal-content">
|
|
|
|
<div class="modal-header">
|
|
|
|
<h4 class="modal-title">
|
|
|
|
{{ i18n.t("repositories.modal_assign_items_to_task.title") }}
|
|
|
|
</h4>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="close"
|
|
|
|
data-dismiss="modal"
|
|
|
|
aria-label="Close"
|
|
|
|
>
|
|
|
|
<span aria-hidden="true">×</span>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
<div class="modal-body">
|
|
|
|
<div class="description">
|
|
|
|
{{
|
|
|
|
i18n.t("repositories.modal_assign_items_to_task.body.description")
|
|
|
|
}}
|
|
|
|
</div>
|
|
|
|
|
2023-05-05 16:31:35 +08:00
|
|
|
<div class="project-selector level-selector">
|
2023-05-03 19:39:10 +08:00
|
|
|
<label>
|
2023-05-05 16:31:35 +08:00
|
|
|
{{
|
|
|
|
i18n.t(
|
|
|
|
"repositories.modal_assign_items_to_task.body.project_select.label"
|
|
|
|
)
|
|
|
|
}}
|
2023-05-03 19:39:10 +08:00
|
|
|
</label>
|
|
|
|
|
|
|
|
<SelectSearch
|
2023-05-18 01:01:16 +08:00
|
|
|
:value="selectedProject"
|
2023-05-03 19:39:10 +08:00
|
|
|
ref="projectsSelector"
|
|
|
|
@change="changeProject"
|
|
|
|
:options="projects"
|
2023-06-09 20:20:41 +08:00
|
|
|
:isLoading="projectsLoading"
|
2023-05-05 16:31:35 +08:00
|
|
|
:placeholder="
|
|
|
|
i18n.t(
|
|
|
|
'repositories.modal_assign_items_to_task.body.project_select.placeholder'
|
|
|
|
)
|
|
|
|
"
|
2023-05-26 17:47:35 +08:00
|
|
|
:no-options-placeholder="
|
|
|
|
i18n.t(
|
|
|
|
'repositories.modal_assign_items_to_task.body.project_select.no_options_placeholder'
|
|
|
|
)
|
|
|
|
"
|
2023-05-05 16:31:35 +08:00
|
|
|
:searchPlaceholder="
|
|
|
|
i18n.t(
|
|
|
|
'repositories.modal_assign_items_to_task.body.project_select.placeholder'
|
|
|
|
)
|
|
|
|
"
|
2023-05-03 19:39:10 +08:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2023-05-05 16:31:35 +08:00
|
|
|
<div class="experiment-selector level-selector">
|
2023-05-03 19:39:10 +08:00
|
|
|
<label>
|
2023-05-05 16:31:35 +08:00
|
|
|
{{
|
|
|
|
i18n.t(
|
|
|
|
"repositories.modal_assign_items_to_task.body.experiment_select.label"
|
|
|
|
)
|
|
|
|
}}
|
2023-05-03 19:39:10 +08:00
|
|
|
</label>
|
|
|
|
|
|
|
|
<SelectSearch
|
2023-05-18 01:01:16 +08:00
|
|
|
:value="selectedExperiment"
|
2023-05-03 19:39:10 +08:00
|
|
|
:disabled="!selectedProject"
|
|
|
|
ref="experimentsSelector"
|
|
|
|
@change="changeExperiment"
|
|
|
|
:options="experiments"
|
2023-06-09 20:20:41 +08:00
|
|
|
:isLoading="experimentsLoading"
|
2023-05-03 19:39:10 +08:00
|
|
|
:placeholder="experimentsSelectorPlaceholder"
|
2023-05-27 03:10:53 +08:00
|
|
|
:no-options-placeholder="
|
|
|
|
i18n.t(
|
|
|
|
'repositories.modal_assign_items_to_task.body.experiment_select.no_options_placeholder'
|
|
|
|
)
|
|
|
|
"
|
2023-05-05 16:31:35 +08:00
|
|
|
:searchPlaceholder="
|
|
|
|
i18n.t(
|
|
|
|
'repositories.modal_assign_items_to_task.body.experiment_select.placeholder'
|
|
|
|
)
|
|
|
|
"
|
2023-05-03 19:39:10 +08:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
|
2023-05-05 16:31:35 +08:00
|
|
|
<div class="task-selector level-selector">
|
2023-05-03 19:39:10 +08:00
|
|
|
<label>
|
2023-05-05 16:31:35 +08:00
|
|
|
{{
|
|
|
|
i18n.t(
|
|
|
|
"repositories.modal_assign_items_to_task.body.task_select.label"
|
|
|
|
)
|
|
|
|
}}
|
2023-05-03 19:39:10 +08:00
|
|
|
</label>
|
|
|
|
|
|
|
|
<SelectSearch
|
2023-05-18 01:01:16 +08:00
|
|
|
:value="selectedTask"
|
2023-05-03 19:39:10 +08:00
|
|
|
:disabled="!selectedExperiment"
|
|
|
|
ref="tasksSelector"
|
|
|
|
@change="changeTask"
|
|
|
|
:options="tasks"
|
2023-06-09 20:20:41 +08:00
|
|
|
:isLoading="tasksLoading"
|
2023-05-24 16:47:27 +08:00
|
|
|
:placeholder="tasksSelectorPlaceholder"
|
|
|
|
:no-options-placeholder="
|
2023-05-05 16:31:35 +08:00
|
|
|
i18n.t(
|
2023-05-24 16:47:27 +08:00
|
|
|
'repositories.modal_assign_items_to_task.body.task_select.no_options_placeholder'
|
2023-05-05 16:31:35 +08:00
|
|
|
)
|
|
|
|
"
|
|
|
|
:searchPlaceholder="
|
|
|
|
i18n.t(
|
|
|
|
'repositories.modal_assign_items_to_task.body.task_select.placeholder'
|
|
|
|
)
|
|
|
|
"
|
2023-05-03 19:39:10 +08:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="modal-footer">
|
2023-05-05 16:31:35 +08:00
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
class="btn btn-primary"
|
|
|
|
data-dismiss="modal"
|
|
|
|
:disabled="!selectedTask"
|
|
|
|
@click="assign"
|
|
|
|
>
|
2023-05-17 22:17:19 +08:00
|
|
|
{{ i18n.t("repositories.modal_assign_items_to_task.assign.text") }}
|
2023-05-03 19:39:10 +08:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-05-05 16:31:35 +08:00
|
|
|
import SelectSearch from "../shared/select_search.vue";
|
2023-05-03 19:39:10 +08:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "AssignItemsToTaskModalContainer",
|
|
|
|
props: {
|
|
|
|
visibility: Boolean,
|
2023-05-05 16:31:35 +08:00
|
|
|
urls: Object
|
2023-05-03 19:39:10 +08:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2023-05-05 16:31:35 +08:00
|
|
|
rowsToAssign: [],
|
|
|
|
projects: [],
|
|
|
|
experiments: [],
|
|
|
|
tasks: [],
|
2023-05-03 19:39:10 +08:00
|
|
|
selectedProject: null,
|
|
|
|
selectedExperiment: null,
|
2023-05-05 16:31:35 +08:00
|
|
|
selectedTask: null,
|
2023-06-09 20:20:41 +08:00
|
|
|
projectsLoading: null,
|
|
|
|
experimentsLoading: null,
|
|
|
|
tasksLoading: null,
|
2023-05-05 16:31:35 +08:00
|
|
|
showCallback: null
|
2023-05-03 19:39:10 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
SelectSearch
|
|
|
|
},
|
2023-05-05 16:31:35 +08:00
|
|
|
created() {
|
|
|
|
window.AssignItemsToTaskModalComponent = this;
|
|
|
|
},
|
2023-05-03 19:39:10 +08:00
|
|
|
mounted() {
|
2023-05-05 16:31:35 +08:00
|
|
|
$(this.$refs.modal).on("shown.bs.modal", () => {
|
2023-06-09 20:20:41 +08:00
|
|
|
this.projectsLoading = true;
|
|
|
|
|
2023-05-05 16:31:35 +08:00
|
|
|
$.get(this.projectURL, data => {
|
|
|
|
if (Array.isArray(data)) {
|
|
|
|
this.projects = data;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.projects = [];
|
2023-06-09 20:20:41 +08:00
|
|
|
}).always(() => {
|
|
|
|
this.projectsLoading = false;
|
2023-05-05 16:31:35 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
$(this.$refs.modal).on("hidden.bs.modal", () => {
|
2023-05-24 16:47:27 +08:00
|
|
|
this.resetSelectors();
|
2023-05-05 16:31:35 +08:00
|
|
|
this.$emit("close");
|
2023-05-03 19:39:10 +08:00
|
|
|
});
|
|
|
|
},
|
2023-05-05 16:31:35 +08:00
|
|
|
beforeDestroy() {
|
|
|
|
delete window.AssignItemsToTaskModalComponent;
|
|
|
|
},
|
2023-05-03 19:39:10 +08:00
|
|
|
computed: {
|
|
|
|
experimentsSelectorPlaceholder() {
|
|
|
|
if (this.selectedProject) {
|
2023-05-05 16:31:35 +08:00
|
|
|
return this.i18n.t(
|
|
|
|
"repositories.modal_assign_items_to_task.body.experiment_select.placeholder"
|
|
|
|
);
|
2023-05-03 19:39:10 +08:00
|
|
|
}
|
2023-05-05 16:31:35 +08:00
|
|
|
return this.i18n.t(
|
|
|
|
"repositories.modal_assign_items_to_task.body.experiment_select.disabled_placeholder"
|
|
|
|
);
|
2023-05-03 19:39:10 +08:00
|
|
|
},
|
|
|
|
tasksSelectorPlaceholder() {
|
|
|
|
if (this.selectedExperiment) {
|
2023-05-05 16:31:35 +08:00
|
|
|
return this.i18n.t(
|
|
|
|
"repositories.modal_assign_items_to_task.body.task_select.placeholder"
|
|
|
|
);
|
2023-05-03 19:39:10 +08:00
|
|
|
}
|
2023-05-05 16:31:35 +08:00
|
|
|
return this.i18n.t(
|
|
|
|
"repositories.modal_assign_items_to_task.body.task_select.disabled_placeholder"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
projectURL() {
|
|
|
|
return `${this.urls.projects}`;
|
|
|
|
},
|
|
|
|
experimentURL() {
|
|
|
|
return `${this.urls.experiments}?project_id=${this.selectedProject ||
|
|
|
|
""}`;
|
|
|
|
},
|
|
|
|
taskURL() {
|
|
|
|
return `${this.urls.tasks}?experiment_id=${this.selectedExperiment ||
|
|
|
|
""}`;
|
|
|
|
},
|
|
|
|
assignURL() {
|
|
|
|
return this.urls.assign.replace(":module_id", this.selectedTask);
|
2023-05-03 19:39:10 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
2023-05-05 16:31:35 +08:00
|
|
|
visibility() {
|
|
|
|
if (this.visibility) {
|
2023-05-03 19:39:10 +08:00
|
|
|
this.showModal();
|
|
|
|
} else {
|
|
|
|
this.hideModal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
showModal() {
|
2023-05-05 16:31:35 +08:00
|
|
|
$(this.$refs.modal).modal("show");
|
|
|
|
|
|
|
|
this.rowsToAssign = this.showCallback();
|
2023-05-03 19:39:10 +08:00
|
|
|
},
|
2023-05-05 16:31:35 +08:00
|
|
|
hideModal() {
|
|
|
|
$(this.$refs.modal).modal("hide");
|
2023-05-03 19:39:10 +08:00
|
|
|
},
|
|
|
|
changeProject(value) {
|
2023-05-05 16:31:35 +08:00
|
|
|
this.selectedProject = value;
|
|
|
|
this.resetExperimentSelector();
|
|
|
|
this.resetTaskSelector();
|
2023-05-03 19:39:10 +08:00
|
|
|
|
2023-06-09 20:20:41 +08:00
|
|
|
this.experimentsLoading = true;
|
2023-05-05 16:31:35 +08:00
|
|
|
$.get(this.experimentURL, data => {
|
|
|
|
if (Array.isArray(data)) {
|
|
|
|
this.experiments = data;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.experiments = [];
|
2023-06-09 20:20:41 +08:00
|
|
|
}).always(() => {
|
|
|
|
this.experimentsLoading = false;
|
2023-05-05 16:31:35 +08:00
|
|
|
});
|
2023-05-03 19:39:10 +08:00
|
|
|
},
|
|
|
|
changeExperiment(value) {
|
|
|
|
this.selectedExperiment = value;
|
2023-05-05 16:31:35 +08:00
|
|
|
this.resetTaskSelector();
|
|
|
|
|
2023-06-09 20:20:41 +08:00
|
|
|
this.tasksLoading = true;
|
2023-05-05 16:31:35 +08:00
|
|
|
$.get(this.taskURL, data => {
|
|
|
|
if (Array.isArray(data)) {
|
|
|
|
this.tasks = data;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
this.tasks = [];
|
2023-06-09 20:20:41 +08:00
|
|
|
}).always(() => {
|
|
|
|
this.tasksLoading = false;
|
2023-05-05 16:31:35 +08:00
|
|
|
});
|
2023-05-03 19:39:10 +08:00
|
|
|
},
|
|
|
|
changeTask(value) {
|
|
|
|
this.selectedTask = value;
|
2023-05-05 16:31:35 +08:00
|
|
|
},
|
|
|
|
resetProjectSelector() {
|
|
|
|
this.projects = [];
|
|
|
|
this.selectedProject = null;
|
|
|
|
},
|
|
|
|
resetExperimentSelector() {
|
|
|
|
this.experiments = [];
|
|
|
|
this.selectedExperiment = null;
|
|
|
|
},
|
|
|
|
resetTaskSelector() {
|
|
|
|
this.tasks = [];
|
|
|
|
this.selectedTask = null;
|
|
|
|
},
|
|
|
|
resetSelectors() {
|
|
|
|
this.resetTaskSelector();
|
|
|
|
this.resetExperimentSelector();
|
|
|
|
this.resetProjectSelector();
|
|
|
|
},
|
|
|
|
assign() {
|
|
|
|
if (!this.selectedTask) return;
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: this.assignURL,
|
|
|
|
type: "PATCH",
|
|
|
|
dataType: "json",
|
|
|
|
data: { rows_to_assign: this.rowsToAssign }
|
2023-05-17 22:17:19 +08:00
|
|
|
}).done(({assigned_count}) => {
|
|
|
|
const skipped_count = this.rowsToAssign.length - assigned_count;
|
|
|
|
|
|
|
|
if (skipped_count) {
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('repositories.modal_assign_items_to_task.assign.flash_some_assignments_success', {assigned_count: assigned_count, skipped_count: skipped_count }), 'success');
|
|
|
|
} else {
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('repositories.modal_assign_items_to_task.assign.flash_all_assignments_success', {count: assigned_count}), 'success');
|
|
|
|
}
|
|
|
|
}).fail(() => {
|
|
|
|
HelperModule.flashAlertMsg(this.i18n.t('repositories.modal_assign_items_to_task.assign.flash_assignments_failure'), 'danger');
|
2023-05-05 16:31:35 +08:00
|
|
|
}).always(() => {
|
|
|
|
this.resetSelectors();
|
2023-06-20 20:29:35 +08:00
|
|
|
this.reloadTable();
|
2023-05-05 16:31:35 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
setShowCallback(callback) {
|
|
|
|
this.showCallback = callback;
|
|
|
|
},
|
2023-06-20 20:29:35 +08:00
|
|
|
reloadTable() {
|
2023-05-05 16:31:35 +08:00
|
|
|
$('.repository-row-selector:checked').trigger('click');
|
2023-06-20 20:29:35 +08:00
|
|
|
$('.repository-table')
|
|
|
|
.find('table')
|
|
|
|
.dataTable()
|
|
|
|
.api()
|
|
|
|
.ajax
|
|
|
|
.reload();
|
2023-05-03 19:39:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|