Move the FormControl declaration inside the component

This commit is contained in:
mauriziovitale84
2016-10-11 10:43:35 +01:00
parent c65ebbcb29
commit 1783e0d2c9
3 changed files with 23 additions and 15 deletions

View File

@@ -50,7 +50,7 @@
</div>
</div>
<br><br>
<button type="submit" class="mdl-button mdl-js-button mdl-button--fab" (click)="createReport()" >
<button type="submit" class="mdl-button mdl-js-button mdl-button--fab" (click)="showReport()" >
<i class="material-icons">refresh</i>
</button>
<div *ngIf="debug">

View File

@@ -20,8 +20,7 @@ import { AlfrescoTranslationService } from 'ng2-alfresco-core';
import { AnalyticsService } from '../services/analytics.service';
import { ReportModel, ReportQuery, ParameterValueModel, ReportParameterModel } from '../models/report.model';
import { Chart } from '../models/chart.model';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import * as moment from 'moment';
import { FormGroup, FormBuilder } from '@angular/forms';
@Component({
moduleId: module.id,
@@ -63,12 +62,8 @@ export class AnalyticsComponent implements OnInit, OnChanges {
}
ngOnInit() {
let today = moment().format('YYYY-MM-DD');
this.reportForm = this.formBuilder.group({
dateRange: this.formBuilder.group({
startDate: [today, Validators.required],
endDate: [today, Validators.required]
})
dateRange: new FormGroup({})
});
}
@@ -86,33 +81,36 @@ export class AnalyticsComponent implements OnInit, OnChanges {
(res: ReportModel) => {
this.reportDetails = res;
if (this.reportDetails.hasParameters()) {
this.retriveParameterOptions(this.reportDetails.definition.parameters);
this.retrieveParameterOptions(this.reportDetails.definition.parameters);
} else {
this.onSuccess.emit(res);
}
this.onSuccess.emit(res);
},
(err: any) => {
this.onError.emit(err);
console.log(err);
this.onError.emit(err);
},
() => console.log('Login done')
() => console.log('retrive done')
);
}
private retriveParameterOptions(parameters: ReportParameterModel[]) {
private retrieveParameterOptions(parameters: ReportParameterModel[]) {
parameters.forEach((param) => {
this.analyticsService.getParamValuesByType(param.type).subscribe(
(opts: ParameterValueModel[]) => {
param.options = opts;
this.onSuccess.emit(this.reportDetails);
},
(err: any) => {
console.log(err);
this.onError.emit(err);
},
() => console.log(`${param.type} options loaded`)
);
});
}
public createReport() {
public showReport() {
this.analyticsService.getReportsByParams(this.reportDetails.id, this.reportParamQuery).subscribe(
(res: Chart[]) => {
this.reports = res;

View File

@@ -16,7 +16,7 @@
*/
import { Component, Input, Output, EventEmitter, ViewChild, ElementRef } from '@angular/core';
import { AbstractControl, FormGroup, FormBuilder } from '@angular/forms';
import { AbstractControl, FormGroup, FormBuilder, FormControl, Validators } from '@angular/forms';
import { WidgetComponent } from './../widget.component';
import * as moment from 'moment';
@@ -78,6 +78,16 @@ export class DateRangeWidget extends WidgetComponent {
}
initForm() {
let today = moment().format('YYYY-MM-DD');
let startDateControl = new FormControl(today);
startDateControl.setValidators(Validators.required);
this.dateRange.addControl('startDate', startDateControl);
let endDateControl = new FormControl(today);
endDateControl.setValidators(Validators.required);
this.dateRange.addControl('endDate', endDateControl);
this.dateRange.setValidators(dateCheck);
this.dateRange.valueChanges.subscribe(data => this.onGroupValueChanged(data));
}