feat: add view adhoc query component (#548)

Fixes: #538
This commit is contained in:
Rishabh Verma
2020-01-06 07:07:16 +05:30
committed by Jivjyot Singh
parent df12a6b4ba
commit 24dd42ec37
9 changed files with 231 additions and 1 deletions
@@ -58,7 +58,7 @@
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;" [routerLink]="[row.id]" class="select-row"></tr>
</table>
@@ -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<Object> {
/**
* @param {OrganizationService} organizationService Organization service.
*/
constructor(private organizationService: OrganizationService) {}
/**
* Returns the adhoc query data.
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const adhocQueryId = route.paramMap.get('id');
return this.organizationService.getAdhocQuery(adhocQueryId);
}
}
@@ -0,0 +1,74 @@
<div fxLayout="row" fxLayoutAlign="end" fxLayoutGap="2%" fxLayout.lt-md="column" class="container m-b-20">
<button mat-raised-button color="primary">
<fa-icon icon="edit"></fa-icon>&nbsp;&nbsp;
Edit
</button>
<button mat-raised-button color="warn" (click)="deleteAdhocQuery()">
<fa-icon icon="trash"></fa-icon>&nbsp;&nbsp;
Delete
</button>
</div>
<div class="container">
<mat-card>
<mat-card-content>
<div fxLayout="row wrap" class="content">
<div fxFlex="50%" class="mat-body-strong">
Name
</div>
<div fxFlex="50%">
{{ adhocQueryData.name }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Query
</div>
<div fxFlex="50%">
{{ adhocQueryData.query }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Table Affected
</div>
<div fxFlex="50%">
{{ adhocQueryData.tableName }}
</div>
<div fxFlex="50%" class="mat-body-strong" *ngIf="adhocQueryData.reportRunFrequency">
Report Run Frequency
</div>
<div fxFlex="50%" *ngIf="adhocQueryData.reportRunFrequency">
{{ adhocQueryData.reportRunFrequency }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Status
</div>
<div fxFlex="50%">
{{ adhocQueryData.isActive === true ? 'Active' : 'Inactive' }}
</div>
<div fxFlex="50%" class="mat-body-strong">
Created By
</div>
<div fxFlex="50%">
{{ adhocQueryData.createdBy }}
</div>
</div>
</mat-card-content>
</mat-card>
</div>
@@ -0,0 +1,10 @@
.container {
max-width: 37rem;
.content {
div {
margin: 1rem 0;
word-wrap: break-word;
}
}
}
@@ -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<ViewAdhocQueryComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ViewAdhocQueryComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ViewAdhocQueryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -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']);
});
}
});
}
}