Changeset View
Changeset View
Standalone View
Standalone View
src/app/_shared/notifcations/notifications.component.ts
- This file was moved from src/app/notification/notification.component.ts.
import { Component, OnInit, OnDestroy, ChangeDetectorRef } from '@angular/core'; | import { Component, OnInit, OnDestroy, ChangeDetectorRef } from '@angular/core'; | ||||
import { MatDialog, MatDialogRef, MatSnackBar } from '@angular/material'; | import { MatDialog, MatDialogRef, MatSnackBar } from '@angular/material'; | ||||
import { Router, ActivatedRoute } from '@angular/router'; | import { Router, ActivatedRoute } from '@angular/router'; | ||||
import { Subject } from 'rxjs/Subject'; | import { Subject } from 'rxjs/Subject'; | ||||
import { ConfirmDeletionDialogComponent } from '../_dialogs/confirmDeletion.dialog.component'; | import { ConfirmDeletionDialogComponent } from '../../_dialogs/confirmDeletion.dialog.component'; | ||||
import { Notification } from '../_models/notification'; | import { Notification } from '../../_models/notification'; | ||||
import { Post } from '../_models/post'; | import { Post } from '../../_models/post'; | ||||
import { SuperNotification } from '../_models/superNotification'; | import { SuperNotification } from '../../_models/superNotification'; | ||||
import { NavBarService } from '../_services/navBar.service'; | import { NavBarService } from '../../_services/navBar.service'; | ||||
import { NotificationService } from '../_services/notification.service'; | import { NotificationService } from '../../_services/notification.service'; | ||||
import { RouteService } from '../_services/route.service'; | import { RouteService } from '../../_services/route.service'; | ||||
@Component({ | @Component({ | ||||
templateUrl: 'notification.component.html' | templateUrl: 'notifications.component.html', | ||||
styleUrls: ['./notifications.component.scss'] | |||||
}) | }) | ||||
export class NotificationComponent implements OnInit, OnDestroy { | export class NotificationsComponent implements OnInit, OnDestroy { | ||||
archivedPosts: Post[] = []; | archivedPosts: Post[] = []; | ||||
componentDestroyed: Subject<boolean> = new Subject(); | componentDestroyed: Subject<boolean> = new Subject(); | ||||
index = 1; | index = 1; | ||||
limit = 10; | limit = 10; | ||||
loading = true; | loading = true; | ||||
notifications: Notification[] = []; | notifications: Notification[] = []; | ||||
offset = 10; | offset = 10; | ||||
superNotification: SuperNotification; | superNotification: SuperNotification; | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | deleteNotifications() { | ||||
const dialogRef = this.dialog.open(ConfirmDeletionDialogComponent); | const dialogRef = this.dialog.open(ConfirmDeletionDialogComponent); | ||||
dialogRef.afterClosed() | dialogRef.afterClosed() | ||||
.takeUntil(this.componentDestroyed) | .takeUntil(this.componentDestroyed) | ||||
.subscribe(result => { | .subscribe(result => { | ||||
if (result.bool) { | if (result.bool) { | ||||
this.notificationService.deleteNotifications(); | this.notificationService.deleteNotifications(); | ||||
this.notifications = []; | this.notifications = []; | ||||
this.navBarService.notifications.next(0); | this.navBarService.notifications.next(0); | ||||
const snackBarRef = this.snackBar.open('Notifications Deleted Successfully', 'Close', { | this.snackBar.open('Notifications Deleted Successfully', 'Close', { | ||||
duration: 3000 | duration: 3000 | ||||
}); | }); | ||||
} | } | ||||
}); | }); | ||||
this.cdRef.detectChanges(); | this.cdRef.detectChanges(); | ||||
} | } | ||||
Show All 18 Lines | this.notificationService.getSuperNotification(this.limit, (this.offset * page) - this.limit) | ||||
this.index = page; | this.index = page; | ||||
this.totalCount = this.superNotification.count; | this.totalCount = this.superNotification.count; | ||||
this.navBarService.notifications.next(this.superNotification.count); | this.navBarService.notifications.next(this.superNotification.count); | ||||
this.cdRef.detectChanges(); | this.cdRef.detectChanges(); | ||||
this.loading = false; | this.loading = false; | ||||
}); | }); | ||||
} | } | ||||
goto(areaID: string, postID: number, comments: number[] = []) { | goto(n: Notification) { | ||||
let commentString = ''; | let commentString = ''; | ||||
for (let i = 0; i < comments.length; i++) { | for (let i = 0; i < n.comments.length; i++) { | ||||
if (i !== 0) { | if (i !== 0) { | ||||
commentString += '-'; | commentString += '-'; | ||||
} | } | ||||
commentString += comments[i]; | commentString += n.comments[i]; | ||||
} | } | ||||
this.routeService.addNextRouteByIndex(this.index); | this.routeService.addNextRouteByIndex(this.index); | ||||
this.navBarService.notifications.next(this.superNotification.count - 1); | this.navBarService.notifications.next(this.superNotification.count - 1); | ||||
this.router.navigateByUrl('/areas/' + areaID + '/' + postID + '/' + commentString); | this.router.navigateByUrl('/areas/' + n.area + '/' + n.post.id + '/' + commentString); | ||||
} | } | ||||
} | } |