in progress
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
<div *ngFor="let notification of notificationPage.content">
|
||||
<div>{{notification.title}}</div>
|
||||
</div>
|
||||
@@ -1,6 +1,6 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NotificationBadgeComponent } from './notification.component';
|
||||
import { NotificationBadgeComponent } from './badge.component';
|
||||
|
||||
describe('NotificationBadgeComponent', () => {
|
||||
let component: NotificationBadgeComponent;
|
||||
13
@overflow/notification/component/badge/badge.component.ts
Normal file
13
@overflow/notification/component/badge/badge.component.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Component, Input, EventEmitter, Output, ViewChild, OnInit } from '@angular/core';
|
||||
import { Notification } from '@overflow/commons-typescript/model/notification';
|
||||
import { Page } from '@overflow/commons-typescript/model/commons/Page';
|
||||
import { Paginator } from 'primeng/primeng';
|
||||
|
||||
@Component({
|
||||
selector: 'of-notification-badge',
|
||||
templateUrl: './badge.component.html',
|
||||
})
|
||||
export class NotificationBadgeComponent {
|
||||
|
||||
@Input() notificationPage: Page<Notification>;
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
import { Component, OnInit, Input, AfterContentInit } from '@angular/core';
|
||||
import { Router } from '@angular/router';
|
||||
import { Store, select } from '@ngrx/store';
|
||||
import { RPCClientError } from '@loafer/ng-rpc';
|
||||
import { Notification } from '@overflow/commons-typescript/model/notification';
|
||||
import * as ListStore from '../../store/list';
|
||||
import * as DetailStore from '../../store/detail';
|
||||
import { ReadAllByMemberSelector, ReadSelector } from '../../store';
|
||||
import { AuthSelector } from '@overflow/member/store';
|
||||
import { Member } from '@overflow/commons-typescript/model/member';
|
||||
// import { PageParams, Page } from 'app/commons/model';
|
||||
import { MarkAsRead } from '../../store/detail';
|
||||
|
||||
@Component({
|
||||
selector: 'of-notification-badge',
|
||||
templateUrl: './notification.component.html',
|
||||
})
|
||||
export class NotificationBadgeComponent implements OnInit, AfterContentInit {
|
||||
notification$ = this.listStore.pipe(select(ReadAllByMemberSelector.select('page')));
|
||||
mark$ = this.detailStore.pipe(select(ReadSelector.select('notification')));
|
||||
isOpen = false;
|
||||
notifications: Notification[] = null;
|
||||
badgeCount = 0;
|
||||
|
||||
|
||||
constructor(
|
||||
private router: Router,
|
||||
private listStore: Store<ListStore.State>,
|
||||
private detailStore: Store<DetailStore.State>
|
||||
) { }
|
||||
|
||||
ngOnInit() {
|
||||
// this.notification$.subscribe(
|
||||
// (page: Page) => {
|
||||
// if (page !== null) {
|
||||
// this.notifications = page.content;
|
||||
// this.getUnconfirmedCount(this.notifications);
|
||||
// }
|
||||
// },
|
||||
// (error: RPCClientError) => {
|
||||
// console.log(error.response.message);
|
||||
// }
|
||||
// );
|
||||
this.mark$.subscribe(
|
||||
(n: Notification) => {
|
||||
if (n !== null && n.confirmDate !== null) {
|
||||
this.getNotifications(0);
|
||||
}
|
||||
},
|
||||
(error: RPCClientError) => {
|
||||
console.log(error.response.message);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
ngAfterContentInit() {
|
||||
this.getNotifications(0);
|
||||
}
|
||||
|
||||
getNotifications(pageIndex: number) {
|
||||
// this.listStore.select(AuthSelector.select('member')).subscribe(
|
||||
// (member: Member) => {
|
||||
// const pageParams: PageParams = {
|
||||
// pageNo: '0',
|
||||
// countPerPage: '10',
|
||||
// sortCol: 'id',
|
||||
// sortDirection: 'descending'
|
||||
// };
|
||||
// this.listStore.dispatch(new ListStore.ReadAllByMember({ member, pageParams }));
|
||||
// },
|
||||
// (error) => {
|
||||
// console.log(error);
|
||||
// }
|
||||
// );
|
||||
}
|
||||
|
||||
getUnconfirmedCount(notifications: Notification[]) {
|
||||
let totalCnt = 0;
|
||||
notifications.map( function(v, i) {
|
||||
if (v.confirmDate === null) {
|
||||
totalCnt += 1;
|
||||
}
|
||||
});
|
||||
this.badgeCount = totalCnt;
|
||||
}
|
||||
|
||||
|
||||
mark(notification: Notification, e: Event) {
|
||||
this.detailStore.dispatch(new DetailStore.MarkAsRead(notification));
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
handleClick(n: Notification) {
|
||||
alert('Will redirect to ' + n.url);
|
||||
}
|
||||
|
||||
handleMarkAllAsRead() {
|
||||
|
||||
// this.listStore.select(AuthSelector.select('member')).subscribe(
|
||||
// (member: Member) => {
|
||||
// const pageParams: PageParams = {
|
||||
// pageNo: '0',
|
||||
// countPerPage: '10',
|
||||
// sortCol: 'id',
|
||||
// sortDirection: 'descending'
|
||||
// };
|
||||
// this.listStore.dispatch(new ListStore.MarkAllAsRead({ member, pageParams }));
|
||||
// },
|
||||
// (error) => {
|
||||
// console.log(error);
|
||||
// }
|
||||
// );
|
||||
}
|
||||
|
||||
handleViewAll() {
|
||||
this.isOpen = false;
|
||||
this.router.navigate(['notification']);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { NotificationListComponent } from './list/list.component';
|
||||
import { NotificationBadgeComponent } from './badge/badge.component';
|
||||
|
||||
export const COMPONENTS = [
|
||||
NotificationListComponent,
|
||||
NotificationBadgeComponent
|
||||
];
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
<of-notification-badge [notificationPage]="notificationPage$ | async"
|
||||
></of-notification-badge>
|
||||
@@ -0,0 +1,72 @@
|
||||
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/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';
|
||||
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',
|
||||
})
|
||||
export class NotificationBadgeContainerComponent implements OnInit {
|
||||
notificationPage$: Observable<Page<Notification>>;
|
||||
|
||||
constructor(
|
||||
private store: Store<ListStore.State>,
|
||||
private route: ActivatedRoute
|
||||
) {
|
||||
this.notificationPage$ = store.pipe(select(NotificationSelector.select('page')));
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.getNotifications();
|
||||
}
|
||||
|
||||
|
||||
getNotifications() {
|
||||
this.store.select(AuthSelector.select('member')).subscribe(
|
||||
(member: Member) => {
|
||||
const pageParams: PageParams = {
|
||||
pageNo: 0,
|
||||
countPerPage: 10,
|
||||
sortCol: 'id',
|
||||
sortDirection: 'descending',
|
||||
};
|
||||
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: 0,
|
||||
countPerPage: 10,
|
||||
sortCol: 'id',
|
||||
sortDirection: 'descending'
|
||||
};
|
||||
this.store.dispatch(new ListStore.MarkAllAsRead({ member, pageParams }));
|
||||
},
|
||||
(error) => {
|
||||
console.log(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
notificationSelected(notification: Notification) {
|
||||
// this.router.navigate([notification.url]);
|
||||
alert('redirect to ' + notification.url);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
import { NotificationListContainerComponent } from './list/list-container.component';
|
||||
import { NotificationBadgeContainerComponent } from './badge/badge-container.component';
|
||||
|
||||
export const CONTAINER_COMPONENTS = [
|
||||
NotificationBadgeContainerComponent,
|
||||
NotificationListContainerComponent,
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user