@@ -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 'app/organization/organization.service';
|
||||
|
||||
/**
|
||||
* Adhoc Query template data resolver.
|
||||
*/
|
||||
@Injectable()
|
||||
export class AdhocQueryTemplateResolver implements Resolve<Object> {
|
||||
|
||||
/**
|
||||
* @param {OrganizationService} organizationService Organization service.
|
||||
*/
|
||||
constructor(private organizationService: OrganizationService) {}
|
||||
|
||||
/**
|
||||
* Returns the adhoc query template data.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
resolve(): Observable<any> {
|
||||
return this.organizationService.getAdhocQueryTemplate();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class="container m-b-20" fxLayout="row" fxLayoutAlign="end" fxLayoutGap="20px">
|
||||
<button mat-raised-button color="primary">
|
||||
<button mat-raised-button color="primary" [routerLink]="['create']">
|
||||
<fa-icon icon="plus"></fa-icon>
|
||||
Create AdHoc Query
|
||||
</button>
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
<div class="container">
|
||||
|
||||
<mat-card>
|
||||
|
||||
<form [formGroup]="adhocQueryForm" (ngSubmit)="submit()">
|
||||
|
||||
<mat-card-content>
|
||||
|
||||
<div fxLayout="column">
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput required formControlName="name">
|
||||
<mat-error *ngIf="adhocQueryForm.controls.name.hasError('required')">
|
||||
Name is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>SQL Query</mat-label>
|
||||
<textarea matInput required formControlName="query"></textarea>
|
||||
<mat-error *ngIf="adhocQueryForm.controls.query.hasError('required')">
|
||||
SQL Query is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Insert into table</mat-label>
|
||||
<input matInput required formControlName="tableName">
|
||||
<mat-error *ngIf="adhocQueryForm.controls.tableName.hasError('required')">
|
||||
Insert into table is <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Table Fields</mat-label>
|
||||
<textarea matInput required formControlName="tableFields"></textarea>
|
||||
<mat-error *ngIf="adhocQueryForm.controls.tableFields.hasError('required')">
|
||||
Table Fields are <strong>required</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Email</mat-label>
|
||||
<input matInput formControlName="email">
|
||||
<mat-error *ngIf="adhocQueryForm.controls.email.hasError('email')">
|
||||
Email is <strong>invalid</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field>
|
||||
<mat-label>Report Run Frequency</mat-label>
|
||||
<mat-select formControlName="reportRunFrequency">
|
||||
<mat-option *ngFor="let reportRunFrequency of reportRunFrequencyData" [value]="reportRunFrequency.id">
|
||||
{{ reportRunFrequency.value }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field *ngIf="adhocQueryForm.controls.reportRunFrequency.value === 5">
|
||||
<mat-label>Custom Report Run Frequency (Days)</mat-label>
|
||||
<input type="number" matInput required formControlName="reportRunEvery">
|
||||
<mat-error *ngIf="adhocQueryForm.controls.reportRunEvery.hasError('required')">
|
||||
Custom Report Run Frequency is <strong>required</strong>
|
||||
</mat-error>
|
||||
<mat-error *ngIf="adhocQueryForm.controls.reportRunEvery.hasError('min')">
|
||||
Custom Report Run Frequency <strong>must be larger than 0</strong>
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
|
||||
<mat-checkbox labelPosition="before" formControlName="isActive">
|
||||
Active
|
||||
</mat-checkbox>
|
||||
|
||||
</div>
|
||||
|
||||
</mat-card-content>
|
||||
|
||||
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
|
||||
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
|
||||
<button mat-raised-button color="primary" [disabled]="!adhocQueryForm.valid">Submit</button>
|
||||
</mat-card-actions>
|
||||
|
||||
</form>
|
||||
|
||||
</mat-card>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,3 @@
|
||||
.container {
|
||||
max-width: 37rem;
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CreateAdhocQueryComponent } from './create-adhoc-query.component';
|
||||
|
||||
describe('CreateAdhocQueryComponent', () => {
|
||||
let component: CreateAdhocQueryComponent;
|
||||
let fixture: ComponentFixture<CreateAdhocQueryComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ CreateAdhocQueryComponent ]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(CreateAdhocQueryComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,89 @@
|
||||
/** Angular Imports */
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
|
||||
/** Custom Services */
|
||||
import { OrganizationService } from '../../organization.service';
|
||||
|
||||
/**
|
||||
* Create Adhoc Query component.
|
||||
*/
|
||||
@Component({
|
||||
selector: 'mifosx-create-adhoc-query',
|
||||
templateUrl: './create-adhoc-query.component.html',
|
||||
styleUrls: ['./create-adhoc-query.component.scss']
|
||||
})
|
||||
export class CreateAdhocQueryComponent implements OnInit {
|
||||
|
||||
/** Adhoc Query form. */
|
||||
adhocQueryForm: FormGroup;
|
||||
/** Adhoc Query template data. */
|
||||
adhocQueryTemplateData: any;
|
||||
/** Report run frequencies data. */
|
||||
reportRunFrequencyData: any;
|
||||
|
||||
/**
|
||||
* Retrieves the adhoc query template data from `resolve`.
|
||||
* @param {FormBuilder} formBuilder Form Builder.
|
||||
* @param {OrganizationService} organizationService Organization Service.
|
||||
* @param {ActivatedRoute} route Activated Route.
|
||||
* @param {Router} router Router for navigation.
|
||||
*/
|
||||
constructor(private formBuilder: FormBuilder,
|
||||
private organizationService: OrganizationService,
|
||||
private route: ActivatedRoute,
|
||||
private router: Router) {
|
||||
this.route.data.subscribe((data: { adhocQueryTemplate: any }) => {
|
||||
this.adhocQueryTemplateData = data.adhocQueryTemplate;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the adhoc query form and sets the conditional controls of the adhoc query form.
|
||||
*/
|
||||
ngOnInit() {
|
||||
this.createAdhocQueryForm();
|
||||
this.setConditionalControls();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the adhoc query form.
|
||||
*/
|
||||
createAdhocQueryForm() {
|
||||
this.reportRunFrequencyData = this.adhocQueryTemplateData.reportRunFrequencies;
|
||||
this.adhocQueryForm = this.formBuilder.group({
|
||||
'name': ['', Validators.required],
|
||||
'query': ['', Validators.required],
|
||||
'tableName': ['', Validators.required],
|
||||
'tableFields': ['', Validators.required],
|
||||
'email': ['', Validators.email],
|
||||
'reportRunFrequency': [''],
|
||||
'isActive': [false]
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the conditional controls of the adhoc query form
|
||||
*/
|
||||
setConditionalControls() {
|
||||
this.adhocQueryForm.get('reportRunFrequency').valueChanges.subscribe(reportRunFrequencyId => {
|
||||
if (reportRunFrequencyId === 5) {
|
||||
this.adhocQueryForm.addControl('reportRunEvery', new FormControl('', [Validators.required, Validators.min(1)]));
|
||||
} else {
|
||||
this.adhocQueryForm.removeControl('reportRunEvery');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits the adhoc query form and creates adhoc query,
|
||||
* if successful redirects to view adhoc query.
|
||||
*/
|
||||
submit() {
|
||||
this.organizationService.createAdhocQuery(this.adhocQueryForm.value).subscribe((response: any) => {
|
||||
this.router.navigate(['../', response.resourceId], { relativeTo: this.route });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import { EntityDataTableChecksComponent } from './entity-data-table-checks/entit
|
||||
import { WorkingDaysComponent } from './working-days/working-days.component';
|
||||
import { CreateOfficeComponent } from './offices/create-office/create-office.component';
|
||||
import { CreatePaymentTypeComponent } from './payment-types/create-payment-type/create-payment-type.component';
|
||||
import { CreateAdhocQueryComponent } from './adhoc-query/create-adhoc-query/create-adhoc-query.component';
|
||||
|
||||
/** Custom Resolvers */
|
||||
import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver';
|
||||
@@ -45,6 +46,7 @@ import { PaymentTypeResolver } from './payment-types/payment-type.resolver';
|
||||
import { PasswordPreferencesTemplateResolver } from './password-preferences/password-preferences-template.resolver';
|
||||
import { EntityDataTableChecksResolver } from './entity-data-table-checks/entity-data-table-checks.resolver';
|
||||
import { WorkingDaysResolver } from './working-days/working-days.resolver';
|
||||
import { AdhocQueryTemplateResolver } from './adhoc-query/adhoc-query-template.resolver';
|
||||
|
||||
/** Organization Routes */
|
||||
const routes: Routes = [
|
||||
@@ -142,6 +144,14 @@ const routes: Routes = [
|
||||
adhocQueries: AdhocQueriesResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'create',
|
||||
component: CreateAdhocQueryComponent,
|
||||
data: { title: extract('Create Adhoc Query'), breadcrumb: 'Create' },
|
||||
resolve: {
|
||||
adhocQueryTemplate: AdhocQueryTemplateResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: ViewAdhocQueryComponent,
|
||||
@@ -261,7 +271,8 @@ const routes: Routes = [
|
||||
PaymentTypeResolver,
|
||||
PasswordPreferencesTemplateResolver,
|
||||
EntityDataTableChecksResolver,
|
||||
WorkingDaysResolver
|
||||
WorkingDaysResolver,
|
||||
AdhocQueryTemplateResolver
|
||||
]
|
||||
})
|
||||
export class OrganizationRoutingModule { }
|
||||
|
||||
@@ -26,6 +26,7 @@ import { CreateOfficeComponent } from './offices/create-office/create-office.com
|
||||
import { CreateEmployeeComponent } from './employees/create-employee/create-employee.component';
|
||||
import { CreatePaymentTypeComponent } from './payment-types/create-payment-type/create-payment-type.component';
|
||||
import { ViewEmployeeComponent } from './employees/view-employee/view-employee.component';
|
||||
import { CreateAdhocQueryComponent } from './adhoc-query/create-adhoc-query/create-adhoc-query.component';
|
||||
|
||||
/**
|
||||
* Organization Module
|
||||
@@ -57,7 +58,8 @@ import { ViewEmployeeComponent } from './employees/view-employee/view-employee.c
|
||||
CreateOfficeComponent,
|
||||
CreateEmployeeComponent,
|
||||
CreatePaymentTypeComponent,
|
||||
ViewEmployeeComponent
|
||||
ViewEmployeeComponent,
|
||||
CreateAdhocQueryComponent
|
||||
]
|
||||
})
|
||||
export class OrganizationModule { }
|
||||
|
||||
@@ -92,6 +92,21 @@ export class OrganizationService {
|
||||
return this.http.get(`/adhocquery/${adhocQueryId}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Observable<any>} Adhoc query Template data
|
||||
*/
|
||||
getAdhocQueryTemplate(): Observable<any> {
|
||||
return this.http.get(`/adhocquery/template`);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any} adhocQuery Adhoc Query to be created.
|
||||
* @returns {Observable<any>}
|
||||
*/
|
||||
createAdhocQuery(adhocQuery: any): Observable<any> {
|
||||
return this.http.post('/adhocquery', adhocQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} adhocQueryId Adhoc Query ID of adhoc query to be deleted.
|
||||
* @returns {Observable<any>}
|
||||
|
||||
Reference in New Issue
Block a user