From 3db2070ef32e19bbdba5b1355565783afc502c38 Mon Sep 17 00:00:00 2001 From: MarcZierle Date: Wed, 22 Jun 2022 11:58:10 +0200 Subject: [PATCH] add websockets and react to updates --- src/App.vue | 43 +++++++++++- src/api/index.js | 8 ++- src/components/PhotoItem.vue | 123 ++++++++++++++++++----------------- src/store/index.js | 40 +++++++++--- src/views/CreateLog.vue | 7 +- src/views/LogsList.vue | 63 ++++++++++++++---- src/views/ManagePhotos.vue | 8 +++ 7 files changed, 207 insertions(+), 85 deletions(-) diff --git a/src/App.vue b/src/App.vue index 144c928..7295241 100644 --- a/src/App.vue +++ b/src/App.vue @@ -22,6 +22,8 @@ import {darkTheme} from 'naive-ui' import NavBar from '@/components/NavBar.vue' +import store from '@/store/index.js' + export default defineComponent({ components: { NavBar, @@ -41,7 +43,46 @@ export default defineComponent({ //return !(currentPage == 'Home' || currentPage == 'CameraCapture') return !(currentPage == 'CameraCapture') } - } + }, + created() { + console.log("Starting connection to WebSocket Server") + this.connection = new WebSocket("wss://zierle-training-staging.riezel.com/ws/notifications/") + + this.connection.onmessage = function(event) { + console.log(event); + + let data = JSON.parse(event.data) + + if (data.type === 'update_photolog_pdf') { + store.dispatch('setPhotoLogField', + {id: data.content.id, field: 'status', value: null} + ) + store.dispatch('setPhotoLogField', + { + id: data.content.id, field: 'pdf', + value: 'https://minio.riezel.com/zierle-training/' + data.content.pdf + } + ) + store.dispatch('loadPhotoLogList') + } else if (data.type === 'update_photo') { + store.dispatch('loadPhoto', data.content.id) + store.dispatch('setPhotoStatus', { + id: data.content.id, + status: null + }) + } + } + + this.connection.onopen = function(event) { + console.log(event) + console.log("Successfully connected to the echo websocket server...") + } + + this.connection.onerror = function(event) { + console.error("Error while connecting to the websocket:") + console.error(event) + } + }, }) diff --git a/src/api/index.js b/src/api/index.js index dec8db9..7831ee8 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -1,9 +1,9 @@ import axios from 'axios' const apiClient = axios.create({ - baseURL: 'https://zierle-training.riezel.com/api/v1', + baseURL: 'https://zierle-training-staging.riezel.com/api/v1', withCredentials: false, - timeout: 120000, + timeout: 10000, headers: { Accept: 'application/json', 'Content-Type': 'application/json' @@ -125,6 +125,10 @@ export function addNewPhoto(original_image, cropped_image=null, group_id=null, o return apiClient.post('/addphoto/', data, config) } +export function loadPhoto(id) { + return apiClient.get('/photo/' + id+'/') +} + export function updatePhoto(photo) { return apiClient.put('/updatephoto/'+photo.id+'/', photo) } diff --git a/src/components/PhotoItem.vue b/src/components/PhotoItem.vue index 6331c26..b6cb7f9 100644 --- a/src/components/PhotoItem.vue +++ b/src/components/PhotoItem.vue @@ -1,64 +1,66 @@ \ No newline at end of file diff --git a/src/views/ManagePhotos.vue b/src/views/ManagePhotos.vue index 0fa0d79..af982c5 100644 --- a/src/views/ManagePhotos.vue +++ b/src/views/ManagePhotos.vue @@ -25,6 +25,7 @@ :can_change_ocr="true" :can_change_tag="true" :can_delete="true" + :loading="photosStatus[photo.id] === 'cropping'" @update:group="change_group_modal(photo.id)" @update:crop="change_crop_modal(photo.id)" @update:ocr="change_ocr_modal(photo.id)" @@ -216,6 +217,9 @@ export default { photos() { return this.$store.state.photos }, + photosStatus() { + return this.$store.state.photosStatus + }, groups_select_options() { if (this.photoGroups.length > 0) { let options = [] @@ -338,6 +342,10 @@ export default { rotate: rotate }).then(()=>{ setTimeout(()=>{ + this.$store.dispatch('setPhotoStatus', { + id: this.current_photo, + status: 'cropping' + }) this.$store.dispatch('cropPhoto', { id: this.current_photo, mode: 'bbox'