fix: update farm printers webcam to new webcam db namespace

Signed-off-by: Stefan Dej <meteyou@gmail.com>
This commit is contained in:
Stefan Dej committed 2021-11-05 20:45:11 +01:00
1 parent 7e9a274ff7
commit 89f2b2ce0b
6 files changed
+39 -11

No files matched your search

+9 -9
View File
@@ -33,7 +33,7 @@
:loading="printer.socket.isConnecting"
:toolbar-color="isCurrentPrinter ? 'primary' : ''"
>
<template v-slot:buttons v-if="printer.socket.isConnected && printer_webcams.length">
<template v-slot:buttons v-show="printer.socket.isConnected && printer_webcams.length">
<v-menu :offset-y="true" title="Webcam">
<template v-slot:activator="{ on, attrs }">
<v-btn text v-bind="attrs" v-on="on">
@@ -42,7 +42,7 @@
</v-btn>
</template>
<v-list dense class="py-0">
<v-list-item link @click="currentCamName = 'off'">
<v-list-item link @click="currentCamId = 'off'">
<v-list-item-icon class="mr-0">
<v-icon small>mdi-webcam-off</v-icon>
</v-list-item-icon>
@@ -50,7 +50,7 @@
<v-list-item-title>{{ $t('Panels.FarmPrinterPanel.WebcamOff') }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item v-for="webcam of printer_webcams" v-bind:key="webcam.index" link @click="currentCamName = webcam.name">
<v-list-item v-for="webcam of printer_webcams" v-bind:key="webcam.index" link @click="currentCamId = webcam.id">
<v-list-item-icon class="mr-0">
<v-icon small>{{ webcam.icon }}</v-icon>
</v-list-item-icon>
@@ -70,7 +70,7 @@
class="d-flex align-end"
ref="imageDiv"
>
<div v-if="printer.socket.isConnected && currentCamName !== 'off' && currentWebcam" class="webcamContainer">
<div v-if="printer.socket.isConnected && currentCamId !== 'off' && currentWebcam" class="webcamContainer">
<template v-if="'service' in currentWebcam && currentWebcam.service === 'mjpegstreamer'">
<webcam-mjpegstreamer :cam-settings="currentWebcam"></webcam-mjpegstreamer>
</template>
@@ -153,12 +153,12 @@ export default class FarmPrinterPanel extends Mixins(BaseMixin) {
return this.$store.getters['farm/'+this.printer._namespace+'/isCurrentPrinter']
}
get currentCamName() {
return this.$store.getters['farm/'+this.printer._namespace+'/getSetting']('currentCamName', 'off')
get currentCamId() {
return this.$store.getters['farm/'+this.printer._namespace+'/getSetting']('currentCamId', 'off')
}
set currentCamName(newVal) {
this.$store.dispatch('farm/'+this.printer._namespace+'/setSettings', { currentCamName: newVal })
set currentCamId(newVal) {
this.$store.dispatch('farm/'+this.printer._namespace+'/setSettings', { currentCamId: newVal })
}
get printer_name() {
@@ -198,7 +198,7 @@ export default class FarmPrinterPanel extends Mixins(BaseMixin) {
}
get currentWebcam() {
const currentCam = this.printer_webcams.find((webcam: any) => webcam.name === this.currentCamName)
const currentCam = this.printer_webcams.find((webcam: any) => webcam.id === this.currentCamId)
if (currentCam) return currentCam
return false
+12
View File
@@ -201,9 +201,21 @@ export const actions: ActionTree<FarmPrinterState, RootState> = {
action: 'getMainsailData'
})
}
if (payload.namespaces.includes('webcams')) {
dispatch('sendObj', {
method: 'server.database.get_item',
params: { namespace: 'webcams' },
action: 'getWebcamsData'
})
}
},
getMainsailData({ commit }, payload) {
commit('setMainsailData', payload.value)
},
getWebcamsData({ commit }, payload) {
commit('setWebcamsData', payload.value)
}
}
+8 -1
View File
@@ -2,6 +2,7 @@ import {defaultLogoColor, themeDir, thumbnailBigMin} from '@/store/variables'
import {convertName} from '@/plugins/helpers'
import {GetterTree} from 'vuex'
import {FarmPrinterState} from '@/store/farm/printer/types'
import {GuiWebcamStateWebcam} from '@/store/gui/webcam/types'
// eslint-disable-next-line
export const getters: GetterTree<FarmPrinterState, any> = {
@@ -237,6 +238,12 @@ export const getters: GetterTree<FarmPrinterState, any> = {
},
getPrinterWebcams: (state) => {
return state.data.gui.webcam.configs ?? []
const webcams: GuiWebcamStateWebcam[] = []
Object.keys(state.data.webcams).forEach((id: string) => {
webcams.push({...state.data?.webcams[id], id})
})
return webcams
}
}
+2 -1
View File
@@ -22,7 +22,8 @@ export const getDefaultState = (): FarmPrinterState => {
wsData: [],
},
data: {
gui: getGuiDefaultState()
gui: getGuiDefaultState(),
webcams: {}
},
settings: {
+4
View File
@@ -82,4 +82,8 @@ export const mutations: MutationTree<FarmPrinterState> = {
setDataDeep(state.data.gui, payload)
},
setWebcamsData(state, payload) {
Vue.set(state.data, 'webcams', payload)
},
}
+4
View File
@@ -1,5 +1,6 @@
import { GuiState } from '@/store/gui/types'
import { FileStateFile } from '@/store/files/types'
import {GuiWebcamStateWebcam} from '@/store/gui/webcam/types'
export interface FarmPrinterState {
_namespace: string
@@ -19,6 +20,9 @@ export interface FarmPrinterState {
},
data: {
gui: GuiState
webcams: {
[key: string]: GuiWebcamStateWebcam
}
// eslint-disable-next-line
[key: string]: any
},