@@ -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 });
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user