From 75f7b7319a704e6f4a9a5d4401d929c121a37bb0 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Wed, 23 Nov 2022 20:50:45 +0200 Subject: [PATCH 01/16] Added base implementation of edge docker install instructions controller --- .../docker/instructions.md | 88 +++++++++++++++++++ .../server/controller/BaseController.java | 4 + .../server/controller/EdgeController.java | 21 +++++ .../edge/DefaultEdgeInstallService.java | 71 +++++++++++++++ .../service/edge/EdgeInstallService.java | 27 ++++++ .../server/controller/AbstractWebTest.java | 8 +- .../controller/BaseEdgeControllerTest.java | 21 ++++- .../docker/expected-install-instructions.md | 88 +++++++++++++++++++ 8 files changed, 321 insertions(+), 7 deletions(-) create mode 100644 application/src/main/data/json/edge/install_instructions/docker/instructions.md create mode 100644 application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java create mode 100644 application/src/main/java/org/thingsboard/server/service/edge/EdgeInstallService.java create mode 100644 application/src/test/resources/edge/install_instructions/docker/expected-install-instructions.md diff --git a/application/src/main/data/json/edge/install_instructions/docker/instructions.md b/application/src/main/data/json/edge/install_instructions/docker/instructions.md new file mode 100644 index 0000000000..15a7db1d74 --- /dev/null +++ b/application/src/main/data/json/edge/install_instructions/docker/instructions.md @@ -0,0 +1,88 @@ +## Install edge and connect to cloud instructions + +### Localhost warning + +Localhost cannot be used for docker install - please update baseUrl to the IP address of your machine! + +Here is the list of commands, that can be used to quickly install and connect edge to the cloud using docker-compose. + +### Prerequisites + +Install Docker CE and Docker Compose. + +### Create data and logs folders + +Run following commands to create a directory for storing data and logs and then change its owner to docker container user, to be able to change user, chown command is used, which requires sudo permissions (command will request password for a sudo access): + +```bash +mkdir -p ~/.mytb-edge-data && sudo chown -R 799:799 ~/.mytb-edge-data +mkdir -p ~/.mytb-edge-logs && sudo chown -R 799:799 ~/.mytb-edge-logs +{:copy-code} +``` + +### Running ThingsBoard Edge as docker service + +Create docker compose file for ThingsBoard Edge service: + +```bash +nano docker-compose.yml +{:copy-code} +``` + +Add the following lines to the yml file: + +``` +version: '2.2' +services: +mytbedge: +restart: always +image: "thingsboard/tb-edge:3.4.1EDGE" +ports: +- "8080:8080" +- "1883:1883" +- "5683-5688:5683-5688/udp" +environment: +SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/tb-edge +CLOUD_ROUTING_KEY: ${CLOUD_ROUTING_KEY} +CLOUD_ROUTING_SECRET: ${CLOUD_ROUTING_SECRET} +CLOUD_RPC_HOST: ${BASE_URL} +volumes: +- ~/.mytb-edge-data:/data +- ~/.mytb-edge-logs:/var/log/tb-edge +postgres: +restart: always +image: "postgres:12" +ports: +- "5432" +environment: +POSTGRES_DB: tb-edge +POSTGRES_PASSWORD: postgres +volumes: +- ~/.mytb-edge-data/db:/var/lib/postgresql/data +{:copy-code} +``` + +### Ports warning [Optional] +If ThingsBoard Edge is going to be running on the same machine where ThingsBoard server is running you’ll need to update docker compose port mapping. +Please update next lines of docker compose: +ports: +- “18080:8080” +- “11883:1883” +- “15683-15688:5683-5688/udp” + Please make sure ports above are not used by any other application. + + +Execute the following commands to up this docker compose directly: + +```bash +docker-compose pull +docker-compose up +{:copy-code} +``` + +### Open ThingsBoard Edge UI + +Once started, you will be able to open ThingsBoard Edge UI using the following link http://localhost:8080. + +If during installation process you have changed edge HTTP_BIND_PORT please use that port instead for Edge UI URL: +http://localhost:HTTP_BIND_PORT diff --git a/application/src/main/java/org/thingsboard/server/controller/BaseController.java b/application/src/main/java/org/thingsboard/server/controller/BaseController.java index ffc3fcf3cd..1a8db80149 100644 --- a/application/src/main/java/org/thingsboard/server/controller/BaseController.java +++ b/application/src/main/java/org/thingsboard/server/controller/BaseController.java @@ -131,6 +131,7 @@ import org.thingsboard.server.queue.discovery.PartitionService; import org.thingsboard.server.queue.provider.TbQueueProducerProvider; import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.service.component.ComponentDiscoveryService; +import org.thingsboard.server.service.edge.EdgeInstallService; import org.thingsboard.server.service.edge.EdgeNotificationService; import org.thingsboard.server.service.edge.rpc.EdgeRpcService; import org.thingsboard.server.service.entitiy.TbNotificationEntityService; @@ -281,6 +282,9 @@ public abstract class BaseController { @Autowired(required = false) protected EdgeRpcService edgeRpcService; + @Autowired(required = false) + protected EdgeInstallService edgeInstallService; + @Autowired protected TbNotificationEntityService notificationEntityService; diff --git a/application/src/main/java/org/thingsboard/server/controller/EdgeController.java b/application/src/main/java/org/thingsboard/server/controller/EdgeController.java index 6a5dd44d0b..12e02aa0bd 100644 --- a/application/src/main/java/org/thingsboard/server/controller/EdgeController.java +++ b/application/src/main/java/org/thingsboard/server/controller/EdgeController.java @@ -63,6 +63,7 @@ import org.thingsboard.server.service.security.model.SecurityUser; import org.thingsboard.server.service.security.permission.Operation; import org.thingsboard.server.service.security.permission.Resource; +import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -595,4 +596,24 @@ public class EdgeController extends BaseController { return edgeBulkImportService.processBulkImport(request, user); } + + @ApiOperation(value = "Get Edge Docker Install Instructions (getEdgeDockerInstallInstructions)", + notes = "Get a docker install instructions for provided edge id." + TENANT_AUTHORITY_PARAGRAPH, + produces = MediaType.APPLICATION_JSON_VALUE) + @PreAuthorize("hasAnyAuthority('TENANT_ADMIN')") + @RequestMapping(value = "/edge/instructions/{edgeId}", method = RequestMethod.GET) + @ResponseBody + public String getEdgeDockerInstallInstructions( + @ApiParam(value = EDGE_ID_PARAM_DESCRIPTION, required = true) + @PathVariable("edgeId") String strEdgeId, + HttpServletRequest request) throws ThingsboardException { + try { + EdgeId edgeId = new EdgeId(toUUID(strEdgeId)); + edgeId = checkNotNull(edgeId); + Edge edge = checkEdgeId(edgeId, Operation.READ); + return checkNotNull(edgeInstallService.getDockerInstallInstructions(getTenantId(), edge, request)); + } catch (Exception e) { + throw handleException(e); + } + } } diff --git a/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java b/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java new file mode 100644 index 0000000000..e281efbf16 --- /dev/null +++ b/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java @@ -0,0 +1,71 @@ +/** + * 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. + */ +package org.thingsboard.server.service.edge; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.thingsboard.server.common.data.edge.Edge; +import org.thingsboard.server.common.data.id.TenantId; +import org.thingsboard.server.service.install.InstallScripts; +import org.thingsboard.server.service.security.system.SystemSecurityService; + +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +@Service +@Slf4j +@RequiredArgsConstructor +public class DefaultEdgeInstallService implements EdgeInstallService { + + private static final String EDGE_DIR = "edge"; + + private static final String EDGE_INSTALL_INSTRUCTIONS_DIR = "install_instructions"; + + private final InstallScripts installScripts; + private final SystemSecurityService systemSecurityService; + + @Override + public String getDockerInstallInstructions(TenantId tenantId, Edge edge, HttpServletRequest request) { + String baseUrl = request.getServerName(); + String template = readFile(resolveFile("docker", "instructions.md")); + template = template.replace("${BASE_URL}", baseUrl); + template = template.replace("${CLOUD_ROUTING_KEY}", edge.getRoutingKey()); + template = template.replace("${CLOUD_ROUTING_SECRET}", edge.getSecret()); + return template; + } + + private String readFile(Path file) { + try { + return new String(Files.readAllBytes(file), StandardCharsets.UTF_8); + } catch (IOException e) { + log.warn("Failed to read file: {}", file, e); + throw new RuntimeException(e); + } + } + + private Path resolveFile(String subDir, String... subDirs) { + return getEdgeInstallInstructionsDir().resolve(Paths.get(subDir, subDirs)); + } + + private Path getEdgeInstallInstructionsDir() { + return Paths.get(installScripts.getDataDir(), InstallScripts.JSON_DIR, EDGE_DIR, EDGE_INSTALL_INSTRUCTIONS_DIR); + } +} diff --git a/application/src/main/java/org/thingsboard/server/service/edge/EdgeInstallService.java b/application/src/main/java/org/thingsboard/server/service/edge/EdgeInstallService.java new file mode 100644 index 0000000000..54ad0de55d --- /dev/null +++ b/application/src/main/java/org/thingsboard/server/service/edge/EdgeInstallService.java @@ -0,0 +1,27 @@ +/** + * 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. + */ +package org.thingsboard.server.service.edge; + +import org.thingsboard.server.common.data.edge.Edge; +import org.thingsboard.server.common.data.id.TenantId; + +import javax.servlet.http.HttpServletRequest; + +public interface EdgeInstallService { + + String getDockerInstallInstructions(TenantId tenantId, Edge edge, HttpServletRequest request); + +} diff --git a/application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java b/application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java index e2b7d700bd..4d8e7c8488 100644 --- a/application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/AbstractWebTest.java @@ -701,16 +701,16 @@ public abstract class AbstractWebTest extends AbstractInMemoryStorageTest { } protected Edge constructEdge(String name, String type) { - return constructEdge(tenantId, name, type); + return constructEdge(tenantId, name, type, StringUtils.randomAlphanumeric(20), StringUtils.randomAlphanumeric(20)); } - protected Edge constructEdge(TenantId tenantId, String name, String type) { + protected Edge constructEdge(TenantId tenantId, String name, String type, String routingKey, String secret) { Edge edge = new Edge(); edge.setTenantId(tenantId); edge.setName(name); edge.setType(type); - edge.setSecret(StringUtils.randomAlphanumeric(20)); - edge.setRoutingKey(StringUtils.randomAlphanumeric(20)); + edge.setRoutingKey(routingKey); + edge.setSecret(secret); return edge; } diff --git a/application/src/test/java/org/thingsboard/server/controller/BaseEdgeControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/BaseEdgeControllerTest.java index fa466ce93f..a6dde57752 100644 --- a/application/src/test/java/org/thingsboard/server/controller/BaseEdgeControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/BaseEdgeControllerTest.java @@ -57,6 +57,10 @@ import org.thingsboard.server.gen.edge.v1.RuleChainUpdateMsg; import org.thingsboard.server.gen.edge.v1.UserCredentialsUpdateMsg; import org.thingsboard.server.gen.edge.v1.UserUpdateMsg; +import java.io.File; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -92,7 +96,7 @@ public abstract class BaseEdgeControllerTest extends AbstractControllerTest { } } - @Before + @Before public void beforeTest() throws Exception { loginSysAdmin(); @@ -327,7 +331,7 @@ public abstract class BaseEdgeControllerTest extends AbstractControllerTest { String customerIdStr = customerId.getId().toString(); String msgError = msgErrorNoFound("Customer", customerIdStr); - doPost("/api/customer/" + customerIdStr+ "/edge/" + savedEdge.getId().getId().toString()) + doPost("/api/customer/" + customerIdStr + "/edge/" + savedEdge.getId().getId().toString()) .andExpect(status().isNotFound()) .andExpect(statusReason(containsString(msgError))); @@ -876,4 +880,15 @@ public abstract class BaseEdgeControllerTest extends AbstractControllerTest { Edge edge = constructEdge(name, "default"); return doPost("/api/edge", edge, Edge.class); } -} + + @Test + public void testGetEdgeInstallInstructions() throws Exception { + Edge edge = constructEdge(tenantId, "Edge for Test Docker Install Instructions", "default", "7390c3a6-69b0-9910-d155-b90aca4b772e", "l7q4zsjplzwhk16geqxy"); + Edge savedEdge = doPost("/api/edge", edge, Edge.class); + String installInstructions = doGet("/api/edge/instructions/" + savedEdge.getId().getId().toString(), String.class); + URL resource = this.getClass().getClassLoader().getResource("edge/install_instructions/docker/expected-install-instructions.md"); + File file = new File(resource.toURI()); + Assert.assertEquals(new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8), installInstructions); + } + +} \ No newline at end of file diff --git a/application/src/test/resources/edge/install_instructions/docker/expected-install-instructions.md b/application/src/test/resources/edge/install_instructions/docker/expected-install-instructions.md new file mode 100644 index 0000000000..e9a175bef9 --- /dev/null +++ b/application/src/test/resources/edge/install_instructions/docker/expected-install-instructions.md @@ -0,0 +1,88 @@ +## Install edge and connect to cloud instructions + +### Localhost warning + +Localhost cannot be used for docker install - please update baseUrl to the IP address of your machine! + +Here is the list of commands, that can be used to quickly install and connect edge to the cloud using docker-compose. + +### Prerequisites + +Install Docker CE and Docker Compose. + +### Create data and logs folders + +Run following commands to create a directory for storing data and logs and then change its owner to docker container user, to be able to change user, chown command is used, which requires sudo permissions (command will request password for a sudo access): + +```bash +mkdir -p ~/.mytb-edge-data && sudo chown -R 799:799 ~/.mytb-edge-data +mkdir -p ~/.mytb-edge-logs && sudo chown -R 799:799 ~/.mytb-edge-logs +{:copy-code} +``` + +### Running ThingsBoard Edge as docker service + +Create docker compose file for ThingsBoard Edge service: + +```bash +nano docker-compose.yml +{:copy-code} +``` + +Add the following lines to the yml file: + +``` +version: '2.2' +services: +mytbedge: +restart: always +image: "thingsboard/tb-edge:3.4.1EDGE" +ports: +- "8080:8080" +- "1883:1883" +- "5683-5688:5683-5688/udp" +environment: +SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/tb-edge +CLOUD_ROUTING_KEY: 7390c3a6-69b0-9910-d155-b90aca4b772e +CLOUD_ROUTING_SECRET: l7q4zsjplzwhk16geqxy +CLOUD_RPC_HOST: localhost +volumes: +- ~/.mytb-edge-data:/data +- ~/.mytb-edge-logs:/var/log/tb-edge +postgres: +restart: always +image: "postgres:12" +ports: +- "5432" +environment: +POSTGRES_DB: tb-edge +POSTGRES_PASSWORD: postgres +volumes: +- ~/.mytb-edge-data/db:/var/lib/postgresql/data +{:copy-code} +``` + +### Ports warning [Optional] +If ThingsBoard Edge is going to be running on the same machine where ThingsBoard server is running you’ll need to update docker compose port mapping. +Please update next lines of docker compose: +ports: +- “18080:8080” +- “11883:1883” +- “15683-15688:5683-5688/udp” + Please make sure ports above are not used by any other application. + + +Execute the following commands to up this docker compose directly: + +```bash +docker-compose pull +docker-compose up +{:copy-code} +``` + +### Open ThingsBoard Edge UI + +Once started, you will be able to open ThingsBoard Edge UI using the following link http://localhost:8080. + +If during installation process you have changed edge HTTP_BIND_PORT please use that port instead for Edge UI URL: +http://localhost:HTTP_BIND_PORT From 4893980352fe9fe285f7ce501382c805d42918ff Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Wed, 23 Nov 2022 20:54:49 +0200 Subject: [PATCH 02/16] Added ConditionalOnProperty for DefaultEdgeInstallService --- .../server/service/edge/DefaultEdgeInstallService.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java b/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java index e281efbf16..e183cebca0 100644 --- a/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java +++ b/application/src/main/java/org/thingsboard/server/service/edge/DefaultEdgeInstallService.java @@ -17,11 +17,12 @@ package org.thingsboard.server.service.edge; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Service; import org.thingsboard.server.common.data.edge.Edge; import org.thingsboard.server.common.data.id.TenantId; +import org.thingsboard.server.queue.util.TbCoreComponent; import org.thingsboard.server.service.install.InstallScripts; -import org.thingsboard.server.service.security.system.SystemSecurityService; import javax.servlet.http.HttpServletRequest; import java.io.IOException; @@ -33,6 +34,8 @@ import java.nio.file.Paths; @Service @Slf4j @RequiredArgsConstructor +@ConditionalOnProperty(prefix = "edges", value = "enabled", havingValue = "true") +@TbCoreComponent public class DefaultEdgeInstallService implements EdgeInstallService { private static final String EDGE_DIR = "edge"; @@ -40,7 +43,6 @@ public class DefaultEdgeInstallService implements EdgeInstallService { private static final String EDGE_INSTALL_INSTRUCTIONS_DIR = "install_instructions"; private final InstallScripts installScripts; - private final SystemSecurityService systemSecurityService; @Override public String getDockerInstallInstructions(TenantId tenantId, Edge edge, HttpServletRequest request) { From b0790490058f2e81083438dbbb3293df8c8d748e Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 24 Nov 2022 10:35:25 +0200 Subject: [PATCH 03/16] Edge instructions UI implementation --- ui-ngx/src/app/core/http/edge.service.ts | 6 +++- .../edge-instructions-dialog.component.html | 26 ++++++++++++++++ .../edge-instructions-dialog.component.scss | 3 ++ .../edge-instructions-dialog.component.ts | 31 +++++++++++++++++++ .../home/pages/edge/edge.component.html | 9 ++++++ .../modules/home/pages/edge/edge.module.ts | 4 ++- .../pages/edge/edges-table-config.resolver.ts | 24 ++++++++++++++ .../assets/locale/locale.constant-en_US.json | 1 + 8 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html create mode 100644 ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss create mode 100644 ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts diff --git a/ui-ngx/src/app/core/http/edge.service.ts b/ui-ngx/src/app/core/http/edge.service.ts index 27cfefb6d6..d9ab289873 100644 --- a/ui-ngx/src/app/core/http/edge.service.ts +++ b/ui-ngx/src/app/core/http/edge.service.ts @@ -16,7 +16,7 @@ import { Injectable } from '@angular/core'; import { defaultHttpOptionsFromConfig, RequestConfig } from './http-utils'; -import { Observable } from 'rxjs'; +import { Observable, of } from 'rxjs'; import { HttpClient } from '@angular/common/http'; import { PageLink, TimePageLink } from '@shared/models/page/page-link'; import { PageData } from '@shared/models/page/page-data'; @@ -113,4 +113,8 @@ export class EdgeService { public bulkImportEdges(entitiesData: BulkImportRequest, config?: RequestConfig): Observable { return this.http.post('/api/edge/bulk_import', entitiesData, defaultHttpOptionsFromConfig(config)); } + + public getEdgeInstructions(edgeId: string, config?: RequestConfig): Observable { + return this.http.get(`/api/edge/instructions/${edgeId}`, defaultHttpOptionsFromConfig(config)); + } } diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html new file mode 100644 index 0000000000..3a68cb0069 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html @@ -0,0 +1,26 @@ +
+ +

