From 546e49e50e9117f89dead6958ac1fd77bbef36a4 Mon Sep 17 00:00:00 2001 From: jedi Date: Fri, 1 Nov 2024 22:26:15 +0100 Subject: [PATCH 1/2] stash events admin frontend --- web/src/App.vue | 8 ++- web/src/components/AddEventModal.vue | 86 ++++++++++++++++++++++++++++ web/src/components/AsyncLoader.vue | 2 +- web/src/store.js | 19 ++++++ web/src/utils.js | 4 +- web/src/views/admin/Events.vue | 22 +++++-- 6 files changed, 131 insertions(+), 10 deletions(-) create mode 100644 web/src/components/AddEventModal.vue diff --git a/web/src/App.vue b/web/src/App.vue index cad130c..bd4956f 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -3,6 +3,7 @@ + @@ -14,12 +15,13 @@ import AddItemModal from '@/components/AddItemModal'; import {mapState, mapMutations, mapActions, mapGetters} from 'vuex'; import AddTicketModal from "@/components/AddTicketModal.vue"; import AddBoxModal from "@/components/AddBoxModal.vue"; +import AddEventModal from "@/components/AddEventModal.vue"; export default { name: 'app', - components: {AddBoxModal, Navbar, AddItemModal, AddTicketModal}, + components: {AddBoxModal, AddEventModal, Navbar, AddItemModal, AddTicketModal}, computed: { - ...mapState(['loadedItems', 'layout', 'toasts', 'showAddBoxModal']), + ...mapState(['loadedItems', 'layout', 'toasts', 'showAddBoxModal', 'showAddEventModal']), ...mapGetters(['isLoggedIn']), }, data: () => ({ @@ -27,7 +29,7 @@ export default { addTicketModalOpen: false }), methods: { - ...mapMutations(['removeToast', 'createToast', 'closeAddBoxModal', 'openAddBoxModal']), + ...mapMutations(['removeToast', 'createToast', 'closeAddBoxModal', 'openAddBoxModal', 'closeAddEventModal']), ...mapActions(['loadEvents', 'scheduleAfterInit']), openAddItemModal() { this.addItemModalOpen = true; diff --git a/web/src/components/AddEventModal.vue b/web/src/components/AddEventModal.vue new file mode 100644 index 0000000..387aeb2 --- /dev/null +++ b/web/src/components/AddEventModal.vue @@ -0,0 +1,86 @@ + + + + + \ No newline at end of file diff --git a/web/src/components/AsyncLoader.vue b/web/src/components/AsyncLoader.vue index 393175c..00bf841 100644 --- a/web/src/components/AsyncLoader.vue +++ b/web/src/components/AsyncLoader.vue @@ -57,7 +57,7 @@ export default { color: #17a2b8; } -.async-wrapper.loaded > .loader-wrapper > .loader-ellipsis { +.async-wrapper.loaded > .loader-wrapper { display: none; } diff --git a/web/src/store.js b/web/src/store.js index 844775a..0724070 100644 --- a/web/src/store.js +++ b/web/src/store.js @@ -54,6 +54,7 @@ const store = createStore({ afterInitHandlers: [], showAddBoxModal: false, + showAddEventModal: false, test: ['foo', 'bar', 'baz'], shippingVoucherTypes: { @@ -179,6 +180,12 @@ const store = createStore({ closeAddBoxModal(state) { state.showAddBoxModal = false; }, + openAddEventModal(state) { + state.showAddEventModal = true; + }, + closeAddEventModal(state) { + state.showAddEventModal = false; + }, createToast(state, {title, message, color}) { var toast = {title, message, color, key: state.keyIncrement} state.toasts.push(toast); @@ -321,6 +328,18 @@ const store = createStore({ if (data && success) commit('replaceEvents', data); }, + async createEvent({commit, dispatch, state}, event) { + const {data, success} = await http.post('/2/events/', event, state.user.token); + if (data && success) + commit('replaceEvents', [...state.events, data]); + }, + async deleteEvent({commit, dispatch, state}, event_id) { + const {data, success} = await http.delete(`/2/events/${event_id}/`, state.user.token); + if (success) { + await dispatch('loadEvents') + commit('replaceEvents', [...state.events.filter(e => e.eid !== event_id)]) + } + }, async fetchTicketStates({commit, state}) { if (!state.user.token) return; if (state.fetchedData.states > Date.now() - 1000 * 60 * 60 * 24) return; diff --git a/web/src/utils.js b/web/src/utils.js index 6e9d8e4..5910521 100644 --- a/web/src/utils.js +++ b/web/src/utils.js @@ -95,8 +95,8 @@ const http = { "Authorization": `Token ${token}`, }, }); - const success = response.status === 200 || response.status === 201; - return {data: await response.json() || {}, success}; + const success = response.status === 204; + return {data: await response.text() || {}, success}; } } diff --git a/web/src/views/admin/Events.vue b/web/src/views/admin/Events.vue index 36fd5ca..1aab608 100644 --- a/web/src/views/admin/Events.vue +++ b/web/src/views/admin/Events.vue @@ -4,13 +4,19 @@ :items="events" :keyName="'slug'" > -