feat: master search tool and page (#1190)

Fixes: #1189
This commit is contained in:
Karan Takalkar
2020-08-10 16:49:46 +05:30
committed by GitHub
parent a27169d8fe
commit bc57a061c4
17 changed files with 426 additions and 38 deletions
@@ -0,0 +1,22 @@
<div class="container">
<mat-card fxLayout="column" fxLayoutGap="2%">
<mat-error *ngIf="overload">Searched query resulted more than 200 records, showing first 200 records.</mat-error>
<mat-list>
<mat-list-item (click)="navigate(entity)" *ngFor="let entity of searchResults">
<h3 matLine><span class="link">{{ entity.entityName }}</span> | #{{ entity.entityAccountNo }}</h3>
<p matLine>
<span>Entity: {{ entity.entityType }}
| {{ ['CLIENT','GROUP', 'CENTER'].includes(entity.entityType) ? 'Office' : 'Client' }}: {{ entity.parentName }}
</span>
</p>
</mat-list-item>
</mat-list>
</mat-card>
</div>
@@ -0,0 +1,18 @@
mat-list {
padding-top: 0px;
}
mat-list-item {
.link {
color: blue;
text-decoration: underline;
width: fit-content;
&:hover{
cursor: pointer;
}
}
margin-block: 20px;
&:hover{
background-color: #f5f5f5;
}
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SearchPageComponent } from './search-page.component';
describe('SearchPageComponent', () => {
let component: SearchPageComponent;
let fixture: ComponentFixture<SearchPageComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SearchPageComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SearchPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,62 @@
/** Angular Imports */
import { Component } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
/**
* Search Page Component
*/
@Component({
selector: 'mifosx-search-page',
templateUrl: './search-page.component.html',
styleUrls: ['./search-page.component.scss']
})
export class SearchPageComponent {
/** Search Results */
searchResults: any;
/** Flags if number of search results exceed 200 */
overload: boolean;
/**
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private route: ActivatedRoute,
private router: Router) {
this.route.data.subscribe(( data: { searchResults: any }) => {
this.searchResults = data.searchResults;
this.overload = this.searchResults.length > 200 ? true : false;
if (this.overload) {
this.searchResults = this.searchResults.slice(0, 200);
}
});
}
/**
* Returns link to entity view page.
* @param {any} entity Entity
*/
navigate(entity: any) {
switch (entity.entityType) {
case 'CLIENT':
this.router.navigate(['clients', entity.entityId]);
break;
case 'CENTER':
this.router.navigate(['centers', entity.entityId]);
break;
case 'GROUP':
this.router.navigate(['groups', entity.entityId]);
break;
case 'SHARE':
this.router.navigate(['clients', entity.parentId, 'sharesaccounts', entity.entityId]);
break;
case 'SAVING':
this.router.navigate(['clients', entity.parentId, 'savingsaccounts', entity.entityId]);
break;
case 'LOAN':
this.router.navigate(['clients', entity.parentId, 'loans', entity.entityId]);
break;
}
}
}