1- import { Component , Input , OnInit , TemplateRef , ViewChild } from '@angular/core' ;
1+ import {
2+ Component ,
3+ EventEmitter ,
4+ Input ,
5+ OnInit ,
6+ Output ,
7+ TemplateRef ,
8+ ViewChild
9+ } from '@angular/core' ;
210import { BehaviorSubject , Observable , of } from 'rxjs' ;
311import { RgwBucketService } from '~/app/shared/api/rgw-bucket.service' ;
412import { ActionLabelsI18n } from '~/app/shared/constants/app.constants' ;
@@ -11,10 +19,16 @@ import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
1119import { URLBuilderService } from '~/app/shared/services/url-builder.service' ;
1220import { Bucket } from '../models/rgw-bucket' ;
1321import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context' ;
22+ import { CellTemplate } from '~/app/shared/enum/cell-template.enum' ;
1423import { catchError , switchMap } from 'rxjs/operators' ;
15- import { TopicConfiguration } from '~/app/shared/models/notification-configuration.model' ;
24+ import { ModalCdsService } from '~/app/shared/services/modal-cds.service' ;
25+ import { NotificationService } from '~/app/shared/services/notification.service' ;
1626import { ListWithDetails } from '~/app/shared/classes/list-with-details.class' ;
17- import { CellTemplate } from '~/app/shared/enum/cell-template.enum' ;
27+ import { TopicConfiguration } from '~/app/shared/models/notification-configuration.model' ;
28+ import { RgwNotificationFormComponent } from '../rgw-notification-form/rgw-notification-form.component' ;
29+ import { DeleteConfirmationModalComponent } from '~/app/shared/components/delete-confirmation-modal/delete-confirmation-modal.component' ;
30+ import { NotificationType } from '~/app/shared/enum/notification-type.enum' ;
31+ import { Icons } from '~/app/shared/enum/icons.enum' ;
1832
1933const BASE_URL = 'rgw/bucket' ;
2034@Component ( {
@@ -25,6 +39,8 @@ const BASE_URL = 'rgw/bucket';
2539} )
2640export class RgwBucketNotificationListComponent extends ListWithDetails implements OnInit {
2741 @Input ( ) bucket : Bucket ;
42+ @Output ( ) updateBucketDetails = new EventEmitter ( ) ;
43+ @ViewChild ( TableComponent , { static : true } )
2844 table : TableComponent ;
2945 permission : Permission ;
3046 tableActions : CdTableAction [ ] ;
@@ -37,11 +53,13 @@ export class RgwBucketNotificationListComponent extends ListWithDetails implemen
3753 filterTpl : TemplateRef < any > ;
3854 @ViewChild ( 'eventTpl' , { static : true } )
3955 eventTpl : TemplateRef < any > ;
40-
56+ modalRef : any ;
4157 constructor (
4258 private rgwBucketService : RgwBucketService ,
4359 private authStorageService : AuthStorageService ,
44- public actionLabels : ActionLabelsI18n
60+ public actionLabels : ActionLabelsI18n ,
61+ private modalService : ModalCdsService ,
62+ private notificationService : NotificationService
4563 ) {
4664 super ( ) ;
4765 }
@@ -74,6 +92,28 @@ export class RgwBucketNotificationListComponent extends ListWithDetails implemen
7492 }
7593 ] ;
7694
95+ const createAction : CdTableAction = {
96+ permission : 'create' ,
97+ icon : Icons . add ,
98+ click : ( ) => this . openNotificationModal ( this . actionLabels . CREATE ) ,
99+ name : this . actionLabels . CREATE
100+ } ;
101+ const editAction : CdTableAction = {
102+ permission : 'update' ,
103+ icon : Icons . edit ,
104+ disable : ( ) => this . selection . hasMultiSelection ,
105+ click : ( ) => this . openNotificationModal ( this . actionLabels . EDIT ) ,
106+ name : this . actionLabels . EDIT
107+ } ;
108+ const deleteAction : CdTableAction = {
109+ permission : 'delete' ,
110+ icon : Icons . destroy ,
111+ click : ( ) => this . deleteAction ( ) ,
112+ disable : ( ) => ! this . selection . hasSelection ,
113+ name : this . actionLabels . DELETE ,
114+ canBePrimary : ( selection : CdTableSelection ) => selection . hasMultiSelection
115+ } ;
116+ this . tableActions = [ createAction , editAction , deleteAction ] ;
77117 this . notification$ = this . subject . pipe (
78118 switchMap ( ( ) =>
79119 this . rgwBucketService . listNotification ( this . bucket . bucket ) . pipe (
@@ -89,4 +129,48 @@ export class RgwBucketNotificationListComponent extends ListWithDetails implemen
89129 fetchData ( ) {
90130 this . subject . next ( [ ] ) ;
91131 }
132+
133+ openNotificationModal ( type : string ) {
134+ const modalRef = this . modalService . show ( RgwNotificationFormComponent , {
135+ bucket : this . bucket ,
136+ selectedNotification : this . selection . first ( ) ,
137+ editing : type === this . actionLabels . EDIT ? true : false
138+ } ) ;
139+ modalRef ?. close ?. subscribe ( ( ) => this . updateBucketDetails . emit ( ) ) ;
140+ }
141+
142+ updateSelection ( selection : CdTableSelection ) {
143+ this . selection = selection ;
144+ }
145+
146+ deleteAction ( ) {
147+ const selectedNotificationId = this . selection . selected . map ( ( notification ) => notification . Id ) ;
148+ this . modalRef = this . modalService . show ( DeleteConfirmationModalComponent , {
149+ itemDescription : $localize `Notification` ,
150+ itemNames : selectedNotificationId ,
151+ actionDescription : $localize `delete` ,
152+ submitAction : ( ) => this . submitDeleteNotifications ( selectedNotificationId )
153+ } ) ;
154+ }
155+
156+ submitDeleteNotifications ( notificationId : string [ ] ) {
157+ this . rgwBucketService
158+ . deleteNotification ( this . bucket . bucket , notificationId . join ( ',' ) )
159+ . subscribe ( {
160+ next : ( ) => {
161+ this . notificationService . show (
162+ NotificationType . success ,
163+ $localize `Notifications deleted successfully.`
164+ ) ;
165+ this . modalService . dismissAll ( ) ;
166+ } ,
167+ error : ( ) => {
168+ this . notificationService . show (
169+ NotificationType . success ,
170+ $localize `Failed to delete notifications. Please try again.`
171+ ) ;
172+ }
173+ } ) ;
174+ this . modalRef ?. close ?. subscribe ( ( ) => this . updateBucketDetails . emit ( ) ) ;
175+ }
92176}
0 commit comments