ffplayout/pages/message.vue

449 lines
18 KiB
Vue
Raw Normal View History

2020-04-28 11:52:20 -04:00
<template>
2024-04-16 12:13:28 -04:00
<div>
<div class="flex flex-col items-center pt-10 px-8">
<div class="mt-2 w-full max-w-4xl">
<div class="flex flex-col xs:flex-row w-full gap-4">
<div class="grow xs:max-w-72">
<select
v-model="selected"
class="select select-sm select-bordered w-full"
@change="onChange($event)"
>
<option v-for="item in presets" :key="item.name">{{ item.name }}</option>
</select>
</div>
<div class="join">
<button
class="btn btn-sm join-item btn-primary"
:title="$t('message.savePreset')"
@click="savePreset()"
>
<i class="bi-cloud-upload" />
</button>
<button
class="btn btn-sm join-item btn-primary"
:title="$t('message.newPreset')"
@click="showCreateModal = true"
>
<i class="bi-file-plus" />
</button>
<button
class="btn btn-sm join-item btn-primary"
:title="$t('message.delPreset')"
@click="showDeleteModal = true"
>
<i class="bi-file-minus" />
</button>
</div>
2023-01-11 04:54:25 -05:00
</div>
2024-04-16 12:13:28 -04:00
<form class="my-6 w-full" @submit.prevent="submitMessage">
<textarea
v-model="form.text"
class="textarea textarea-bordered w-full"
rows="4"
:placeholder="$t('message.placeholder')"
/>
2023-01-11 04:54:25 -05:00
2024-04-16 12:13:28 -04:00
<div class="mt-2 grid xs:grid-cols-[auto_150px_150px] gap-4">
<div class="grow">
<div class="form-control">
<label class="cursor-pointer p-0">
<div class="label">
<span class="label-text">{{ $t('message.xAxis') }}</span>
</div>
<input
v-model="form.x"
class="input input-sm input-bordered w-full"
type="text"
placeholder="X"
required
/>
2024-04-16 12:13:28 -04:00
</label>
</div>
<div class="form-control">
<label class="cursor-pointer p-0">
<div class="label">
<span class="label-text">{{ $t('message.yAxis') }}</span>
</div>
<input
v-model="form.y"
class="input input-sm input-bordered w-full"
type="text"
placeholder="Y"
required
/>
2024-04-16 12:13:28 -04:00
</label>
</div>
2024-04-16 08:07:50 -04:00
</div>
2024-04-16 12:13:28 -04:00
<div class="xs:mt-10">
<div class="form-control">
<label class="label cursor-pointer p-0">
<span class="label-text">{{ $t('message.showBox') }}</span>
<input
v-model="form.showBox"
type="checkbox"
class="checkbox checkbox-xs rounded-sm"
/>
2024-04-16 12:13:28 -04:00
</label>
</div>
<label class="mt-2 form-control w-full">
2024-04-16 08:07:50 -04:00
<div class="label">
2024-04-16 12:13:28 -04:00
<span class="label-text">{{ $t('message.boxColor') }}</span>
2024-04-16 08:07:50 -04:00
</div>
<input
2024-04-16 12:13:28 -04:00
v-model="form.boxColor"
type="color"
class="input input-sm input-bordered w-full p-1"
2024-04-16 08:07:50 -04:00
required
/>
2024-04-06 17:12:06 -04:00
</label>
2023-01-11 04:54:25 -05:00
</div>
2024-04-16 12:13:28 -04:00
<label class="form-control w-full xs:mt-[68px]">
2024-04-06 17:12:06 -04:00
<div class="label">
2024-04-16 12:13:28 -04:00
<span class="label-text">{{ $t('message.boxAlpha') }}</span>
2024-04-06 17:12:06 -04:00
</div>
<input
2024-04-16 12:13:28 -04:00
v-model="form.boxAlpha"
2024-04-06 17:12:06 -04:00
type="number"
min="0"
max="1"
step="0.01"
2024-04-16 12:13:28 -04:00
class="input input-sm input-bordered w-full"
2024-04-06 17:12:06 -04:00
required
/>
2024-04-06 17:12:06 -04:00
</label>
</div>
2024-04-16 12:13:28 -04:00
<div class="grid xs:grid-cols-[150px_150px_auto] gap-4 mt-2">
<div>
<label class="form-control w-full">
<div class="label">
<span class="label-text">{{ $t('message.size') }}</span>
</div>
<input
v-model="form.fontSize"
type="number"
class="input input-sm input-bordered w-full"
required
/>
2024-04-16 12:13:28 -04:00
</label>
2024-04-06 17:12:06 -04:00
2024-04-16 12:13:28 -04:00
<label class="form-control w-full mt-2">
<div class="label">
<span class="label-text">{{ $t('message.fontColor') }}</span>
</div>
<input
v-model="form.fontColor"
type="color"
class="input input-sm input-bordered w-full p-1"
required
/>
2024-04-16 12:13:28 -04:00
</label>
</div>
<div>
<label class="form-control w-full">
<div class="label">
<span class="label-text">{{ $t('message.spacing') }}</span>
</div>
<input
v-model="form.fontSpacing"
type="number"
class="input input-sm input-bordered w-full"
required
/>
2024-04-16 12:13:28 -04:00
</label>
<label class="form-control w-full mt-2">
<div class="label">
<span class="label-text">{{ $t('message.fontAlpha') }}</span>
</div>
<input
v-model="form.fontAlpha"
type="number"
class="input input-sm input-bordered w-full"
min="0"
max="1"
step="0.01"
required
/>
2024-04-16 12:13:28 -04:00
</label>
</div>
<div class="grow">
<label class="form-control w-full">
<div class="label">
<span class="label-text">{{ $t('message.overallAlpha') }}</span>
</div>
<input
v-model="form.overallAlpha"
type="text"
class="input input-sm input-bordered w-full"
required
/>
2024-04-16 12:13:28 -04:00
</label>
<label class="form-control w-full xs:max-w-[150px] mt-2">
<div class="label">
<span class="label-text">{{ $t('message.borderWidth') }}</span>
</div>
<input
v-model="form.border"
type="number"
class="input input-sm input-bordered w-full"
required
/>
2024-04-16 12:13:28 -04:00
</label>
</div>
2023-01-11 04:54:25 -05:00
</div>
2024-04-16 12:13:28 -04:00
<div class="mt-5">
<button class="btn btn-primary send-btn" type="submit">{{ $t('message.send') }}</button>
</div>
</form>
</div>
2023-01-11 04:54:25 -05:00
</div>
2024-04-16 12:13:28 -04:00
<GenericModal :show="showCreateModal" :title="$t('message.newPreset')" :modal-action="createNewPreset">
<label class="form-control w-full">
<div class="label">
<span class="label-text">{{ $t('message.name') }}</span>
</div>
<input v-model="newPresetName" type="text" class="input input-bordered w-full" />
2024-04-16 12:13:28 -04:00
</label>
</GenericModal>
2024-04-06 17:12:06 -04:00
2024-04-16 12:13:28 -04:00
<GenericModal
:show="showDeleteModal"
:title="$t('message.delPreset')"
:text="`${$t('message.delText')}: <strong> ${selected}</strong>?`"
:modal-action="deletePreset"
/>
</div>
2020-04-28 11:52:20 -04:00
</template>
2023-01-11 04:54:25 -05:00
<script setup lang="ts">
const { t } = useI18n()
2023-01-11 04:54:25 -05:00
const authStore = useAuth()
const configStore = useConfig()
const indexStore = useIndex()
const { numberToHex, hexToNumber } = stringFormatter()
useHead({
2024-04-06 17:12:06 -04:00
title: 'Messages | ffplayout',
2023-01-11 04:54:25 -05:00
})
interface PresetName {
name: string
value: number
}
2023-01-11 04:54:25 -05:00
const form = ref({
id: 0,
name: '',
text: '',
x: '0',
y: '0',
fontSize: 24,
fontSpacing: 4,
fontColor: '#ffffff',
fontAlpha: 1.0,
showBox: true,
boxColor: '#000000',
boxAlpha: 0.8,
border: 4,
overallAlpha: '1',
})
2024-04-06 17:12:06 -04:00
const showCreateModal = ref(false)
const showDeleteModal = ref(false)
2023-01-11 04:54:25 -05:00
const selected = ref(null)
const newPresetName = ref('')
const presets = ref([] as PresetName[])
onMounted(() => {
getPreset(-1)
})
async function getPreset(index: number) {
2024-06-12 03:17:44 -04:00
fetch(`/api/presets/${configStore.configChannel[configStore.configID].id}`, {
2023-01-11 04:54:25 -05:00
method: 'GET',
headers: authStore.authHeader,
})
.then((response) => response.json())
.then((data) => {
if (index === -1) {
presets.value = [{ value: -1, name: '' }]
for (let i = 0; i < data.length; i++) {
const elem = data[i]
presets.value.push({ value: i, name: elem.name })
}
2020-04-28 11:52:20 -04:00
2023-01-11 04:54:25 -05:00
form.value = {
id: 0,
name: '',
text: '',
x: '0',
y: '0',
fontSize: 24,
fontSpacing: 4,
fontColor: '#ffffff',
fontAlpha: 1.0,
showBox: true,
boxColor: '#000000',
boxAlpha: 0.8,
border: 4,
overallAlpha: '1',
2020-04-28 11:52:20 -04:00
}
2023-01-11 04:54:25 -05:00
} else {
const fColor = data[index].fontcolor.split('@')
const bColor = data[index].boxcolor.split('@')
form.value = {
id: data[index].id,
name: data[index].name,
text: data[index].text,
x: data[index].x,
y: data[index].y,
fontSize: data[index].fontsize,
fontSpacing: data[index].line_spacing,
fontColor: fColor[0],
2023-01-11 04:54:25 -05:00
fontAlpha: fColor[1] ? hexToNumber(fColor[1]) : 1.0,
showBox: data[index].box === '1' ? true : false,
boxColor: bColor[0],
2023-01-11 04:54:25 -05:00
boxAlpha: bColor[1] ? hexToNumber(bColor[1]) : 1.0,
border: data[index].boxborderw,
overallAlpha: data[index].alpha,
2020-04-28 11:52:20 -04:00
}
}
2023-01-11 04:54:25 -05:00
})
}
2020-04-28 11:52:20 -04:00
2023-01-11 04:54:25 -05:00
function onChange(event: any) {
selected.value = event.target.value
2020-04-28 11:52:20 -04:00
2023-01-11 04:54:25 -05:00
getPreset(event.target.selectedIndex - 1)
}
2020-04-28 11:52:20 -04:00
2023-01-11 04:54:25 -05:00
async function savePreset() {
if (selected.value) {
const preset = {
id: form.value.id,
name: form.value.name,
text: form.value.text,
x: form.value.x,
y: form.value.y,
fontsize: form.value.fontSize,
line_spacing: form.value.fontSpacing,
fontcolor:
form.value.fontAlpha === 1
? form.value.fontColor
: form.value.fontColor + '@' + numberToHex(form.value.fontAlpha),
box: form.value.showBox ? '1' : '0',
boxcolor:
form.value.boxAlpha === 1
? form.value.boxColor
: form.value.boxColor + '@' + numberToHex(form.value.boxAlpha),
boxborderw: form.value.border,
alpha: form.value.overallAlpha,
2024-06-12 03:17:44 -04:00
channel_id: configStore.configChannel[configStore.configID].id,
2023-01-11 04:54:25 -05:00
}
2020-04-28 11:52:20 -04:00
const response = await fetch(`/api/presets/${form.value.id}`, {
2023-01-11 04:54:25 -05:00
method: 'PUT',
2024-04-16 08:07:50 -04:00
headers: { ...configStore.contentType, ...authStore.authHeader },
2023-01-11 04:54:25 -05:00
body: JSON.stringify(preset),
})
if (response.status === 200) {
indexStore.msgAlert('success', t('message.saveDone'), 2)
2023-01-11 04:54:25 -05:00
} else {
indexStore.msgAlert('error', t('message.saveFailed'), 2)
2023-01-11 04:54:25 -05:00
}
}
}
2024-04-16 08:07:50 -04:00
async function createNewPreset(create: boolean) {
2024-04-06 17:12:06 -04:00
showCreateModal.value = false
2024-04-16 08:07:50 -04:00
if (create) {
const preset = {
name: newPresetName.value,
text: form.value.text,
x: form.value.x.toString(),
y: form.value.y.toString(),
fontsize: form.value.fontSize.toString(),
line_spacing: form.value.fontSpacing.toString(),
fontcolor:
form.value.fontAlpha === 1
? form.value.fontColor
: form.value.fontColor + '@' + numberToHex(form.value.fontAlpha),
box: form.value.showBox ? '1' : '0',
boxcolor:
form.value.boxAlpha === 1
? form.value.boxColor
: form.value.boxColor + '@' + numberToHex(form.value.boxAlpha),
boxborderw: form.value.border.toString(),
alpha: form.value.overallAlpha.toString(),
2024-06-12 03:17:44 -04:00
channel_id: configStore.configChannel[configStore.configID].id,
2024-04-16 08:07:50 -04:00
}
2020-04-29 04:30:17 -04:00
2024-04-16 08:07:50 -04:00
const response = await fetch('/api/presets/', {
method: 'POST',
headers: { ...configStore.contentType, ...authStore.authHeader },
body: JSON.stringify(preset),
})
2023-01-11 04:54:25 -05:00
2024-04-16 08:07:50 -04:00
if (response.status === 200) {
indexStore.msgAlert('success', t('message.saveDone'), 2)
2024-04-16 08:07:50 -04:00
getPreset(-1)
} else {
indexStore.msgAlert('error', t('message.saveFailed'), 2)
2024-04-16 08:07:50 -04:00
}
2023-01-11 04:54:25 -05:00
}
2024-04-16 08:07:50 -04:00
newPresetName.value = ''
2023-01-11 04:54:25 -05:00
}
2024-04-06 17:12:06 -04:00
async function deletePreset(del: boolean) {
showDeleteModal.value = false
if (del && selected.value && selected.value !== '') {
await fetch(`/api/presets/${form.value.id}`, {
2023-01-11 04:54:25 -05:00
method: 'DELETE',
headers: authStore.authHeader,
})
getPreset(-1)
2020-04-28 11:52:20 -04:00
}
}
2023-01-11 04:54:25 -05:00
async function submitMessage() {
const obj = {
text: form.value.text,
x: form.value.x.toString(),
y: form.value.y.toString(),
fontsize: form.value.fontSize.toString(),
line_spacing: form.value.fontSpacing.toString(),
fontcolor: form.value.fontColor + '@' + numberToHex(form.value.fontAlpha),
alpha: form.value.overallAlpha.toString(),
box: form.value.showBox ? '1' : '0',
boxcolor: form.value.boxColor + '@' + numberToHex(form.value.boxAlpha),
boxborderw: form.value.border.toString(),
}
2024-06-12 03:17:44 -04:00
const response = await fetch(`/api/control/${configStore.configChannel[configStore.configID].id}/text/`, {
2023-01-11 04:54:25 -05:00
method: 'POST',
2024-04-16 08:07:50 -04:00
headers: { ...configStore.contentType, ...authStore.authHeader },
2023-01-11 04:54:25 -05:00
body: JSON.stringify(obj),
})
if (response.status === 200) {
indexStore.msgAlert('success', t('message.sendDone'), 2)
2023-01-11 04:54:25 -05:00
} else {
indexStore.msgAlert('error', t('message.sendFailed'), 2)
2023-01-11 04:54:25 -05:00
}
2020-04-28 11:52:20 -04:00
}
2023-01-11 04:54:25 -05:00
</script>