feat: add view notifications page (#1170)

Fixes: #1169
This commit is contained in:
Karan Takalkar
2020-08-03 16:24:20 +05:30
committed by GitHub
parent ac280d2447
commit 30139026bd
11 changed files with 246 additions and 2 deletions
+2 -2
View File
@@ -34,8 +34,7 @@ import { OrganizationModule } from './organization/organization.module';
import { TemplatesModule } from './templates/templates.module';
import { UsersModule } from './users/users.module';
import { ReportsModule } from './reports/reports.module';
import { NotificationsModule } from './notifications/notifications.module';
/** Main Routing Module */
import { AppRoutingModule } from './app-routing.module';
@@ -68,6 +67,7 @@ import { AppRoutingModule } from './app-routing.module';
OrganizationModule,
TemplatesModule,
UsersModule,
NotificationsModule,
AppRoutingModule,
],
declarations: [WebAppComponent, NotFoundComponent],
@@ -73,6 +73,12 @@
</mat-icon>
<a matLine>Navigation</a>
</mat-list-item>
<mat-list-item [routerLink]="['/notifications']">
<mat-icon matListIcon>
<fa-icon icon="bell" size="sm"></fa-icon>
</mat-icon>
<a matLine>Notifications</a>
</mat-list-item>
<mat-list-item [routerLink]="['/accounting/journal-entries/frequent-postings']">
<mat-icon matListIcon>
<fa-icon icon="sync" size="sm"></fa-icon>
@@ -0,0 +1,26 @@
<div class="container">
<div class="mat-elevation-z8">
<table mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="notification">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Notification </th>
<td mat-cell *matCellDef="let notification"> {{ notification.content }} </td>
</ng-container>
<ng-container matColumnDef="createdAt">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Created At </th>
<td mat-cell *matCellDef="let notification"> {{ notification.createdAt }} </td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
</div>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { NotificationsPageComponent } from './notifications-page.component';
describe('NotificationsPageComponent', () => {
let component: NotificationsPageComponent;
let fixture: ComponentFixture<NotificationsPageComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ NotificationsPageComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(NotificationsPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,54 @@
/** Angular Imports */
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatTableDataSource, MatPaginator, MatSort } from '@angular/material';
import { ActivatedRoute } from '@angular/router';
/**
* Notifications Page Component
*/
@Component({
selector: 'mifosx-notifications-page',
templateUrl: './notifications-page.component.html',
styleUrls: ['./notifications-page.component.scss']
})
export class NotificationsPageComponent implements OnInit {
/** Notifications data. */
notificationsData: any;
/** Columns to be displayed in notifications table. */
displayedColumns: string[] = ['notification', 'createdAt'];
/** Data source for notifications table. */
dataSource: MatTableDataSource<any>;
/** Paginator for notifications table. */
@ViewChild(MatPaginator) paginator: MatPaginator;
/** Sorter for notifications table. */
@ViewChild(MatSort) sort: MatSort;
/**
* Retrieves the notifications data from `resolve`.
* @param {ActivatedRoute} route Activated Route.
*/
constructor(private route: ActivatedRoute) {
this.route.data.subscribe(( data: { notifications: any }) => {
this.notificationsData = data.notifications.pageItems;
});
}
/**
* Sets the notifications table.
*/
ngOnInit() {
this.setNotifications();
}
/**
* Initializes the data source, paginator and sorter for notifications table.
*/
setNotifications() {
this.dataSource = new MatTableDataSource(this.notificationsData);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
}
@@ -0,0 +1,37 @@
/** Angular Imports */
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
/** Routing Imports */
import { Route } from '../core/route/route.service';
/** Translation Imports */
import { extract } from '../core/i18n/i18n.service';
/** Custom Components */
import { NotificationsPageComponent } from './notifications-page/notifications-page.component';
/** Custom Resolvers */
import { NotificationsResolver } from './notifications.resolver';
/** Notification Routes */
const routes: Routes = [
Route.withShell([
{
path: 'notifications',
component: NotificationsPageComponent,
data: { title: extract('Notifications'), breadcrumb: 'Notifications' },
resolve: {
notifications: NotificationsResolver
}
}
])
];
@NgModule({
imports: [RouterModule.forChild(routes)],
providers: [NotificationsResolver],
exports: [RouterModule]
})
export class NotificationsRoutingModule { }
@@ -0,0 +1,25 @@
/** Angular Imports */
import { NgModule } from '@angular/core';
/** Custom Modules */
import { SharedModule } from '../shared/shared.module';
import { PipesModule } from '../pipes/pipes.module';
import { NotificationsRoutingModule } from './notifications-routing.module';
/** Custom Components */
import { NotificationsPageComponent } from './notifications-page/notifications-page.component';
/**
* Notifications Module
*/
@NgModule({
declarations: [
NotificationsPageComponent
],
imports: [
SharedModule,
PipesModule,
NotificationsRoutingModule
]
})
export class NotificationsModule { }
@@ -0,0 +1,30 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { NotificationsService } from './notifications.service';
/**
* Notifications data resolver.
*/
@Injectable()
export class NotificationsResolver implements Resolve<Object> {
/**
* @param {NotificationsService} notificationsService Notifications service.
*/
constructor(private notificationsService: NotificationsService) {}
/**
* Returns the Notifications data.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
return this.notificationsService.getNotifications(true);
}
}
@@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { NotificationsService } from './notifications.service';
describe('NotificationsService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: NotificationsService = TestBed.get(NotificationsService);
expect(service).toBeTruthy();
});
});
@@ -0,0 +1,29 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
/** rxjs Imports */
import { Observable } from 'rxjs';
/**
* Notification service.
*/
@Injectable({
providedIn: 'root'
})
export class NotificationsService {
/**
* @param {HttpClient} http Http Client to send requests.
*/
constructor(private http: HttpClient) { }
/**
* @returns {Observable<any>} Notifications.
*/
getNotifications(isRead: boolean): Observable<any> {
const httpParams = new HttpParams().set('isRead', isRead.toString());
return this.http.get('/notifications', { params: httpParams });
}
}