From 7357a1fb4ca6d8f72f96249f68291a3ddd7df030 Mon Sep 17 00:00:00 2001 From: punwai Date: Sat, 21 Dec 2019 12:49:24 +0700 Subject: [PATCH] feat: add adhoc query component (#515) Fixes: #511 --- .../adhoc-query/adhoc-queries.resolver.ts | 30 +++++++ .../adhoc-query/adhoc-query.component.html | 69 ++++++++++++++++ .../adhoc-query/adhoc-query.component.scss | 15 ++++ .../adhoc-query/adhoc-query.component.spec.ts | 25 ++++++ .../adhoc-query/adhoc-query.component.ts | 79 +++++++++++++++++++ .../organization-routing.module.ts | 18 ++++- .../organization/organization.component.html | 2 +- src/app/organization/organization.module.ts | 4 +- src/app/organization/organization.service.ts | 7 ++ 9 files changed, 246 insertions(+), 3 deletions(-) create mode 100644 src/app/organization/adhoc-query/adhoc-queries.resolver.ts create mode 100644 src/app/organization/adhoc-query/adhoc-query.component.html create mode 100644 src/app/organization/adhoc-query/adhoc-query.component.scss create mode 100644 src/app/organization/adhoc-query/adhoc-query.component.spec.ts create mode 100644 src/app/organization/adhoc-query/adhoc-query.component.ts diff --git a/src/app/organization/adhoc-query/adhoc-queries.resolver.ts b/src/app/organization/adhoc-query/adhoc-queries.resolver.ts new file mode 100644 index 000000000..e5b66c16e --- /dev/null +++ b/src/app/organization/adhoc-query/adhoc-queries.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 { OrganizationService } from '../organization.service'; + +/** + * Adhoc Queries data resolver. + */ +@Injectable() +export class AdhocQueriesResolver implements Resolve { + + /** + * @param {OrganizationService} organizationService Organization service. + */ + constructor(private organizationService: OrganizationService) {} + + /** + * Returns the adhoc queries data. + * @returns {Observable} + */ + resolve(): Observable { + return this.organizationService.getAdhocQueries(); + } + +} diff --git a/src/app/organization/adhoc-query/adhoc-query.component.html b/src/app/organization/adhoc-query/adhoc-query.component.html new file mode 100644 index 000000000..6c10648dc --- /dev/null +++ b/src/app/organization/adhoc-query/adhoc-query.component.html @@ -0,0 +1,69 @@ +
+ +
+ +
+ +
+ + Filter + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name {{ adhocquery.name }} SQL Query {{ adhocquery.query }} Table Affected {{ adhocquery.tableName }} Email {{ adhocquery.email }} Report Run Frequency {{ adhocquery.reportRunFrequency }} Status +
+ +
+
Created By {{ adhocquery.createdBy }}
+ + + +
+ +
diff --git a/src/app/organization/adhoc-query/adhoc-query.component.scss b/src/app/organization/adhoc-query/adhoc-query.component.scss new file mode 100644 index 000000000..9b40653e2 --- /dev/null +++ b/src/app/organization/adhoc-query/adhoc-query.component.scss @@ -0,0 +1,15 @@ +table { + width: 100%; + + .select-row:hover { + cursor: pointer; + } +} + +.true { + color: #32cd32; +} + +.false { + color: #f44366; +} diff --git a/src/app/organization/adhoc-query/adhoc-query.component.spec.ts b/src/app/organization/adhoc-query/adhoc-query.component.spec.ts new file mode 100644 index 000000000..7bb8b8ed9 --- /dev/null +++ b/src/app/organization/adhoc-query/adhoc-query.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AdhocQueryComponent } from './adhoc-query.component'; + +describe('AdhocQueryComponent', () => { + let component: AdhocQueryComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ AdhocQueryComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(AdhocQueryComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/organization/adhoc-query/adhoc-query.component.ts b/src/app/organization/adhoc-query/adhoc-query.component.ts new file mode 100644 index 000000000..0fab9d9d5 --- /dev/null +++ b/src/app/organization/adhoc-query/adhoc-query.component.ts @@ -0,0 +1,79 @@ +/** Angular Imports */ +import { Component, OnInit, ViewChild } from '@angular/core'; +import { MatTableDataSource, MatPaginator, MatSort } from '@angular/material'; +import { ActivatedRoute } from '@angular/router'; + +/** rxjs Imports */ +import { of } from 'rxjs'; + +/** + * Adhoc Query component. + */ +@Component({ + selector: 'mifosx-adhoc-query', + templateUrl: './adhoc-query.component.html', + styleUrls: ['./adhoc-query.component.scss'] +}) +export class AdhocQueryComponent implements OnInit { + + /** Adhoc Queries data. */ + adhocQueriesData: any; + /** Columns to be displayed in adhoc queries table. */ + displayedColumns: string[] = ['name', 'query', 'tableName', 'email', 'reportRunFrequency', 'isActive', 'createdBy']; + /** Data source for adhoc queries table. */ + dataSource: MatTableDataSource; + + /** Paginator for adhoc queries table. */ + @ViewChild(MatPaginator) paginator: MatPaginator; + /** Sorter for adhoc queries table. */ + @ViewChild(MatSort) sort: MatSort; + + /** + * Retrieves the adhoc queries data from `resolve`. + * @param {ActivatedRoute} route Activated Route. + */ + constructor(private route: ActivatedRoute) { + this.route.data.subscribe(( data: { adhocQueries: any }) => { + this.adhocQueriesData = data.adhocQueries; + }); + } + + /** + * Filters data in adhoc queries table based on passed value. + * @param {string} filterValue Value to filter data. + */ + applyFilter(filterValue: string) { + this.dataSource.filter = filterValue.trim().toLowerCase(); + } + + /** + * Sets the adhoc queries table. + */ + ngOnInit() { + this.setAdhocQueries(); + this.setReportRunFrequency(); + } + + /** + * Sets report run frequency to its corresponding values + */ + setReportRunFrequency() { + for (let i = 0; i < this.adhocQueriesData.length; i++) { + for (let j = 0; j < this.adhocQueriesData[i].reportRunFrequencies.length; j++) { + if (this.adhocQueriesData[i].reportRunFrequencies[j].id === this.adhocQueriesData[i].reportRunFrequency) { + this.adhocQueriesData[i].reportRunFrequency = this.adhocQueriesData[i].reportRunFrequencies[j].value; + } + } + } + } + + /** + * Initializes the data source, paginator and sorter for adhoc queries table. + */ + setAdhocQueries() { + this.dataSource = new MatTableDataSource(this.adhocQueriesData); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + } + +} diff --git a/src/app/organization/organization-routing.module.ts b/src/app/organization/organization-routing.module.ts index 9beb93ded..f191802de 100644 --- a/src/app/organization/organization-routing.module.ts +++ b/src/app/organization/organization-routing.module.ts @@ -15,6 +15,7 @@ import { OfficesComponent } from './offices/offices.component'; import { EmployeesComponent } from './employees/employees.component'; import { CurrenciesComponent } from './currencies/currencies.component'; import { SmsCampaignsComponent } from './sms-campaigns/sms-campaigns.component'; +import { AdhocQueryComponent } from './adhoc-query/adhoc-query.component'; /** Custom Resolvers */ import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver'; @@ -22,6 +23,7 @@ import { OfficesResolver } from './offices/offices.resolver'; import { EmployeesResolver } from './employees/employees.resolver'; import { CurrenciesResolver } from './currencies/currencies.resolver'; import { SmsCampaignsResolver } from './sms-campaigns/sms-campaigns.resolver'; +import { AdhocQueriesResolver } from './adhoc-query/adhoc-queries.resolver'; /** Organization Routes */ const routes: Routes = [ @@ -73,6 +75,19 @@ const routes: Routes = [ resolve: { smsCampaigns: SmsCampaignsResolver } + }, + { + path: 'adhoc-query', + data: { title: extract('Adhoc Query'), breadcrumb: 'Adhoc Query' }, + children: [ + { + path: '', + component: AdhocQueryComponent, + resolve: { + adhocQueries: AdhocQueriesResolver + } + } + ] } ] } @@ -92,7 +107,8 @@ const routes: Routes = [ OfficesResolver, EmployeesResolver, CurrenciesResolver, - SmsCampaignsResolver + SmsCampaignsResolver, + AdhocQueriesResolver ] }) export class OrganizationRoutingModule { } diff --git a/src/app/organization/organization.component.html b/src/app/organization/organization.component.html index 732261f42..fc8c34088 100644 --- a/src/app/organization/organization.component.html +++ b/src/app/organization/organization.component.html @@ -137,7 +137,7 @@

Define SMS Campaigns for Organization

- + diff --git a/src/app/organization/organization.module.ts b/src/app/organization/organization.module.ts index 93c24f46a..7c37f5fc8 100644 --- a/src/app/organization/organization.module.ts +++ b/src/app/organization/organization.module.ts @@ -13,6 +13,7 @@ import { OfficesComponent } from './offices/offices.component'; import { EmployeesComponent } from './employees/employees.component'; import { CurrenciesComponent } from './currencies/currencies.component'; import { SmsCampaignsComponent } from './sms-campaigns/sms-campaigns.component'; +import { AdhocQueryComponent } from './adhoc-query/adhoc-query.component'; /** * Organization Module @@ -31,7 +32,8 @@ import { SmsCampaignsComponent } from './sms-campaigns/sms-campaigns.component'; OfficesComponent, EmployeesComponent, CurrenciesComponent, - SmsCampaignsComponent + SmsCampaignsComponent, + AdhocQueryComponent ] }) export class OrganizationModule { } diff --git a/src/app/organization/organization.service.ts b/src/app/organization/organization.service.ts index d1d0299d0..d6bd99396 100644 --- a/src/app/organization/organization.service.ts +++ b/src/app/organization/organization.service.ts @@ -53,4 +53,11 @@ export class OrganizationService { return this.http.get('/smscampaigns'); } + /** + * @returns {Observable} Adhoc Queries data + */ + getAdhocQueries(): Observable { + return this.http.get('/adhocquery'); + } + }