491 lines
18 KiB
Vue
491 lines
18 KiB
Vue
<template>
|
|
<div class="container">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-12">
|
|
<div class="card">
|
|
<div class="card-header d-flex justify-content-between">
|
|
<p>Arborescence : cliquer/glisser pour réorganiser l'arborescence</p>
|
|
<div class="form-inline">
|
|
<input type="text" class="form-control mr-1" placeholder="Nouveau dossier" v-model="newFolderFR">
|
|
<input type="submit" value="Ajouter" class="btn btn-primary" @click="addFolder">
|
|
</div>
|
|
</div>
|
|
<div class="card-body FoldersPage">
|
|
<div v-show="alertVisible" class="alert alert-success" role="alert">{{alertMsg}}</div>
|
|
<div v-show="alertErrorVisible" class="alert alert-danger" role="alert">{{alertMsg}}</div>
|
|
<VueNestable v-model="nestableItems" @change="changeOrder" :hooks="{'beforeMove': beforeMove}">
|
|
<VueNestableHandle slot-scope="{ item }" :item="item">
|
|
<span>
|
|
<i v-if="item.children.length" @click="hideChildren(item)" class="fas fa-minus-circle"></i>
|
|
<i @click="showChildren(item)" class="fas fa-plus-circle" style="display:none;"></i>
|
|
<i v-if="!staticFolders.includes(item.id)" class="fas fa-arrows-alt"></i>
|
|
{{ item.name.fr }}
|
|
</span>
|
|
<span>
|
|
<span v-if="!staticFolders.includes(item.id)">Autorisation : <input type="checkbox" v-model="item.needAuthorization" @change="toggleAuthorization(item)"></span>
|
|
<i v-if="!staticFolders.includes(item.id)" @click="modifyName(item)" class="fas fa-pencil-alt"></i>
|
|
<i v-if="!staticFolders.includes(item.id)" @click="AskDeleteFolder(item)" class="fas fa-trash-alt"></i>
|
|
</span>
|
|
</VueNestableHandle>
|
|
</VueNestable>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- Modal Edit -->
|
|
<div class="modal fade" id="staticBackdrop" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="staticBackdropLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="staticBackdropLabel">Dossier</h5>
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="form-group">
|
|
<input type="text" class="form-control" placeholder="Nom du dossier FR" v-model="folderNameFR">
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="text" class="form-control" placeholder="Nom du dossier EN" v-model="folderNameEN">
|
|
</div>
|
|
<div class="form-group">
|
|
<input type="text" class="form-control" placeholder="Nom du dossier DE" v-model="folderNameDE">
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Annuler</button>
|
|
<button type="button" class="btn btn-success" @click="registerNewName">Enregistrer</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<!-- Modal Delete -->
|
|
<div class="modal fade" id="DeleteModal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="staticBackdropLabel" aria-hidden="true">
|
|
<div class="modal-dialog" role="document">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="DeleteModalLabel">Attention !</h5>
|
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
<span aria-hidden="true">×</span>
|
|
</button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<p>Ceci effacera le dossier ainsi que tous les dossiers enfants. Continuer ?</p>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">Non</button>
|
|
<button type="button" class="btn btn-success" @click="deleteFolder">Oui</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
props: [
|
|
'folders',
|
|
'static_folders'
|
|
],
|
|
computed: {
|
|
test: {
|
|
get: function() {
|
|
let allDirectories = this.directories.sort((a, b) =>(a.order > b.order) ? 1 : ((b.order > a.order) ? -1 : 0));
|
|
allDirectories.forEach(child => {
|
|
child.name = JSON.parse(child.name);
|
|
if(child.children && child.children.length){
|
|
child.children = this.orderChildren(child);
|
|
} else {
|
|
child.children = [];
|
|
}
|
|
});
|
|
return allDirectories;
|
|
}
|
|
}
|
|
},
|
|
mounted() {
|
|
console.log('Folders Component mounted.');
|
|
this.staticFolders = this.static_folders.split(',').map(Number);
|
|
let parseDirectories = JSON.parse(this.folders);
|
|
this.directories = this.recursiveDir(parseDirectories);
|
|
if(this.test){
|
|
this.nestableItems = this.test
|
|
}
|
|
},
|
|
watch: {
|
|
test() {
|
|
if(!this.done){
|
|
this.nestableItems = this.test;
|
|
this.done = true;
|
|
}
|
|
}
|
|
},
|
|
data() {
|
|
return {
|
|
directories: [],
|
|
nestableItems: [],
|
|
done: false,
|
|
newFolderFR: "",
|
|
folderNameFR: "",
|
|
folderNameEN: "",
|
|
folderNameDE: "",
|
|
folderId: "",
|
|
alertMsg: '',
|
|
alertVisible: false,
|
|
alertErrorVisible: false,
|
|
staticFolders: []
|
|
}
|
|
},
|
|
methods: {
|
|
toggleAuthorization(item) {
|
|
let _this2 = this;
|
|
axios.post('/folders/toggle-authorization', {id: item.id})
|
|
.then(function (response) {
|
|
let parseDirectories = response.data;
|
|
_this2.directories = _this2.recursiveDir(parseDirectories);
|
|
if(_this2.test){
|
|
_this2.nestableItems = _this2.test
|
|
}
|
|
_this2.showAlert("Sauvegardé !");
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
});
|
|
},
|
|
hideChildren(folder) {
|
|
document.querySelector('.nestable-item-' + folder.id + " .fa-minus-circle").style.display = "none";
|
|
document.querySelector('.nestable-item-' + folder.id + " .fa-plus-circle").style.display = "inline-block";
|
|
if (folder.children && folder.children.length) {
|
|
let children = folder.children;
|
|
children.forEach(child => {
|
|
document.querySelector('.nestable-item-' + child.id).style.display = "none";
|
|
})
|
|
}
|
|
|
|
},
|
|
showChildren(folder) {
|
|
document.querySelector('.nestable-item-' + folder.id + " .fa-minus-circle").style.display = "inline-block";
|
|
document.querySelector('.nestable-item-' + folder.id + " .fa-plus-circle").style.display = "none";
|
|
if (folder.children && folder.children.length) {
|
|
let children = folder.children;
|
|
children.forEach(child => {
|
|
document.querySelector('.nestable-item-' + child.id).style.display = "block";
|
|
})
|
|
}
|
|
|
|
},
|
|
modifyName(folder) {
|
|
this.folderNameFR = folder.name.fr;
|
|
this.folderNameEN = folder.name.en;
|
|
this.folderNameDE = folder.name.de;
|
|
this.folderId = folder.id;
|
|
$('#staticBackdrop').modal('show');
|
|
},
|
|
registerNewName() {
|
|
this.done = false;
|
|
let _this2 = this;
|
|
axios.post('/save-folder-name', {id: this.folderId, name: JSON.stringify({fr: this.folderNameFR, en: this.folderNameEN, de: this.folderNameDE})})
|
|
.then(function (response) {
|
|
let parseDirectories = response.data;
|
|
_this2.directories = _this2.recursiveDir(parseDirectories);
|
|
if(_this2.test){
|
|
_this2.nestableItems = _this2.test
|
|
}
|
|
$('#staticBackdrop').modal('hide');
|
|
_this2.showAlert("Dossier renommé !");
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
});
|
|
},
|
|
addFolder() {
|
|
if (this.newFolderFR.length < 1){
|
|
this.showAlertError("Nom du dossier vide.");
|
|
return;
|
|
}
|
|
this.done = false;
|
|
let _this2 = this;
|
|
axios.post('/add-folder', {name: JSON.stringify({fr: this.newFolderFR}), order: this.nestableItems.length})
|
|
.then(function (response) {
|
|
let parseDirectories = response.data;
|
|
_this2.directories = _this2.recursiveDir(parseDirectories);
|
|
if(_this2.test){
|
|
_this2.nestableItems = _this2.test
|
|
}
|
|
_this2.newFolderFR = '';
|
|
_this2.showAlert("Dossier ajouté !");
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
});
|
|
},
|
|
AskDeleteFolder(folder) {
|
|
this.folderId = folder.id;
|
|
$('#DeleteModal').modal('show');
|
|
},
|
|
deleteFolder() {
|
|
this.done = false;
|
|
axios.post('/delete-folder', {id: this.folderId})
|
|
.then(response => {
|
|
if (response.data.status === 'OK'){
|
|
let parseDirectories = response.data.directories;
|
|
this.directories = this.recursiveDir(parseDirectories);
|
|
if(this.test){
|
|
this.nestableItems = this.test
|
|
}
|
|
this.folderId = '';
|
|
$('#DeleteModal').modal('hide');
|
|
this.showAlert("Dossier supprimé !");
|
|
}else{
|
|
$('#DeleteModal').modal('hide');
|
|
this.showAlertError(response.data.error);
|
|
}
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
});
|
|
},
|
|
displayChildrenName(folder) {
|
|
let childs = "";
|
|
if (folder.children && folder.children.length) {
|
|
folder.children.forEach((element, index) => {
|
|
childs += element.name + " - ";
|
|
if (element.children && element.children.length) {
|
|
childs += this.displayChildrenName(element);
|
|
}
|
|
})
|
|
}
|
|
return childs;
|
|
},
|
|
beforeMove({dragItem, pathFrom, pathTo}) {
|
|
// Item 4 can not be nested more than one level
|
|
if (this.staticFolders.includes(dragItem.id)) {
|
|
return pathTo.length === 1
|
|
}
|
|
// All other items can be
|
|
return true
|
|
},
|
|
assignOrder(children, parentId) {
|
|
children.forEach((element, index) => {
|
|
element.order = index;
|
|
element.parent = parentId;
|
|
if (element.children && element.children.length) {
|
|
element.children = this.assignOrder(element.children, element.id);
|
|
} else {
|
|
element.children = [];
|
|
}
|
|
});
|
|
return children;
|
|
},
|
|
orderChildren(folder) {
|
|
if (folder.children && folder.children.length) {
|
|
folder.children = folder.children.sort((a, b) => (a.order > b.order) ? 1 : ((b.order > a.order) ? -1 : 0))
|
|
folder.children.forEach(child => {
|
|
child.name = JSON.parse(child.name);
|
|
if (child.children && child.children.length) {
|
|
child.children = this.orderChildren(child);
|
|
} else {
|
|
child.children = [];
|
|
}
|
|
});
|
|
return folder.children
|
|
}
|
|
},
|
|
changeOrder() {
|
|
let list = this.assignOrder(this.nestableItems, null);
|
|
axios.post('/save-folder-order', {
|
|
folders: list,
|
|
})
|
|
.then(function (response) {
|
|
console.log(response);
|
|
})
|
|
.catch(function (error) {
|
|
console.log(error);
|
|
});
|
|
},
|
|
recursiveDir(list, parent = null) {
|
|
let root = list.filter(e => e.parent == parent);
|
|
for (let i = 0; i < root.length; i++) {
|
|
let childs = this.recursiveDir(list, root[i].id);
|
|
root[i].children = [];
|
|
for (let j = 0; j < childs.length; j++) {
|
|
root[i].children.push(childs[j])
|
|
}
|
|
if (!root[i].children.length) delete root[i].children
|
|
}
|
|
return root
|
|
},
|
|
showAlert(msg) {
|
|
this.alertMsg = msg;
|
|
this.alertVisible = true;
|
|
setTimeout(() => {
|
|
this.alertVisible = false;
|
|
}, 1800);
|
|
},
|
|
showAlertError(msg) {
|
|
this.alertMsg = msg;
|
|
this.alertErrorVisible = true;
|
|
setTimeout(() => {
|
|
this.alertErrorVisible = false;
|
|
}, 1800);
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss">
|
|
main {
|
|
width: 100%;
|
|
min-height: 100%;
|
|
}
|
|
|
|
.FoldersPage {
|
|
h2 {
|
|
margin-bottom: 40px;
|
|
}
|
|
|
|
.fa-arrows-alt {
|
|
margin-right: 10px;
|
|
}
|
|
|
|
.nestable-handle {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.fa-pencil-alt {
|
|
margin-left: 10px;
|
|
}
|
|
|
|
.fa-minus-circle, .fa-plus-circle, .fa-trash-alt, .fa-pencil-alt {
|
|
cursor: pointer;
|
|
}
|
|
|
|
.header-box {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
}
|
|
|
|
.add-folder {
|
|
display: flex;
|
|
align-content: center;
|
|
justify-content: center;
|
|
|
|
.el-input {
|
|
margin-right: 10px;
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Style for nestable
|
|
*/
|
|
.nestable {
|
|
position: relative;
|
|
}
|
|
|
|
.nestable-rtl {
|
|
direction: rtl;
|
|
}
|
|
|
|
.nestable .nestable-list {
|
|
margin: 0;
|
|
padding: 0 0 0 40px;
|
|
list-style-type: none;
|
|
}
|
|
|
|
.nestable-rtl .nestable-list {
|
|
padding: 0 40px 0 0;
|
|
}
|
|
|
|
.nestable > .nestable-list {
|
|
padding: 0;
|
|
}
|
|
|
|
.nestable-item,
|
|
.nestable-item-copy {
|
|
margin: 10px 0 0;
|
|
}
|
|
|
|
.nestable-item:first-child,
|
|
.nestable-item-copy:first-child {
|
|
margin-top: 0;
|
|
}
|
|
|
|
.nestable-item .nestable-list,
|
|
.nestable-item-copy .nestable-list {
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.nestable-item {
|
|
position: relative;
|
|
}
|
|
|
|
.nestable-item.is-dragging .nestable-list {
|
|
pointer-events: none;
|
|
}
|
|
|
|
.nestable-item.is-dragging * {
|
|
opacity: 0;
|
|
filter: alpha(opacity=0);
|
|
}
|
|
|
|
.nestable-item.is-dragging:before {
|
|
content: ' ';
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
background-color: rgba(106, 127, 233, 0.274);
|
|
border: 1px dashed rgb(73, 100, 241);
|
|
-webkit-border-radius: 5px;
|
|
border-radius: 5px;
|
|
}
|
|
|
|
.nestable-drag-layer {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
z-index: 100;
|
|
pointer-events: none;
|
|
}
|
|
|
|
.nestable-rtl .nestable-drag-layer {
|
|
left: auto;
|
|
right: 0;
|
|
}
|
|
|
|
.nestable-drag-layer > .nestable-list {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
padding: 0;
|
|
background-color: rgba(106, 127, 233, 0.274);
|
|
}
|
|
|
|
.nestable-rtl .nestable-drag-layer > .nestable-list {
|
|
padding: 0;
|
|
}
|
|
|
|
.nestable [draggable="true"] {
|
|
cursor: move;
|
|
}
|
|
|
|
.nestable-handle {
|
|
display: inline;
|
|
}
|
|
|
|
.nestable-item-content {
|
|
background-color: #EEE;
|
|
padding: 7px 10px 5px 10px;
|
|
border-radius: 5px;
|
|
|
|
&:hover {
|
|
background-color: #DDD;
|
|
}
|
|
}
|
|
</style>
|