ffplayout/components/ConfigGui.vue
2024-02-29 08:15:19 +01:00

154 lines
5.9 KiB
Vue

<template>
<div>
<div class="container">
<h2 class="pb-4 pt-3">Channel Configuration</h2>
<div class="w-100" style="height: 43px">
<div class="float-end">
<button class="btn btn-primary" @click="addChannel()">Add new Channel</button>
</div>
</div>
<form
v-if="configStore.configGui && configStore.configGui[configStore.configID]"
@submit.prevent="onSubmitGui"
>
<div class="mb-3 row">
<label for="configName" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-10">
<input
type="text"
class="form-control"
id="configName"
v-model="configStore.configGui[configStore.configID].name"
/>
</div>
</div>
<div class="mb-3 row">
<label for="configUrl" class="col-sm-2 col-form-label">Preview URL</label>
<div class="col-sm-10">
<input
type="text"
class="form-control"
id="configUrl"
v-model="configStore.configGui[configStore.configID].preview_url"
/>
</div>
</div>
<div class="mb-3 row">
<label for="configPath" class="col-sm-2 col-form-label">Config Path</label>
<div class="col-sm-10">
<input
type="text"
class="form-control"
id="configPath"
v-model="configStore.configGui[configStore.configID].config_path"
/>
</div>
</div>
<div class="mb-3 row">
<label for="configExtensions" class="col-sm-2 col-form-label">Extra Extensions</label>
<div class="col-sm-10">
<input
type="text"
class="form-control"
id="configExtensions"
v-model="configStore.configGui[configStore.configID].extra_extensions"
/>
</div>
</div>
<div class="mb-3 row">
<label for="configService" class="col-sm-2 col-form-label">Service</label>
<div class="col-sm-10">
<input
type="text"
class="form-control"
id="configService"
v-model="configStore.configGui[configStore.configID].service"
disabled
/>
</div>
</div>
<div class="row">
<div class="col-1" style="min-width: 158px">
<div class="btn-group">
<button class="btn btn-primary" type="submit">Save</button>
<button
class="btn btn-danger"
v-if="
configStore.configGui.length > 1 &&
configStore.configGui[configStore.configID].id > 1
"
@click="deleteChannel()"
>
Delete
</button>
</div>
</div>
</div>
</form>
</div>
</div>
</template>
<script setup lang="ts">
const { $_ } = useNuxtApp()
const authStore = useAuth()
const configStore = useConfig()
const indexStore = useIndex()
async function addChannel() {
const channels = $_.cloneDeep(configStore.configGui)
const newChannel = $_.cloneDeep(configStore.configGui[configStore.configGui.length - 1])
const playoutConfigPath = newChannel.config_path.match(/.*\//)
const confName = `channel${String(channels.length + 1).padStart(3, '0')}`
newChannel.id = channels.length + 1
newChannel.name = `Channel ${Math.random().toString(36).substring(7)}`
newChannel.config_path = `${playoutConfigPath}${confName}.yml`
newChannel.service = `ffplayout@${confName}.service`
channels.push(newChannel)
configStore.configGui = channels
configStore.configID = configStore.configGui.length - 1
}
async function onSubmitGui() {
/*
Save GUI settings.
*/
const update = await configStore.setGuiConfig(configStore.configGui[configStore.configID])
if (update.status) {
indexStore.msgAlert('alert-success', 'Update GUI config success!', 2)
} else {
indexStore.msgAlert('alert-danger', 'Update GUI config failed!', 2)
}
}
async function deleteChannel() {
const config = $_.cloneDeep(configStore.configGui)
const id = config[configStore.configID].id
if (id === 1) {
indexStore.msgAlert('alert-warning', 'First channel can not be deleted!', 2)
return
}
const response = await fetch(`/api/channel/${id}`, {
method: 'DELETE',
headers: authStore.authHeader,
})
config.splice(configStore.configID, 1)
configStore.configGui = config
configStore.configID = configStore.configGui.length - 1
await configStore.getPlayoutConfig()
if (response.status === 200) {
indexStore.msgAlert('alert-success', 'Delete GUI config success!', 2)
} else {
indexStore.msgAlert('alert-danger', 'Delete GUI config failed!', 2)
}
}
</script>