sintonia_webapp/resources/js/composables/content/models/show/show.ts
2025-03-19 10:57:20 +01:00

117 lines
No EOL
3.8 KiB
TypeScript

import { VSelect, VTextarea, VTextField } from "vuetify/components";
import type {ShowInstances} from "@models/show/showInstances";
import type {ShowDays} from "@models/show/showDays.ts";
import type {ShowDjs} from "@models/show/showDjs.ts";
import axios, {type AxiosResponse} from "axios";
export interface Show {
id?: number;
name: string;
url: string;
genre: string;
description: string;
color: string;
backgroundColor: string;
liveStreamUsingAirtimeAuth: boolean;
liveStreamUsingCustomAuth: boolean;
liveStreamUser?: string;
liveStreamPass?: string;
imagePath?: string;
hasAutoplaylist: boolean;
autoplaylistId?: number;
autoplaylistRepeat: boolean;
// Relationships
block?: any;
showDays?: ShowDays[];
showDjs?: ShowDjs[];
showInstances?: ShowInstances[];
playlist?: any;
}
export function showForm(item: Show) {
const visibleFields = {
name: 'Nome',
url: 'URL',
genre: 'Genere',
description: 'Descrizione',
color: 'Colore',
backgroundColor: 'Colore di sfondo',
liveStreamUsingAirtimeAuth: 'Autenticazione Airtime',
liveStreamUsingCustomAuth: 'Autenticazione personalizzata',
liveStreamUser: 'Utente di streaming',
liveStreamPass: 'Password di streaming',
linked: 'Collegato',
isLinkable: 'Collegabile',
imagePath: 'Percorso immagine',
hasAutoplaylist: 'Ha playlist automatica',
autoplaylistId: 'ID Playlist automatica',
autoplaylistRepeat: 'Ripeti playlist automatica'
};
return () => {
const fields = {};
Object.keys(visibleFields).forEach((key) => {
fields[key] = {
label: visibleFields[key],
value: item[key as keyof Show],
component: VTextField,
disabled: false
};
switch (key) {
case 'liveStreamUsingAirtimeAuth':
case 'liveStreamUsingCustomAuth':
case 'linked':
case 'isLinkable':
case 'hasAutoplaylist':
fields[key].component = VSelect;
fields[key].props = {
items: [
{ text: 'Sì', value: true },
{ text: 'No', value: false }
]
};
break;
case 'description':
fields[key].component = VTextarea;
break;
case 'autoplaylistId':
// Optional handling if you have a way to fetch or display playlist names
fields[key].props = {
items: [], // Populate this with actual playlist options if available
labelKey: 'name', // Assuming playlists have a name property
valueKey: 'id'
};
break;
case 'imagePath':
fields[key].props = { type: 'file' }; // If you want to upload an image file
break;
default:
// For other fields, keep as text field by default
break;
}
});
return fields;
};
}
export async function getShows(scheduled = null , dateRangeScheduledStart = "", dateRangeScheduledEnd = "") {
return await axios.get(`/show`, {
params: {
scheduled: scheduled,
dateRangeScheduledStart: dateRangeScheduledStart,
dateRangeScheduledEnd: dateRangeScheduledEnd,
}
}).then((response: AxiosResponse) => {
return response.data
}).catch((error: Error) => {
console.log("Error: "+ error);
})
}