info_outline + {{ 'edge.install-connect-instructions' | translate }}

+ + +
+ + +
+
+ +
+
+ +
+
diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss new file mode 100644 index 0000000000..5cfbcc9657 --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss @@ -0,0 +1,3 @@ +:host { +} + diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts new file mode 100644 index 0000000000..9b0e5a8fce --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts @@ -0,0 +1,31 @@ +import { Component, Inject } from '@angular/core'; +import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog"; +import { DialogComponent } from "@shared/components/dialog.component"; +import { Store } from "@ngrx/store"; +import { AppState } from "@core/core.state"; +import { Router } from "@angular/router"; + +export interface EdgeInstructionsData { + instructions: string; +} + +@Component({ + selector: 'tb-edge-instructions', + templateUrl: './edge-instructions-dialog.component.html', + styleUrls: ['./edge-instructions-dialog.component.scss'] +}) +export class EdgeInstructionsDialogComponent extends DialogComponent { + + instructions: string = this.data.instructions; + + constructor(protected store: Store, + protected router: Router, + public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: EdgeInstructionsData) { + super(store, router, dialogRef); + } + + cancel(): void { + this.dialogRef.close(null); + } +} diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge.component.html b/ui-ngx/src/app/modules/home/pages/edge/edge.component.html index 6acc4cba0c..f4609aff36 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge.component.html +++ b/ui-ngx/src/app/modules/home/pages/edge/edge.component.html @@ -112,6 +112,15 @@ edge.sync +
+ +
> { @@ -526,6 +530,23 @@ export class EdgesTableConfigResolver implements Resolve { + this.dialog.open(EdgeInstructionsDialogComponent, { + disableClose: false, + panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], + data: { + instructions: edgeInstructionsTemplate + } + }); + } + ) + } + onEdgeAction(action: EntityAction, config: EntityTableConfig): boolean { switch (action.action) { case 'open': @@ -558,6 +579,9 @@ export class EdgesTableConfigResolver implements Resolve Date: Thu, 24 Nov 2022 11:03:38 +0200 Subject: [PATCH 04/16] Edge instructions added license headers --- ui-ngx/src/app/core/http/edge.service.ts | 4 ++-- .../edge-instructions-dialog.component.html | 17 +++++++++++++++++ .../edge-instructions-dialog.component.scss | 15 +++++++++++++++ .../edge/edge-instructions-dialog.component.ts | 16 ++++++++++++++++ .../modules/home/pages/edge/edge.component.html | 2 +- .../pages/edge/edges-table-config.resolver.ts | 2 +- 6 files changed, 52 insertions(+), 4 deletions(-) diff --git a/ui-ngx/src/app/core/http/edge.service.ts b/ui-ngx/src/app/core/http/edge.service.ts index d9ab289873..85ebbb1282 100644 --- a/ui-ngx/src/app/core/http/edge.service.ts +++ b/ui-ngx/src/app/core/http/edge.service.ts @@ -114,7 +114,7 @@ export class EdgeService { return this.http.post('/api/edge/bulk_import', entitiesData, defaultHttpOptionsFromConfig(config)); } - public getEdgeInstructions(edgeId: string, config?: RequestConfig): Observable { - return this.http.get(`/api/edge/instructions/${edgeId}`, defaultHttpOptionsFromConfig(config)); + public getEdgeDockerInstallInstructions(edgeId: string, config?: RequestConfig): Observable { + return this.http.get(`/api/edge/instructions/${edgeId}`, defaultHttpOptionsFromConfig(config)); } } diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html index 3a68cb0069..fc375316e0 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.html @@ -1,3 +1,20 @@ +

info_outline diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss index 5cfbcc9657..3da1d18971 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.scss @@ -1,3 +1,18 @@ +/** + * 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. + */ :host { } diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts index 9b0e5a8fce..c96f06535b 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/pages/edge/edge-instructions-dialog.component.ts @@ -1,3 +1,19 @@ +/// +/// 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, Inject } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog"; import { DialogComponent } from "@shared/components/dialog.component"; diff --git a/ui-ngx/src/app/modules/home/pages/edge/edge.component.html b/ui-ngx/src/app/modules/home/pages/edge/edge.component.html index f4609aff36..e1304c3e06 100644 --- a/ui-ngx/src/app/modules/home/pages/edge/edge.component.html +++ b/ui-ngx/src/app/modules/home/pages/edge/edge.component.html @@ -113,7 +113,7 @@

-