mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
* #1175 Separate analytics generator and hide analytics parameters * Remove unused code fix unit test * Rollback mandatory field (appId) * fix the onChanges problem * #1175 - rebased branch
This commit is contained in:
committed by
Mario Romano
parent
b05247dade
commit
537be1e058
@@ -0,0 +1,119 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2016 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, EventEmitter, OnChanges, Input, Output, SimpleChanges } from '@angular/core';
|
||||
import { AlfrescoTranslationService, LogService } from 'ng2-alfresco-core';
|
||||
import { AnalyticsService } from '../services/analytics.service';
|
||||
import { ReportQuery } from '../models/report.model';
|
||||
import { Chart } from '../models/chart.model';
|
||||
|
||||
@Component({
|
||||
moduleId: module.id,
|
||||
selector: 'activiti-analytics-generator',
|
||||
templateUrl: './analytics-generator.component.html',
|
||||
styleUrls: ['./analytics-generator.component.css']
|
||||
})
|
||||
export class AnalyticsGeneratorComponent implements OnChanges {
|
||||
|
||||
@Input()
|
||||
reportId: number;
|
||||
|
||||
@Input()
|
||||
reportParamQuery: ReportQuery = undefined;
|
||||
|
||||
@Output()
|
||||
onSuccess = new EventEmitter();
|
||||
|
||||
@Output()
|
||||
onError = new EventEmitter();
|
||||
|
||||
reports: Chart[];
|
||||
|
||||
showDetails: boolean = false;
|
||||
|
||||
public barChartOptions: any = {
|
||||
responsive: true,
|
||||
scales: {
|
||||
yAxes: [{
|
||||
ticks: {
|
||||
beginAtZero: true,
|
||||
stepSize: 1
|
||||
}
|
||||
}],
|
||||
xAxes: [{
|
||||
ticks: {
|
||||
},
|
||||
stacked: true
|
||||
}]
|
||||
}
|
||||
};
|
||||
|
||||
constructor(private translateService: AlfrescoTranslationService,
|
||||
private analyticsService: AnalyticsService,
|
||||
private logService: LogService) {
|
||||
logService.info('AnalyticsGeneratorComponent');
|
||||
if (translateService) {
|
||||
translateService.addTranslationFolder('ng2-activiti-analytics', 'node_modules/ng2-activiti-analytics/src');
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (this.reportId && this.reportParamQuery) {
|
||||
this.generateReport(this.reportId, this.reportParamQuery);
|
||||
} else {
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
|
||||
public generateReport(reportId, reportParamQuery) {
|
||||
this.analyticsService.getReportsByParams(reportId, reportParamQuery).subscribe(
|
||||
(res: Chart[]) => {
|
||||
this.reports = res;
|
||||
this.onSuccess.emit(res);
|
||||
},
|
||||
(err: any) => {
|
||||
this.onError.emit(err);
|
||||
this.logService.error(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public reset() {
|
||||
if (this.reports) {
|
||||
this.reports = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
public refresh(report): void {
|
||||
/**
|
||||
* (My guess), for Angular to recognize the change in the dataset
|
||||
* it has to change the dataset variable directly,
|
||||
* so one way around it, is to clone the data, change it and then
|
||||
* assign it;
|
||||
*/
|
||||
let clone = JSON.parse(JSON.stringify(report));
|
||||
report.datasets = clone.datasets;
|
||||
}
|
||||
|
||||
toggleDetailsTable() {
|
||||
this.showDetails = !this.showDetails;
|
||||
}
|
||||
|
||||
isShowDetails(): boolean {
|
||||
return this.showDetails;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user