Added edit and remove collection.

This commit is contained in:
Keith Holliday
2019-10-16 07:11:34 -06:00
parent 18a0c391f6
commit ed53b433b5
5 changed files with 88 additions and 6 deletions

View File

@@ -5,7 +5,8 @@
<ul> <ul>
<li> <li>
<div class="flex-wrap"> <div class="flex-wrap">
<h3 class="title">Add New Collection</h3> <h3 class="title" v-if='!newCollection.hasOwnProperty("collectionIndex")'>Add 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="hideModel">
<i class="material-icons">close</i> <i class="material-icons">close</i>
@@ -23,7 +24,8 @@
</ul> </ul>
</div> </div>
<div slot="footer"> <div slot="footer">
<button @click="addNewCollection">Add</button> <button @click="addNewCollection" v-if='!newCollection.hasOwnProperty("collectionIndex")'>Add</button>
<button @click="saveCollection" v-if='newCollection.hasOwnProperty("collectionIndex")'>Save</button>
</div> </div>
</modal> </modal>
</div> </div>
@@ -35,6 +37,7 @@ import modal from "../../components/modal";
export default { export default {
props: { props: {
show: Boolean, show: Boolean,
editingCollection: Object,
}, },
components: { components: {
modal, modal,
@@ -48,6 +51,12 @@ export default {
}, },
} }
}, },
watch: {
show() {
if (!this.editingCollection.collectionIndex);
this.newCollection = Object.assign({}, this.editingCollection);
},
},
methods: { methods: {
addNewCollection() { addNewCollection() {
const newCollection = Object.assign({}, this.newCollection); const newCollection = Object.assign({}, this.newCollection);
@@ -58,6 +67,15 @@ export default {
requests: [], requests: [],
}; };
}, },
saveCollection() {
const savedCollection = Object.assign({}, this.newCollection);
this.$emit('saved-collection', savedCollection);
this.newCollection = {
name: '',
folders: [],
requests: [],
};
},
hideModel() { hideModel() {
this.$emit('hide-model'); this.$emit('hide-model');
}, },

View File

@@ -12,13 +12,15 @@
<label @click="toggleShowChildren"> <label @click="toggleShowChildren">
{{collection.name}} {{collection.name}}
</label> </label>
<button class="add-button" @click="editCollection">e</button>
<button class="add-button" @click="removeCollection">x</button>
<button class="add-button" @click="toggleModal">+</button> <button class="add-button" @click="toggleModal">+</button>
</div> </div>
<div v-show="showChildren"> <div v-show="showChildren">
<ul> <ul>
<li v-for="(folder, index) in collection.folders" :key="folder.name"> <li v-for="(folder, index) in collection.folders" :key="folder.name">
<folder :folder="folder" :folderIndex="index" /> <folder :folder="folder" :folderIndex="index" :collection-index="collectionIndex" />
</li> </li>
</ul> </ul>
@@ -94,6 +96,18 @@ export default {
}); });
this.showModal = false; this.showModal = false;
}, },
editCollection() {
this.$emit('edit-collection', {
collectionIndex: this.collectionIndex,
collection: this.collection,
});
},
removeCollection() {
if (!confirm("Are you sure you want to remove this collection?")) return;
this.$store.commit('postwoman/removeCollection', {
collectionIndex: this.collectionIndex,
});
},
} }
}; };
</script> </script>

View File

@@ -4,6 +4,7 @@
<i @click="toggleShowChildren" v-show='!showChildren' class="material-icons">arrow_right</i> <i @click="toggleShowChildren" v-show='!showChildren' class="material-icons">arrow_right</i>
<i @click="toggleShowChildren" v-show='showChildren' class="material-icons">arrow_drop_down</i> <i @click="toggleShowChildren" v-show='showChildren' class="material-icons">arrow_drop_down</i>
<div @click="toggleShowChildren">{{folder.name}}</div> <div @click="toggleShowChildren">{{folder.name}}</div>
<button class="add-button" @click="removeFolder">x</button>
</div> </div>
<div v-show="showChildren"> <div v-show="showChildren">
@@ -30,6 +31,14 @@
display: flex; display: flex;
align-items: center; align-items: center;
} }
.add-button {
padding: 0;
width: 20px;
margin: 0;
height: 20px;
border-radius: 50%;
}
</style> </style>
<script> <script>
@@ -56,6 +65,13 @@ export default {
selectRequest(request) { selectRequest(request) {
this.$store.commit('postwoman/selectRequest', { request }); this.$store.commit('postwoman/selectRequest', { request });
}, },
removeFolder() {
if (!confirm("Are you sure you want to remove this folder?")) return;
this.$store.commit('postwoman/removeFolder', {
collectionIndex: this.collectionIndex,
folderIndex: this.folderIndex,
});
},
} }
}; };
</script> </script>

View File

@@ -3,7 +3,10 @@
<addCollection <addCollection
v-bind:show="showAddModel" v-bind:show="showAddModel"
v-on:new-collection="addNewCollection" v-on:new-collection="addNewCollection"
v-on:hide-model='toggleModal'> v-on:hide-model='toggleModal'
v-bind:editing-collection="selectedCollection"
v-on:saved-collection="savedCollection"
>
</addCollection> </addCollection>
<div class='header'> <div class='header'>
@@ -14,7 +17,11 @@
<ul> <ul>
<li v-for="(collection, index) in collections" :key="collection.name"> <li v-for="(collection, index) in collections" :key="collection.name">
<collection :collection-index="index" :collection="collection"></collection> <collection
:collection-index="index"
:collection="collection"
v-on:edit-collection="editCollection"
></collection>
</li> </li>
</ul> </ul>
</div> </div>
@@ -52,6 +59,7 @@
data() { data() {
return { return {
showAddModel: false, showAddModel: false,
selectedCollection: {},
} }
}, },
computed: { computed: {
@@ -67,6 +75,16 @@
this.$store.commit('postwoman/addCollection', newCollection); this.$store.commit('postwoman/addCollection', newCollection);
this.showAddModel = false; this.showAddModel = false;
}, },
editCollection(payload) {
const { collection, collectionIndex } = payload;
this.selectedCollection = Object.assign({ collectionIndex }, collection);
this.showAddModel = true;
},
savedCollection(savedCollection) {
this.$store.commit('postwoman/saveCollection', { savedCollection });
this.showAddModel = false;
this.selectedCollection = {};
},
}, },
} }

View File

@@ -80,11 +80,27 @@ export const mutations = {
state.collections.push(newCollection); state.collections.push(newCollection);
}, },
removeCollection (state, payload) {
const { collectionIndex } = payload;
state.collections.splice(collectionIndex, 1)
},
saveCollection (state, payload) {
const { savedCollection } = payload;
state.collections[savedCollection.collectionIndex] = savedCollection;
},
addFolder (state, payload) { addFolder (state, payload) {
const { collectionIndex, folder } = payload; const { collectionIndex, folder } = payload;
state.collections[collectionIndex].folders.push(folder); state.collections[collectionIndex].folders.push(folder);
}, },
removeFolder (state, payload) {
const { collectionIndex, folderIndex } = payload;
console.log(collectionIndex)
state.collections[collectionIndex].folders.splice(folderIndex, 1)
},
addRequest (state, payload) { addRequest (state, payload) {
const { collectionIndex, folderIndex, request } = payload; const { collectionIndex, folderIndex, request } = payload;
state.collections[collectionIndex].folders[folderIndex].push(request); state.collections[collectionIndex].folders[folderIndex].push(request);