diff --git a/src/app/organization/adhoc-query/adhoc-query.component.html b/src/app/organization/adhoc-query/adhoc-query.component.html index 6c10648dc..78748d061 100644 --- a/src/app/organization/adhoc-query/adhoc-query.component.html +++ b/src/app/organization/adhoc-query/adhoc-query.component.html @@ -58,7 +58,7 @@ - + diff --git a/src/app/organization/adhoc-query/adhoc-query.resolver.ts b/src/app/organization/adhoc-query/adhoc-query.resolver.ts new file mode 100644 index 000000000..f4ec3096a --- /dev/null +++ b/src/app/organization/adhoc-query/adhoc-query.resolver.ts @@ -0,0 +1,31 @@ +/** Angular Imports */ +import { Injectable } from '@angular/core'; +import { Resolve, ActivatedRouteSnapshot } from '@angular/router'; + +/** rxjs Imports */ +import { Observable } from 'rxjs'; + +/** Custom Services */ +import { OrganizationService } from 'app/organization/organization.service'; + +/** + * Adhoc Query data resolver. + */ +@Injectable() +export class AdhocQueryResolver implements Resolve { + + /** + * @param {OrganizationService} organizationService Organization service. + */ + constructor(private organizationService: OrganizationService) {} + + /** + * Returns the adhoc query data. + * @returns {Observable} + */ + resolve(route: ActivatedRouteSnapshot): Observable { + const adhocQueryId = route.paramMap.get('id'); + return this.organizationService.getAdhocQuery(adhocQueryId); + } + +} diff --git a/src/app/organization/adhoc-query/view-adhoc-query/view-adhoc-query.component.html b/src/app/organization/adhoc-query/view-adhoc-query/view-adhoc-query.component.html new file mode 100644 index 000000000..2d78f7877 --- /dev/null +++ b/src/app/organization/adhoc-query/view-adhoc-query/view-adhoc-query.component.html @@ -0,0 +1,74 @@ +
+ + +
+ +
+ + + + + +
+ +
+ Name +
+ +
+ {{ adhocQueryData.name }} +
+ +
+ Query +
+ +
+ {{ adhocQueryData.query }} +
+ +
+ Table Affected +
+ +
+ {{ adhocQueryData.tableName }} +
+ +
+ Report Run Frequency +
+ +
+ {{ adhocQueryData.reportRunFrequency }} +
+ +
+ Status +
+ +
+ {{ adhocQueryData.isActive === true ? 'Active' : 'Inactive' }} +
+ +
+ Created By +
+ +
+ {{ adhocQueryData.createdBy }} +
+ +
+ +
+ +
+ +
diff --git a/src/app/organization/adhoc-query/view-adhoc-query/view-adhoc-query.component.scss b/src/app/organization/adhoc-query/view-adhoc-query/view-adhoc-query.component.scss new file mode 100644 index 000000000..46cf44760 --- /dev/null +++ b/src/app/organization/adhoc-query/view-adhoc-query/view-adhoc-query.component.scss @@ -0,0 +1,10 @@ +.container { + max-width: 37rem; + + .content { + div { + margin: 1rem 0; + word-wrap: break-word; + } + } +} diff --git a/src/app/organization/adhoc-query/view-adhoc-query/view-adhoc-query.component.spec.ts b/src/app/organization/adhoc-query/view-adhoc-query/view-adhoc-query.component.spec.ts new file mode 100644 index 000000000..517d5c42e --- /dev/null +++ b/src/app/organization/adhoc-query/view-adhoc-query/view-adhoc-query.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ViewAdhocQueryComponent } from './view-adhoc-query.component'; + +describe('ViewAdhocQueryComponent', () => { + let component: ViewAdhocQueryComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ViewAdhocQueryComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ViewAdhocQueryComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/organization/adhoc-query/view-adhoc-query/view-adhoc-query.component.ts b/src/app/organization/adhoc-query/view-adhoc-query/view-adhoc-query.component.ts new file mode 100644 index 000000000..9be43652b --- /dev/null +++ b/src/app/organization/adhoc-query/view-adhoc-query/view-adhoc-query.component.ts @@ -0,0 +1,61 @@ +/** Angular Imports */ +import { Component, OnInit } from '@angular/core'; +import { ActivatedRoute, Router } from '@angular/router'; +import { MatDialog } from '@angular/material'; + +/** Custom Services */ +import { OrganizationService } from 'app/organization/organization.service'; + +/** Custom Components */ +import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component'; + +/** + * View Adhoc Query Component. + */ +@Component({ + selector: 'mifosx-view-adhoc-query', + templateUrl: './view-adhoc-query.component.html', + styleUrls: ['./view-adhoc-query.component.scss'] +}) +export class ViewAdhocQueryComponent implements OnInit { + + /** Adhoc query data. */ + adhocQueryData: any; + + /** + * Retrieves the adhoc query data from `resolve`. + * @param {OrganizationService} organizationService Organization Service. + * @param {ActivatedRoute} route Activated Route. + * @param {Router} router Router for navigation. + * @param {MatDialog} dialog Dialog reference. + */ + constructor(private organizationService: OrganizationService, + private route: ActivatedRoute, + private router: Router, + private dialog: MatDialog) { + this.route.data.subscribe((data: { adhocQuery: any }) => { + this.adhocQueryData = data.adhocQuery; + }); + } + + ngOnInit() { + } + + /** + * Deletes the adhoc query and redirects to adhoc queries. + */ + deleteAdhocQuery() { + const deleteAdhocQueryDialogRef = this.dialog.open(DeleteDialogComponent, { + data: { deleteContext: `adhoc query ${this.adhocQueryData.id}` } + }); + deleteAdhocQueryDialogRef.afterClosed().subscribe((response: any) => { + if (response.delete) { + this.organizationService.deleteAdhocQuery(this.adhocQueryData.id) + .subscribe(() => { + this.router.navigate(['/organization/adhoc-query']); + }); + } + }); + } + +} diff --git a/src/app/organization/organization-routing.module.ts b/src/app/organization/organization-routing.module.ts index 3cb69db8e..b9369d48e 100644 --- a/src/app/organization/organization-routing.module.ts +++ b/src/app/organization/organization-routing.module.ts @@ -18,6 +18,7 @@ import { ViewEmployeeComponent } from './employees/view-employee/view-employee.c import { CurrenciesComponent } from './currencies/currencies.component'; import { SmsCampaignsComponent } from './sms-campaigns/sms-campaigns.component'; import { AdhocQueryComponent } from './adhoc-query/adhoc-query.component'; +import { ViewAdhocQueryComponent } from './adhoc-query/view-adhoc-query/view-adhoc-query.component'; import { TellersComponent } from './tellers/tellers.component'; import { PaymentTypesComponent } from './payment-types/payment-types.component'; import { PasswordPreferencesComponent } from './password-preferences/password-preferences.component'; @@ -34,6 +35,7 @@ import { EmployeeResolver } from './employees/employee.resolver'; import { CurrenciesResolver } from './currencies/currencies.resolver'; import { SmsCampaignsResolver } from './sms-campaigns/sms-campaigns.resolver'; import { AdhocQueriesResolver } from './adhoc-query/adhoc-queries.resolver'; +import { AdhocQueryResolver } from './adhoc-query/adhoc-query.resolver'; import { TellersResolver } from './tellers/tellers.resolver'; import { PaymentTypesResolver } from './payment-types/payment-types.resolver'; import { PasswordPreferencesTemplateResolver } from './password-preferences/password-preferences-template.resolver'; @@ -135,6 +137,14 @@ const routes: Routes = [ resolve: { adhocQueries: AdhocQueriesResolver } + }, + { + path: ':id', + component: ViewAdhocQueryComponent, + data: { title: extract('View Adhoc Query'), routeResolveBreadcrumb: ['adhocQuery', 'name']}, + resolve: { + adhocQuery: AdhocQueryResolver + } } ] }, @@ -209,6 +219,7 @@ const routes: Routes = [ CurrenciesResolver, SmsCampaignsResolver, AdhocQueriesResolver, + AdhocQueryResolver, TellersResolver, PaymentTypesResolver, PasswordPreferencesTemplateResolver, diff --git a/src/app/organization/organization.module.ts b/src/app/organization/organization.module.ts index 3f2ddd717..b676e0564 100644 --- a/src/app/organization/organization.module.ts +++ b/src/app/organization/organization.module.ts @@ -14,6 +14,7 @@ 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'; +import { ViewAdhocQueryComponent } from './adhoc-query/view-adhoc-query/view-adhoc-query.component'; import { TellersComponent } from './tellers/tellers.component'; import { PaymentTypesComponent } from './payment-types/payment-types.component'; import { PasswordPreferencesComponent } from './password-preferences/password-preferences.component'; @@ -43,6 +44,7 @@ import { ViewEmployeeComponent } from './employees/view-employee/view-employee.c CurrenciesComponent, SmsCampaignsComponent, AdhocQueryComponent, + ViewAdhocQueryComponent, TellersComponent, PaymentTypesComponent, PasswordPreferencesComponent, diff --git a/src/app/organization/organization.service.ts b/src/app/organization/organization.service.ts index dadbbf37b..573c7130f 100644 --- a/src/app/organization/organization.service.ts +++ b/src/app/organization/organization.service.ts @@ -84,6 +84,22 @@ export class OrganizationService { return this.http.get('/adhocquery'); } + /** + * @param {string} adhocQueryId Adhoc Query ID of adhoc query. + * @returns {Observable} Adhoc query. + */ + getAdhocQuery(adhocQueryId: string): Observable { + return this.http.get(`/adhocquery/${adhocQueryId}`); + } + + /** + * @param {string} adhocQueryId Adhoc Query ID of adhoc query to be deleted. + * @returns {Observable} + */ + deleteAdhocQuery(adhocQueryId: string): Observable { + return this.http.delete(`/adhocquery/${adhocQueryId}`); + } + /** * @returns {Observable} Tellers data */