scinote-web/app/javascript/vue/projects/modals/move.vue

136 lines
4.4 KiB
Vue
Raw Normal View History

2023-12-01 07:01:08 +08:00
<template>
<div ref="modal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<form @submit.prevent="submit">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i class="sn-icon sn-icon-close"></i>
</button>
<h4 class="modal-title truncate !block" id="edit-project-modal-label">
{{ this.title }}
</h4>
2023-12-01 07:01:08 +08:00
</div>
<div class="modal-body">
<div class="mb-4">{{ this.description }}</div>
<div class="mb-4">
<div class="sci-input-container-v2 left-icon">
<input type="text"
v-model="query"
class="sci-input-field"
ref="input"
autofocus="true"
:placeholder="i18n.t('projects.index.modal_move_folder.find_folder')" />
<i class="sn-icon sn-icon-search"></i>
</div>
</div>
<div class="max-h-80 overflow-y-auto">
<div class="p-2 flex items-center gap-2 cursor-pointer text-sn-blue hover:bg-sn-super-light-grey"
@click="selectFolder(null)"
:class="{'!bg-sn-super-light-blue': selectedFolderId == null}">
<i class="sn-icon sn-icon-projects"></i>
{{ i18n.t('projects.index.modal_move_folder.projects') }}
</div>
<MoveTree :objects="filteredFoldersTree" :value="selectedFolderId" @selectFolder="selectFolder" />
2023-12-01 07:01:08 +08:00
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">{{ i18n.t('general.cancel') }}</button>
<button class="btn btn-primary" type="submit">
{{ i18n.t('projects.index.modal_move_folder.submit') }}
</button>
2023-12-01 07:01:08 +08:00
</div>
</div>
</form>
2023-12-01 07:01:08 +08:00
</div>
</div>
</template>
<script>
2023-12-11 16:18:22 +08:00
/* global HelperModule */
2023-12-01 07:01:08 +08:00
import axios from '../../../packs/custom_axios.js';
2023-12-11 16:18:22 +08:00
import modalMixin from '../../shared/modal_mixin';
2023-12-01 07:01:08 +08:00
import MoveTree from './move_tree.vue';
export default {
2023-12-11 16:18:22 +08:00
name: 'NewProjectModal',
2023-12-01 07:01:08 +08:00
props: {
selectedObjects: Array,
foldersTreeUrl: String,
moveToUrl: String,
},
2023-12-11 16:18:22 +08:00
mixins: [modalMixin],
2023-12-01 07:01:08 +08:00
data() {
return {
selectedFolderId: null,
foldersTree: [],
query: '',
};
},
components: {
2023-12-11 16:18:22 +08:00
MoveTree,
2023-12-01 07:01:08 +08:00
},
mounted() {
axios.get(this.foldersTreeUrl).then((response) => {
this.foldersTree = response.data;
});
},
computed: {
itemsName() {
2023-12-11 16:18:22 +08:00
return this.i18n.t(`projects.index.modal_move_folder.items.${this.itemsType}`);
2023-12-01 07:01:08 +08:00
},
title() {
2023-12-11 16:18:22 +08:00
return this.i18n.t('projects.index.modal_move_folder.title', { items: this.itemsName });
2023-12-01 07:01:08 +08:00
},
description() {
2023-12-11 16:18:22 +08:00
return this.i18n.t('projects.index.modal_move_folder.description', { items: this.itemsName });
2023-12-01 07:01:08 +08:00
},
itemsType() {
2023-12-11 16:18:22 +08:00
const allTypes = this.selectedObjects.map((obj) => obj.type);
2023-12-01 07:01:08 +08:00
const uniqueTypes = [...new Set(allTypes)];
2023-12-11 16:18:22 +08:00
if (uniqueTypes.length === 1) {
2023-12-01 07:01:08 +08:00
return uniqueTypes[0];
}
2023-12-11 16:18:22 +08:00
return 'projects_and_folders';
2023-12-01 07:01:08 +08:00
},
filteredFoldersTree() {
2023-12-11 16:18:22 +08:00
if (this.query === '') {
2023-12-01 07:01:08 +08:00
return this.foldersTree;
}
return this.filteredFoldersTreeHelper(this.foldersTree);
2023-12-11 16:18:22 +08:00
},
2023-12-01 07:01:08 +08:00
},
methods: {
filteredFoldersTreeHelper(foldersTree) {
return foldersTree.map(({ folder, children }) => {
if (folder.name.toLowerCase().includes(this.query.toLowerCase())) {
return { folder, children };
}
const filteredChildren = this.filteredFoldersTreeHelper(children);
return filteredChildren.length ? { folder, children: filteredChildren } : null;
}).filter(Boolean);
},
2023-12-01 07:01:08 +08:00
selectFolder(folderId) {
this.selectedFolderId = folderId;
},
submit() {
axios.post(this.moveToUrl, {
destination_folder_id: this.selectedFolderId || 'root_folder',
2023-12-11 16:18:22 +08:00
movables: this.selectedObjects.map((obj) => (
{
2023-12-01 07:01:08 +08:00
id: obj.id,
type: obj.type,
}
2023-12-11 16:18:22 +08:00
)),
2023-12-01 07:01:08 +08:00
}).then((response) => {
this.$emit('move');
HelperModule.flashAlertMsg(response.data.message, 'success');
}).catch((error) => {
HelperModule.flashAlertMsg(error.response.data.message, 'danger');
2023-12-11 16:18:22 +08:00
});
2023-12-01 07:01:08 +08:00
},
2023-12-11 16:18:22 +08:00
},
};
2023-12-01 07:01:08 +08:00
</script>