| /******************************************************************************** |
| * 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, OnDestroy } from '@angular/core'; |
| import { NavigatorService } from '../../../navigator/navigator.service'; |
| import { MDMNotificationService } from '../../../core/mdm-notification.service'; |
| import { TranslateService } from '@ngx-translate/core'; |
| import { NodeService } from '../../../navigator/node.service'; |
| import { forkJoin, Observable } from 'rxjs'; |
| import { Node } from '../../../navigator/node'; |
| import { SelectItem } from 'primeng/api'; |
| import { PropertyService } from 'src/app/core/property.service'; |
| |
| @Component({ |
| selector: 'mdm5-chartViewerNavCard', |
| templateUrl: 'chart-viewer-nav-card.component.html', |
| providers: [] |
| }) |
| export class ChartViewerNavCardComponent implements OnInit, OnDestroy { |
| private _contextUrl: string; |
| |
| modes: SelectItem[] = [ |
| { label: 'Chart', value: 'chart'}, |
| { label: 'Table', value: 'table'}, |
| ]; |
| selectedMode = 'chart'; |
| |
| selectedNode: Node; |
| channelGroup: Node; |
| channels: Node[]; |
| subscription: any; |
| |
| showLegend = false; |
| dataAvailable = false; |
| |
| constructor(private navigatorService: NavigatorService, |
| private notificationService: MDMNotificationService, |
| private translateService: TranslateService, |
| private nodeService: NodeService, |
| private _prop: PropertyService) { |
| this._contextUrl = _prop.getUrl('mdm/environments'); |
| } |
| |
| ngOnInit() { |
| this.onSelectedNodeChange(this.navigatorService.getSelectedNode()); |
| this.subscription = this.navigatorService.selectedNodeChanged.subscribe( |
| node => this.onSelectedNodeChange(node), |
| error => this.notificationService.notifyError(this.translateService.instant('details.mdm-detail-view.cannot-update-node'), error) |
| ); |
| } |
| |
| ngOnDestroy() { |
| this.subscription.unsubscribe(); |
| } |
| |
| onSelectedNodeChange(node: Node) { |
| if (!node) { |
| this.dataAvailable = false; |
| return; |
| } |
| this.selectedNode = node; |
| |
| if (node && node.type === 'Channel') { |
| this.loadChannelGroup(node) |
| .flatMap(channelGroup => forkJoin([Observable.of(channelGroup), this.loadChannels(channelGroup)])) |
| .subscribe(([channelGroup, channels]) => { |
| this.channelGroup = channelGroup; |
| this.channels = [node]; |
| this.dataAvailable = true; |
| }); |
| } else { |
| this.dataAvailable = false; |
| } |
| } |
| |
| loadChannelGroup(channel: Node) { |
| let url = this._contextUrl + '/' + channel.sourceName + '/channelgroups?filter=Channel.Id eq \"' + channel.id + '\"'; |
| return this.nodeService.getNode(url).map(channelGroup => channelGroup[0]); |
| } |
| |
| loadChannels(channelgroup: Node) { |
| let url = this._contextUrl + '/' + channelgroup.sourceName + '/channels?filter=ChannelGroup.Id eq \"' + channelgroup.id + '\"'; |
| return this.nodeService.getNode(url); |
| } |
| } |