feat(FE): axios helper func
This commit is contained in:
parent
50a8497bf4
commit
bba0f09389
4 changed files with 33 additions and 58 deletions
|
@ -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<Show[]> => {
|
||||
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
|
||||
|
|
|
@ -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<Show[]> => {
|
||||
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
|
||||
|
|
|
@ -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<ShowInstance[]> {
|
||||
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<ShowInstance[]> {
|
||||
const filteredParams = cleanOptions(options);
|
||||
|
||||
return await axios.get(`/showInstances`, { params: filteredParams }).then((response: AxiosResponse) => {
|
||||
return response.data
|
||||
}).catch((error: Error) => {
|
||||
console.log("Error: " + error);
|
||||
});
|
||||
}
|
5
resources/js/helpers/AxiosHelper.ts
Normal file
5
resources/js/helpers/AxiosHelper.ts
Normal file
|
@ -0,0 +1,5 @@
|
|||
export function cleanOptions(options: Object): Object {
|
||||
return Object.fromEntries(
|
||||
Object.entries(options).filter(([_, value]) => value !== undefined && value !== null)
|
||||
);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue