| import { Injectable } from '@angular/core'; |
| |
| import { Notification } from '../model/notification'; |
| import { FilterSelection } from '../model/filter-selection'; |
| |
| @Injectable() |
| export class NotificationSearchSortService { |
| |
| constructor() { } |
| |
| private getSortedNotifications(notifications: Notification[]): Notification[] { |
| return notifications.sort((a, b) => a.createDate > b.createDate ? 1 : -1); |
| } |
| /* |
| private getAllSortedNotifications(): Observable<Notification[]> { |
| return this.getSortedNotifications(this.getAllNotifications()); |
| } |
| */ |
| |
| private searchNotifications(searchInput: string, filterSelection: FilterSelection, notifications: Notification[]): Notification[] { |
| return notifications.filter(notification => { |
| if ((filterSelection.all || filterSelection.status) && notification.status.includes(searchInput)) { |
| return true; |
| } |
| if ((filterSelection.all || filterSelection.notificationText) && notification.notificationText.includes(searchInput)) { |
| return true; |
| } |
| if ((filterSelection.all || filterSelection.freeText) && notification.freeText.includes(searchInput)) { |
| return true; |
| } |
| if ((filterSelection.all || filterSelection.freeTextExtended) && notification.freeTextExtended.includes(searchInput)) { |
| return true; |
| } |
| if ((filterSelection.all || filterSelection.responsibilityForwarding) && |
| notification.responsibilityForwarding.includes(searchInput)) { |
| return true; |
| } |
| if ((filterSelection.all || filterSelection.responsibilityControlPoint) && |
| notification.responsibilityControlPoint.includes(searchInput)) { |
| return true; |
| } |
| if ((filterSelection.all || filterSelection.creator) && notification.createUser.includes(searchInput)) { |
| return true; |
| } |
| if ((filterSelection.all || filterSelection.clerk) && notification.clerk.includes(searchInput)) { |
| return true; |
| } |
| }); |
| } |
| |
| searchFirstNotifications(notifications: Notification[], searchInput: string, filterSelection: FilterSelection): Notification[] { |
| return this.searchNotifications(searchInput, filterSelection, notifications).splice(0, 5); |
| } |
| |
| searchAllNotifications(notifications: Notification[], searchInput: string, filterSelection: FilterSelection): Notification[] { |
| return this.searchNotifications(searchInput, filterSelection, notifications); |
| } |
| |
| } |