From 4327f4d3a6a15a3e857ab8574ef986cfb0c9a56a Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Tue, 22 Oct 2019 21:04:23 +0300 Subject: [PATCH] Showed dashboards based on edge assignment --- ui/src/app/api/entity.service.js | 2 +- .../add-dashboards-to-edge.controller.js | 11 ++++++++-- ui/src/app/dashboard/dashboards.controller.js | 22 +++++++++++++++---- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/ui/src/app/api/entity.service.js b/ui/src/app/api/entity.service.js index 2adac9e6a5..4700b06e99 100644 --- a/ui/src/app/api/entity.service.js +++ b/ui/src/app/api/entity.service.js @@ -78,7 +78,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device $log.error('Get Alarm Entity is not implemented!'); break; case types.entityType.edge: - promise = edgeService.getEdge(entityId, true, config); + promise = edgeService.getEdge(entityId, config); break; } return promise; diff --git a/ui/src/app/dashboard/add-dashboards-to-edge.controller.js b/ui/src/app/dashboard/add-dashboards-to-edge.controller.js index f9c28d8112..1541fd0dd0 100644 --- a/ui/src/app/dashboard/add-dashboards-to-edge.controller.js +++ b/ui/src/app/dashboard/add-dashboards-to-edge.controller.js @@ -14,10 +14,11 @@ * limitations under the License. */ /*@ngInject*/ -export default function AddDashboardsToEdgeController(dashboardService, $mdDialog, $q, edgeId, dashboards) { +export default function AddDashboardsToEdgeController(dashboardService, types, $mdDialog, $q, edgeId, edgeCustomerId, dashboards) { var vm = this; + vm.types = types; vm.dashboards = dashboards; vm.searchText = ''; @@ -52,7 +53,13 @@ export default function AddDashboardsToEdgeController(dashboardService, $mdDialo fetchMoreItems_: function () { if (vm.dashboards.hasNext && !vm.dashboards.pending) { vm.dashboards.pending = true; - dashboardService.getTenantDashboards(vm.dashboards.nextPageLink).then( + var fetchDashboardsPromise; + if (edgeCustomerId === vm.types.id.nullUid) { + fetchDashboardsPromise = dashboardService.getTenantDashboards(vm.dashboards.nextPageLink); + } else { + fetchDashboardsPromise = dashboardService.getCustomerDashboards(edgeCustomerId, vm.dashboards.nextPageLink); + } + fetchDashboardsPromise.then( function success(dashboards) { vm.dashboards.data = vm.dashboards.data.concat(dashboards.data); vm.dashboards.nextPageLink = dashboards.nextPageLink; diff --git a/ui/src/app/dashboard/dashboards.controller.js b/ui/src/app/dashboard/dashboards.controller.js index fab11b0b9c..1c5e03ae00 100644 --- a/ui/src/app/dashboard/dashboards.controller.js +++ b/ui/src/app/dashboard/dashboards.controller.js @@ -57,8 +57,8 @@ export function DashboardCardController(types) { } /*@ngInject*/ -export function DashboardsController(userService, dashboardService, customerService, importExport, types, - $state, $stateParams, $mdDialog, $document, $q, $translate) { +export function DashboardsController(userService, dashboardService, customerService, importExport, edgeService, + $state, $stateParams, $mdDialog, $document, $q, $translate, types) { var customerId = $stateParams.customerId; var edgeId = $stateParams.edgeId; @@ -159,6 +159,13 @@ export function DashboardsController(userService, dashboardService, customerServ if (edgeId) { vm.edgeDashboardsTitle = $translate.instant('edge.dashboards'); + edgeService.getEdge(edgeId).then( + function success(edge) { + if (edge.customerId) { + vm.edgeCustomerId = edge.customerId; + } + } + ) } if (vm.dashboardsScope === 'tenant') { @@ -769,7 +776,14 @@ export function DashboardsController(userService, dashboardService, customerServ $event.stopPropagation(); } var pageSize = 10; - dashboardService.getTenantDashboards({limit: pageSize, textSearch: ''}).then( + var fetchDashboardsPromise; + if (vm.edgeCustomerId.id === vm.types.id.nullUid) { + fetchDashboardsPromise = dashboardService.getTenantDashboards({limit: pageSize, textSearch: ''}); + } else { + fetchDashboardsPromise = dashboardService.getCustomerDashboards(vm.edgeCustomerId.id, {limit: pageSize, textSearch: ''}); + } + + fetchDashboardsPromise.then( function success(_dashboards) { var dashboards = { pageSize: pageSize, @@ -787,7 +801,7 @@ export function DashboardsController(userService, dashboardService, customerServ controller: 'AddDashboardsToEdgeController', controllerAs: 'vm', templateUrl: addDashboardsToEdgeTemplate, - locals: {edgeId: edgeId, dashboards: dashboards}, + locals: {edgeId: edgeId, edgeCustomerId: vm.edgeCustomerId.id, dashboards: dashboards}, parent: angular.element($document[0].body), fullscreen: true, targetEvent: $event