ffplayout/components/ConfigChannel.vue

119 lines
4.1 KiB
Vue
Raw Normal View History

2023-01-11 04:54:25 -05:00
<template>
2024-04-04 17:28:25 -04:00
<div class="w-full max-w-[800px]">
2024-04-16 08:07:50 -04:00
<h2 class="pt-3 text-3xl">{{ $t('config.channelConf') }}</h2>
2024-04-04 17:28:25 -04:00
<div class="w-full flex justify-end my-4">
<button v-if="authStore.role === 'GlobalAdmin'" class="btn btn-sm btn-primary" @click="addChannel()">{{ $t('config.addChannel') }}</button>
2024-04-04 17:28:25 -04:00
</div>
<form
2024-06-12 03:17:44 -04:00
v-if="configStore.configChannel && configStore.configChannel[configStore.configID]"
2024-04-04 17:28:25 -04:00
class="w-full"
2024-04-16 12:13:28 -04:00
@submit.prevent="onSubmitGui"
2024-04-04 17:28:25 -04:00
>
<label class="form-control w-full">
<div class="label">
2024-04-16 08:07:50 -04:00
<span class="label-text">{{ $t('config.name') }}</span>
2023-01-11 04:54:25 -05:00
</div>
2024-04-04 17:28:25 -04:00
<input
2024-06-12 03:17:44 -04:00
v-model="configStore.configChannel[configStore.configID].name"
2024-04-04 17:28:25 -04:00
type="text"
placeholder="Type here"
class="input input-bordered w-full"
/>
2024-04-04 17:28:25 -04:00
</label>
<label class="form-control w-full mt-5">
<div class="label">
2024-04-16 08:07:50 -04:00
<span class="label-text">{{ $t('config.previewUrl') }}</span>
2023-01-11 04:54:25 -05:00
</div>
2024-04-04 17:28:25 -04:00
<input
2024-06-12 03:17:44 -04:00
v-model="configStore.configChannel[configStore.configID].preview_url"
2024-04-04 17:28:25 -04:00
type="text"
class="input input-bordered w-full"
/>
2024-04-04 17:28:25 -04:00
</label>
<label class="form-control w-full mt-5">
<div class="label">
2024-04-16 08:07:50 -04:00
<span class="label-text">{{ $t('config.extensions') }}</span>
2023-01-11 04:54:25 -05:00
</div>
2024-04-04 17:28:25 -04:00
<input
2024-06-12 03:17:44 -04:00
v-model="configStore.configChannel[configStore.configID].extra_extensions"
2024-04-04 17:28:25 -04:00
type="text"
class="input input-bordered w-full"
/>
2024-04-04 17:28:25 -04:00
</label>
2024-04-07 09:45:26 -04:00
<div class="join my-4">
2024-04-16 08:07:50 -04:00
<button class="join-item btn btn-primary" type="submit">{{ $t('config.save') }}</button>
2024-04-04 17:28:25 -04:00
<button
v-if="authStore.role === 'GlobalAdmin' && configStore.configChannel.length > 1 && configStore.configChannel[configStore.configID].id > 1"
2024-04-16 12:13:28 -04:00
class="join-item btn btn-primary"
2024-04-04 17:28:25 -04:00
@click="deleteChannel()"
>
2024-04-16 08:07:50 -04:00
{{ $t('config.delete') }}
2024-04-04 17:28:25 -04:00
</button>
</div>
</form>
2023-01-11 04:54:25 -05:00
</div>
</template>
<script setup lang="ts">
const { $_ } = useNuxtApp()
2024-04-16 08:07:50 -04:00
const { t } = useI18n()
2023-01-11 04:54:25 -05:00
const authStore = useAuth()
const configStore = useConfig()
const indexStore = useIndex()
async function addChannel() {
2024-06-12 03:17:44 -04:00
const channels = $_.cloneDeep(configStore.configChannel)
const newChannel = $_.cloneDeep(configStore.configChannel[configStore.configChannel.length - 1])
2023-01-11 04:54:25 -05:00
newChannel.id = channels.length + 1
newChannel.name = `Channel ${Math.random().toString(36).substring(7)}`
channels.push(newChannel)
2024-06-12 03:17:44 -04:00
configStore.configChannel = channels
configStore.configID = configStore.configChannel.length - 1
2023-01-11 04:54:25 -05:00
}
async function onSubmitGui() {
/*
Save GUI settings.
*/
2024-06-17 12:05:56 -04:00
const update = await configStore.setChannelConfig(configStore.configChannel[configStore.configID])
2023-01-11 04:54:25 -05:00
if (update.status) {
2024-04-16 08:07:50 -04:00
indexStore.msgAlert('success', t('config.updateChannelSuccess'), 2)
2023-01-11 04:54:25 -05:00
} else {
2024-04-16 08:07:50 -04:00
indexStore.msgAlert('error', t('config.updateChannelFailed'), 2)
2023-01-11 04:54:25 -05:00
}
}
async function deleteChannel() {
2024-06-12 03:17:44 -04:00
const config = $_.cloneDeep(configStore.configChannel)
2023-01-11 04:54:25 -05:00
const id = config[configStore.configID].id
if (id === 1) {
2024-04-16 08:07:50 -04:00
indexStore.msgAlert('warning', t('config.errorChannelDelete'), 2)
2023-01-11 04:54:25 -05:00
return
}
const response = await fetch(`/api/channel/${id}`, {
2023-01-11 04:54:25 -05:00
method: 'DELETE',
headers: authStore.authHeader,
})
config.splice(configStore.configID, 1)
2024-06-12 03:17:44 -04:00
configStore.configChannel = config
configStore.configID = configStore.configChannel.length - 1
2023-01-11 04:54:25 -05:00
await configStore.getPlayoutConfig()
if (response.status === 200) {
2024-04-16 08:07:50 -04:00
indexStore.msgAlert('success', t('config.errorChannelDelete'), 2)
2023-01-11 04:54:25 -05:00
} else {
2024-04-16 08:07:50 -04:00
indexStore.msgAlert('error', t('config.deleteChannelFailed'), 2)
2023-01-11 04:54:25 -05:00
}
}
</script>