implemented deletion
This commit is contained in:
parent
394bf9ee83
commit
3412049f3a
4 changed files with 12 additions and 4 deletions
|
@ -32,7 +32,7 @@
|
||||||
<td v-for="(column, index) in columns" :key="index">{{ item[column] }}</td>
|
<td v-for="(column, index) in columns" :key="index">{{ item[column] }}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button class="btn btn-outline-secondary" v-for="(action, a_index) in actions" :key="a_index" @click="action.fun&&action.fun(item, action)">{{action.name}}</button>
|
<button class="btn btn-outline-secondary" v-for="(action, a_index) in actions" :key="a_index" @click.stop="action.fun&&action.fun(item)" >{{action.name}}</button>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -48,6 +48,9 @@ const store = new Vuex.Store({
|
||||||
const item = state.loadedItems.filter(({ item_uid }) => item_uid === updatedItem.item_uid)[0];
|
const item = state.loadedItems.filter(({ item_uid }) => item_uid === updatedItem.item_uid)[0];
|
||||||
Object.assign(item, updatedItem);
|
Object.assign(item, updatedItem);
|
||||||
},
|
},
|
||||||
|
removeItem(state, item) {
|
||||||
|
state.loadedItems = state.loadedItems.filter(it => it !== item );
|
||||||
|
},
|
||||||
appendItem(state, item) {
|
appendItem(state, item) {
|
||||||
state.loadedItems.push(item);
|
state.loadedItems.push(item);
|
||||||
}
|
}
|
||||||
|
@ -79,6 +82,10 @@ const store = new Vuex.Store({
|
||||||
const { data } = await axios.put(`/1/${getters.getEventSlug}/item/${item.uid}`, item);
|
const { data } = await axios.put(`/1/${getters.getEventSlug}/item/${item.uid}`, item);
|
||||||
commit('updateItem', data);
|
commit('updateItem', data);
|
||||||
},
|
},
|
||||||
|
async deleteItem({ commit, getters }, item) {
|
||||||
|
await axios.delete(`/1/${getters.getEventSlug}/item/${item.uid}`, item);
|
||||||
|
commit('removeItem',item);
|
||||||
|
},
|
||||||
async postItem({ commit, getters }, item) {
|
async postItem({ commit, getters }, item) {
|
||||||
let blob = await fetch(item.dataImage).then(res => res.blob());
|
let blob = await fetch(item.dataImage).then(res => res.blob());
|
||||||
let file = new File([blob], 'dot.png', blob);
|
let file = new File([blob], 'dot.png', blob);
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
:columns="['cid', 'name']"
|
:columns="['cid', 'name']"
|
||||||
:actions="[
|
:actions="[
|
||||||
{name:'enlarge'},
|
{name:'enlarge'},
|
||||||
{name:'content', fun: (item,action) => showBoxContent(item.name)},
|
{name:'content', fun: item => showBoxContent(item.name)},
|
||||||
{name:'delete'},
|
{name:'delete'},
|
||||||
]"
|
]"
|
||||||
:items="loadedBoxes"
|
:items="loadedBoxes"
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
:columns="['uid', 'description', 'box']"
|
:columns="['uid', 'description', 'box']"
|
||||||
:actions="[
|
:actions="[
|
||||||
{name: 'enlarge'},
|
{name: 'enlarge'},
|
||||||
{name: 'delete'}
|
{name: 'delete',fun: item => deleteItem(item)}
|
||||||
]"
|
]"
|
||||||
:items="loadedItems"
|
:items="loadedItems"
|
||||||
:keyName="'uid'"
|
:keyName="'uid'"
|
||||||
|
@ -54,7 +54,7 @@ import Table from '@/components/Table';
|
||||||
import Cards from '@/components/Cards';
|
import Cards from '@/components/Cards';
|
||||||
import Modal from '@/components/Modal';
|
import Modal from '@/components/Modal';
|
||||||
import EditItem from '@/components/EditItem';
|
import EditItem from '@/components/EditItem';
|
||||||
import { mapState } from 'vuex';
|
import {mapActions, mapState} from 'vuex';
|
||||||
import config from '../config';
|
import config from '../config';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -66,6 +66,7 @@ export default {
|
||||||
components: { Table, Cards, Modal, EditItem },
|
components: { Table, Cards, Modal, EditItem },
|
||||||
computed: mapState(['loadedItems', 'layout']),
|
computed: mapState(['loadedItems', 'layout']),
|
||||||
methods: {
|
methods: {
|
||||||
|
...mapActions(['deleteItem']),
|
||||||
openModalWith(item) { // Opens the editing modal with a copy of the selected item.
|
openModalWith(item) { // Opens the editing modal with a copy of the selected item.
|
||||||
this.selectedItem = { ...item };
|
this.selectedItem = { ...item };
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue