+19
-17
@@ -83,32 +83,34 @@ export class EditBusinessRuleParametersComponent implements OnChanges {
|
||||
} else { // Child Parameter
|
||||
const parent: ReportParameter = this.paramData
|
||||
.find((entry: any) => entry.name === param.parentParameterName);
|
||||
// TODO: Refactor once Report Parameter Model is updated for multi-child support.
|
||||
if (parent.childParameter instanceof Array) {
|
||||
parent.childParameter.push(param);
|
||||
} else {
|
||||
parent.childParameter = [];
|
||||
parent.childParameter.push(param);
|
||||
}
|
||||
const parentNames = this.parentParameters.map(parameter => parameter.name);
|
||||
if (!parentNames.includes(parent.name)) {
|
||||
this.parentParameters.push(parent);
|
||||
} else {
|
||||
const index = parentNames.indexOf(parent.name);
|
||||
this.parentParameters[index] = parent;
|
||||
}
|
||||
parent.childParameters.push(param);
|
||||
this.updateParentParameters(parent);
|
||||
}
|
||||
});
|
||||
this.setChildControls();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the array of parent parameters.
|
||||
* @param {ReportParameter} parent Parent report parameter
|
||||
*/
|
||||
updateParentParameters(parent: ReportParameter) {
|
||||
const parentNames = this.parentParameters.map(parameter => parameter.name);
|
||||
if (!parentNames.includes(parent.name)) { // Parent's first child.
|
||||
this.parentParameters.push(parent);
|
||||
} else { // Parent already has a child
|
||||
const index = parentNames.indexOf(parent.name);
|
||||
this.parentParameters[index] = parent;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribes to changes in parent parameters value, builds child parameter vis-a-vis parent's value.
|
||||
*/
|
||||
setChildControls() {
|
||||
this.parentParameters.forEach((param: ReportParameter) => {
|
||||
this.ReportForm.get(param.name).valueChanges.subscribe((option: any) => {
|
||||
param.childParameter.forEach((child: ReportParameter) => {
|
||||
param.childParameters.forEach((child: ReportParameter) => {
|
||||
if (child.displayType === 'none') {
|
||||
this.ReportForm.addControl(child.name, new FormControl(child.defaultVal));
|
||||
} else {
|
||||
@@ -183,10 +185,10 @@ export class EditBusinessRuleParametersComponent implements OnChanges {
|
||||
* TODO: Replace report object with report name once reports service is refactored.
|
||||
*/
|
||||
getResponseHeaders() {
|
||||
const report = { name: this.paramValue.reportName };
|
||||
const reportName = this.paramValue.reportName;
|
||||
delete this.paramValue.reportName;
|
||||
const formattedResponse = this.formatUserResponse(this.paramValue, true);
|
||||
this.reportsService.getRunReportData(report, formattedResponse).subscribe(
|
||||
this.reportsService.getRunReportData(reportName, formattedResponse).subscribe(
|
||||
(response: any) => {
|
||||
this.templateParameters.emit(response.columnHeaders);
|
||||
},
|
||||
|
||||
+19
-17
@@ -69,7 +69,7 @@ export class BusinessRuleParametersComponent implements OnChanges {
|
||||
createRunReportForm() {
|
||||
this.paramData.forEach(
|
||||
(param: any) => {
|
||||
if (!param.parentParameterName) { // Non Child Parameter
|
||||
if (!param.parentParameterName) { // Non-Child Parameter
|
||||
this.ReportForm.addControl(param.name, new FormControl('', Validators.required));
|
||||
if (param.displayType === 'select') {
|
||||
this.fetchSelectOptions(param, param.name);
|
||||
@@ -77,32 +77,34 @@ export class BusinessRuleParametersComponent implements OnChanges {
|
||||
} else { // Child Parameter
|
||||
const parent: ReportParameter = this.paramData
|
||||
.find((entry: any) => entry.name === param.parentParameterName);
|
||||
// TODO: Refactor once Report Parameter Model is updated for multi-child support.
|
||||
if (parent.childParameter instanceof Array) {
|
||||
parent.childParameter.push(param);
|
||||
} else {
|
||||
parent.childParameter = [];
|
||||
parent.childParameter.push(param);
|
||||
}
|
||||
const parentNames = this.parentParameters.map(parameter => parameter.name);
|
||||
if (!parentNames.includes(parent.name)) {
|
||||
this.parentParameters.push(parent);
|
||||
} else {
|
||||
const index = parentNames.indexOf(parent.name);
|
||||
this.parentParameters[index] = parent;
|
||||
}
|
||||
parent.childParameters.push(param);
|
||||
this.updateParentParameters(parent);
|
||||
}
|
||||
});
|
||||
this.setChildControls();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the array of parent parameters.
|
||||
* @param {ReportParameter} parent Parent report parameter
|
||||
*/
|
||||
updateParentParameters(parent: ReportParameter) {
|
||||
const parentNames = this.parentParameters.map(parameter => parameter.name);
|
||||
if (!parentNames.includes(parent.name)) { // Parent's first child.
|
||||
this.parentParameters.push(parent);
|
||||
} else { // Parent already has a child
|
||||
const index = parentNames.indexOf(parent.name);
|
||||
this.parentParameters[index] = parent;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribes to changes in parent parameters value, builds child parameter vis-a-vis parent's value.
|
||||
*/
|
||||
setChildControls() {
|
||||
this.parentParameters.forEach((param: ReportParameter) => {
|
||||
this.ReportForm.get(param.name).valueChanges.subscribe((option: any) => {
|
||||
param.childParameter.forEach((child: ReportParameter) => {
|
||||
param.childParameters.forEach((child: ReportParameter) => {
|
||||
if (child.displayType === 'none') {
|
||||
this.ReportForm.addControl(child.name, new FormControl(child.defaultVal));
|
||||
} else {
|
||||
@@ -168,7 +170,7 @@ export class BusinessRuleParametersComponent implements OnChanges {
|
||||
*/
|
||||
getResponseHeaders() {
|
||||
const formattedresponse = this.formatUserResponse(this.ReportForm.value, true);
|
||||
this.reportsService.getRunReportData({ name: this.reportName }, formattedresponse).subscribe(
|
||||
this.reportsService.getRunReportData(this.reportName, formattedresponse).subscribe(
|
||||
(response: any) => {
|
||||
this.templateParameters.emit(response.columnHeaders);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user