member_webapp/@overflow/notification/container/badge/badge-container.component.ts

79 lines
2.8 KiB
TypeScript
Raw Normal View History

2018-05-25 11:59:18 +00:00
import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
2018-05-27 09:12:20 +00:00
import { AfterContentInit, OnDestroy, OnChanges, SimpleChanges } from '@angular/core/src/metadata/lifecycle_hooks';
2018-05-25 11:59:18 +00:00
import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
2018-05-28 10:35:06 +00:00
import { Domain, DomainMember } from '@overflow/commons-typescript/model/domain';
2018-05-27 09:12:20 +00:00
import * as NotificationEntityStore from '../../store/entity/notification';
import { NotificationEntitySelector } from '../../store/';
2018-05-28 10:35:06 +00:00
import { AuthContainerSelector } from '@overflow/shared/auth/store';
2018-05-25 11:59:18 +00:00
import { PageParams } from '@overflow/commons-typescript/model/commons/PageParams';
import { Page } from '@overflow/commons-typescript/model/commons/Page';
import { Notification } from '@overflow/commons-typescript/model/notification';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'of-notification-badge-container',
templateUrl: './badge-container.component.html',
})
2018-05-27 09:12:20 +00:00
export class NotificationBadgeContainerComponent implements OnInit, OnChanges {
2018-05-25 11:59:18 +00:00
notificationPage$: Observable<Page<Notification>>;
2018-05-27 09:12:20 +00:00
@Output() viewAll = new EventEmitter();
@Output() select = new EventEmitter<Notification>();
2018-05-25 11:59:18 +00:00
constructor(
2018-05-27 09:12:20 +00:00
private store: Store<NotificationEntityStore.State>,
2018-05-25 11:59:18 +00:00
private route: ActivatedRoute
) {
2018-05-27 09:12:20 +00:00
// this.notificationPage$ = store.pipe(select(NotificationEntitySelector.selectAll));
2018-05-25 11:59:18 +00:00
}
ngOnInit() {
this.getNotifications();
}
2018-05-27 09:12:20 +00:00
ngOnChanges(changes: SimpleChanges): void {
this.getNotifications();
}
2018-05-25 11:59:18 +00:00
getNotifications() {
2018-05-28 10:35:06 +00:00
this.store.select(AuthContainerSelector.selectDomainMember).subscribe(
(domainMember: DomainMember) => {
2018-05-25 11:59:18 +00:00
const pageParams: PageParams = {
pageNo: 0,
countPerPage: 10,
sortCol: 'id',
sortDirection: 'descending',
};
2018-05-28 10:35:06 +00:00
this.store.dispatch(new NotificationEntityStore.ReadAllByMember({ member: domainMember.member, pageParams }));
2018-05-25 11:59:18 +00:00
}
2018-05-28 10:35:06 +00:00
);
2018-05-25 11:59:18 +00:00
}
markAllasRead() {
2018-05-28 10:35:06 +00:00
// this.store.select(AuthSelector.select('member')).subscribe(
// (member: Member) => {
// const pageParams: PageParams = {
// pageNo: 0,
// countPerPage: 10,
// sortCol: 'id',
// sortDirection: 'descending'
// };
// this.store.dispatch(new NotificationEntityStore.MarkAllAsRead({ member, pageParams }));
// },
// (error) => {
// console.log(error);
// }
// );
2018-05-25 11:59:18 +00:00
}
2018-05-27 09:12:20 +00:00
onSelect(notification: Notification) {
this.select.emit(notification);
2018-05-25 11:59:18 +00:00
}
2018-05-27 09:12:20 +00:00
onViewAll() {
this.viewAll.emit();
}
2018-05-25 11:59:18 +00:00
}