fix: multiple bugs in home/core/institution modules (#1225)
Fixes: #1224
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
<button
|
||||
mat-icon-button class="ml-1" matTooltip="Notifications"
|
||||
[matMenuTriggerFor]="notificationsMenu" (menuClosed)="menuClosed()"
|
||||
[matBadge]="unreadNotifications.length" [matBadgeHidden]="!unreadNotifications.length" matBadgeColor="warn" matBadgeSize="medium"
|
||||
>
|
||||
<fa-icon icon="bell" size="lg"></fa-icon>
|
||||
</button>
|
||||
|
||||
<mat-menu class="mifosx-notifications-menu" #notificationsMenu="matMenu" [overlapTrigger]="false">
|
||||
|
||||
<button mat-menu-item class="unread" *ngFor="let notification of unreadNotifications" [routerLink]="[routeMap[notification.objectType], notification.objectId]">
|
||||
{{ notification.content }}*<br>
|
||||
<span class="time">[{{ notification.createdAt }}]</span>
|
||||
</button>
|
||||
|
||||
<button mat-menu-item *ngFor="let notification of displayedReadNotifications" [routerLink]="[routeMap[notification.objectType], notification.objectId]">
|
||||
{{ notification.content }}<br>
|
||||
<span class="time">[{{ notification.createdAt }}]</span>
|
||||
</button>
|
||||
|
||||
<button mat-menu-item class="view-all" [routerLink]="['/notifications']">View All Notifications</button>
|
||||
|
||||
</mat-menu>
|
||||
@@ -1,21 +0,0 @@
|
||||
.mifosx-notifications-menu {
|
||||
|
||||
max-height: 20rem !important;
|
||||
width: 12.5rem !important;
|
||||
|
||||
.mat-menu-content {
|
||||
padding: 0 !important;
|
||||
}
|
||||
|
||||
[mat-menu-item] {
|
||||
height: 5rem;
|
||||
line-height: 2.2rem;
|
||||
.time{
|
||||
font-size: small;
|
||||
}
|
||||
&.unread, &.view-all {
|
||||
background-color: #E0F7FF !important;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { NotificationsTrayComponent } from './notifications-tray.component';
|
||||
|
||||
describe('NotificationsTrayComponent', () => {
|
||||
let component: NotificationsTrayComponent;
|
||||
let fixture: ComponentFixture<NotificationsTrayComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ NotificationsTrayComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(NotificationsTrayComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -1,109 +0,0 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core';
|
||||
|
||||
/** RxJS Imports */
|
||||
import { forkJoin } from 'rxjs';
|
||||
|
||||
/** Custom Services */
|
||||
import { NotificationsService } from '../notifications.service';
|
||||
|
||||
/**
|
||||
* Notifications Tray Component
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-notifications-tray',
|
||||
templateUrl: './notifications-tray.component.html',
|
||||
styleUrls: ['./notifications-tray.component.scss'],
|
||||
encapsulation: ViewEncapsulation.None
|
||||
})
|
||||
export class NotificationsTrayComponent implements OnInit, OnDestroy {
|
||||
|
||||
/** Read Notifications */
|
||||
readNotifications: any[] = [];
|
||||
/** Displayed Read Notifications */
|
||||
displayedReadNotifications: any[] = [];
|
||||
/** Unread Notifications */
|
||||
unreadNotifications: any[] = [];
|
||||
/** Timer to refetch notifications every 60 seconds */
|
||||
timer: any;
|
||||
|
||||
/**
|
||||
* Gets router link prefix from notification's objectType attribute
|
||||
* Shares, Savings, Deposits, Loans routes inaccessible because of dependency on entity ID.
|
||||
*/
|
||||
routeMap: any = {
|
||||
'client' : '/clients/',
|
||||
'group' : '/groups/',
|
||||
'loan' : '/loans/',
|
||||
'center' : '/centers/',
|
||||
'shareAccount' : '/shares-accounts/',
|
||||
'fixedDeposit' : '/fixed-deposits-accounts/',
|
||||
'recurringDepositAccount': '/recurringdeposits/',
|
||||
'savingsAccount' : '/savingsaccounts/',
|
||||
'shareProduct': '/products/share-products/',
|
||||
'loanProduct' : '/products/loan-products/'
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {NotificationsService} notificationsService Notifications Service
|
||||
*/
|
||||
constructor(public notificationsService: NotificationsService) {
|
||||
forkJoin([this.notificationsService.getNotifications(true), this.notificationsService.getNotifications(false)])
|
||||
.subscribe((response: any[]) => {
|
||||
this.readNotifications = response[0].pageItems;
|
||||
this.unreadNotifications = response[1].pageItems;
|
||||
this.setNotifications();
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
setTimeout(() => { this.fetchUnreadNotifications(); }, 60000);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
clearTimeout(this.timer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restructures displayed read notifications vis-a-vis unread notifications.
|
||||
*/
|
||||
setNotifications() {
|
||||
const length = this.unreadNotifications.length;
|
||||
this.displayedReadNotifications = length < 9 ? this.readNotifications.slice(0, 9 - length) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively fetch unread notifications.
|
||||
*/
|
||||
fetchUnreadNotifications() {
|
||||
this.notificationsService.getNotifications(false).subscribe((response: any) => {
|
||||
this.unreadNotifications = this.unreadNotifications.concat(response.pageItems);
|
||||
this.setNotifications();
|
||||
});
|
||||
// this.mockNotifications(); // Uncomment for Testing.
|
||||
this.timer = setTimeout(() => { this.fetchUnreadNotifications(); }, 60000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update read/unread notifications.
|
||||
*/
|
||||
menuClosed() {
|
||||
// Update the server for read notifications.
|
||||
this.notificationsService.updateNotifications().subscribe(() => {});
|
||||
// Update locally for read notifications.
|
||||
this.readNotifications = this.unreadNotifications.concat(this.readNotifications);
|
||||
this.unreadNotifications = [];
|
||||
this.setNotifications();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to test notifications in case of faulty backend.
|
||||
*/
|
||||
mockNotifications() {
|
||||
this.notificationsService.getMockUnreadNotification().subscribe((response: any) => {
|
||||
this.unreadNotifications = this.unreadNotifications.concat(response.pageItems);
|
||||
this.setNotifications();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,23 +8,18 @@ import { NotificationsRoutingModule } from './notifications-routing.module';
|
||||
|
||||
/** Custom Components */
|
||||
import { NotificationsPageComponent } from './notifications-page/notifications-page.component';
|
||||
import { NotificationsTrayComponent } from './notifications-tray/notifications-tray.component';
|
||||
|
||||
/**
|
||||
* Notifications Module
|
||||
*/
|
||||
@NgModule({
|
||||
declarations: [
|
||||
NotificationsPageComponent,
|
||||
NotificationsTrayComponent
|
||||
NotificationsPageComponent
|
||||
],
|
||||
imports: [
|
||||
SharedModule,
|
||||
PipesModule,
|
||||
NotificationsRoutingModule
|
||||
],
|
||||
exports: [
|
||||
NotificationsTrayComponent
|
||||
]
|
||||
})
|
||||
export class NotificationsModule { }
|
||||
|
||||
Reference in New Issue
Block a user