mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Add createDefaultReports feature
This commit is contained in:
@@ -81,6 +81,40 @@ describe('Test ng2-activiti-analytics Report list', () => {
|
|||||||
expect(component.isReportsEmpty()).toBeTruthy();
|
expect(component.isReportsEmpty()).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return the default reports when the report list is empty', (done) => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
component.onSuccess.subscribe(() => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(element.querySelector('#report-list-0 > i').innerHTML).toBe('assignment');
|
||||||
|
expect(element.querySelector('#report-list-0 > span').innerHTML).toBe('Fake Test Process definition heat map');
|
||||||
|
expect(element.querySelector('#report-list-1 > span').innerHTML).toBe('Fake Test Process definition overview');
|
||||||
|
expect(element.querySelector('#report-list-2 > span').innerHTML).toBe('Fake Test Process instances overview');
|
||||||
|
expect(element.querySelector('#report-list-3 > span').innerHTML).toBe('Fake Test Task overview');
|
||||||
|
expect(element.querySelector('#report-list-4 > span').innerHTML).toBe('Fake Test Task service level agreement');
|
||||||
|
expect(component.isReportsEmpty()).toBeFalsy();
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: []
|
||||||
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: []
|
||||||
|
});
|
||||||
|
|
||||||
|
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||||
|
status: 200,
|
||||||
|
contentType: 'json',
|
||||||
|
responseText: reportList
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('Report render the report list relative to a single app', (done) => {
|
it('Report render the report list relative to a single app', (done) => {
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
@@ -60,13 +60,20 @@ export class AnalyticsReportListComponent implements OnInit {
|
|||||||
this.getReportListByAppId();
|
this.getReportListByAppId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the report list by app id
|
||||||
|
*/
|
||||||
getReportListByAppId() {
|
getReportListByAppId() {
|
||||||
this.analyticsService.getReportList().subscribe(
|
this.analyticsService.getReportList().subscribe(
|
||||||
(res: ReportParametersModel[]) => {
|
(res: ReportParametersModel[]) => {
|
||||||
res.forEach((report) => {
|
if (res && res.length === 0) {
|
||||||
this.reportObserver.next(report);
|
this.createDefaultReports();
|
||||||
});
|
} else {
|
||||||
this.onSuccess.emit(res);
|
res.forEach((report) => {
|
||||||
|
this.reportObserver.next(report);
|
||||||
|
});
|
||||||
|
this.onSuccess.emit(res);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
(err: any) => {
|
(err: any) => {
|
||||||
this.onError.emit(err);
|
this.onError.emit(err);
|
||||||
@@ -75,6 +82,28 @@ export class AnalyticsReportListComponent implements OnInit {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the default reports and return the report list
|
||||||
|
*/
|
||||||
|
createDefaultReports() {
|
||||||
|
this.analyticsService.createDefaultReports().subscribe(
|
||||||
|
() => {
|
||||||
|
this.analyticsService.getReportList().subscribe(
|
||||||
|
(response: ReportParametersModel[]) => {
|
||||||
|
response.forEach((report) => {
|
||||||
|
this.reportObserver.next(report);
|
||||||
|
});
|
||||||
|
this.onSuccess.emit(response);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the report list is empty
|
||||||
|
* @returns {boolean|ReportParametersModel[]}
|
||||||
|
*/
|
||||||
isReportsEmpty(): boolean {
|
isReportsEmpty(): boolean {
|
||||||
return this.reports === undefined || (this.reports && this.reports.length === 0);
|
return this.reports === undefined || (this.reports && this.reports.length === 0);
|
||||||
}
|
}
|
||||||
|
@@ -46,9 +46,6 @@ export class AnalyticsService {
|
|||||||
let reportModel = new ReportParametersModel(report);
|
let reportModel = new ReportParametersModel(report);
|
||||||
reports.push(reportModel);
|
reports.push(reportModel);
|
||||||
});
|
});
|
||||||
if (body && body.length === 0) {
|
|
||||||
return this.createDefaultReports();
|
|
||||||
}
|
|
||||||
return reports;
|
return reports;
|
||||||
}).catch(this.handleError);
|
}).catch(this.handleError);
|
||||||
}
|
}
|
||||||
@@ -215,9 +212,15 @@ export class AnalyticsService {
|
|||||||
}).catch(this.handleError);
|
}).catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
public createDefaultReports(): ReportParametersModel[] {
|
public createDefaultReports(): Observable<any> {
|
||||||
let reports: ReportParametersModel[] = [];
|
let url = `${this.alfrescoSettingsService.getBPMApiBaseUrl()}/app/rest/reporting/default-reports`;
|
||||||
return reports;
|
let options = this.getRequestOptions();
|
||||||
|
let body = {};
|
||||||
|
return this.http
|
||||||
|
.post(url, body, options)
|
||||||
|
.map((res: any) => {
|
||||||
|
return res;
|
||||||
|
}).catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getHeaders(): Headers {
|
public getHeaders(): Headers {
|
||||||
|
Reference in New Issue
Block a user