diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 3cc737845..84e16dfb3 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -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], diff --git a/src/app/core/shell/sidenav/sidenav.component.html b/src/app/core/shell/sidenav/sidenav.component.html index 6053e593a..098736766 100644 --- a/src/app/core/shell/sidenav/sidenav.component.html +++ b/src/app/core/shell/sidenav/sidenav.component.html @@ -73,6 +73,12 @@ Navigation + + + + + Notifications + diff --git a/src/app/notifications/notifications-page/notifications-page.component.html b/src/app/notifications/notifications-page/notifications-page.component.html new file mode 100644 index 000000000..7a4be348e --- /dev/null +++ b/src/app/notifications/notifications-page/notifications-page.component.html @@ -0,0 +1,26 @@ + + + + + + + + Notification + {{ notification.content }} + + + + Created At + {{ notification.createdAt }} + + + + + + + + + + + + diff --git a/src/app/notifications/notifications-page/notifications-page.component.scss b/src/app/notifications/notifications-page/notifications-page.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/notifications/notifications-page/notifications-page.component.spec.ts b/src/app/notifications/notifications-page/notifications-page.component.spec.ts new file mode 100644 index 000000000..6047a8b14 --- /dev/null +++ b/src/app/notifications/notifications-page/notifications-page.component.spec.ts @@ -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; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ NotificationsPageComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(NotificationsPageComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/notifications/notifications-page/notifications-page.component.ts b/src/app/notifications/notifications-page/notifications-page.component.ts new file mode 100644 index 000000000..81e052ba5 --- /dev/null +++ b/src/app/notifications/notifications-page/notifications-page.component.ts @@ -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; + + /** 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; + } + +} diff --git a/src/app/notifications/notifications-routing.module.ts b/src/app/notifications/notifications-routing.module.ts new file mode 100644 index 000000000..927a7cacc --- /dev/null +++ b/src/app/notifications/notifications-routing.module.ts @@ -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 { } diff --git a/src/app/notifications/notifications.module.ts b/src/app/notifications/notifications.module.ts new file mode 100644 index 000000000..bd5859a73 --- /dev/null +++ b/src/app/notifications/notifications.module.ts @@ -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 { } diff --git a/src/app/notifications/notifications.resolver.ts b/src/app/notifications/notifications.resolver.ts new file mode 100644 index 000000000..8ec659d87 --- /dev/null +++ b/src/app/notifications/notifications.resolver.ts @@ -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 { + + /** + * @param {NotificationsService} notificationsService Notifications service. + */ + constructor(private notificationsService: NotificationsService) {} + + /** + * Returns the Notifications data. + * @returns {Observable} + */ + resolve(): Observable { + return this.notificationsService.getNotifications(true); + } + +} diff --git a/src/app/notifications/notifications.service.spec.ts b/src/app/notifications/notifications.service.spec.ts new file mode 100644 index 000000000..70045188f --- /dev/null +++ b/src/app/notifications/notifications.service.spec.ts @@ -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(); + }); +}); diff --git a/src/app/notifications/notifications.service.ts b/src/app/notifications/notifications.service.ts new file mode 100644 index 000000000..9137310e9 --- /dev/null +++ b/src/app/notifications/notifications.service.ts @@ -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} Notifications. + */ + getNotifications(isRead: boolean): Observable { + const httpParams = new HttpParams().set('isRead', isRead.toString()); + return this.http.get('/notifications', { params: httpParams }); + } + +}