| /******************************************************************************** |
| * 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, ViewChild, Input, OnChanges, SimpleChanges } from '@angular/core'; |
| |
| import { LazyLoadEvent, Column } from 'primeng/primeng'; |
| import { Table } from 'primeng/table'; |
| |
| import { Node } from '../../../navigator/node'; |
| import { ChartViewerDataService, getDataArray } from '../../services/chart-viewer-data.service'; |
| import { MeasuredValues } from '../../model/chartviewer.model'; |
| |
| @Component({ |
| selector: 'mdm5-dataTable', |
| templateUrl: 'data-table.component.html', |
| providers: [] |
| }) |
| export class DataTableComponent implements OnChanges { |
| @ViewChild('datatable') |
| private table: Table; |
| |
| @Input() |
| channelGroup = new Node(); |
| @Input() |
| channels = [new Node()]; |
| |
| tableLoading = false; |
| cols: Column[] = []; |
| totalRecords = 0; |
| recordsPerPage = 10; |
| datapoints = []; |
| |
| constructor(private chartviewerService: ChartViewerDataService) { |
| } |
| |
| ngOnChanges(changes: SimpleChanges) { |
| for (let propName in changes) { |
| if (propName === 'channelGroup' || propName === 'channels') { |
| this.table.reset(); |
| } |
| } |
| } |
| |
| load(mv: MeasuredValues[]) { |
| let zip = (rows => rows[0].map((_, c) => rows.map(row => row[c]))); |
| |
| this.cols = mv.map((m, i) => Object.assign(new Column(), { header: m.name, field: i })); |
| this.datapoints = zip(mv.map(m => getDataArray(m).values)); |
| } |
| |
| loadLazy(event: LazyLoadEvent) { |
| if (this.channelGroup === undefined) { |
| return; |
| } |
| |
| setTimeout(() => { |
| this.tableLoading = true; |
| this.totalRecords = this.chartviewerService.getNumberOfRows(this.channelGroup); |
| this.chartviewerService.loadMeasuredValues(this.channelGroup, this.channels, event.first, event.rows).subscribe(mv => { |
| this.load(mv); |
| this.tableLoading = false; |
| }, |
| () => this.tableLoading = false); |
| }, 0); |
| } |
| } |