Refactor admin/queue to use Composition API (#8676)
* refactor(client): refactor admin/queue to use Composition API * Apply review suggestion from @Johann150 Co-authored-by: Johann150 <johann@qwertqwefsday.eu> Co-authored-by: Johann150 <johann@qwertqwefsday.eu>
This commit is contained in:
		| @@ -26,62 +26,40 @@ | |||||||
| </div> | </div> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <script lang="ts"> | <script lang="ts" setup> | ||||||
| import { defineComponent, markRaw, onMounted, onUnmounted, ref } from 'vue'; | import { onMounted, onUnmounted, ref } from 'vue'; | ||||||
| import number from '@/filters/number'; | import number from '@/filters/number'; | ||||||
| import MkQueueChart from '@/components/queue-chart.vue'; | import MkQueueChart from '@/components/queue-chart.vue'; | ||||||
| import * as os from '@/os'; | import * as os from '@/os'; | ||||||
|  |  | ||||||
| export default defineComponent({ | const activeSincePrevTick = ref(0); | ||||||
| 	components: { | const active = ref(0); | ||||||
| 		MkQueueChart | const waiting = ref(0); | ||||||
| 	}, | const delayed = ref(0); | ||||||
|  | const jobs = ref([]); | ||||||
|  |  | ||||||
| 	props: { | const props = defineProps<{ | ||||||
| 		domain: { | 	domain: string, | ||||||
| 			type: String, | 	connection: any, | ||||||
| 			required: true, | }>(); | ||||||
| 		}, |  | ||||||
| 		connection: { |  | ||||||
| 			required: true, |  | ||||||
| 		}, |  | ||||||
| 	}, |  | ||||||
|  |  | ||||||
| 	setup(props) { | onMounted(() => { | ||||||
| 		const activeSincePrevTick = ref(0); | 	os.api(props.domain === 'inbox' ? 'admin/queue/inbox-delayed' : props.domain === 'deliver' ? 'admin/queue/deliver-delayed' : null, {}).then(result => { | ||||||
| 		const active = ref(0); | 		jobs.value = result; | ||||||
| 		const waiting = ref(0); | 	}); | ||||||
| 		const delayed = ref(0); |  | ||||||
| 		const jobs = ref([]); |  | ||||||
|  |  | ||||||
| 		onMounted(() => { | 	const onStats = (stats) => { | ||||||
| 			os.api(props.domain === 'inbox' ? 'admin/queue/inbox-delayed' : props.domain === 'deliver' ? 'admin/queue/deliver-delayed' : null, {}).then(result => { | 		activeSincePrevTick.value = stats[props.domain].activeSincePrevTick; | ||||||
| 				jobs.value = result; | 		active.value = stats[props.domain].active; | ||||||
| 			}); | 		waiting.value = stats[props.domain].waiting; | ||||||
|  | 		delayed.value = stats[props.domain].delayed; | ||||||
|  | 	}; | ||||||
|  |  | ||||||
| 			const onStats = (stats) => { | 	props.connection.on('stats', onStats); | ||||||
| 				activeSincePrevTick.value = stats[props.domain].activeSincePrevTick; |  | ||||||
| 				active.value = stats[props.domain].active; |  | ||||||
| 				waiting.value = stats[props.domain].waiting; |  | ||||||
| 				delayed.value = stats[props.domain].delayed; |  | ||||||
| 			}; |  | ||||||
|  |  | ||||||
| 			props.connection.on('stats', onStats); | 	onUnmounted(() => { | ||||||
|  | 		props.connection.off('stats', onStats); | ||||||
| 			onUnmounted(() => { | 	}); | ||||||
| 				props.connection.off('stats', onStats); |  | ||||||
| 			}); |  | ||||||
| 		}); |  | ||||||
|  |  | ||||||
| 		return { |  | ||||||
| 			jobs, |  | ||||||
| 			activeSincePrevTick, |  | ||||||
| 			active, |  | ||||||
| 			waiting, |  | ||||||
| 			delayed, |  | ||||||
| 			number, |  | ||||||
| 		}; |  | ||||||
| 	}, |  | ||||||
| }); | }); | ||||||
| </script> | </script> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -6,71 +6,60 @@ | |||||||
| 	<XQueue :connection="connection" domain="deliver"> | 	<XQueue :connection="connection" domain="deliver"> | ||||||
| 		<template #title>Out</template> | 		<template #title>Out</template> | ||||||
| 	</XQueue> | 	</XQueue> | ||||||
| 	<MkButton danger @click="clear()"><i class="fas fa-trash-alt"></i> {{ $ts.clearQueue }}</MkButton> | 	<MkButton danger @click="clear()"><i class="fas fa-trash-alt"></i> {{ i18n.ts.clearQueue }}</MkButton> | ||||||
| </MkSpacer> | </MkSpacer> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
| <script lang="ts"> | <script lang="ts" setup> | ||||||
| import { defineComponent, markRaw } from 'vue'; | import { markRaw, onMounted, onBeforeUnmount, nextTick } from 'vue'; | ||||||
| import MkButton from '@/components/ui/button.vue'; | import MkButton from '@/components/ui/button.vue'; | ||||||
| import XQueue from './queue.chart.vue'; | import XQueue from './queue.chart.vue'; | ||||||
| import * as os from '@/os'; | import * as os from '@/os'; | ||||||
| import { stream } from '@/stream'; | import { stream } from '@/stream'; | ||||||
| import * as symbols from '@/symbols'; | import * as symbols from '@/symbols'; | ||||||
| import * as config from '@/config'; | import * as config from '@/config'; | ||||||
|  | import { i18n } from '@/i18n'; | ||||||
|  |  | ||||||
| export default defineComponent({ | const connection = markRaw(stream.useChannel('queueStats')) | ||||||
| 	components: { |  | ||||||
| 		MkButton, |  | ||||||
| 		XQueue, |  | ||||||
| 	}, |  | ||||||
|  |  | ||||||
| 	emits: ['info'], | function clear() { | ||||||
|  | 	os.confirm({ | ||||||
|  | 		type: 'warning', | ||||||
|  | 		title: i18n.ts.clearQueueConfirmTitle, | ||||||
|  | 		text: i18n.ts.clearQueueConfirmText, | ||||||
|  | 	}).then(({ canceled }) => { | ||||||
|  | 		if (canceled) return; | ||||||
|  |  | ||||||
| 	data() { | 		os.apiWithDialog('admin/queue/clear'); | ||||||
| 		return { | 	}); | ||||||
| 			[symbols.PAGE_INFO]: { | } | ||||||
| 				title: this.$ts.jobQueue, |  | ||||||
| 				icon: 'fas fa-clipboard-list', |  | ||||||
| 				bg: 'var(--bg)', |  | ||||||
| 				actions: [{ |  | ||||||
| 					asFullButton: true, |  | ||||||
| 					icon: 'fas fa-up-right-from-square', |  | ||||||
| 					text: this.$ts.dashboard, |  | ||||||
| 					handler: () => { |  | ||||||
| 						window.open(config.url + '/queue', '_blank'); |  | ||||||
| 					}, |  | ||||||
| 				}], |  | ||||||
| 			}, |  | ||||||
| 			connection: markRaw(stream.useChannel('queueStats')), |  | ||||||
| 		} |  | ||||||
| 	}, |  | ||||||
|  |  | ||||||
| 	mounted() { | onMounted(() => { | ||||||
| 		this.$nextTick(() => { | 	nextTick(() => { | ||||||
| 			this.connection.send('requestLog', { | 		connection.send('requestLog', { | ||||||
| 				id: Math.random().toString().substr(2, 8), | 			id: Math.random().toString().substr(2, 8), | ||||||
| 				length: 200 | 			length: 200 | ||||||
| 			}); |  | ||||||
| 		}); | 		}); | ||||||
| 	}, | 	}); | ||||||
|  | }) | ||||||
|  |  | ||||||
| 	beforeUnmount() { | onBeforeUnmount(() => { | ||||||
| 		this.connection.dispose(); | 	connection.dispose(); | ||||||
| 	}, | }); | ||||||
|  |  | ||||||
| 	methods: { | defineExpose({ | ||||||
| 		clear() { | 	[symbols.PAGE_INFO]: { | ||||||
| 			os.confirm({ | 		title: i18n.ts.jobQueue, | ||||||
| 				type: 'warning', | 		icon: 'fas fa-clipboard-list', | ||||||
| 				title: this.$ts.clearQueueConfirmTitle, | 		bg: 'var(--bg)', | ||||||
| 				text: this.$ts.clearQueueConfirmText, | 		actions: [{ | ||||||
| 			}).then(({ canceled }) => { | 			asFullButton: true, | ||||||
| 				if (canceled) return; | 			icon: 'fas fa-up-right-from-square', | ||||||
|  | 			text: i18n.ts.dashboard, | ||||||
| 				os.apiWithDialog('admin/queue/clear', {}); | 			handler: () => { | ||||||
| 			}); | 				window.open(config.url + '/queue', '_blank'); | ||||||
| 		} | 			}, | ||||||
|  | 		}], | ||||||
| 	} | 	} | ||||||
| }); | }); | ||||||
| </script> | </script> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Andreas Nedbal
					Andreas Nedbal