import { Component , Injector , ViewEncapsulation , OnInit } from '@angular/core' ; import { appModuleAnimation } from '@shared/animations/routerTransition' ; import { NotificationServiceProxy , UserNotification , UserNotificationState } from '@shared/service-proxies/service-proxies' ; import { IFormattedUserNotification , UserNotificationHelper } from './UserNotificationHelper' ; import { PagedListingComponentBase , PagedRequestDto } from '@shared/common/paged-listing-component-base' ; import { finalize } from 'rxjs/operators' ; import { DateTimeService } from '@app/shared/common/timing/date-time.service' ; @ Component ( { templateUrl : './notifications.component.html' , styleUrls : [ ] , encapsulation : ViewEncapsulation . None , animations : [ appModuleAnimation ( ) ] } ) export class NotificationsComponent extends PagedListingComponentBase < any > implements OnInit { readStateFilter = 'ALL' ; dateRange : Date [ ] = [ this . _dateTimeService . getStartOfDay ( ) . toJSDate ( ) , this . _dateTimeService . getEndOfDay ( ) . toJSDate ( ) ] ; constructor ( injector , private _notificationService , private _userNotificationHelper , private _dateTimeService ) { super ( injector ) ; } onSearch ( ) { this . refresh ( ) ; } setAsRead ( record ) { this . setNotificationAsRead ( record , ( ) => { this . refresh ( ) ; } ) ; } isRead ( record ) { return record . formattedNotification . state === 'READ' ; } formatRecord ( record ) { return this . _userNotificationHelper . format ( record , false ) ; } formatNotification ( record ) { const formattedRecord = this . formatRecord ( record ) ; return abp . utils . truncateStringWithPostfix ( formattedRecord . text , 120 ) ; } formatNotifications ( records ) { const formattedRecords = [ ] ; for ( const record of records ) { record . formattedNotification = this . formatRecord ( record ) ; formattedRecords . push ( record ) ; } return formattedRecords ; } truncateString ( text , length ) { return abp . utils . truncateStringWithPostfix ( text , length ) ; } protected fetchDataList ( request , pageNumber , finishedCallback ) { this . _notificationService . getUserNotifications ( this . readStateFilter === 'ALL' ? undefined : UserNotificationState . Unread , this . _dateTimeService . getStartOfDayForDate ( this . dateRange [ 0 ] ) , this . _dateTimeService . getEndOfDayForDate ( this . dateRange [ 1 ] ) , request . maxResultCount , request . skipCount ) . pipe ( finalize ( finishedCallback ) ) . subscribe ( ( result ) => { this . dataList = this . formatNotifications ( result . items ) ; this . showPaging ( result ) ; } ) ; } setAllNotificationsAsRead ( ) { this . _userNotificationHelper . setAllAsRead ( ( ) => { this . refresh ( ) ; } ) ; } openNotificationSettingsModal ( ) { this . _userNotificationHelper . openSettingsModal ( ) ; } setNotificationAsRead ( userNotification , callback ) { this . _userNotificationHelper . setAsRead ( userNotification . id , ( ) => { if ( callback ) { callback ( ) ; } } ) ; } deleteNotification ( userNotification ) { this . _notificationService . deleteNotification ( userNotification . id ) . subscribe ( ( ) => { this . refresh ( ) ; this . notify . success ( this . l ( 'SuccessfullyDeleted' ) ) ; } ) ; } public getRowClass ( formattedRecord ) { return formattedRecord . state === 'READ' ? 'notification-read' : '' ; } }