member_webapp/@overflow/notification/container/list/list-container.component.ts
crusader cd1e53f67a ing
2018-06-04 17:25:29 +09:00

75 lines
2.8 KiB
TypeScript

import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import { AfterContentInit, OnDestroy } from '@angular/core/src/metadata/lifecycle_hooks';
import { Store, select } from '@ngrx/store';
import { Observable } from 'rxjs';
import * as NotificationEntityStore from '../../store/entity/notification';
import { NotificationEntitySelector } from '../../store/';
import { AuthSelector } from '@overflow/shared/auth/store';
import { Member } from '@overflow/commons-typescript/model/member';
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';
import { DomainMember } from '@overflow/commons-typescript/model/domain';
@Component({
selector: 'of-notification-container',
templateUrl: './list-container.component.html',
})
export class NotificationListContainerComponent implements OnInit {
notificationPage$: Observable<Page<Notification>>;
@Output() pageChange = new EventEmitter<number>();
pageNo: number;
constructor(
private store: Store<NotificationEntityStore.State>,
private route: ActivatedRoute
) {
// this.notificationPage$ = store.pipe(select(NotificationEntitySelector.selectAll));
}
ngOnInit() {
this.route.queryParams.subscribe(queryParams => {
this.pageNo = queryParams['page'] || 0;
this.getNotifications();
});
}
onPageChange(pageNo: number) {
this.pageChange.emit(pageNo);
}
getNotifications() {
this.store.select(AuthSelector.selectDomainMember).subscribe(
(domainMember: DomainMember) => {
const pageParams: PageParams = {
pageNo: this.pageNo,
countPerPage: 10,
sortCol: 'id',
sortDirection: 'descending',
};
this.store.dispatch(new NotificationEntityStore.ReadAllByMember({ member: domainMember.member, pageParams }));
}
);
}
markAllasRead() {
this.store.select(AuthSelector.selectDomainMember).subscribe(
(domainMember: DomainMember) => {
const pageParams: PageParams = {
pageNo: this.pageNo,
countPerPage: 10,
sortCol: 'id',
sortDirection: 'descending',
};
this.store.dispatch(new NotificationEntityStore.MarkAllAsRead({ member: domainMember.member, pageParams }));
}
);
}
notificationSelected(notification: Notification) {
// this.router.navigate([notification.url]);
alert('redirect to ' + notification.url);
}
}