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

160 lines
No EOL
5.4 KiB
TypeScript

import {VCheckbox, VSelect, VTextarea, VTextField} from "vuetify/components";
import RadioGroup from "@partials/fields/smartblock/RadioGroup.vue";
import SmartBlockLimit from "@partials/fields/smartblock/SmartBlockLimit.vue";
import SmartBlockCriteriaFieldGroup from "@partials/fields/smartblock/SmartBlockCriteriaFieldGroup.vue";
import type {SmartBlockContent} from "@models/smartblock/smartblockContent.ts";
import type {SmartBlockCriteria} from "@models/smartblock/smartblockCriteria.ts";
import {cleanOptions} from "@/helpers/AxiosHelper.ts";
import axios, {type AxiosResponse} from "axios";
export interface SmartBlock {
id?: number; // ID del blocco (opzionale)
name: string; // Nome del blocco
creator_id: number; // ID del creatore
description?: string; // Descrizione del blocco (opzionale)
length: number; // Lunghezza del blocco
type: string; // Tipo del blocco
contents?: SmartBlockContent[]; // Contenuti associati (opzionale)
criteria?: SmartBlockCriteria[]; // Criteri associati (opzionale)
tracks?: SmartBlockContent[];
}
export const baseSmartBlock = (): SmartBlock => {
return {
id: 0,
name: '',
creator_id: 0,
description: '',
length: 0,
type: 'dynamic',
contents: null,
criteria: [],
tracks: [],
}
}
export const SmartBlockTableHeader = [
{title: 'Nome', value: 'name'},
{title: 'Creato da', value: 'creator.login'},
{title: 'Durata', value: 'visible_length'},
{title: 'Ultima modifica', value: 'utime'},
{title: 'Azioni', value: 'actions'}
];
export const getSmartBlock = async (options: {
id?: number | null;
page?: Number | null;
per_page?: Number | null;
all?: string | null;
}): Promise<SmartBlock[]> => {
const filteredParams = cleanOptions(options);
return await axios.get(`/smartblock`, {params: filteredParams})
.then((response: AxiosResponse) => {
return response.data
}).catch((error: Error) => {
console.log("Error: " + error);
})
}
export const deleteSmartBlock = async (smartblockIds: Number[]) => {
return axios.delete(`smartblock`, {
data: {
_method: 'DELETE',
'smartblockIds': smartblockIds
}
})
}
export function smartblock(item) {
const visibleFields = {
name: {
title: 'Nome',
required: true,
},
description: {
title: 'Descrizione',
required: false
},
type: {
title: 'Tipologia blocco',
required: true,
radioButtons: [
{
label: 'Dinamico',
value: 'dynamic'
},
{
label: 'Statico',
value: 'static'
}
]
},
criteria: {
title: 'Seleziona i criteri',
required: true
}
}
return () => {
const fields = {}
Object.keys(visibleFields).forEach((key) => {
fields[key] = {
label: visibleFields[key].title,
value: item !== null ? item[key] : '',
required: visibleFields[key].required,
component: VTextField
}
// console.log(fields)
switch (key) {
case 'name':
fields[key].component = VTextField
break
case 'description':
fields[key].component = VTextarea
break
case 'type':
fields[key].component = RadioGroup
fields[key].radioButtons = visibleFields[key].radioButtons
break
case 'criteria':
fields[key].component = SmartBlockCriteriaFieldGroup
break
// case 'limit':
// fields[key].component = SmartBlockLimit
// break
// case 'repeat_tracks':
// case 'overflow_tracks':
// fields[key].component = VCheckbox
// fields[key].type = 'checkbox'
// break
// case 'sort':
// fields[key].component = VSelect
// fields[key].items = [
// {
// title: 'Random',
// value: 'random'
// },
// {
// title: 'Dal più recente',
// value: 'newest'
// },
// {
// title: 'Dal meno recente',
// value: 'oldest'
// },
// {
// title: 'Più recentemente andate in onda',
// value: 'mostrecentplay'
// },
// {
// title: 'Meno recentemente andate in onda',
// value: 'leastrecentplay'
// }
// ]
// break
}
})
// console.log(fields)
return fields
}
}