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 {VTextarea, VTextField} from "vuetify/components";
|
||||||
import axios, {type AxiosResponse} from "axios";
|
import axios, {type AxiosResponse} from "axios";
|
||||||
import type {Show} from "@models/show/show.ts";
|
import type {Show} from "@models/show/show.ts";
|
||||||
|
import {cleanOptions} from "@/helpers/AxiosHelper.ts";
|
||||||
|
|
||||||
export function playlist(item) {
|
export function playlist(item) {
|
||||||
const visibleFields = {
|
const visibleFields = {
|
||||||
|
@ -48,9 +49,7 @@ export const getPlaylist = async (options: {
|
||||||
per_page?: Number | null;
|
per_page?: Number | null;
|
||||||
all?: string | null;
|
all?: string | null;
|
||||||
}): Promise<Show[]> => {
|
}): Promise<Show[]> => {
|
||||||
const filteredParams = Object.fromEntries(
|
const filteredParams = cleanOptions(options);
|
||||||
Object.entries(options).filter(([_, value]) => value !== undefined && value !== null)
|
|
||||||
);
|
|
||||||
return await axios.get(`/playlist`, {params: filteredParams})
|
return await axios.get(`/playlist`, {params: filteredParams})
|
||||||
.then((response: AxiosResponse) => {
|
.then((response: AxiosResponse) => {
|
||||||
return response.data.data
|
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 {ShowDays} from "@models/show/showDays";
|
||||||
import type {ShowDjs} from "@models/show/showDjs";
|
import type {ShowDjs} from "@models/show/showDjs";
|
||||||
import axios, {type AxiosResponse} from "axios";
|
import axios, {type AxiosResponse} from "axios";
|
||||||
|
import {cleanOptions} from "@/helpers/AxiosHelper.ts";
|
||||||
|
|
||||||
export interface Show {
|
export interface Show {
|
||||||
id?: number;
|
id?: number;
|
||||||
|
@ -66,9 +67,7 @@ export const getShow = async (options: {
|
||||||
per_page?: Number | null;
|
per_page?: Number | null;
|
||||||
all?: string | null;
|
all?: string | null;
|
||||||
}): Promise<Show[]> => {
|
}): Promise<Show[]> => {
|
||||||
const filteredParams = Object.fromEntries(
|
const filteredParams = cleanOptions(options);
|
||||||
Object.entries(options).filter(([_, value]) => value !== undefined && value !== null)
|
|
||||||
);
|
|
||||||
return await axios.get(`/show`, {params: filteredParams})
|
return await axios.get(`/show`, {params: filteredParams})
|
||||||
.then((response: AxiosResponse) => {
|
.then((response: AxiosResponse) => {
|
||||||
return response.data
|
return response.data
|
||||||
|
|
|
@ -1,22 +1,24 @@
|
||||||
import {VDatePicker, VSelect, VTextField} from "vuetify/components";
|
import {VDatePicker, VSelect, VTextField} from "vuetify/components";
|
||||||
import type {Show} from "@models/show/show";
|
import type {Show} from "@models/show/show";
|
||||||
import axios, {type AxiosResponse} from "axios";
|
import axios, {type AxiosResponse} from "axios";
|
||||||
|
import {cleanOptions} from "@/helpers/AxiosHelper.ts";
|
||||||
|
|
||||||
export interface ShowInstance {
|
export interface ShowInstance {
|
||||||
id?: number;
|
id?: number;
|
||||||
starts: string; // ISO datetime string
|
starts: string;
|
||||||
ends: string; // ISO datetime string
|
ends: string;
|
||||||
|
instance_description: '',
|
||||||
showId: number;
|
showId: number;
|
||||||
record: number; // 0|1 or similar
|
record: number;
|
||||||
rebroadcast: number; // 0|1 or similar
|
rebroadcast: number;
|
||||||
timeFilled: string; // Duration format (HH:MM:SS)
|
timeFilled: string;
|
||||||
created?: string; // ISO datetime string (optional)
|
created?: string;
|
||||||
modifiedInstance: boolean;
|
modifiedInstance: boolean;
|
||||||
autoplaylistBuilt: boolean;
|
autoplaylistBuilt: boolean;
|
||||||
|
|
||||||
// Relationships
|
// Relationships
|
||||||
Playlist?: any; // Assuming File interface exists
|
Playlist?: any;
|
||||||
show?: Show; // Reference to Show interface
|
show?: Show;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const baseShowInstance = (): ShowInstance => {
|
export const baseShowInstance = (): ShowInstance => {
|
||||||
|
@ -24,6 +26,7 @@ export const baseShowInstance = (): ShowInstance => {
|
||||||
id: null,
|
id: null,
|
||||||
starts: '',
|
starts: '',
|
||||||
ends: '',
|
ends: '',
|
||||||
|
instance_description: '',
|
||||||
showId: 0,
|
showId: 0,
|
||||||
record: 0,
|
record: 0,
|
||||||
rebroadcast: 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: {
|
export async function getShowInstances(options: {
|
||||||
showId?: number | null;
|
showId?: number | null;
|
||||||
starts?: string | null;
|
starts?: string | null;
|
||||||
ends?: string | null;
|
ends?: string | null;
|
||||||
withShow?: boolean | null;
|
withShow?: boolean | null;
|
||||||
}): Promise<ShowInstance[]> {
|
}): Promise<ShowInstance[]> {
|
||||||
const filteredParams = Object.fromEntries(
|
const filteredParams = cleanOptions(options);
|
||||||
Object.entries(options).filter(([_, value]) => value !== undefined && value !== null)
|
|
||||||
);
|
|
||||||
|
|
||||||
return await axios.get(`/showInstances`, { params: filteredParams }).then((response: AxiosResponse) => {
|
return await axios.get(`/showInstances`, { params: filteredParams }).then((response: AxiosResponse) => {
|
||||||
return response.data
|
return response.data
|
||||||
|
@ -96,3 +56,15 @@ export const deleteShowInstance = async (showInstancesIds: Number[]) => {
|
||||||
return axios.delete(`showInstances`, {data: {'showInstancesIds': showInstancesIds}})
|
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