diff --git a/deploy/dev/.backend.env b/deploy/dev/.backend.env new file mode 100644 index 0000000..bfddc4a --- /dev/null +++ b/deploy/dev/.backend.env @@ -0,0 +1 @@ +HTTP_HOST=core \ No newline at end of file diff --git a/deploy/dev/Dockerfile.backend b/deploy/dev/Dockerfile.backend new file mode 100644 index 0000000..19c2efd --- /dev/null +++ b/deploy/dev/Dockerfile.backend @@ -0,0 +1,13 @@ +FROM python:3.11-bookworm +LABEL authors="lagertonne" + +ENV PYTHONUNBUFFERED 1 +RUN mkdir /code +WORKDIR /code +COPY requirements.dev.txt /code/ +COPY requirements.prod.txt /code/ +RUN apt update && apt install -y mariadb-client +RUN pip install -r requirements.dev.txt +RUN pip install -r requirements.prod.txt +RUN pip install mysqlclient +COPY .. /code/ \ No newline at end of file diff --git a/deploy/dev/Dockerfile.frontend b/deploy/dev/Dockerfile.frontend new file mode 100644 index 0000000..0a41d1a --- /dev/null +++ b/deploy/dev/Dockerfile.frontend @@ -0,0 +1,6 @@ +FROM docker.io/node:22 + +RUN mkdir /web +WORKDIR /web +COPY package.json /web/ +RUN npm install diff --git a/deploy/dev/docker-compose.yml b/deploy/dev/docker-compose.yml new file mode 100644 index 0000000..411179e --- /dev/null +++ b/deploy/dev/docker-compose.yml @@ -0,0 +1,33 @@ +services: + core: + build: + context: ../../core + dockerfile: ../deploy/dev/Dockerfile.backend + command: bash -c 'python manage.py migrate && python manage.py runserver 0.0.0.0:8000' + #environment: + # - DATABASE_URL + volumes: + - ../../core:/code + - ./.backend.env:/code/.env + ports: + - "8000:8000" + + frontend: + build: + context: ../../web + dockerfile: ../deploy/dev/Dockerfile.frontend + command: npm run serve + volumes: + - ../../web:/web:ro + - /web/node_modules + - ./vue.config.js:/web/vue.config.js + ports: + - "8080:8080" + + db: + image: mariadb + environment: + MARIADB_RANDOM_ROOT_PASSWORD: true + MARIADB_DATABASE: system3 + MARIADB_USER: system3 + MARIADB_PASSWORD: system3 \ No newline at end of file diff --git a/deploy/dev/vue.config.js b/deploy/dev/vue.config.js new file mode 100644 index 0000000..f8f3c26 --- /dev/null +++ b/deploy/dev/vue.config.js @@ -0,0 +1,27 @@ +// vue.config.js + +module.exports = { + devServer: { + headers: { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Headers": "*", + "Access-Control-Allow-Methods": "*" + }, + proxy: { + '^/media/2': { + target: 'http://core:8000/', + }, + '^/api/2': { + target: 'http://core:8000/', + }, + '^/api/1': { + target: 'http://core:8000/', + }, + '^/ws/2': { + target: 'http://core:8000/', + ws: true, + logLevel: 'debug', + }, + } + } +} \ No newline at end of file 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/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'" > -