Add reports filter by appId

This commit is contained in:
mauriziovitale84
2016-10-12 20:16:25 +01:00
parent f23bb3e4c3
commit 72e33756fb
5 changed files with 98 additions and 35 deletions

View File

@@ -69,7 +69,7 @@
<analytics-report-list (reportClick)="onReportClick($event)"></analytics-report-list>
</div>
<div class="mdl-cell mdl-cell--8-col task-column mdl-shadow--2dp">
<activiti-analytics *ngIf="report" [reportId]="report.id"></activiti-analytics>
<activiti-analytics [appId]="appId" *ngIf="report" [reportId]="report.id"></activiti-analytics>
</div>
</div>
</div>

View File

@@ -69,7 +69,8 @@ export var reportDefParamProcessDef = {
'definition': '{ "parameters" :[{"id":"processDefinitionId","name":null,"nameKey":null,"type":"processDefinition","value":null,"dependsOn":null}]}'
};
export var reportDefParamProcessDefOptions = [
export var reportDefParamProcessDefOptions = {
'size': 4, 'total': 4, 'start': 0, 'data': [
{
'id': 'FakeProcessTest 1:1:1',
'name': 'Fake Process Test 1 Name ',
@@ -90,7 +91,23 @@ export var reportDefParamProcessDefOptions = [
'name': 'Fake Process Test 3 Name ',
'version': 1
}
];
]
};
export var reportDefParamProcessDefOptionsApp = {
'size': 2, 'total': 2, 'start': 2, 'data': [
{
'id': 'FakeProcessTest 1:1:1',
'name': 'Fake Process Test 1 Name ',
'version': 1
},
{
'id': 'FakeProcessTest 1:2:1',
'name': 'Fake Process Test 1 Name ',
'version': 2
}
]
};
export var reportDefParamTask = {
'id': 2006,

View File

@@ -33,8 +33,8 @@ import { DebugElement, SimpleChange } from '@angular/core';
import {
reportDefParamCheck, reportDefParamDateRange, chartProcessDefOverview, chartTaskOverview, fieldDateRange,
fieldDateRangeInterval, fieldDuration, fieldNumber, fieldProcessDef, fieldStatus, fieldTask, fieldTypeFiltering,
reportDefParamDuration, reportDefParamNumber, reportDefParamTaskOptions, reportDefParamStatus,
reportDefParamRangeInterval, reportDefParamProcessDef, reportDefParamProcessDefOptions, reportDefParamTask
reportDefParamDuration, reportDefParamNumber, reportDefParamTaskOptions, reportDefParamStatus, reportDefParamRangeInterval,
reportDefParamProcessDef, reportDefParamProcessDefOptions, reportDefParamProcessDefOptionsApp, reportDefParamTask
} from '../assets/analyticsComponent.mock';
export const ANALYTICS_DIRECTIVES: any[] = [
@@ -255,7 +255,9 @@ describe('Test ng2-activiti-analytics Report ', () => {
});
});
it('Should render a dropdown with all the process definition when the definition parameter type is \'processDefinition\' ', (done) => {
it('Should render a dropdown with all the process definition when the definition parameter type is \'processDefinition\' and the' +
' reportId change' +
' ', (done) => {
fixture.detectChanges();
component.onSuccessParamOpt.subscribe(() => {
@@ -289,6 +291,41 @@ describe('Test ng2-activiti-analytics Report ', () => {
});
it('Should render a dropdown with all the process definition when the definition parameter type is \'processDefinition\' and the' +
' appId change' +
' ', (done) => {
fixture.detectChanges();
component.onSuccessParamOpt.subscribe(() => {
fixture.detectChanges();
let dropDown: any = element.querySelector('#select-processDefinitionId');
expect(dropDown).toBeDefined();
expect(dropDown.length).toEqual(3);
expect(dropDown[0].innerHTML).toEqual('Choose One');
expect(dropDown[1].innerHTML).toEqual('Fake Process Test 1 Name (v 1) ');
expect(dropDown[2].innerHTML).toEqual('Fake Process Test 1 Name (v 2) ');
done();
});
let appId = 1;
component.appId = appId;
let change = new SimpleChange(null, appId);
component.ngOnChanges({ 'appId': change });
jasmine.Ajax.requests.first().respondWith({
status: 200,
contentType: 'json',
responseText: reportDefParamProcessDef
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: reportDefParamProcessDefOptionsApp
});
});
it('Should render the Process definition overview report ', (done) => {
fixture.detectChanges();

View File

@@ -33,6 +33,9 @@ export class AnalyticsComponent implements OnInit, OnChanges {
@ViewChild('processDefinition')
processDefinition: any;
@Input()
appId: string;
@Input()
reportId: string;
@@ -85,13 +88,13 @@ export class AnalyticsComponent implements OnInit, OnChanges {
this.dropDownSub = this.onDropdownChanged.subscribe((field) => {
let paramDependOn: ReportParameterModel = this.reportDetails.definition.parameters.find(p => p.dependsOn === field.id);
if (paramDependOn) {
this.retrieveParameterOptions(this.reportDetails.definition.parameters, this.reportId, field.value);
this.retrieveParameterOptions(this.reportDetails.definition.parameters, this.appId, this.reportId, field.value);
}
});
this.paramOpts = this.onSuccessParamsReport.subscribe((report: ReportModel) => {
if (report.hasParameters()) {
this.retrieveParameterOptions(report.definition.parameters);
this.retrieveParameterOptions(report.definition.parameters, this.appId);
}
});
}
@@ -102,6 +105,12 @@ export class AnalyticsComponent implements OnInit, OnChanges {
this.getParamsReports(reportId.currentValue);
return;
}
let appId = changes['appId'];
if (appId && (appId.currentValue || appId.currentValue === null)) {
this.getParamsReports(this.reportId);
return;
}
}
public getParamsReports(reportId: string) {
@@ -119,9 +128,9 @@ export class AnalyticsComponent implements OnInit, OnChanges {
);
}
private retrieveParameterOptions(parameters: ReportParameterModel[], reportId?: string, processDefinitionId?: string) {
private retrieveParameterOptions(parameters: ReportParameterModel[], appId: string, reportId?: string, processDefinitionId?: string) {
parameters.forEach((param) => {
this.analyticsService.getParamValuesByType(param.type, this.reportId, processDefinitionId).subscribe(
this.analyticsService.getParamValuesByType(param.type, appId, reportId, processDefinitionId).subscribe(
(opts: ParameterValueModel[]) => {
param.options = opts;
this.onSuccessParamOpt.emit(opts);

View File

@@ -64,11 +64,11 @@ export class AnalyticsService {
}).catch(this.handleError);
}
getParamValuesByType(type: string, reportId?: string, processDefinitionId?: string) {
getParamValuesByType(type: string, appId: string, reportId?: string, processDefinitionId?: string) {
if (type === 'status') {
return this.getProcessStatusValues();
} else if (type === 'processDefinition') {
return this.getProcessDefinitionsValues();
return this.getProcessDefinitionsValues(appId);
} else if (type === 'dateInterval') {
return this.getDateIntervalValues();
} else if (type === 'task') {
@@ -109,8 +109,8 @@ export class AnalyticsService {
});
}
getProcessDefinitionsValues(appId?: string): Observable<any> {
let url = `${this.alfrescoSettingsService.getBPMApiBaseUrl()}/app/rest/reporting/process-definitions`;
getProcessDefinitionsValues(appId: string): Observable<any> {
let url = `${this.alfrescoSettingsService.getBPMApiBaseUrl()}/app/rest/process-definitions`;
let params: URLSearchParams;
if (appId) {
params = new URLSearchParams();
@@ -122,7 +122,7 @@ export class AnalyticsService {
.map((res: any) => {
let paramOptions: ParameterValueModel[] = [];
let body = res.json();
body.forEach((opt) => {
body.data.forEach((opt) => {
paramOptions.push(new ParameterValueModel(opt));
});
return paramOptions;