refactor: split 'components/collections/addCollection.vue' to 'addCollection', 'editCollection'
This commit is contained in:
@@ -1,14 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<modal v-if="show" @close="hideModel">
|
<modal v-if="show" @close="hideModal">
|
||||||
<div slot="header">
|
<div slot="header">
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<div class="flex-wrap">
|
<div class="flex-wrap">
|
||||||
<h3 class="title" v-if='!newCollection.hasOwnProperty("collectionIndex")'>New Collection</h3>
|
<h3 class="title">New Collection</h3>
|
||||||
<h3 class="title" v-if='newCollection.hasOwnProperty("collectionIndex")'>Edit Collection</h3>
|
|
||||||
<div>
|
<div>
|
||||||
<button class="icon" @click="hideModel" >
|
<button class="icon" @click="hideModal" >
|
||||||
<i class="material-icons">close</i>
|
<i class="material-icons">close</i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -19,21 +18,17 @@
|
|||||||
<div slot="body">
|
<div slot="body">
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<input type="text" v-model="newCollection.name" placeholder="My New Collection" />
|
<input type="text" v-model="name" placeholder="My New Collection" />
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div slot="footer">
|
<div slot="footer">
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<button class="icon" @click="addNewCollection" v-if='!newCollection.hasOwnProperty("collectionIndex")'>
|
<button class="icon" @click="addNewCollection">
|
||||||
<i class="material-icons">add</i>
|
<i class="material-icons">add</i>
|
||||||
<span>Create</span>
|
<span>Create</span>
|
||||||
</button>
|
</button>
|
||||||
<button class="icon" @click="saveCollection" v-if='newCollection.hasOwnProperty("collectionIndex")'>
|
|
||||||
<i class="material-icons">save</i>
|
|
||||||
<span>Save</span>
|
|
||||||
</button>
|
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@@ -47,47 +42,22 @@ import modal from "../../components/modal";
|
|||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
show: Boolean,
|
show: Boolean,
|
||||||
editingCollection: Object,
|
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
modal,
|
modal,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
newCollection: {
|
name: undefined,
|
||||||
name: '',
|
|
||||||
folders: [],
|
|
||||||
requests: [],
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
|
||||||
show() {
|
|
||||||
if (!this.editingCollection.collectionIndex) return;
|
|
||||||
this.newCollection = Object.assign({}, this.editingCollection);
|
|
||||||
},
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
addNewCollection() {
|
addNewCollection() {
|
||||||
const newCollection = Object.assign({}, this.newCollection);
|
this.$store.commit('postwoman/addNewCollection', { name: this.$data.name })
|
||||||
this.$emit('new-collection', newCollection);
|
this.$emit('hide-modal')
|
||||||
this.newCollection = {
|
|
||||||
name: '',
|
|
||||||
folders: [],
|
|
||||||
requests: [],
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
saveCollection() {
|
hideModal() {
|
||||||
const savedCollection = Object.assign({}, this.newCollection);
|
this.$emit('hide-modal')
|
||||||
this.$emit('saved-collection', savedCollection);
|
|
||||||
this.newCollection = {
|
|
||||||
name: '',
|
|
||||||
folders: [],
|
|
||||||
requests: [],
|
|
||||||
};
|
|
||||||
},
|
|
||||||
hideModel() {
|
|
||||||
this.$emit('hide-model');
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
67
components/collections/editCollection.vue
Normal file
67
components/collections/editCollection.vue
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<modal v-if="show" @close="hideModel">
|
||||||
|
<div slot='header'>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<div class="flex-wrap">
|
||||||
|
<h3 class="title">Edit Collection</h3>
|
||||||
|
<div>
|
||||||
|
<button class="icon" @click="hideModel" >
|
||||||
|
<i class="material-icons">close</i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div slot="body">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<input type="text" v-model="name" v-bind:placeholder="editingCollection.name" />
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div slot="footer">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<button class="icon" @click="saveCollection">
|
||||||
|
<i class="material-icons">save</i>
|
||||||
|
<span>Save</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</modal>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import modal from "../../components/modal";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
show: Boolean,
|
||||||
|
editingCollection: Object,
|
||||||
|
editingCollectionIndex: Number,
|
||||||
|
},
|
||||||
|
components: {
|
||||||
|
modal,
|
||||||
|
},
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
name: undefined,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
saveCollection() {
|
||||||
|
const collectionUpdated = { ...this.$props.editingCollection, name: this.$data.name }
|
||||||
|
this.$store.commit('postwoman/editCollection', { collection: collectionUpdated, collectionIndex: this.$props.editingCollectionIndex })
|
||||||
|
this.$emit('hide-modal');
|
||||||
|
},
|
||||||
|
hideModel() {
|
||||||
|
this.$emit('hide-modal');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -64,7 +64,7 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
hideModel() {
|
hideModel() {
|
||||||
this.$emit('hide-model');
|
this.$emit('hide-modal');
|
||||||
},
|
},
|
||||||
openDialogChooseFileToReplaceWith() {
|
openDialogChooseFileToReplaceWith() {
|
||||||
this.$refs.inputChooseFileToReplaceWith.click();
|
this.$refs.inputChooseFileToReplaceWith.click();
|
||||||
|
|||||||
@@ -1,25 +1,29 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="collections-wrapper">
|
<div class="collections-wrapper">
|
||||||
<addCollection
|
<addCollection
|
||||||
v-bind:show="showAddModel"
|
v-bind:show="showModalAdd"
|
||||||
v-on:new-collection="addNewCollection"
|
v-on:hide-modal='displayModalAdd(false)'
|
||||||
v-on:hide-model='toggleModal'
|
|
||||||
v-bind:editing-collection="selectedCollection"
|
|
||||||
v-on:saved-collection="savedCollection"
|
|
||||||
>
|
>
|
||||||
</addCollection>
|
</addCollection>
|
||||||
|
<editCollection
|
||||||
|
v-bind:show="showModalEdit"
|
||||||
|
v-bind:editingCollection="editingCollection"
|
||||||
|
v-bind:editingCollectionIndex="editingCollectionIndex"
|
||||||
|
v-on:hide-modal='displayModalEdit(false)'
|
||||||
|
>
|
||||||
|
</editCollection>
|
||||||
|
|
||||||
<importExportCollections :show="showImportExportModal" v-on:hide-model='toggleImportExport'></importExportCollections>
|
<importExportCollections :show="showModalImportExport" v-on:hide-modal='displayImportExport(false)'></importExportCollections>
|
||||||
|
|
||||||
<div class='flex-wrap'>
|
<div class='flex-wrap'>
|
||||||
<div>
|
<div>
|
||||||
<button class="icon" @click="toggleModal">
|
<button class="icon" @click="displayModalAdd(true)">
|
||||||
<i class="material-icons">add</i>
|
<i class="material-icons">add</i>
|
||||||
<span>New</span>
|
<span>New</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<button class="icon" @click="toggleImportExport">
|
<button class="icon" @click="displayImportExport(true)">
|
||||||
<i class="material-icons">import_export</i>
|
<i class="material-icons">import_export</i>
|
||||||
<span>Import / Export</span>
|
<span>Import / Export</span>
|
||||||
</button>
|
</button>
|
||||||
@@ -31,7 +35,7 @@
|
|||||||
<collection
|
<collection
|
||||||
:collection-index="index"
|
:collection-index="index"
|
||||||
:collection="collection"
|
:collection="collection"
|
||||||
v-on:edit-collection="editCollection"
|
v-on:edit-collection="editCollection(collection, index)"
|
||||||
></collection>
|
></collection>
|
||||||
</li>
|
</li>
|
||||||
<li v-if="collections.length === 0">
|
<li v-if="collections.length === 0">
|
||||||
@@ -50,6 +54,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import addCollection from "./addCollection";
|
import addCollection from "./addCollection";
|
||||||
|
import editCollection from "./editCollection";
|
||||||
import importExportCollections from "./importExportCollections";
|
import importExportCollections from "./importExportCollections";
|
||||||
import collection from './collection'
|
import collection from './collection'
|
||||||
|
|
||||||
@@ -57,40 +62,42 @@
|
|||||||
components: {
|
components: {
|
||||||
collection,
|
collection,
|
||||||
addCollection,
|
addCollection,
|
||||||
|
editCollection,
|
||||||
importExportCollections,
|
importExportCollections,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
showAddModel: false,
|
showModalAdd: false,
|
||||||
showImportExportModal: false,
|
showModalEdit: false,
|
||||||
selectedCollection: {},
|
showModalImportExport: false,
|
||||||
|
editingCollection: undefined,
|
||||||
|
editingCollectionIndex: undefined,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
collections () {
|
collections () {
|
||||||
return this.$store.state.postwoman.collections;
|
return this.$store.state.postwoman.collections
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
toggleModal() {
|
displayModalAdd(shouldDisplay) {
|
||||||
this.showAddModel = !this.showAddModel;
|
this.showModalAdd = shouldDisplay
|
||||||
},
|
},
|
||||||
toggleImportExport() {
|
displayModalEdit(shouldDisplay) {
|
||||||
this.showImportExportModal = !this.showImportExportModal;
|
this.showModalEdit = shouldDisplay
|
||||||
|
|
||||||
|
if (!shouldDisplay) {
|
||||||
|
this.$data.editingCollection = undefined
|
||||||
|
this.$data.editingCollectionIndex = undefined
|
||||||
|
}
|
||||||
},
|
},
|
||||||
addNewCollection(newCollection) {
|
displayImportExport(shouldDisplay) {
|
||||||
this.$store.commit('postwoman/addCollection', newCollection);
|
this.showModalImportExport = shouldDisplay
|
||||||
this.showAddModel = false;
|
|
||||||
},
|
},
|
||||||
editCollection(payload) {
|
editCollection(collection, collectionIndex) {
|
||||||
const { collection, collectionIndex } = payload;
|
this.$data.editingCollection = collection
|
||||||
this.selectedCollection = Object.assign({ collectionIndex }, collection);
|
this.$data.editingCollectionIndex = collectionIndex
|
||||||
this.showAddModel = true;
|
this.displayModalEdit(true)
|
||||||
},
|
|
||||||
savedCollection(savedCollection) {
|
|
||||||
this.$store.commit('postwoman/saveCollection', { savedCollection });
|
|
||||||
this.showAddModel = false;
|
|
||||||
this.selectedCollection = {};
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,10 +74,21 @@ export const mutations = {
|
|||||||
|
|
||||||
importCollections (state, collections) {
|
importCollections (state, collections) {
|
||||||
state.collections = [...state.collections, ...collections];
|
state.collections = [...state.collections, ...collections];
|
||||||
|
|
||||||
|
let index = 0;
|
||||||
|
for (let collection of collections) {
|
||||||
|
collection.collectionIndex = index;
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
addCollection (state, newCollection) {
|
addNewCollection (state, collection) {
|
||||||
state.collections.push(newCollection);
|
state.collections.push({
|
||||||
|
name: '',
|
||||||
|
folders: [],
|
||||||
|
requests: [],
|
||||||
|
...collection,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
removeCollection (state, payload) {
|
removeCollection (state, payload) {
|
||||||
@@ -85,9 +96,9 @@ export const mutations = {
|
|||||||
state.collections.splice(collectionIndex, 1)
|
state.collections.splice(collectionIndex, 1)
|
||||||
},
|
},
|
||||||
|
|
||||||
saveCollection (state, payload) {
|
editCollection (state, payload) {
|
||||||
const { savedCollection } = payload;
|
const { collection, collectionIndex } = payload
|
||||||
state.collections[savedCollection.collectionIndex] = savedCollection;
|
state.collections[collectionIndex] = collection
|
||||||
},
|
},
|
||||||
|
|
||||||
addFolder (state, payload) {
|
addFolder (state, payload) {
|
||||||
|
|||||||
Reference in New Issue
Block a user