88} from "@angular/core" ;
99import { CommonModule } from "@angular/common" ;
1010import { FormsModule } from "@angular/forms" ;
11- import { GalleryService , GALLERY_CATEGORIES , GalleryCategories } from "@entities/gallery" ;
11+ import { GalleryService , GalleryCategories } from "@entities/gallery" ;
12+ import { AdminSettingsService } from "@entities/admin-settings" ;
1213import { Gallery , ImageCategory } from "@shared/models" ;
1314import { GalleryFormComponent } from "./ui/gallery-form/gallery-form.component" ;
1415import { ImagePopupComponent , ListViewComponent , ListViewColumn , CardViewComponent , CardViewConfig } from "@shared/ui" ;
@@ -26,6 +27,7 @@ import { environment } from "@environments/environment";
2627} )
2728export class GalleryComponent implements OnInit {
2829 private galleryService = inject ( GalleryService ) ;
30+ private adminSettingsService = inject ( AdminSettingsService ) ;
2931 env = signal ( environment ) ;
3032
3133 isDragging = signal ( false ) ;
@@ -35,7 +37,14 @@ export class GalleryComponent implements OnInit {
3537
3638 images = this . galleryService . images ;
3739
38- filters = signal < ImageCategory [ ] > ( GALLERY_CATEGORIES ) ;
40+ // Dynamic categories from admin settings.
41+ // Falls back to ['all'] if settings not loaded yet.
42+ filters = computed < ImageCategory [ ] > ( ( ) => {
43+ const settings = this . adminSettingsService . settings ( ) ;
44+ const cats = settings ?. galleryCategories ?? [ ] ;
45+ return [ 'all' , ...cats ] as ImageCategory [ ] ;
46+ } ) ;
47+
3948 activeFilter = signal < ImageCategory > ( GalleryCategories . ALL ) ;
4049
4150 columns = signal < ListViewColumn [ ] > ( [
@@ -69,15 +78,20 @@ export class GalleryComponent implements OnInit {
6978 currentImage ! : Gallery ;
7079
7180 ngOnInit ( ) {
81+ // Load settings if not yet cached
82+ if ( ! this . adminSettingsService . settings ( ) ) {
83+ this . adminSettingsService . getSettings ( ) . subscribe ( ) ;
84+ }
7285 this . galleryService . getImages ( ) . subscribe ( ) ;
7386 }
7487
7588 getEmptyImage ( ) : Gallery {
89+ const firstCat = this . filters ( ) . find ( f => f !== 'all' ) ?? GalleryCategories . ALL ;
7690 return {
7791 id : "" ,
7892 imageUrl : "" ,
7993 title : "" ,
80- category : GalleryCategories . VISAGE , // Default
94+ category : firstCat ,
8195 status : "draft" ,
8296 alt : "" ,
8397 } ;
@@ -89,7 +103,7 @@ export class GalleryComponent implements OnInit {
89103 }
90104
91105 openModal ( image : Gallery ) {
92- this . currentImage = { ...image } ; // Create a copy for editing
106+ this . currentImage = { ...image } ;
93107 this . isModalOpen . set ( true ) ;
94108 }
95109
@@ -104,12 +118,10 @@ export class GalleryComponent implements OnInit {
104118 const formData = excludeFormDataProperties ( convertFormData ( ...args ) , [ "id" , "createdAt" , "updatedAt" ] ) ;
105119
106120 if ( ! image . id ) {
107- // New image
108121 this . galleryService . createImage ( formData ) . subscribe ( ( ) => {
109122 this . closeModal ( ) ;
110123 } ) ;
111124 } else {
112- // Update existing
113125 this . galleryService
114126 . updateImage ( image . id , formData )
115127 . subscribe ( ( ) => {
@@ -150,7 +162,6 @@ export class GalleryComponent implements OnInit {
150162 const files = event . dataTransfer ?. files ;
151163 if ( files && files . length > 0 ) {
152164 console . log ( `${ files . length } files dropped` ) ;
153- // Here you would handle the file upload logic
154165 }
155166 }
156167}
0 commit comments