diff --git a/resources/js/composables/content/models/playlist.ts b/resources/js/composables/content/models/playlist.ts index 7c22d1c..ff7d477 100644 --- a/resources/js/composables/content/models/playlist.ts +++ b/resources/js/composables/content/models/playlist.ts @@ -1,6 +1,7 @@ import {VTextarea, VTextField} from "vuetify/components"; import axios, {type AxiosResponse} from "axios"; import type {Show} from "@models/show/show.ts"; +import {cleanOptions} from "@/helpers/AxiosHelper.ts"; export function playlist(item) { const visibleFields = { @@ -48,9 +49,7 @@ export const getPlaylist = async (options: { per_page?: Number | null; all?: string | null; }): Promise => { - const filteredParams = Object.fromEntries( - Object.entries(options).filter(([_, value]) => value !== undefined && value !== null) - ); + const filteredParams = cleanOptions(options); return await axios.get(`/playlist`, {params: filteredParams}) .then((response: AxiosResponse) => { return response.data.data diff --git a/resources/js/composables/content/models/show/show.ts b/resources/js/composables/content/models/show/show.ts index d65261e..20583b7 100644 --- a/resources/js/composables/content/models/show/show.ts +++ b/resources/js/composables/content/models/show/show.ts @@ -2,6 +2,7 @@ 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 {cleanOptions} from "@/helpers/AxiosHelper.ts"; export interface Show { id?: number; @@ -66,9 +67,7 @@ export const getShow = async (options: { per_page?: Number | null; all?: string | null; }): Promise => { - const filteredParams = Object.fromEntries( - Object.entries(options).filter(([_, value]) => value !== undefined && value !== null) - ); + const filteredParams = cleanOptions(options); return await axios.get(`/show`, {params: filteredParams}) .then((response: AxiosResponse) => { return response.data diff --git a/resources/js/composables/content/models/show/showInstance.ts b/resources/js/composables/content/models/show/showInstance.ts index 62248ce..105b021 100644 --- a/resources/js/composables/content/models/show/showInstance.ts +++ b/resources/js/composables/content/models/show/showInstance.ts @@ -1,22 +1,24 @@ import {VDatePicker, VSelect, VTextField} from "vuetify/components"; import type {Show} from "@models/show/show"; import axios, {type AxiosResponse} from "axios"; +import {cleanOptions} from "@/helpers/AxiosHelper.ts"; export interface ShowInstance { id?: number; - starts: string; // ISO datetime string - ends: string; // ISO datetime string + starts: string; + ends: string; + instance_description: '', showId: number; - record: number; // 0|1 or similar - rebroadcast: number; // 0|1 or similar - timeFilled: string; // Duration format (HH:MM:SS) - created?: string; // ISO datetime string (optional) + record: number; + rebroadcast: number; + timeFilled: string; + created?: string; modifiedInstance: boolean; autoplaylistBuilt: boolean; // Relationships - Playlist?: any; // Assuming File interface exists - show?: Show; // Reference to Show interface + Playlist?: any; + show?: Show; } export const baseShowInstance = (): ShowInstance => { @@ -24,6 +26,7 @@ export const baseShowInstance = (): ShowInstance => { id: null, starts: '', ends: '', + instance_description: '', showId: 0, record: 0, rebroadcast: 0, @@ -34,56 +37,13 @@ export const baseShowInstance = (): ShowInstance => { }; }; - -export function showInstancesForm(item: ShowInstance) { - const visibleFields = { - starts: 'Inizio', - ends: 'Fine', - description: 'Descrizione', - }; - - return () => { - const fields = {}; - Object.keys(visibleFields).forEach((key) => { - fields[key] = { - label: visibleFields[key], - value: item[key as keyof ShowInstance], - component: VTextField, - disabled: false - }; - - switch (key) { - case 'starts': - case 'ends': - fields[key].component = VDatePicker; - fields[key].props = { - type: 'datetime-local', - step: 300 // 5-minute increments - }; - break; - case 'description': - fields[key].component = VSelect; - fields[key].props = { - type: 'datetime-local', - step: 300 // 5-minute increments - }; - break; - } - }); - - return fields; - }; -} - export async function getShowInstances(options: { showId?: number | null; starts?: string | null; ends?: string | null; withShow?: boolean | null; }): Promise { - const filteredParams = Object.fromEntries( - Object.entries(options).filter(([_, value]) => value !== undefined && value !== null) - ); + const filteredParams = cleanOptions(options); return await axios.get(`/showInstances`, { params: filteredParams }).then((response: AxiosResponse) => { return response.data @@ -96,3 +56,15 @@ export const deleteShowInstance = async (showInstancesIds: Number[]) => { return axios.delete(`showInstances`, {data: {'showInstancesIds': showInstancesIds}}) } +export async function getShowInstance(options: { + showInstanceId?: number | null; + withShow?: boolean | null; +}): Promise { + const filteredParams = cleanOptions(options); + + return await axios.get(`/showInstances`, { params: filteredParams }).then((response: AxiosResponse) => { + return response.data + }).catch((error: Error) => { + console.log("Error: " + error); + }); +} \ No newline at end of file diff --git a/resources/js/helpers/AxiosHelper.ts b/resources/js/helpers/AxiosHelper.ts new file mode 100644 index 0000000..da3c385 --- /dev/null +++ b/resources/js/helpers/AxiosHelper.ts @@ -0,0 +1,5 @@ +export function cleanOptions(options: Object): Object { + return Object.fromEntries( + Object.entries(options).filter(([_, value]) => value !== undefined && value !== null) + ); +} \ No newline at end of file