sintonia_webapp/resources/js/composables/content/models/show/show.ts

169 lines
4.8 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 type {
AutocompleteFieldConfig,
CheckboxFieldConfig,
CheckBoxConditionalType,
ColorPickerFieldConfig,
FieldDefinition,
FieldDefinitions, FileFieldConfig,
TextareaConfig,
TextFieldConfig
} from "@models/misc/FormInterface.ts";
import {markRaw} from "vue";
import {VCheckbox, VColorPicker, VSelect, VFileInput, VTextarea, VTextField} from "vuetify/components";
import ColorPickerButton from "@partials/fields/misc/ColorPickerButton.vue";
import CheckBoxConditional from "@partials/fields/misc/CheckBoxConditional.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,
autoplaylistRepeat: false,
}
}
const fieldDefinitions: FieldDefinitions = {
name: {
label: 'Nome',
component: VTextField,
disabled: false
} as TextFieldConfig,
url: {
label: 'URL',
component: VTextField,
disabled: false
} as TextFieldConfig,
genre: {
label: 'Genere',
component: VTextField,
disabled: false
} as TextFieldConfig,
description: {
label: 'Descrizione',
component: VTextarea,
disabled: false
} as TextareaConfig,
backgroundColor: {
label: 'Colore di sfondo',
component: ColorPickerButton,
disabled: false,
} as ColorPickerFieldConfig,
liveStreamUsingAirtimeAuth: {
component: CheckBoxConditional,
props: {
checkBoxForm: {
checkBoxField: {label: 'Autenticazione Airtime'},
fields: {
liveStreamUser: {
label: 'Utente streaming',
component: VTextField,
disabled: true
} as TextFieldConfig,
liveStreamPass: {
label: 'Password di streaming',
component: VTextField,
disabled: true
} as TextFieldConfig,
}
}
}
}, // TODO Add the ts interface
imagePath: {
label: 'Percorso immagine',
component: VFileInput,
props: {type: 'file'},
disabled: false
} as FileFieldConfig,
hasAutoplaylist: {
label: 'Ha playlist automatica',
component: VCheckbox,
disabled: false
} as CheckboxFieldConfig,
autoplaylistRepeat: {
label: 'Ripeti playlist automatica',
component: VCheckbox,
disabled: false
} as CheckboxFieldConfig
};
export function showForm(item: Show) {
const fields = {};
Object.keys(fieldDefinitions).forEach((key) => {
fields[key] = {
...fieldDefinitions[key],
value: item[key as keyof Show]
};
});
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}})
}