[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" [reportId]="report.id"
[hideParameters]="false" [hideParameters]="false"
(editReport)="onEditReport($event)" (editReport)="onEditReport($event)"
(reportSaved)="onReportSaved()" (reportSaved)="onReportSaved($event)"
(reportDeleted)="onReportDeleted()"> (reportDeleted)="onReportDeleted()">
</activiti-analytics> </activiti-analytics>
<div *ngIf="!report">
<span>{{'ANALYTICS_REPORT.NO_REPORT_MESSAGE' | translate}}</span>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -115,8 +115,8 @@ export class ActivitiDemoComponent implements AfterViewInit {
this.dataProcesses = new ObjectDataTableAdapter( this.dataProcesses = new ObjectDataTableAdapter(
[], [],
[ [
{type: 'text', key: 'name', title: 'Name', cssClass: 'full-width name-column', sortable: true}, { type: 'text', key: 'name', title: 'Name', cssClass: 'full-width name-column', sortable: true },
{type: 'text', key: 'started', title: 'Started', cssClass: 'hidden', sortable: true} { type: 'text', key: 'started', title: 'Started', cssClass: 'hidden', sortable: true }
] ]
); );
this.dataProcesses.setSorting(new DataSorting('started', 'desc')); this.dataProcesses.setSorting(new DataSorting('started', 'desc'));
@@ -209,13 +209,13 @@ export class ActivitiDemoComponent implements AfterViewInit {
this.analyticsreportlist.reload(); this.analyticsreportlist.reload();
} }
onReportSaved() { onReportSaved(reportId) {
this.analyticsreportlist.reload(); this.analyticsreportlist.reload(reportId);
} }
onReportDeleted() { onReportDeleted() {
this.selectFirstReport = true;
this.analyticsreportlist.reload(); this.analyticsreportlist.reload();
this.analyticsreportlist.selectReport(null);
} }
navigateStartProcess() { navigateStartProcess() {

View File

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

View File

@@ -28,14 +28,14 @@ declare let jasmine: any;
describe('AnalyticsReportListComponent', () => { describe('AnalyticsReportListComponent', () => {
let reportList = [ let reportList = [
{'id': 2002, 'name': 'Fake Test Process definition heat map'}, { 'id': 2002, 'name': 'Fake Test Process definition heat map' },
{'id': 2003, 'name': 'Fake Test Process definition overview'}, { 'id': 2003, 'name': 'Fake Test Process definition overview' },
{'id': 2004, 'name': 'Fake Test Process instances overview'}, { 'id': 2004, 'name': 'Fake Test Process instances overview' },
{'id': 2005, 'name': 'Fake Test Task overview'}, { 'id': 2005, 'name': 'Fake Test Task overview' },
{'id': 2006, 'name': 'Fake Test Task service level agreement'} { 'id': 2006, 'name': 'Fake Test Task service level agreement' }
]; ];
let reportSelected = {'id': 2003, 'name': 'Fake Test Process definition overview'}; let reportSelected = { 'id': 2003, 'name': 'Fake Test Process definition overview' };
let component: AnalyticsReportListComponent; let component: AnalyticsReportListComponent;
let fixture: ComponentFixture<AnalyticsReportListComponent>; let fixture: ComponentFixture<AnalyticsReportListComponent>;
@@ -57,7 +57,9 @@ describe('AnalyticsReportListComponent', () => {
let translateService = TestBed.get(AlfrescoTranslationService); let translateService = TestBed.get(AlfrescoTranslationService);
spyOn(translateService, 'addTranslationFolder').and.stub(); 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(() => { beforeEach(() => {
@@ -174,13 +176,13 @@ describe('AnalyticsReportListComponent', () => {
it('Should return false if the current report is different', () => { it('Should return false if the current report is different', () => {
component.selectReport(reportSelected); component.selectReport(reportSelected);
let anotherReport = {'id': 111, 'name': 'Another Fake Test Process definition overview'}; let anotherReport = { 'id': 111, 'name': 'Another Fake Test Process definition overview' };
expect(component.isSelected(anotherReport)).toBe(false); expect(component.isSelected(anotherReport)).toBe(false);
}); });
it('Should reload the report list', (done) => { it('Should reload the report list', (done) => {
component.initObserver(); component.initObserver();
let report = new ReportParametersModel({'id': 2002, 'name': 'Fake Test Process definition heat map'}); let report = new ReportParametersModel({ 'id': 2002, 'name': 'Fake Test Process definition heat map' });
component.reports = [report]; component.reports = [report];
expect(component.reports.length).toEqual(1); expect(component.reports.length).toEqual(1);
component.reload(); component.reload();
@@ -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', () => { describe('layout', () => {

View File

@@ -26,7 +26,7 @@ import { ReportParametersModel } from '../models/report.model';
templateUrl: './analytics-report-list.component.html', templateUrl: './analytics-report-list.component.html',
styleUrls: ['./analytics-report-list.component.css'] styleUrls: ['./analytics-report-list.component.css']
}) })
export class AnalyticsReportListComponent implements OnInit { export class AnalyticsReportListComponent implements OnInit {
public static LAYOUT_LIST: string = 'LIST'; public static LAYOUT_LIST: string = 'LIST';
public static LAYOUT_GRID: string = 'GRID'; public static LAYOUT_GRID: string = 'GRID';
@@ -76,15 +76,15 @@ export class AnalyticsReportListComponent implements OnInit {
/** /**
* Reload the component * Reload the component
*/ */
reload() { reload(reportId?) {
this.reset(); this.reset();
this.getReportList(this.appId); this.getReportList(this.appId, reportId);
} }
/** /**
* Get the report list * Get the report list
*/ */
getReportList(appId: string) { getReportList(appId: string, reportId?: string) {
this.analyticsService.getReportList(appId).subscribe( this.analyticsService.getReportList(appId).subscribe(
(res: ReportParametersModel[]) => { (res: ReportParametersModel[]) => {
if (res && res.length === 0) { if (res && res.length === 0) {
@@ -93,6 +93,10 @@ export class AnalyticsReportListComponent implements OnInit {
res.forEach((report) => { res.forEach((report) => {
this.reportObserver.next(report); this.reportObserver.next(report);
}); });
if (reportId) {
console.log('SELEZIONO IL REPORT!');
this.selectReportByReportId(reportId);
}
if (this.selectFirst) { if (this.selectFirst) {
this.selectFirstReport(); this.selectFirstReport();
} }
@@ -149,6 +153,14 @@ export class AnalyticsReportListComponent implements OnInit {
this.reportClick.emit(report); 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() { selectFirstReport() {
this.selectReport(this.reports[0]); this.selectReport(this.reports[0]);
this.selectFirst = false; this.selectFirst = false;

View File

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

View File

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

View File

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

View File

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