From 71dd7de6cd6fc537bbddda342f6f71da51dd6ef6 Mon Sep 17 00:00:00 2001 From: Dima Landiak Date: Thu, 14 Dec 2017 15:46:16 +0200 Subject: [PATCH 1/3] added some funcs to rest client --- .../thingsboard/client/tools/RestClient.java | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java index d635dbcb3e..63bcd6b3c4 100644 --- a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java +++ b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java @@ -26,9 +26,16 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.support.HttpRequestWrapper; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; +import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Device; +import org.thingsboard.server.common.data.alarm.Alarm; +import org.thingsboard.server.common.data.alarm.AlarmSeverity; +import org.thingsboard.server.common.data.alarm.AlarmStatus; +import org.thingsboard.server.common.data.asset.Asset; +import org.thingsboard.server.common.data.id.AssetId; import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.DeviceId; +import org.thingsboard.server.common.data.id.EntityId; import org.thingsboard.server.common.data.security.DeviceCredentials; import java.io.IOException; @@ -71,18 +78,45 @@ public class RestClient implements ClientHttpRequestInterceptor { } } - public Device createDevice(String name) { + public Customer createCustomer(String title) { + Customer customer = new Customer(); + customer.setTitle(title); + return restTemplate.postForEntity(baseURL + "/api/customer", customer, Customer.class).getBody(); + } + + public Device createDevice(String name, String type) { Device device = new Device(); device.setName(name); + device.setType(type); return restTemplate.postForEntity(baseURL + "/api/device", device, Device.class).getBody(); } + public Asset createAsset(String name, String type) { + Asset asset = new Asset(); + asset.setName(name); + asset.setType(type); + return restTemplate.postForEntity(baseURL + "/api/asset", asset, Asset.class).getBody(); + } + + public Alarm createAlarm(String type, AlarmSeverity severity, AlarmStatus status, EntityId originator) { + Alarm alarm = new Alarm(); + alarm.setOriginator(originator); + alarm.setStatus(status); + alarm.setSeverity(severity); + alarm.setType(type); + return restTemplate.postForEntity(baseURL + "/api/alarm", alarm, Alarm.class).getBody(); + } public Device assignDevice(CustomerId customerId, DeviceId deviceId) { return restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/device/{deviceId}", null, Device.class, customerId.toString(), deviceId.toString()).getBody(); } + public Asset assignAsset(CustomerId customerId, AssetId assetId) { + return restTemplate.postForEntity(baseURL + "/api/customer/{customerId}/asset/{assetId}", null, Asset.class, + customerId.toString(), assetId.toString()).getBody(); + } + public DeviceCredentials getCredentials(DeviceId id) { return restTemplate.getForEntity(baseURL + "/api/device/" + id.getId().toString() + "/credentials", DeviceCredentials.class).getBody(); } @@ -91,11 +125,14 @@ public class RestClient implements ClientHttpRequestInterceptor { return restTemplate; } + public String getToken() { + return token; + } + @Override public ClientHttpResponse intercept(HttpRequest request, byte[] bytes, ClientHttpRequestExecution execution) throws IOException { HttpRequest wrapper = new HttpRequestWrapper(request); wrapper.getHeaders().set(JWT_TOKEN_HEADER_PARAM, "Bearer " + token); return execution.execute(wrapper, bytes); } - -} +} \ No newline at end of file From 52edc152556560513cd8c515ae4fee6b83dc3d92 Mon Sep 17 00:00:00 2001 From: Dima Landiak Date: Fri, 15 Dec 2017 12:18:58 +0200 Subject: [PATCH 2/3] minor fix --- .../main/java/org/thingsboard/client/tools/RestClient.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java index 63bcd6b3c4..7000496cdc 100644 --- a/tools/src/main/java/org/thingsboard/client/tools/RestClient.java +++ b/tools/src/main/java/org/thingsboard/client/tools/RestClient.java @@ -98,12 +98,7 @@ public class RestClient implements ClientHttpRequestInterceptor { return restTemplate.postForEntity(baseURL + "/api/asset", asset, Asset.class).getBody(); } - public Alarm createAlarm(String type, AlarmSeverity severity, AlarmStatus status, EntityId originator) { - Alarm alarm = new Alarm(); - alarm.setOriginator(originator); - alarm.setStatus(status); - alarm.setSeverity(severity); - alarm.setType(type); + public Alarm createAlarm(Alarm alarm) { return restTemplate.postForEntity(baseURL + "/api/alarm", alarm, Alarm.class).getBody(); } From c8edbffe43878f624536653eb92b3adefacf22d3 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Wed, 20 Dec 2017 11:42:48 +0200 Subject: [PATCH 3/3] Fix dashboard layout for non standard columns count. --- ui/src/app/common/dashboard-utils.service.js | 18 ++- ui/src/app/components/dashboard.directive.js | 160 +++++++++---------- 2 files changed, 89 insertions(+), 89 deletions(-) diff --git a/ui/src/app/common/dashboard-utils.service.js b/ui/src/app/common/dashboard-utils.service.js index 64a2c646cd..c4b2486b68 100644 --- a/ui/src/app/common/dashboard-utils.service.js +++ b/ui/src/app/common/dashboard-utils.service.js @@ -425,12 +425,26 @@ function DashboardUtils(types, utils, timeService) { var prevColumns = prevGridSettings ? prevGridSettings.columns : 24; var ratio = gridSettings.columns / prevColumns; layout.gridSettings = gridSettings; + var maxRow = 0; for (var w in layout.widgets) { var widget = layout.widgets[w]; + maxRow = Math.max(maxRow, widget.row + widget.sizeY); + } + var newMaxRow = Math.round(maxRow * ratio); + for (w in layout.widgets) { + widget = layout.widgets[w]; + if (widget.row + widget.sizeY == maxRow) { + widget.row = Math.round(widget.row * ratio); + widget.sizeY = newMaxRow - widget.row; + } else { + widget.row = Math.round(widget.row * ratio); + widget.sizeY = Math.round(widget.sizeY * ratio); + } widget.sizeX = Math.round(widget.sizeX * ratio); - widget.sizeY = Math.round(widget.sizeY * ratio); widget.col = Math.round(widget.col * ratio); - widget.row = Math.round(widget.row * ratio); + if (widget.col + widget.sizeX > gridSettings.columns) { + widget.sizeX = gridSettings.columns - widget.col; + } } } diff --git a/ui/src/app/components/dashboard.directive.js b/ui/src/app/components/dashboard.directive.js index 36bda5121e..c489c32f7e 100644 --- a/ui/src/app/components/dashboard.directive.js +++ b/ui/src/app/components/dashboard.directive.js @@ -235,61 +235,6 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $ removeResizeListener(gridsterParent[0], onGridsterParentResize); // eslint-disable-line no-undef }); - $scope.$watchCollection('vm.widgets', function () { - var ids = []; - for (var i=0;i