|
1 | | -import { Component, OnInit, ViewEncapsulation } from '@angular/core'; |
2 | | -import { UnitService } from '../unit.service'; |
| 1 | + |
| 2 | +// Copyright (c) 2020 Lars Hellgren (lars@exelor.com). |
| 3 | +// All rights reserved. |
| 4 | +// |
| 5 | +// This code is licensed under the MIT License. |
| 6 | +// |
| 7 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +// of this software and associated documentation files(the "Software"), to deal |
| 9 | +// in the Software without restriction, including without limitation the rights |
| 10 | +// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell |
| 11 | +// copies of the Software, and to permit persons to whom the Software is |
| 12 | +// furnished to do so, subject to the following conditions : |
| 13 | +// |
| 14 | +// The above copyright notice and this permission notice shall be included in |
| 15 | +// all copies or substantial portions of the Software. |
| 16 | +// |
| 17 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | +// THE SOFTWARE. |
| 24 | + |
| 25 | +import { Component, OnDestroy, OnInit } from '@angular/core'; |
| 26 | +import { DeviceEvent, UnitService } from '../unit.service'; |
3 | 27 | import { PlaceService } from '../places/place.service'; |
| 28 | +import { Subscription } from 'rxjs/Subscription'; |
4 | 29 |
|
5 | 30 | @Component({ |
6 | 31 | selector: 'app-full-view', |
7 | 32 | templateUrl: './full-view.component.html', |
8 | 33 | styleUrls: ['./full-view.component.css'] |
9 | 34 | }) |
10 | | -export class FullViewComponent implements OnInit { |
| 35 | +export class FullViewComponent implements OnInit, OnDestroy { |
| 36 | + deviceId: string; |
| 37 | + documentId: string; |
11 | 38 |
|
12 | | - constructor(private unitService: UnitService, |
13 | | - private placeService: PlaceService) { } |
14 | | - |
15 | | - ngOnInit() { |
16 | | - } |
| 39 | + unitHistoryDisabled = true; |
| 40 | + unitInfoDisabled = true; |
| 41 | + placesDisabled = false; |
17 | 42 |
|
18 | | - get unitId() { |
19 | | - return this.unitService.currentDeviceEvent ? `/${this.unitService.currentDeviceEvent.deviceId}` : ''; |
20 | | - } |
| 43 | + private deviceSelectSubscription: Subscription; |
| 44 | + private enableDetailsSubscription: Subscription; |
21 | 45 |
|
22 | | - get docId() { |
23 | | - return this.unitService.currentDeviceEvent ? `/${this.unitService.currentDeviceEvent.documentId}` : ''; |
| 46 | + constructor(private unitService: UnitService, |
| 47 | + private placeService: PlaceService) { |
24 | 48 | } |
25 | 49 |
|
26 | | - unitHistoryDisabled() { |
27 | | - return !!!this.unitService.currentDeviceEvent; |
28 | | - } |
| 50 | + ngOnInit() { |
| 51 | + this.deviceSelectSubscription = this.unitService.itemSelect$.subscribe((deviceEvent: DeviceEvent) => { |
| 52 | + this.unitHistoryDisabled = !!!deviceEvent; |
| 53 | + if (!!deviceEvent) { |
| 54 | + this.deviceId = deviceEvent.deviceId; |
| 55 | + } |
| 56 | + }); |
29 | 57 |
|
30 | | - unitInfoDisabled() { |
31 | | - return !!!this.unitService.currentDeviceEvent; |
| 58 | + this.enableDetailsSubscription = this.unitService.hasDetails$.subscribe(documentId => { |
| 59 | + if (!!documentId) { |
| 60 | + this.documentId = documentId; |
| 61 | + this.unitInfoDisabled = false; |
| 62 | + } else { |
| 63 | + this.unitInfoDisabled = true; |
| 64 | + } |
| 65 | + }); |
32 | 66 | } |
33 | 67 |
|
34 | | - placesDisabled() { |
35 | | - return false; |
| 68 | + ngOnDestroy() { |
| 69 | + if (this.deviceSelectSubscription) { |
| 70 | + this.deviceSelectSubscription.unsubscribe(); |
| 71 | + } |
| 72 | + if (this.enableDetailsSubscription) { |
| 73 | + this.enableDetailsSubscription.unsubscribe(); |
| 74 | + } |
36 | 75 | } |
37 | 76 |
|
38 | 77 | placeDisabled() { |
|
0 commit comments