From a4e1a3328fd9e4d8408366a543ab83e5bd6f79f8 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 11 Jul 2025 15:03:59 +0200 Subject: [PATCH] feat: spots --- app/Filters/FileFilters.php | 1 + app/Http/Controllers/FileController.php | 16 +++++++--- app/Http/Controllers/PlaylistController.php | 30 ++++++++++------- app/Http/Controllers/SmartBlockController.php | 14 ++++++-- resources/js/components/content/Playlist.vue | 17 +++------- resources/js/components/content/Show.vue | 27 ++++------------ .../js/components/content/SmartBlock.vue | 23 +++++++------ .../content/partials/SmartBlockEditor.vue | 29 +++++++++++++---- .../components/content/partials/Sources.vue | 12 ++++++- .../content/partials/show/ShowForm.vue | 4 +-- .../js/composables/content/archive_page.ts | 14 +++++--- .../js/composables/content/models/playlist.ts | 1 + .../content/models/playlist/playlist.ts | 2 +- .../content/models/smartblock/smartblock.ts | 3 +- .../js/composables/content/playlist_page.ts | 3 ++ .../js/composables/content/show/show_page.ts | 12 ++++--- .../js/composables/content/smartblock_page.ts | 5 ++- resources/js/layouts/partials/Content.vue | 22 +++++++------ resources/js/stores/playlist.store.ts | 2 +- resources/js/stores/showType.store.ts | 32 +++++++++++++++++++ 20 files changed, 172 insertions(+), 97 deletions(-) create mode 100644 resources/js/stores/showType.store.ts diff --git a/app/Filters/FileFilters.php b/app/Filters/FileFilters.php index 97dd1dc..aa5ddf5 100644 --- a/app/Filters/FileFilters.php +++ b/app/Filters/FileFilters.php @@ -3,6 +3,7 @@ namespace App\Filters; use App\Filters\FiltersType\AllFilter; +use App\Filters\FiltersType\IsFilter; use App\Filters\FiltersType\LikeFilter; class FileFilters diff --git a/app/Http/Controllers/FileController.php b/app/Http/Controllers/FileController.php index 904d981..5b348df 100644 --- a/app/Http/Controllers/FileController.php +++ b/app/Http/Controllers/FileController.php @@ -27,11 +27,17 @@ class FileController extends Controller $pagination = $request->per_page; } - return File::searchFilter($request) - ->where('import_status', '=', 0) - ->with('track_type') - ->with('owner') - ->orderBy('artist_name') + $files = File::searchFilter($request) + ->where('import_status', '=', 0) + ->with('track_type') + ->with('owner'); + + if($request->track_type == 'spot'){ + $trackTypes = TrackType::where('code', '=', 'SPOT')->orWhere('parent_id', '=', '3')->pluck('id'); + $files = $files->whereIn('track_type_id', $trackTypes->toArray()); + } + + return $files->orderBy('artist_name') ->paginate($pagination) ->toJson(); } diff --git a/app/Http/Controllers/PlaylistController.php b/app/Http/Controllers/PlaylistController.php index 084eb2e..e843193 100644 --- a/app/Http/Controllers/PlaylistController.php +++ b/app/Http/Controllers/PlaylistController.php @@ -31,17 +31,25 @@ class PlaylistController extends Controller $pagination = $request->per_page; } - return Playlist::searchFilter($request) - ->with( - [ - 'creator', - 'tracks.file', - 'tracks.block', - 'tracks.block.criteria', - 'tracks.block.creator' - ] - ) - ->orderBy('name') + $playlists = Playlist::searchFilter($request) + ->with( + [ + 'creator', + 'tracks.file', + 'tracks.block', + 'tracks.block.criteria', + 'tracks.block.creator' + ] + ); + + if($request->has('playlistType')) { + $playlistType = $request->get('playlistType'); + $playlists = ($playlistType == 'show') + ? $playlists->doesntHave('spotPlaylist') + : $playlists->has('spotPlaylist'); + } + + return $playlists->orderBy('name') ->paginate($pagination) ->toJson(); } catch (\Exception $e) { diff --git a/app/Http/Controllers/SmartBlockController.php b/app/Http/Controllers/SmartBlockController.php index c5cdd57..5b5ffea 100644 --- a/app/Http/Controllers/SmartBlockController.php +++ b/app/Http/Controllers/SmartBlockController.php @@ -30,11 +30,19 @@ class SmartBlockController extends Controller } else { $pagination = $request->per_page; } + $smartblocks = SmartBlock::searchFilter($request) + ->with(['creator', 'tracks', 'tracks.file', 'criteria']); - return SmartBlock::searchFilter($request) - ->with(['creator', 'tracks', 'tracks.file', 'criteria']) + if($request->has('smartblockType')) { + $smartblockType = $request->get('smartblockType'); + $smartblocks = ($smartblockType == 'show') + ? $smartblocks->doesntHave('spotSmartblock') + : $smartblocks->has('spotSmartblock'); + } + + return $smartblocks ->paginate($pagination) - ->toJson();show + ->toJson(); } /** diff --git a/resources/js/components/content/Playlist.vue b/resources/js/components/content/Playlist.vue index 6ef4de3..761a7f8 100644 --- a/resources/js/components/content/Playlist.vue +++ b/resources/js/components/content/Playlist.vue @@ -7,25 +7,16 @@ import {onBeforeMount, onMounted, type PropType, reactive, ref, watch} from "vue import {usePlaylistStore} from "@/stores/playlist.store.ts"; import {baseSmartBlock} from "@models/smartblock/smartblock.ts"; import {basePlaylist} from "@models/playlist/playlist.ts"; +import {useShowTypeStore} from "@stores/showType.store.ts"; const playlistStore = usePlaylistStore(); const { items, listData, headers, selected, loading, search, getItems, editItem, deleteItem } = playlist_page(); -// Props and data -const props = defineProps({ - showType: { - type: String as PropType<'spot' | null>, - required: false, - validator: (value: string) => ['spot'].includes(value), - default: null, - }, -}); - +// Props, data, stores const itemEdited = ref({ id: null }); - const bulk = ref(false) const dialog = reactive({ open: false, @@ -33,7 +24,9 @@ const dialog = reactive({ title: '', text: '' }) +const showTypeStore = useShowTypeStore(); +// Funcs const openDialog = (type, title = '', text = '', bulk = false) => { dialog.open = true dialog.type = type @@ -47,7 +40,7 @@ const edit = (item) => { item = basePlaylist(); } playlistStore.loadPlaylist(item); - playlistStore.currentPlaylist.playlist_type = props.showType; + playlistStore.currentPlaylist.playlist_type = showTypeStore.currentType; itemEdited.value = item; } diff --git a/resources/js/components/content/Show.vue b/resources/js/components/content/Show.vue index 6c108c4..609d9dc 100644 --- a/resources/js/components/content/Show.vue +++ b/resources/js/components/content/Show.vue @@ -5,20 +5,11 @@ import ConfirmDelete from "@partials/dialogs/ConfirmDelete.vue"; import {show_page} from "@/composables/content/show/show_page.ts"; import ShowForm from "@partials/show/ShowForm.vue"; import {baseShow, type Show} from "@models/show/show"; +import {useShowTypeStore} from "@stores/showType.store.ts"; -const {items, listData, headers, selected, loading, search, showType, getItems, editItem, deleteItem} = show_page() - -// Props and data - -const props = defineProps({ - showType: { - type: String as PropType<'show' | 'spot' | null>, - required: true, - validator: (value: string) => ['show', 'spot'].includes(value), - default: null, - }, -}); +const {items, listData, headers, selected, loading, search, getItems, editItem, deleteItem} = show_page() +const showTypeStore = useShowTypeStore(); const showCreateEditMode = ref(false); let showSelected = ref(null); @@ -58,8 +49,8 @@ const saveItem = (item) => { } const cancel = (item) => { - let deleteMessage = `Vuoi cancellare lo ${props.showType} selezionato?` - if (bulk.value.state) deleteMessage = `Vuoi cancellare gli ${props.showType} selezionati?` + let deleteMessage = `Vuoi cancellare lo ${showTypeStore.currentType} selezionato?` + if (bulk.value.state) deleteMessage = `Vuoi cancellare gli ${showTypeStore.currentType} selezionati?` bulk.value.items = item showSelected.value = item?.id openDialog( @@ -95,10 +86,6 @@ const goBack = () => { showSelected.value = null } -onBeforeMount(() => { - showType.value = props.showType -}) - watch(search, (newValue, oldValue) => { const options = {...listData}; getItems(options) @@ -106,7 +93,7 @@ watch(search, (newValue, oldValue) => {