From b098b4c1dc13ece382ede5b07f4391e03b10a545 Mon Sep 17 00:00:00 2001 From: Maksym Dudnik Date: Mon, 28 Nov 2022 13:09:12 +0200 Subject: [PATCH] CE updated --- .../device/device-credentials.module.ts | 7 +- .../device-gateway-command.component.html | 53 +++++++++ .../device-gateway-command.component.ts | 110 ++++++++++++++++++ .../gateway-command-dialog.component.html | 37 +----- .../gateway-command-dialog.component.ts | 62 ++-------- .../gateway/gateway-list-table-config.ts | 2 +- .../shared-home-components.module.ts | 4 +- .../home/pages/device/device.component.html | 1 + 8 files changed, 182 insertions(+), 94 deletions(-) create mode 100644 ui-ngx/src/app/modules/home/components/device/device-gateway-command.component.html create mode 100644 ui-ngx/src/app/modules/home/components/device/device-gateway-command.component.ts diff --git a/ui-ngx/src/app/modules/home/components/device/device-credentials.module.ts b/ui-ngx/src/app/modules/home/components/device/device-credentials.module.ts index 1ceed26e54..924c00e478 100644 --- a/ui-ngx/src/app/modules/home/components/device/device-credentials.module.ts +++ b/ui-ngx/src/app/modules/home/components/device/device-credentials.module.ts @@ -22,6 +22,7 @@ import { DeviceCredentialsComponent } from '@home/components/device/device-crede import { DeviceCredentialsLwm2mComponent } from '@home/components/device/device-credentials-lwm2m.component'; import { DeviceCredentialsLwm2mServerComponent } from '@home/components/device/device-credentials-lwm2m-server.component'; import { DeviceCredentialsMqttBasicComponent } from '@home/components/device/device-credentials-mqtt-basic.component'; +import {DeviceGatewayCommandComponent} from "@home/components/device/device-gateway-command.component"; @NgModule({ declarations: [ @@ -29,7 +30,8 @@ import { DeviceCredentialsMqttBasicComponent } from '@home/components/device/dev DeviceCredentialsComponent, DeviceCredentialsLwm2mComponent, DeviceCredentialsLwm2mServerComponent, - DeviceCredentialsMqttBasicComponent + DeviceCredentialsMqttBasicComponent, + DeviceGatewayCommandComponent ], imports: [ CommonModule, @@ -40,7 +42,8 @@ import { DeviceCredentialsMqttBasicComponent } from '@home/components/device/dev DeviceCredentialsComponent, DeviceCredentialsLwm2mComponent, DeviceCredentialsLwm2mServerComponent, - DeviceCredentialsMqttBasicComponent + DeviceCredentialsMqttBasicComponent, + DeviceGatewayCommandComponent ] }) export class DeviceCredentialsModule { } diff --git a/ui-ngx/src/app/modules/home/components/device/device-gateway-command.component.html b/ui-ngx/src/app/modules/home/components/device/device-gateway-command.component.html new file mode 100644 index 0000000000..6b395fc4bf --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/device/device-gateway-command.component.html @@ -0,0 +1,53 @@ + +
+ + gateway.windows + gateway.linux-macos + +
+ +
+
{{ linuxCode }}
+ +
+
+
+ +
+
{{ windowsCode }}
+ +
+
+
diff --git a/ui-ngx/src/app/modules/home/components/device/device-gateway-command.component.ts b/ui-ngx/src/app/modules/home/components/device/device-gateway-command.component.ts new file mode 100644 index 0000000000..d61925c687 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/device/device-gateway-command.component.ts @@ -0,0 +1,110 @@ +/// +/// Copyright © 2016-2022 The Thingsboard Authors +/// +/// Licensed under the Apache License, Version 2.0 (the "License"); +/// you may not use this file except in compliance with the License. +/// You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, software +/// distributed under the License is distributed on an "AS IS" BASIS, +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +/// See the License for the specific language governing permissions and +/// limitations under the License. +/// + +import {Component, Input, OnInit} from '@angular/core'; +import { + FormControl, +} from '@angular/forms'; +import {Router} from "@angular/router"; +import {Store} from "@ngrx/store"; +import {AppState} from "@core/core.state"; +import {TranslateService} from "@ngx-translate/core"; +import {ActionNotificationShow} from "@core/notification/notification.actions"; +import {DeviceService} from "@core/http/device.service"; + +enum OsType { + linux = 'linux', + macos = 'macos', + windows = 'win' +} + +@Component({ + selector: 'tb-gateway-command', + templateUrl: './device-gateway-command.component.html', + styleUrls: [] +}) + +export class DeviceGatewayCommandComponent implements OnInit { + + @Input() + token: string; + + @Input() + deviceId: string; + + linuxCode: string; + windowsCode: string; + selectedOSControll: FormControl; + osTypes = OsType; + + constructor(protected router: Router, + protected store: Store, + private translate: TranslateService, + private deviceService: DeviceService) { + } + + + ngOnInit(): void { + const HOST = window.location.hostname; + if (this.deviceId) { + this.deviceService.getDeviceCredentials(this.deviceId).subscribe(credentials=>{ + this.token = credentials.credentialsId; + this.createRunCode(HOST); + }) + } + this.selectedOSControll = new FormControl(''); + // @ts-ignore + const platform = window.navigator?.userAgentData?.platform || window.navigator.platform, + macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'], + windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']; + if (macosPlatforms.indexOf(platform) !== -1) { + this.selectedOSControll.setValue(OsType.macos); + } else if (windowsPlatforms.indexOf(platform) !== -1) { + this.selectedOSControll.setValue(OsType.windows); + } else if (/Linux/.test(platform)) { + this.selectedOSControll.setValue(OsType.linux); + } + this.createRunCode(HOST); + } + + createRunCode(HOST) { + this.linuxCode = "docker run -it -v ~/.tb-gateway/logs:/thingsboard_gateway/logs -v " + + "~/.tb-gateway/extensions:/thingsboard_gateway/extensions -v ~/.tb-gateway/config:/thingsboard_gateway/config --name tb-gateway -e host=" + + HOST + + " -e port=1883 -e accessToken=" + + this.token + + " --restart always thingsboard/tb-gateway"; + this.windowsCode = "docker run -it -v %HOMEPATH%/tb-gateway/config:/thingsboard_gateway/config -v " + + "%HOMEPATH%/tb-gateway/extensions:/thingsboard_gateway/extensions -v %HOMEPATH%/tb-gateway/logs:/thingsboard_gateway/logs " + + "--name tb-gateway -e host=" + + HOST + + " -e port=1883 -e accessToken=" + + this.token + + " --restart always thingsboard/tb-gateway"; + } + + onDockerCodeCopied() { + this.store.dispatch(new ActionNotificationShow( + { + message: this.translate.instant('gateway.command-copied-message'), + type: 'success', + target: 'dockerCommandDialogContent', + duration: 1200, + verticalPosition: 'bottom', + horizontalPosition: 'left' + })); + } +} diff --git a/ui-ngx/src/app/modules/home/components/gateway/gateway-command-dialog.component.html b/ui-ngx/src/app/modules/home/components/gateway/gateway-command-dialog.component.html index 34d37d73ea..b6ba116379 100644 --- a/ui-ngx/src/app/modules/home/components/gateway/gateway-command-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/gateway/gateway-command-dialog.component.html @@ -43,42 +43,7 @@
-
- - gateway.windows - gateway.linux-macos - -
- -
-
{{ linuxCode }}
- -
-
-
- -
-
{{ windowsCode }}
- -
-
-
+
+