[ADF-242] Fixed behaviour for saving/deleting reports (#1905)

* [ADF-242] - fix for deleting - saving a report

* [ADF - 242] added test for fixed feature on reports save - delete

* Added translation key
This commit is contained in:
Vito
2017-05-26 09:07:59 -07:00
committed by Eugenio Romano
parent 7b17b10ef1
commit 6e3e3ab5b7
9 changed files with 67 additions and 25 deletions

View File

@@ -167,9 +167,12 @@
[reportId]="report.id"
[hideParameters]="false"
(editReport)="onEditReport($event)"
(reportSaved)="onReportSaved()"
(reportSaved)="onReportSaved($event)"
(reportDeleted)="onReportDeleted()">
</activiti-analytics>
<div *ngIf="!report">
<span>{{'ANALYTICS_REPORT.NO_REPORT_MESSAGE' | translate}}</span>
</div>
</div>
</div>
</div>

View File

@@ -209,13 +209,13 @@ export class ActivitiDemoComponent implements AfterViewInit {
this.analyticsreportlist.reload();
}
onReportSaved() {
this.analyticsreportlist.reload();
onReportSaved(reportId) {
this.analyticsreportlist.reload(reportId);
}
onReportDeleted() {
this.selectFirstReport = true;
this.analyticsreportlist.reload();
this.analyticsreportlist.selectReport(null);
}
navigateStartProcess() {

View File

@@ -21,5 +21,8 @@
"CUSTOM": "Custom action"
}
}
},
"ANALYTICS_REPORT":{
"NO_REPORT_MESSAGE":"No report selected. Choose a report from the list"
}
}

View File

@@ -57,7 +57,9 @@ describe('AnalyticsReportListComponent', () => {
let translateService = TestBed.get(AlfrescoTranslationService);
spyOn(translateService, 'addTranslationFolder').and.stub();
spyOn(translateService, 'get').and.callFake((key) => { return Observable.of(key); });
spyOn(translateService, 'get').and.callFake((key) => {
return Observable.of(key);
});
}));
beforeEach(() => {
@@ -197,6 +199,27 @@ describe('AnalyticsReportListComponent', () => {
});
});
it('Should reload the report list and select the report with the given id', (done) => {
component.initObserver();
expect(component.reports.length).toEqual(0);
component.reload(2002);
component.onSuccess.subscribe(() => {
expect(component.reports.length).toEqual(5);
expect(component.currentReport).toBeDefined();
expect(component.currentReport).not.toBeNull();
expect(component.currentReport.id).toEqual(2002);
done();
});
jasmine.Ajax.requests.mostRecent().respondWith({
status: 200,
contentType: 'json',
responseText: reportList
});
});
});
describe('layout', () => {

View File

@@ -76,15 +76,15 @@ export class AnalyticsReportListComponent implements OnInit {
/**
* Reload the component
*/
reload() {
reload(reportId?) {
this.reset();
this.getReportList(this.appId);
this.getReportList(this.appId, reportId);
}
/**
* Get the report list
*/
getReportList(appId: string) {
getReportList(appId: string, reportId?: string) {
this.analyticsService.getReportList(appId).subscribe(
(res: ReportParametersModel[]) => {
if (res && res.length === 0) {
@@ -93,6 +93,10 @@ export class AnalyticsReportListComponent implements OnInit {
res.forEach((report) => {
this.reportObserver.next(report);
});
if (reportId) {
console.log('SELEZIONO IL REPORT!');
this.selectReportByReportId(reportId);
}
if (this.selectFirst) {
this.selectFirstReport();
}
@@ -149,6 +153,14 @@ export class AnalyticsReportListComponent implements OnInit {
this.reportClick.emit(report);
}
public selectReportByReportId(reportId) {
let reportFound = this.reports.find(report => report.id === reportId);
if (reportFound) {
this.currentReport = reportFound;
this.reportClick.emit(reportFound);
}
}
selectFirstReport() {
this.selectReport(this.reports[0]);
this.selectFirst = false;

View File

@@ -483,7 +483,7 @@ describe('AnalyticsReportParametersComponent', () => {
validForm = true;
});
xit('Should be able to change the report title', (done) => {
it('Should be able to change the report title', (done) => {
let title: HTMLElement = element.querySelector('h4');
title.click();
@@ -514,9 +514,10 @@ describe('AnalyticsReportParametersComponent', () => {
});
it('Should show a dialog to allowing report save', async(() => {
component.saveReportSuccess.subscribe(() => {
component.saveReportSuccess.subscribe((repId) => {
let reportDialogTitle: HTMLElement = <HTMLElement>element.querySelector('#report-dialog');
expect(reportDialogTitle.getAttribute('open')).toBeNull();
expect(repId).toBe('1');
});
component.submit(values);

View File

@@ -372,7 +372,7 @@ export class AnalyticsReportParametersComponent implements OnInit, OnChanges, On
doSave(paramQuery: ReportQuery) {
this.analyticsService.saveReport(this.reportId, paramQuery).subscribe(() => {
this.saveReportSuccess.emit();
this.saveReportSuccess.emit(this.reportId);
});
}

View File

@@ -3,7 +3,7 @@
[hideComponent]="hideParameters"
(onFormValueChanged)="reset()"
(onSuccess)="showReport($event)"
(saveReportSuccess)="onSaveReportSuccess()"
(saveReportSuccess)="onSaveReportSuccess($event)"
(deleteReportSuccess)="onDeleteReportSuccess()"
(onEdit)="onEditReport($event)">
</analytics-report-parameters>

View File

@@ -79,8 +79,8 @@ export class AnalyticsComponent implements OnChanges {
this.editReport.emit(name);
}
public onSaveReportSuccess() {
this.reportSaved.emit();
public onSaveReportSuccess(reportId) {
this.reportSaved.emit(reportId);
}
public onDeleteReportSuccess() {