215 lines
7 KiB
TypeScript
215 lines
7 KiB
TypeScript
import type {ShowInstance} from "@models/show/showInstance.ts";
|
|
import type {ShowDays} from "@models/show/showDays";
|
|
import type {ShowDjs} from "@models/show/showDjs";
|
|
import axios, {type AxiosResponse} from "axios";
|
|
import {VCheckbox, VFileInput, VTextarea, VTextField} from "vuetify/components";
|
|
import ColorPickerButton from "@partials/fields/misc/ColorPickerButton.vue";
|
|
import CheckBoxConditional from "@partials/fields/misc/CheckBoxConditional.vue";
|
|
import PlaylistSelect from "@partials/fields/playlist/PlaylistSelect.vue";
|
|
|
|
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?: ShowInstance[];
|
|
playlist?: any;
|
|
}
|
|
|
|
export const baseShow = (): Show => {
|
|
return {
|
|
id: null,
|
|
name: '',
|
|
url: '',
|
|
genre: '',
|
|
description: '',
|
|
backgroundColor: '',
|
|
liveStreamUsingAirtimeAuth: false,
|
|
liveStreamUser: '',
|
|
liveStreamPass: '',
|
|
imagePath: '',
|
|
hasAutoplaylist: false,
|
|
autoplaylistId: 0,
|
|
autoplaylistRepeat: false,
|
|
showDjs: null
|
|
}
|
|
}
|
|
|
|
const fieldDefinitions = {
|
|
name: {
|
|
label: 'Nome',
|
|
required: true,
|
|
},
|
|
url: {
|
|
label: 'URL',
|
|
required: true,
|
|
},
|
|
genre: {
|
|
label: 'Genere',
|
|
required: true,
|
|
},
|
|
description: {
|
|
label: 'Descrizione',
|
|
required: false,
|
|
},
|
|
backgroundColor: {
|
|
label: 'Colore di sfondo',
|
|
required: false,
|
|
},
|
|
liveStreamUsingAirtimeAuth: {
|
|
label: 'Autenticazione Airtime',
|
|
required: false,
|
|
},
|
|
imagePath: {
|
|
label: 'Percorso immagine',
|
|
required: false,
|
|
},
|
|
hasAutoplaylist: {
|
|
label: 'Ha playlist automatica',
|
|
required: false,
|
|
},
|
|
autoplaylistRepeat: {
|
|
label: 'Ripeti playlist automatica',
|
|
required: false,
|
|
},
|
|
showDjs: {
|
|
label: 'DJs',
|
|
required: false
|
|
}
|
|
};
|
|
|
|
export const showForm = (item: Show) => {
|
|
const fields = {};
|
|
Object.keys(fieldDefinitions).forEach((key) => {
|
|
fields[key] = {
|
|
label: fieldDefinitions[key].label,
|
|
value: item !== null ? item[key as keyof Show] : '',
|
|
required: fieldDefinitions[key].required,
|
|
component: null // Placeholder, will be set in the switch case
|
|
};
|
|
|
|
switch (key) {
|
|
case 'name':
|
|
case 'url':
|
|
case 'genre':
|
|
fields[key].component = VTextField;
|
|
break;
|
|
case 'description':
|
|
fields[key].component = VTextarea;
|
|
break;
|
|
case 'backgroundColor':
|
|
fields[key].component = ColorPickerButton;
|
|
break;
|
|
case 'liveStreamUsingAirtimeAuth':
|
|
fields[key].component = CheckBoxConditional;
|
|
fields[key].value = {
|
|
value: item !== null ? item.liveStreamUsingAirtimeAuth : false,
|
|
};
|
|
fields[key].props = {
|
|
checkBoxForm: {
|
|
checkBoxField: { label: fields[key].label },
|
|
fields: {
|
|
liveStreamUser: {
|
|
label: 'Utente streaming',
|
|
component: VTextField,
|
|
value: item !== null ? item.liveStreamUser : '',
|
|
disabled: true
|
|
},
|
|
liveStreamPass: {
|
|
label: 'Password di streaming',
|
|
component: VTextField,
|
|
value: item !== null ? item.liveStreamPass : '',
|
|
disabled: true
|
|
},
|
|
}
|
|
}
|
|
};
|
|
break;
|
|
case 'imagePath':
|
|
fields[key].component = VFileInput;
|
|
fields[key].props = { type: 'file' };
|
|
break;
|
|
case 'hasAutoplaylist':
|
|
fields[key].component = CheckBoxConditional;
|
|
fields[key].value = {
|
|
value: item !== null ? item.hasAutoplaylist : false,
|
|
};
|
|
fields[key].props = {
|
|
checkBoxForm: {
|
|
checkBoxField: { label: fields[key].label },
|
|
fields: {
|
|
liveStreamUser: {
|
|
label: 'Ripetere playlist?',
|
|
component: VCheckbox,
|
|
value: item.autoplaylistRepeat,
|
|
disabled: true
|
|
},
|
|
playlistId: {
|
|
label: 'Playlist',
|
|
component: PlaylistSelect,
|
|
value: item.autoplaylistId,
|
|
disabled: true
|
|
},
|
|
}
|
|
}
|
|
};
|
|
break;
|
|
case 'DJs':
|
|
fields[key].component = CheckBoxConditional;
|
|
fields[key].value = {
|
|
value: item.showDjs
|
|
};
|
|
}
|
|
});
|
|
return fields;
|
|
};
|
|
|
|
export const showTableHeader = [
|
|
{title: 'Nome', value: 'name'},
|
|
{title: 'dj', value: 'dj'},
|
|
{title: 'Durata', value: 'length'},
|
|
{title: 'Schedulata', value: 'scheduled'},
|
|
{title: 'Azioni', value: 'actions'}
|
|
]
|
|
|
|
export const getShow = async (options: {
|
|
id?: number | null;
|
|
scheduled?: number | null;
|
|
withDjs?: boolean | null;
|
|
isScheduled?: boolean | null;
|
|
page?: Number | null;
|
|
per_page?: Number | null;
|
|
all?: string | null;
|
|
}): Promise<Show[]> => {
|
|
const filteredParams = Object.fromEntries(
|
|
Object.entries(options).filter(([_, value]) => value !== undefined && value !== null)
|
|
);
|
|
return await axios.get(`/show`, {params: filteredParams})
|
|
.then((response: AxiosResponse) => {
|
|
|
|
return response.data
|
|
}).catch((error: Error) => {
|
|
console.log("Error: " + error);
|
|
})
|
|
}
|
|
|
|
export const deleteShow = async (showIds: Number[]) => {
|
|
return axios.delete(`show`, {data: {'showIds': showIds}})
|
|
}
|
|
|