blob: ddbf822cba3e2c88b1333f48e1e25aa043ac364b [file] [log] [blame]
/********************************************************************************
* Copyright (c) 2015-2018 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
********************************************************************************/
import { Component, OnInit, Input, SimpleChanges, OnChanges, Output, EventEmitter } from '@angular/core';
import { ChartViewerDataService } from '../../services/chart-viewer-data.service';
import { Node } from '../../../navigator/node';
import { RequestOptions } from '../../model/chartviewer.model';
@Component({
selector: 'mdm5-request-options',
templateUrl: './request-options.component.html'
})
export class RequestOptionsComponent implements OnInit, OnChanges {
// octive accordion tab, default: -1 (= non is active).
public accordionIndex = undefined;
public readonly minIndex = 1;
// public requestedValues = 1;
public rangeValues: number[] = [];
private maxRequestedValues = 10000;
public numberOfRows = 0;
public numberOfChunks = 600;
public step: number;
public previewEnabled = true;
@Input()
public channelGroups: Node[];
@Output()
public onRequestOptionsChanged = new EventEmitter<RequestOptions>();
constructor(
private chartService: ChartViewerDataService) { }
ngOnInit() {
this.reload();
this.emitRequestOptionsChanged();
}
ngOnChanges(changes: SimpleChanges) {
if (changes['channelGroups']) {
this.reload();
this.emitRequestOptionsChanged();
}
}
private reload() {
if (this.channelGroups != undefined && this.channelGroups.length > 0) {
this.numberOfRows = this.chartService.getNumberOfRows(this.channelGroups[0]);
this.step = Math.min(1000, Math.max(Math.floor(this.numberOfRows / 100), 1));
if (this.numberOfRows < this.numberOfChunks) {
this.previewEnabled = false;
}
const requestedValues = Math.min(this.numberOfRows, this.maxRequestedValues);
this.rangeValues = [this.minIndex, requestedValues];
}
}
public onChangeValueRange(event: Event) {
// check if input string is numeric, set min/max otherwise
if (isNaN(+this.rangeValues[0])) {
this.rangeValues[0] = this.minIndex;
}
if (isNaN(+this.rangeValues[1])) {
this.rangeValues[1] = this.numberOfRows;
}
// reassign for change detection
this.rangeValues = [].concat(this.rangeValues);
}
public onApplySettings(event: Event) {
// close accordion
this.accordionIndex = -1;
// emit options
this.emitRequestOptionsChanged();
}
private emitRequestOptionsChanged() {
this.onRequestOptionsChanged.emit(
new RequestOptions(this.rangeValues[1] - this.rangeValues[0], this.rangeValues[0] - 1, this.previewEnabled, this.numberOfChunks));
}
}