+1
-1
@@ -6,7 +6,7 @@ import { Resolve } from '@angular/router';
|
|||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
/** Custom Services */
|
/** Custom Services */
|
||||||
import { OrganizationService } from '../organization.service';
|
import { OrganizationService } from '../../organization.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adhoc Queries data resolver.
|
* Adhoc Queries data resolver.
|
||||||
+31
@@ -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 and template data resolver.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class AdhocQueryAndTemplateResolver implements Resolve<Object> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OrganizationService} organizationService Organization service.
|
||||||
|
*/
|
||||||
|
constructor(private organizationService: OrganizationService) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the adhoc query and template data.
|
||||||
|
* @returns {Observable<any>}
|
||||||
|
*/
|
||||||
|
resolve(route: ActivatedRouteSnapshot): Observable<any> {
|
||||||
|
const adhocQueryId = route.paramMap.get('id');
|
||||||
|
return this.organizationService.getAdhocQueryAndTemplate(adhocQueryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
<div class="container">
|
||||||
|
|
||||||
|
<mat-card>
|
||||||
|
|
||||||
|
<form [formGroup]="editAdhocQueryForm" (ngSubmit)="submit()">
|
||||||
|
|
||||||
|
<mat-card-content>
|
||||||
|
|
||||||
|
<div fxLayout="column">
|
||||||
|
|
||||||
|
<mat-form-field>
|
||||||
|
<mat-label>Name</mat-label>
|
||||||
|
<input matInput required formControlName="name">
|
||||||
|
<mat-error *ngIf="editAdhocQueryForm.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="editAdhocQueryForm.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="editAdhocQueryForm.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="editAdhocQueryForm.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="editAdhocQueryForm.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="editAdhocQueryForm.controls.reportRunFrequency.value === 5">
|
||||||
|
<mat-label>Custom Report Run Frequency (Days)</mat-label>
|
||||||
|
<input type="number" matInput required formControlName="reportRunEvery">
|
||||||
|
<mat-error *ngIf="editAdhocQueryForm.controls.reportRunEvery.hasError('required')">
|
||||||
|
Custom Report Run Frequency is <strong>required</strong>
|
||||||
|
</mat-error>
|
||||||
|
<mat-error *ngIf="editAdhocQueryForm.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]="!editAdhocQueryForm.valid">Submit</button>
|
||||||
|
</mat-card-actions>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</mat-card>
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
.container {
|
||||||
|
max-width: 37rem;
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { EditAdhocQueryComponent } from './edit-adhoc-query.component';
|
||||||
|
|
||||||
|
describe('EditAdhocQueryComponent', () => {
|
||||||
|
let component: EditAdhocQueryComponent;
|
||||||
|
let fixture: ComponentFixture<EditAdhocQueryComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ EditAdhocQueryComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(EditAdhocQueryComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
/** 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';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Edit Adhoc Query component.
|
||||||
|
*/
|
||||||
|
@Component({
|
||||||
|
selector: 'mifosx-edit-adhoc-query',
|
||||||
|
templateUrl: './edit-adhoc-query.component.html',
|
||||||
|
styleUrls: ['./edit-adhoc-query.component.scss']
|
||||||
|
})
|
||||||
|
export class EditAdhocQueryComponent implements OnInit {
|
||||||
|
|
||||||
|
/** Edit Adhoc Query form. */
|
||||||
|
editAdhocQueryForm: 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: { adhocQueryAndTemplate: any }) => {
|
||||||
|
this.adhocQueryTemplateData = data.adhocQueryAndTemplate;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the edit adhoc query form and sets the conditional controls of the adhoc query form.
|
||||||
|
*/
|
||||||
|
ngOnInit() {
|
||||||
|
this.createEditAdhocQueryForm();
|
||||||
|
this.setConditionalControls();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the edit adhoc query form.
|
||||||
|
*/
|
||||||
|
createEditAdhocQueryForm() {
|
||||||
|
this.reportRunFrequencyData = this.adhocQueryTemplateData.reportRunFrequencies;
|
||||||
|
this.editAdhocQueryForm = this.formBuilder.group({
|
||||||
|
'name': [this.adhocQueryTemplateData.name, Validators.required],
|
||||||
|
'query': [this.adhocQueryTemplateData.query, Validators.required],
|
||||||
|
'tableName': [this.adhocQueryTemplateData.tableName, Validators.required],
|
||||||
|
'tableFields': [this.adhocQueryTemplateData.tableFields, Validators.required],
|
||||||
|
'email': [this.adhocQueryTemplateData.email, Validators.email],
|
||||||
|
'reportRunFrequency': [''],
|
||||||
|
'isActive': [this.adhocQueryTemplateData.isActive]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the conditional controls of the adhoc query form
|
||||||
|
*/
|
||||||
|
setConditionalControls() {
|
||||||
|
this.editAdhocQueryForm.get('reportRunFrequency').valueChanges.subscribe(reportRunFrequencyId => {
|
||||||
|
if (reportRunFrequencyId === 5) {
|
||||||
|
this.editAdhocQueryForm.addControl('reportRunEvery', new FormControl('', [Validators.required, Validators.min(1)]));
|
||||||
|
this.editAdhocQueryForm.get('reportRunEvery').patchValue(this.adhocQueryTemplateData.reportRunEvery);
|
||||||
|
} else {
|
||||||
|
this.editAdhocQueryForm.removeControl('reportRunEvery');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.editAdhocQueryForm.get('reportRunFrequency').patchValue(this.adhocQueryTemplateData.reportRunFrequency);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Submits the adhoc query form and updates adhoc query,
|
||||||
|
* if successful redirects to view adhoc query.
|
||||||
|
*/
|
||||||
|
submit() {
|
||||||
|
this.organizationService.updateAdhocQuery(this.adhocQueryTemplateData.id, this.editAdhocQueryForm.value).subscribe(() => {
|
||||||
|
this.router.navigate(['../'], { relativeTo: this.route });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<div fxLayout="row" fxLayoutAlign="end" fxLayoutGap="2%" fxLayout.lt-md="column" class="container m-b-20">
|
<div fxLayout="row" fxLayoutAlign="end" fxLayoutGap="2%" fxLayout.lt-md="column" class="container m-b-20">
|
||||||
<button mat-raised-button color="primary">
|
<button mat-raised-button color="primary" [routerLink]="['edit']">
|
||||||
<fa-icon icon="edit"></fa-icon>
|
<fa-icon icon="edit"></fa-icon>
|
||||||
Edit
|
Edit
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ import { SettleCashComponent } from './tellers/cashiers/settle-cash/settle-cash.
|
|||||||
import { EditCashierComponent } from './tellers/cashiers/edit-cashier/edit-cashier.component';
|
import { EditCashierComponent } from './tellers/cashiers/edit-cashier/edit-cashier.component';
|
||||||
import { CreateCashierComponent } from './tellers/cashiers/create-cashier/create-cashier.component';
|
import { CreateCashierComponent } from './tellers/cashiers/create-cashier/create-cashier.component';
|
||||||
import { EditHolidayComponent } from './holidays/edit-holiday/edit-holiday.component';
|
import { EditHolidayComponent } from './holidays/edit-holiday/edit-holiday.component';
|
||||||
|
import { EditAdhocQueryComponent } from './adhoc-query/edit-adhoc-query/edit-adhoc-query.component';
|
||||||
|
|
||||||
/** Custom Resolvers */
|
/** Custom Resolvers */
|
||||||
import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver';
|
import { LoanProvisioningCriteriaResolver } from './loan-provisioning-criteria/loan-provisioning-criteria.resolver';
|
||||||
@@ -57,8 +58,8 @@ import { EmployeeResolver } from './employees/employee.resolver';
|
|||||||
import { EditEmployeeResolver } from './employees/edit-employee.resolver';
|
import { EditEmployeeResolver } from './employees/edit-employee.resolver';
|
||||||
import { CurrenciesResolver } from './currencies/currencies.resolver';
|
import { CurrenciesResolver } from './currencies/currencies.resolver';
|
||||||
import { SmsCampaignsResolver } from './sms-campaigns/common-resolvers/sms-campaigns.resolver';
|
import { SmsCampaignsResolver } from './sms-campaigns/common-resolvers/sms-campaigns.resolver';
|
||||||
import { AdhocQueriesResolver } from './adhoc-query/adhoc-queries.resolver';
|
import { AdhocQueriesResolver } from './adhoc-query/common-resolvers/adhoc-queries.resolver';
|
||||||
import { AdhocQueryResolver } from './adhoc-query/adhoc-query.resolver';
|
import { AdhocQueryResolver } from './adhoc-query/common-resolvers/adhoc-query.resolver';
|
||||||
import { TellersResolver } from './tellers/common-resolvers/tellers.resolver';
|
import { TellersResolver } from './tellers/common-resolvers/tellers.resolver';
|
||||||
import { TellerResolver } from './tellers/common-resolvers/teller.resolver';
|
import { TellerResolver } from './tellers/common-resolvers/teller.resolver';
|
||||||
import { PaymentTypesResolver } from './payment-types/payment-types.resolver';
|
import { PaymentTypesResolver } from './payment-types/payment-types.resolver';
|
||||||
@@ -82,6 +83,7 @@ import { ManageFundsResolver } from './manage-funds/manage-funds.resolver';
|
|||||||
import { CashierTransactionTemplateResolver } from './tellers/teller-transaction-template.resolver';
|
import { CashierTransactionTemplateResolver } from './tellers/teller-transaction-template.resolver';
|
||||||
import { EditCashierResolver } from './tellers/common-resolvers/edit-cashier.resolver';
|
import { EditCashierResolver } from './tellers/common-resolvers/edit-cashier.resolver';
|
||||||
import { HolidayTemplateResolver } from './holidays/holiday-template.resolver';
|
import { HolidayTemplateResolver } from './holidays/holiday-template.resolver';
|
||||||
|
import { AdhocQueryAndTemplateResolver } from './adhoc-query/common-resolvers/adhoc-query-and-template.resolver';
|
||||||
|
|
||||||
/** Organization Routes */
|
/** Organization Routes */
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
@@ -288,11 +290,24 @@ const routes: Routes = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: ':id',
|
path: ':id',
|
||||||
component: ViewAdhocQueryComponent,
|
data: { title: extract('View Adhoc Query'), routeParamBreadcrumb: 'id' },
|
||||||
data: { title: extract('View Adhoc Query'), routeResolveBreadcrumb: ['adhocQuery', 'name']},
|
children: [
|
||||||
resolve: {
|
{
|
||||||
adhocQuery: AdhocQueryResolver
|
path: '',
|
||||||
}
|
component: ViewAdhocQueryComponent,
|
||||||
|
resolve: {
|
||||||
|
adhocQuery: AdhocQueryResolver
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'edit',
|
||||||
|
component: EditAdhocQueryComponent,
|
||||||
|
data: { title: extract('Edit Adhoc Query'), breadcrumb: 'Edit', routeParamBreadcrumb: false },
|
||||||
|
resolve: {
|
||||||
|
adhocQueryAndTemplate: AdhocQueryAndTemplateResolver
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -543,6 +558,7 @@ const routes: Routes = [
|
|||||||
WorkingDaysResolver,
|
WorkingDaysResolver,
|
||||||
EditOfficeResolver,
|
EditOfficeResolver,
|
||||||
AdhocQueryTemplateResolver,
|
AdhocQueryTemplateResolver,
|
||||||
|
AdhocQueryAndTemplateResolver,
|
||||||
LoanProvisioningCriteriasResolver,
|
LoanProvisioningCriteriasResolver,
|
||||||
CashierResolver,
|
CashierResolver,
|
||||||
CashiersResolver,
|
CashiersResolver,
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import { AllocateCashComponent } from './tellers/cashiers/allocate-cash/allocate
|
|||||||
import { EditCashierComponent } from './tellers/cashiers/edit-cashier/edit-cashier.component';
|
import { EditCashierComponent } from './tellers/cashiers/edit-cashier/edit-cashier.component';
|
||||||
import { CreateCashierComponent } from './tellers/cashiers/create-cashier/create-cashier.component';
|
import { CreateCashierComponent } from './tellers/cashiers/create-cashier/create-cashier.component';
|
||||||
import { EditHolidayComponent } from './holidays/edit-holiday/edit-holiday.component';
|
import { EditHolidayComponent } from './holidays/edit-holiday/edit-holiday.component';
|
||||||
|
import { EditAdhocQueryComponent } from './adhoc-query/edit-adhoc-query/edit-adhoc-query.component';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Organization Module
|
* Organization Module
|
||||||
@@ -108,6 +109,7 @@ import { EditHolidayComponent } from './holidays/edit-holiday/edit-holiday.compo
|
|||||||
EditCashierComponent,
|
EditCashierComponent,
|
||||||
CreateCashierComponent,
|
CreateCashierComponent,
|
||||||
EditHolidayComponent,
|
EditHolidayComponent,
|
||||||
|
EditAdhocQueryComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class OrganizationModule { }
|
export class OrganizationModule { }
|
||||||
|
|||||||
@@ -225,6 +225,15 @@ export class OrganizationService {
|
|||||||
return this.http.get(`/adhocquery/template`);
|
return this.http.get(`/adhocquery/template`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} adhocQueryId Adhoc Query ID of adhoc query.
|
||||||
|
* @returns {Observable<any>} Adhoc query and template.
|
||||||
|
*/
|
||||||
|
getAdhocQueryAndTemplate(adhocQueryId: string): Observable<any> {
|
||||||
|
const httpParams = new HttpParams().set('template', 'true');
|
||||||
|
return this.http.get(`/adhocquery/${adhocQueryId}`, { params: httpParams });
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {any} adhocQuery Adhoc Query to be created.
|
* @param {any} adhocQuery Adhoc Query to be created.
|
||||||
* @returns {Observable<any>}
|
* @returns {Observable<any>}
|
||||||
@@ -233,6 +242,15 @@ export class OrganizationService {
|
|||||||
return this.http.post('/adhocquery', adhocQuery);
|
return this.http.post('/adhocquery', adhocQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {any} queryId Query Id
|
||||||
|
* @param {any} adhocQuery Adhoc Query to be created.
|
||||||
|
* @returns {Observable<any>}
|
||||||
|
*/
|
||||||
|
updateAdhocQuery(queryId: any, adhocQuery: any): Observable<any> {
|
||||||
|
return this.http.put(`/adhocquery/${queryId}`, adhocQuery);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} adhocQueryId Adhoc Query ID of adhoc query to be deleted.
|
* @param {string} adhocQueryId Adhoc Query ID of adhoc query to be deleted.
|
||||||
* @returns {Observable<any>}
|
* @returns {Observable<any>}
|
||||||
|
|||||||
Reference in New Issue
Block a user