| /******************************************************************************** |
| * 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'; |
| import { Measurement } from '../../model/types/measurement.class'; |
| |
| @Component({ |
| selector: 'mdm5-dataTable', |
| templateUrl: 'data-table.component.html', |
| styleUrls: ['./data-table.component.css'], |
| providers: [] |
| }) |
| export class DataTableComponent implements OnChanges { |
| @ViewChild('datatable') |
| private table: Table; |
| |
| @Input() |
| measurement: Measurement; |
| |
| tableLoading = false; |
| cols: Column[] = []; |
| totalRecords = 0; |
| recordsPerPage = 10; |
| datapoints = []; |
| |
| constructor(private chartviewerService: ChartViewerDataService) { |
| } |
| |
| ngOnChanges(changes: SimpleChanges) { |
| for (const propName in changes) { |
| if (propName === 'measurement') { |
| this.table.reset(); |
| this.cols = []; |
| this.datapoints = []; |
| } |
| } |
| } |
| |
| load(mv: MeasuredValues[]) { |
| const zip = (rows => rows[0].map((_, c) => rows.map(row => row[c]))); |
| // combine the columns of multiple data requests |
| this.cols = this.cols.concat(mv.filter((m, i) => { |
| for (let j = 0; j < this.cols.length; j++) { |
| if (this.cols[j].header === m.name) { |
| return false; |
| } |
| } |
| return true; |
| }).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.measurement) { |
| return; |
| } |
| |
| setTimeout(() => { |
| this.tableLoading = true; |
| |
| for (const channelGroup of this.measurement.channelGroups) { |
| const channels = this.measurement.findChannels(channelGroup); |
| |
| this.totalRecords = channelGroup.numberOfRows; |
| this.chartviewerService.loadMeasuredValues(channelGroup, channels, event.first, event.rows) |
| .subscribe(mv => { |
| this.load(mv); |
| this.tableLoading = false; |
| }, |
| () => this.tableLoading = false); |
| } |
| }, 0); |
| } |
| } |