|
1 | | -import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core'; |
2 | | -import { Gateway, GatewayResponseMany } from '@app/gateway/gateway.model'; |
3 | | -import { Subscription } from 'rxjs'; |
4 | | -import { ChirpstackGatewayService } from '@shared/services/chirpstack-gateway.service'; |
5 | | -import { OrganizationAccessScope } from '@shared/enums/access-scopes'; |
6 | | -import { GatewayService } from '@app/gateway/gateway.service'; |
7 | | -import { MeService } from '@shared/services/me.service'; |
| 1 | +import { AfterViewInit, Component, OnDestroy, OnInit } from "@angular/core"; |
| 2 | +import { Gateway, GatewayResponseMany } from "@app/gateway/gateway.model"; |
| 3 | +import { Subscription } from "rxjs"; |
| 4 | +import { ChirpstackGatewayService } from "@shared/services/chirpstack-gateway.service"; |
| 5 | +import { OrganizationAccessScope } from "@shared/enums/access-scopes"; |
| 6 | +import { GatewayService } from "@app/gateway/gateway.service"; |
| 7 | +import { MeService } from "@shared/services/me.service"; |
8 | 8 |
|
9 | 9 | @Component({ |
10 | | - selector: 'app-gateway-map', |
11 | | - templateUrl: './gateway-map.component.html', |
12 | | - styleUrls: ['./gateway-map.component.scss'], |
| 10 | + selector: "app-gateway-map", |
| 11 | + templateUrl: "./gateway-map.component.html", |
| 12 | + styleUrls: ["./gateway-map.component.scss"], |
13 | 13 | }) |
14 | 14 | export class GatewayMapComponent implements OnInit, OnDestroy, AfterViewInit { |
15 | | - public gateways: Gateway[]; |
16 | | - public coordinateList = []; |
17 | | - private gatewaySubscription: Subscription; |
18 | | - private organizationChangeSubscription: Subscription; |
19 | | - isLoadingResults = true; |
| 15 | + public gateways: Gateway[]; |
| 16 | + public coordinateList = []; |
| 17 | + private gatewaySubscription: Subscription; |
| 18 | + private organizationChangeSubscription: Subscription; |
| 19 | + isLoadingResults = true; |
20 | 20 |
|
21 | | - constructor( |
22 | | - private chirpstackGatewayService: ChirpstackGatewayService, |
23 | | - private gatewayService: GatewayService, |
24 | | - private meService: MeService |
25 | | - ) {} |
| 21 | + constructor( |
| 22 | + private chirpstackGatewayService: ChirpstackGatewayService, |
| 23 | + private gatewayService: GatewayService, |
| 24 | + private meService: MeService |
| 25 | + ) {} |
26 | 26 |
|
27 | | - ngOnInit(): void {} |
| 27 | + ngOnInit(): void {} |
28 | 28 |
|
29 | | - ngAfterViewInit() { |
30 | | - this.organizationChangeSubscription = this.gatewayService.organisationChangeSubject.subscribe( |
31 | | - (x) => { |
32 | | - if (x) { |
33 | | - this.getGatewayWith(x); |
| 29 | + ngAfterViewInit() { |
| 30 | + this.organizationChangeSubscription = this.gatewayService.organisationChangeSubject.subscribe(x => { |
| 31 | + if (x) { |
| 32 | + this.getGatewayWith(x); |
| 33 | + } else { |
| 34 | + this.getGateways(); |
| 35 | + } |
| 36 | + }); |
| 37 | + if (this.gatewayService.selectedOrg) { |
| 38 | + this.getGatewayWith(this.gatewayService.selectedOrg); |
34 | 39 | } else { |
35 | | - this.getGateways(); |
| 40 | + this.getGateways(); |
36 | 41 | } |
37 | | - } |
38 | | - ); |
39 | | - if (this.gatewayService.selectedOrg) { |
40 | | - this.getGatewayWith(this.gatewayService.selectedOrg); |
41 | | - } else { |
42 | | - this.getGateways(); |
43 | 42 | } |
44 | | - } |
45 | 43 |
|
46 | | - private getGateways(): void { |
47 | | - this.gatewaySubscription = this.chirpstackGatewayService |
48 | | - .getMultiple({ |
49 | | - limit: null, |
50 | | - offset: null, |
51 | | - sort: null, |
52 | | - orderOn: null, |
53 | | - }) |
54 | | - .subscribe((gateways: GatewayResponseMany) => { |
| 44 | + private getGateways(): void { |
| 45 | + this.gatewaySubscription = this.chirpstackGatewayService |
| 46 | + .getMultiple({ |
| 47 | + limit: null, |
| 48 | + offset: null, |
| 49 | + sort: null, |
| 50 | + orderOn: null, |
| 51 | + }) |
| 52 | + .subscribe((gateways: GatewayResponseMany) => { |
55 | 53 | this.gateways = gateways.resultList; |
56 | | - this.mapToCoordinateList(); |
57 | | - this.setCanEdit(); |
58 | | - this.isLoadingResults = false; |
59 | | - }); |
60 | | - } |
| 54 | + this.mapToCoordinateList(); |
| 55 | + this.setCanEdit(); |
| 56 | + this.isLoadingResults = false; |
| 57 | + }); |
| 58 | + } |
61 | 59 |
|
62 | | - private getGatewayWith(orgId: number): void { |
63 | | - this.gatewaySubscription = this.chirpstackGatewayService |
64 | | - .getMultiple({ |
65 | | - limit: null, |
66 | | - offset: null, |
67 | | - sort: null, |
68 | | - orderOn: null, |
69 | | - organizationId: orgId, |
70 | | - }) |
71 | | - .subscribe((gateways: GatewayResponseMany) => { |
| 60 | + private getGatewayWith(orgId: number): void { |
| 61 | + this.gatewaySubscription = this.chirpstackGatewayService |
| 62 | + .getMultiple({ |
| 63 | + limit: null, |
| 64 | + offset: null, |
| 65 | + sort: null, |
| 66 | + orderOn: null, |
| 67 | + organizationId: orgId, |
| 68 | + }) |
| 69 | + .subscribe((gateways: GatewayResponseMany) => { |
72 | 70 | this.gateways = gateways.resultList; |
73 | | - this.mapToCoordinateList(); |
74 | | - this.setCanEdit(); |
75 | | - this.isLoadingResults = false; |
76 | | - }); |
77 | | - } |
| 71 | + this.mapToCoordinateList(); |
| 72 | + this.setCanEdit(); |
| 73 | + this.isLoadingResults = false; |
| 74 | + }); |
| 75 | + } |
78 | 76 |
|
79 | | - private mapToCoordinateList() { |
80 | | - const tempcoordinateList = []; |
81 | | - this.gateways.map((gateway) => |
82 | | - tempcoordinateList.push({ |
83 | | - longitude: gateway.location.longitude, |
84 | | - latitude: gateway.location.latitude, |
85 | | - draggable: false, |
86 | | - editEnabled: false, |
87 | | - useGeolocation: false, |
88 | | - markerInfo: { |
89 | | - name: gateway.name, |
90 | | - active: this.gatewayStatus(gateway), |
| 77 | + private mapToCoordinateList() { |
| 78 | + const tempcoordinateList = []; |
| 79 | + this.gateways.map(gateway => |
| 80 | + tempcoordinateList.push({ |
| 81 | + longitude: gateway.location.longitude, |
| 82 | + latitude: gateway.location.latitude, |
| 83 | + draggable: false, |
| 84 | + editEnabled: false, |
| 85 | + useGeolocation: false, |
| 86 | + markerInfo: { |
| 87 | + name: gateway.name, |
| 88 | + active: this.gatewayStatus(gateway), |
91 | 89 | id: gateway.gatewayId, |
92 | 90 | internalOrganizationId: gateway.organizationId, |
93 | 91 | internalOrganizationName: gateway.organizationName, |
94 | | - }, |
95 | | - }) |
96 | | - ); |
97 | | - this.coordinateList = tempcoordinateList; |
98 | | - } |
| 92 | + }, |
| 93 | + }) |
| 94 | + ); |
| 95 | + this.coordinateList = tempcoordinateList; |
| 96 | + } |
99 | 97 |
|
100 | | - gatewayStatus(gateway: Gateway): boolean { |
101 | | - return this.chirpstackGatewayService.isGatewayActive(gateway); |
102 | | - } |
| 98 | + gatewayStatus(gateway: Gateway): boolean { |
| 99 | + return this.chirpstackGatewayService.isGatewayActive(gateway); |
| 100 | + } |
103 | 101 |
|
104 | | - setCanEdit() { |
105 | | - this.gateways.forEach((gateway) => { |
106 | | - gateway.canEdit = this.meService.hasAccessToTargetOrganization( |
107 | | - OrganizationAccessScope.GatewayWrite, |
108 | | - gateway.organizationId |
109 | | - ); |
110 | | - }); |
111 | | - } |
| 102 | + setCanEdit() { |
| 103 | + this.gateways.forEach(gateway => { |
| 104 | + gateway.canEdit = this.meService.hasAccessToTargetOrganization( |
| 105 | + OrganizationAccessScope.GatewayWrite, |
| 106 | + gateway.organizationId |
| 107 | + ); |
| 108 | + }); |
| 109 | + } |
112 | 110 |
|
113 | | - ngOnDestroy() { |
114 | | - // prevent memory leak by unsubscribing |
115 | | - this.gatewaySubscription?.unsubscribe(); |
116 | | - this.organizationChangeSubscription.unsubscribe(); |
117 | | - } |
| 111 | + ngOnDestroy() { |
| 112 | + // prevent memory leak by unsubscribing |
| 113 | + this.gatewaySubscription?.unsubscribe(); |
| 114 | + this.organizationChangeSubscription.unsubscribe(); |
| 115 | + } |
118 | 116 | } |
0 commit comments