fix(fe smartblock): refactored all code with stores and interfaces

This commit is contained in:
Marco Cavalli 2025-04-03 14:42:44 +02:00
parent 9e690dc0c9
commit fa96a43ba4
10 changed files with 738 additions and 261 deletions

View file

@ -1,7 +1,69 @@
import {VCheckbox, VSelect, VTextarea, VTextField} from "vuetify/components";
import RadioGroup from "@partials/fields/smartblock/RadioGroup.vue";
import SmartBlockCriteria from "@partials/fields/smartblock/SmartBlockCriteria.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 = {
@ -30,22 +92,6 @@ export function smartblock(item) {
criteria: {
title: 'Seleziona i criteri',
required: true
},
limit: {
title: 'Limite a',
required: true
},
repeat_tracks: {
title: 'Permetti al ripetizione delle tracce',
required: false
},
overflow_tracks: {
title: 'Permetti all\'ultima traccia di andare oltre il limite',
required: false
},
sort: {
title: 'Ordina per',
required: true
}
}
@ -71,40 +117,41 @@ export function smartblock(item) {
fields[key].radioButtons = visibleFields[key].radioButtons
break
case 'criteria':
fields[key].component = SmartBlockCriteria
break
case 'limit':
fields[key].component = SmartBlockLimit
break
case 'repeat_tracks':
case 'overflow_tracks':
fields[key].component = VCheckbox
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'
}
]
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)

View file

@ -0,0 +1,11 @@
export interface SmartBlockContent {
block_id: number; // ID del blocco associato
file_id: number; // ID del file associato
position: number; // Posizione del contenuto
trackoffset: number; // Offset della traccia
cliplength: number; // Lunghezza del clip
cuein: number; // Punto di inizio del cue
cueout: number; // Punto di fine del cue
fadein: number; // Durata del fade-in
fadeout: number; // Durata del fade-out
}

View file

@ -1,3 +1,129 @@
export interface SmartBlockCriteria {
criteria: string;
modifier: string;
value: string | number; // Può essere stringa o numero, a seconda del valore
extra?: string; // Opzionale, se presente
criteriagroup?: number;
block_id?: number; // Identificatore del blocco associato
}
export const baseSmartBlockCriteria = (): SmartBlockCriteria => {
return {
criteria: '',
modifier: '',
value: '',
extra: '',
criteriagroup: null,
block_id: 0
}
}
export const genericSmartBlockCriteriaList = [
{
type: 'string',
title: 'Nome dell\'Album',
value: 'album_title'
},
{
type: 'string',
title: 'Nome dell\'Artista',
value: 'artist_name'
},
{
type: 'number',
title: 'Bit Rate (kbps)',
value: 'bit_rate'
},
{
type: 'number',
title: 'BPM',
value: 'bpm'
},
{
type: 'string',
title: 'Genere',
value: 'genre'
},
{
type: 'TrackType',
title: 'Tipo di traccia',
value: 'track_type_id'
}
]
export const genericSmartBlockCriteriaModifiersList = [
{
value: 'contains',
title: 'contiene',
type: 'string'
},
{
value: 'does not contain',
title: 'non contiene',
type: 'string'
},
{
value: 'starts with',
title: 'comincia con',
type: 'string'
},
{
value: 'ends with',
title: 'finisce con',
type: 'string'
},
{
value: 'is greater than',
title: 'è maggiore di',
type: 'number'
},
{
value: 'is less than',
title: 'è minore di',
type: 'number'
},
{
value: 'is in the range',
title: 'è tra',
type: 'number'
},
{
value: 'is',
title: 'è uguale a',
type: 'all'
},
{
value: 'is not',
title: 'è diverso da',
type: 'all'
},
]
export const smartBlockCriteriaSortList = [
{
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'
}
]
export function smartblockCriteria() {
const criteria = [ {
type: 'string',
@ -39,7 +165,7 @@ export function smartblockCriteria() {
type: 'string'
},
{
value: 'does not contains',
value: 'does not contain',
title: 'non contiene',
type: 'string'
},