2018-05-25 07:29:06 +00:00
|
|
|
import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
|
2018-05-25 03:31:08 +00:00
|
|
|
import { AfterContentInit, OnDestroy } from '@angular/core/src/metadata/lifecycle_hooks';
|
|
|
|
import { Store, select } from '@ngrx/store';
|
|
|
|
import { Observable } from 'rxjs/Observable';
|
|
|
|
import { Domain } from '@overflow/commons-typescript/model/domain';
|
|
|
|
import * as ListStore from '../../store/notification';
|
|
|
|
import { NotificationSelector } from '../../store';
|
|
|
|
import { AuthSelector } from '../../../member/store';
|
|
|
|
import { Member } from '@overflow/commons-typescript/model/member';
|
|
|
|
import { PageParams } from '@overflow/commons-typescript/model/commons/PageParams';
|
2018-05-25 03:51:42 +00:00
|
|
|
import { Page } from '@overflow/commons-typescript/model/commons/Page';
|
|
|
|
import { Notification } from '@overflow/commons-typescript/model/notification';
|
2018-05-25 07:29:06 +00:00
|
|
|
import { ActivatedRoute } from '@angular/router';
|
2018-05-25 03:31:08 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'of-notification-container',
|
|
|
|
templateUrl: './list-container.component.html',
|
|
|
|
})
|
|
|
|
export class NotificationListContainerComponent implements OnInit {
|
2018-05-25 03:51:42 +00:00
|
|
|
notificationPage$: Observable<Page<Notification>>;
|
2018-05-25 07:29:06 +00:00
|
|
|
@Output() pageChange = new EventEmitter<number>();
|
|
|
|
pageNo: number;
|
2018-05-25 03:31:08 +00:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private store: Store<ListStore.State>,
|
2018-05-25 07:29:06 +00:00
|
|
|
private route: ActivatedRoute
|
2018-05-25 03:31:08 +00:00
|
|
|
) {
|
2018-05-25 03:51:42 +00:00
|
|
|
this.notificationPage$ = store.pipe(select(NotificationSelector.select('page')));
|
2018-05-25 03:31:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-05-25 07:29:06 +00:00
|
|
|
this.route.queryParams.subscribe(queryParams => {
|
|
|
|
this.pageNo = queryParams['page'] || 0;
|
|
|
|
this.getNotifications();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onPageChange(pageNo: number) {
|
|
|
|
this.pageChange.emit(pageNo);
|
|
|
|
}
|
|
|
|
|
|
|
|
getNotifications() {
|
2018-05-25 03:31:08 +00:00
|
|
|
this.store.select(AuthSelector.select('member')).subscribe(
|
|
|
|
(member: Member) => {
|
|
|
|
const pageParams: PageParams = {
|
2018-05-25 07:29:06 +00:00
|
|
|
pageNo: this.pageNo,
|
2018-05-25 03:31:08 +00:00
|
|
|
countPerPage: 10,
|
|
|
|
sortCol: 'id',
|
|
|
|
sortDirection: 'descending',
|
|
|
|
};
|
2018-05-25 07:29:06 +00:00
|
|
|
this.store.dispatch(new ListStore.ReadAllByMember({ member, pageParams }));
|
|
|
|
},
|
|
|
|
(error) => {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
markAllasRead() {
|
|
|
|
this.store.select(AuthSelector.select('member')).subscribe(
|
|
|
|
(member: Member) => {
|
|
|
|
const pageParams: PageParams = {
|
|
|
|
pageNo: this.pageNo,
|
|
|
|
countPerPage: 10,
|
|
|
|
sortCol: 'id',
|
|
|
|
sortDirection: 'descending'
|
|
|
|
};
|
|
|
|
this.store.dispatch(new ListStore.MarkAllAsRead({ member, pageParams }));
|
2018-05-25 03:31:08 +00:00
|
|
|
},
|
|
|
|
(error) => {
|
|
|
|
console.log(error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-05-25 07:29:06 +00:00
|
|
|
notificationSelected(notification: Notification) {
|
|
|
|
// this.router.navigate([notification.url]);
|
|
|
|
alert('redirect to ' + notification.url);
|
|
|
|
}
|
2018-05-25 03:31:08 +00:00
|
|
|
}
|