c3lf-system-3/src/views/Items.vue

105 lines
3.6 KiB
Vue
Raw Normal View History

<template>
<div class="container-fluid px-xl-5 mt-3">
2019-12-23 21:49:21 +01:00
<Modal title="Edit Item" v-if="editingItem" @close="closeEditingModal()">
<template #body>
<EditItem
2019-12-23 21:49:21 +01:00
:item="editingItem"
badge="item_uid"
/>
</template>
<template #buttons>
2019-12-23 21:49:21 +01:00
<button type="button" class="btn btn-secondary" @click="closeEditingModal()">Cancel</button>
<button type="button" class="btn btn-success" @click="saveEditingItem()">Save Changes</button>
</template>
</Modal>
2019-12-23 21:49:21 +01:00
<Lightbox v-if="lightboxItem" :file="lightboxItem.file" @close="closeLightboxModal()"/>
<div class="row" v-if="layout === 'table'">
<div class="col-xl-8 offset-xl-2">
<Table
:columns="['uid', 'description', 'box']"
:actions="[
2019-12-23 21:49:21 +01:00
{name: 'enlarge', fun: item => openEditingModalWith(item)},
2019-12-23 18:43:01 +01:00
{name: 'delete',fun: item => deleteItem(item)}
]"
:items="loadedItems"
:keyName="'uid'"
2019-12-23 21:49:21 +01:00
@itemActivated="openLightboxModalWith($event)"
/>
</div>
</div>
<Cards
v-if="layout === 'cards'"
:columns="['uid', 'description', 'box']"
:actions="[
{name: 'delete'}
]"
:items="loadedItems"
:keyName="'uid'"
v-slot="{ item }"
2019-12-23 21:49:21 +01:00
@itemActivated="openLightboxModalWith($event)"
>
<img
2019-12-22 18:52:08 +01:00
:src="`${baseUrl}/1/thumbs/${item.file}`"
class="card-img-top img-fluid"
>
<div class="card-body">
2019-12-13 00:06:22 +01:00
<h6 class="card-title">{{ item.description }}</h6>
<h6 class="card-subtitle text-secondary">uid: {{ item.uid }} box: {{ item.box }}</h6>
2019-12-23 21:49:21 +01:00
<div class="row mx-auto mt-2">
2019-12-23 21:54:23 +01:00
<div class="btn-group">
<button class="btn btn-outline-secondary" @click.stop="openEditingModalWith(item)">
Edit
</button>
<button class="btn btn-outline-secondary" @click.stop="deleteItem(item)">
Delete
</button>
</div>
2019-12-23 21:49:21 +01:00
</div>
</div>
</Cards>
</div>
</template>
<script>
import Table from '@/components/Table';
import Cards from '@/components/Cards';
import Modal from '@/components/Modal';
import EditItem from '@/components/EditItem';
2019-12-23 18:43:01 +01:00
import {mapActions, mapState} from 'vuex';
2019-12-22 18:52:08 +01:00
import config from '../config';
2019-12-23 21:49:21 +01:00
import Lightbox from '../components/Lightbox';
2019-12-13 00:06:22 +01:00
export default {
name: 'Items',
data: () => ({
2019-12-23 21:49:21 +01:00
lightboxItem: null,
editingItem: null,
2019-12-22 18:52:08 +01:00
baseUrl: config.service.url,
}),
2019-12-23 21:49:21 +01:00
components: {Lightbox, Table, Cards, Modal, EditItem },
computed: mapState(['loadedItems', 'layout']),
2019-12-13 00:06:22 +01:00
methods: {
2019-12-23 18:43:01 +01:00
...mapActions(['deleteItem']),
2019-12-23 21:49:21 +01:00
openLightboxModalWith(item) { // Opens the editing modal with a copy of the selected item.
this.lightboxItem = { ...item };
2019-12-14 23:51:06 +01:00
},
2019-12-23 21:49:21 +01:00
closeLightboxModal() { // Closes the editing modal and discards the edited copy of the item.
this.lightboxItem = null;
2019-12-14 23:51:06 +01:00
},
2019-12-23 21:49:21 +01:00
openEditingModalWith(item) {
this.editingItem = item;
},
closeEditingModal() {
this.editingItem = null;
},
saveEditingItem() { // Saves the edited copy of the item.
this.$store.dispatch('updateItem', this.editingItem);
this.closeLightboxModal();
}
2019-12-13 00:06:22 +01:00
}
};
</script>
<style scoped>
</style>