From f35c1156655673b282add8ea4784d7d98687d4b0 Mon Sep 17 00:00:00 2001 From: Volodymyr Babak Date: Fri, 11 Oct 2019 21:01:03 +0300 Subject: [PATCH] Added manage customer edges --- ui/src/app/api/dashboard.service.js | 37 +++++++++- ui/src/app/api/edge.service.js | 37 ++++++++++ ui/src/app/customer/customer.controller.js | 21 ++++++ .../app/dashboard/dashboard-fieldset.tpl.html | 6 ++ ui/src/app/dashboard/dashboards.controller.js | 50 ++++++++++++++ ui/src/app/dashboard/dashboards.tpl.html | 3 +- ui/src/app/dashboard/index.js | 2 + .../manage-assigned-edges.controller.js | 69 +++++++++++++++++++ .../dashboard/manage-assigned-edges.tpl.html | 51 ++++++++++++++ ui/src/app/edge/edge-card.tpl.html | 2 +- ui/src/app/edge/edge-fieldset.tpl.html | 4 +- ui/src/app/edge/edge.directive.js | 2 +- ui/src/app/locale/locale.constant-en_US.json | 34 +++++++-- 13 files changed, 307 insertions(+), 11 deletions(-) create mode 100644 ui/src/app/dashboard/manage-assigned-edges.controller.js create mode 100644 ui/src/app/dashboard/manage-assigned-edges.tpl.html diff --git a/ui/src/app/api/dashboard.service.js b/ui/src/app/api/dashboard.service.js index cf7b944f02..b0b72e626e 100644 --- a/ui/src/app/api/dashboard.service.js +++ b/ui/src/app/api/dashboard.service.js @@ -42,7 +42,10 @@ function DashboardService($rootScope, $http, $q, $location, $filter) { removeDashboardCustomers: removeDashboardCustomers, makeDashboardPublic: makeDashboardPublic, makeDashboardPrivate: makeDashboardPrivate, - getPublicDashboardLink: getPublicDashboardLink + getPublicDashboardLink: getPublicDashboardLink, + updateDashboardEdges: updateDashboardEdges, + addDashboardEdges: addDashboardEdges, + removeDashboardEdges: removeDashboardEdges } return service; @@ -292,4 +295,36 @@ function DashboardService($rootScope, $http, $q, $location, $filter) { return dashboard; } + function updateDashboardEdges(dashboardId, edgeIds) { + var deferred = $q.defer(); + var url = '/api/dashboard/' + dashboardId + '/edges'; + $http.post(url, edgeIds).then(function success(response) { + deferred.resolve(prepareDashboard(response.data)); + }, function fail() { + deferred.reject(); + }); + return deferred.promise; + } + + function addDashboardEdges(dashboardId, edgeIds) { + var deferred = $q.defer(); + var url = '/api/dashboard/' + dashboardId + '/edges/add'; + $http.post(url, edgeIds).then(function success(response) { + deferred.resolve(prepareDashboard(response.data)); + }, function fail() { + deferred.reject(); + }); + return deferred.promise; + } + + function removeDashboardEdges(dashboardId, edgeIds) { + var deferred = $q.defer(); + var url = '/api/dashboard/' + dashboardId + '/edges/remove'; + $http.post(url, edgeIds).then(function success(response) { + deferred.resolve(prepareDashboard(response.data)); + }, function fail() { + deferred.reject(); + }); + return deferred.promise; + } } diff --git a/ui/src/app/api/edge.service.js b/ui/src/app/api/edge.service.js index 0edb2afe63..954e2828f7 100644 --- a/ui/src/app/api/edge.service.js +++ b/ui/src/app/api/edge.service.js @@ -28,6 +28,7 @@ function EdgeService($http, $q, customerService) { saveEdge: saveEdge, getEdgeTypes: getEdgeTypes, getTenantEdges: getTenantEdges, + getCustomerEdges: getCustomerEdges, assignEdgeToCustomer: assignEdgeToCustomer, unassignEdgeFromCustomer: unassignEdgeFromCustomer, makeEdgePublic: makeEdgePublic @@ -160,6 +161,42 @@ function EdgeService($http, $q, customerService) { return deferred.promise; } + function getCustomerEdges(customerId, pageLink, applyCustomersInfo, config, type) { + var deferred = $q.defer(); + var url = '/api/customer/' + customerId + '/edges?limit=' + pageLink.limit; + if (angular.isDefined(pageLink.textSearch)) { + url += '&textSearch=' + pageLink.textSearch; + } + if (angular.isDefined(pageLink.idOffset)) { + url += '&idOffset=' + pageLink.idOffset; + } + if (angular.isDefined(pageLink.textOffset)) { + url += '&textOffset=' + pageLink.textOffset; + } + if (angular.isDefined(type) && type.length) { + url += '&type=' + type; + } + $http.get(url, config).then(function success(response) { + if (applyCustomersInfo) { + customerService.applyAssignedCustomerInfo(response.data.data, customerId).then( + function success(data) { + response.data.data = data; + deferred.resolve(response.data); + }, + function fail() { + deferred.reject(); + } + ); + } else { + deferred.resolve(response.data); + } + }, function fail() { + deferred.reject(); + }); + + return deferred.promise; + } + function assignEdgeToCustomer(customerId, edgeId) { var deferred = $q.defer(); var url = '/api/customer/' + customerId + '/edge/' + edgeId; diff --git a/ui/src/app/customer/customer.controller.js b/ui/src/app/customer/customer.controller.js index 05a0750e48..2d20a59e2b 100644 --- a/ui/src/app/customer/customer.controller.js +++ b/ui/src/app/customer/customer.controller.js @@ -77,6 +77,20 @@ export default function CustomerController(customerService, $state, $stateParams }, icon: "dashboard" }, + { + onAction: function ($event, item) { + openCustomerEdges($event, item); + }, + name: function() { return $translate.instant('edge.edges') }, + details: function(customer) { + if (customer && customer.additionalInfo && customer.additionalInfo.isPublic) { + return $translate.instant('customer.manage-public-edges') + } else { + return $translate.instant('customer.manage-customer-edges') + } + }, + icon: "toys" + }, { onAction: function ($event, item) { vm.grid.deleteItem($event, item); @@ -215,4 +229,11 @@ export default function CustomerController(customerService, $state, $stateParams } $state.go('home.customers.dashboards', {customerId: customer.id.id}); } + + function openCustomerEdges($event, customer) { + if ($event) { + $event.stopPropagation(); + } + $state.go('home.customers.edges', {customerId: customer.id.id}); + } } diff --git a/ui/src/app/dashboard/dashboard-fieldset.tpl.html b/ui/src/app/dashboard/dashboard-fieldset.tpl.html index 6f1e0742a0..2b11886213 100644 --- a/ui/src/app/dashboard/dashboard-fieldset.tpl.html +++ b/ui/src/app/dashboard/dashboard-fieldset.tpl.html @@ -31,6 +31,12 @@ {{ 'dashboard.unassign-from-customer' | translate }} + + + + + + {{ 'dashboard.delete' | translate }} diff --git a/ui/src/app/dashboard/dashboards.controller.js b/ui/src/app/dashboard/dashboards.controller.js index 67682c8639..7239c24c71 100644 --- a/ui/src/app/dashboard/dashboards.controller.js +++ b/ui/src/app/dashboard/dashboards.controller.js @@ -20,6 +20,7 @@ import dashboardCard from './dashboard-card.tpl.html'; import addDashboardsToCustomerTemplate from './add-dashboards-to-customer.tpl.html'; import makeDashboardPublicDialogTemplate from './make-dashboard-public-dialog.tpl.html'; import manageAssignedCustomersTemplate from './manage-assigned-customers.tpl.html'; +import manageAssignedEdgesTemplate from './manage-assigned-edges.tpl.html'; /* eslint-enable import/no-unresolved, import/default */ @@ -208,6 +209,17 @@ export function DashboardsController(userService, dashboardService, customerServ return dashboard; } }); + dashboardActionsList.push({ + onAction: function ($event, item) { + manageAssignedEdges($event, item); + }, + name: function() { return $translate.instant('action.assign') }, + details: function() { return $translate.instant('dashboard.manage-assigned-edges') }, + icon: "assignment", + isEnabled: function(dashboard) { + return dashboard; + } + }); /*dashboardActionsList.push({ onAction: function ($event, item) { @@ -611,4 +623,42 @@ export function DashboardsController(userService, dashboardService, customerServ $state.go('home.dashboards.dashboard', {dashboardId: dashboard.id.id}); } } + + function manageAssignedEdges($event, dashboard) { + showManageAssignedEdgesDialog($event, [dashboard.id.id], 'manage', dashboard.assignedEdgesIds); + } + + // function assignDashboardsToEdges($event, items) { + // var dashboardIds = []; + // for (var id in items.selections) { + // dashboardIds.push(id); + // } + // showManageAssignedEdgesDialog($event, dashboardIds, 'assign'); + // } + // + // function unassignDashboardsFromEdges($event, items) { + // var dashboardIds = []; + // for (var id in items.selections) { + // dashboardIds.push(id); + // } + // showManageAssignedEdgesDialog($event, dashboardIds, 'unassign'); + // } + + function showManageAssignedEdgesDialog($event, dashboardIds, actionType, assignedEdges) { + if ($event) { + $event.stopPropagation(); + } + $mdDialog.show({ + controller: 'ManageAssignedEdgesController', + controllerAs: 'vm', + templateUrl: manageAssignedEdgesTemplate, + locals: {actionType: actionType, dashboardIds: dashboardIds, assignedEdges: assignedEdges}, + parent: angular.element($document[0].body), + fullscreen: true, + targetEvent: $event + }).then(function () { + vm.grid.refreshList(); + }, function () { + }); + } } diff --git a/ui/src/app/dashboard/dashboards.tpl.html b/ui/src/app/dashboard/dashboards.tpl.html index cfff4b0083..166b3668cf 100644 --- a/ui/src/app/dashboard/dashboards.tpl.html +++ b/ui/src/app/dashboard/dashboards.tpl.html @@ -32,7 +32,8 @@ on-manage-assigned-customers="vm.manageAssignedCustomers(event, vm.grid.detailsConfig.currentItem)" on-unassign-from-customer="vm.unassignFromCustomer(event, vm.grid.detailsConfig.currentItem, vm.customerId)" on-export-dashboard="vm.exportDashboard(event, vm.grid.detailsConfig.currentItem)" - on-delete-dashboard="vm.grid.deleteItem(event, vm.grid.detailsConfig.currentItem)"> + on-delete-dashboard="vm.grid.deleteItem(event, vm.grid.detailsConfig.currentItem)" + on-manage-assigned-edges="vm.manageAssignedEdges(event, vm.grid.detailsConfig.currentItem)"> + +
+ +
+

{{vm.titleText}}

+ + + + +
+
+ + + +
+
+ {{vm.labelText}} + +
+
+
+ + + + {{ vm.actionName | translate }} + + {{ 'action.cancel' | + translate }} + + +
+
\ No newline at end of file diff --git a/ui/src/app/edge/edge-card.tpl.html b/ui/src/app/edge/edge-card.tpl.html index 7a91b07ce2..4f64d4ec34 100644 --- a/ui/src/app/edge/edge-card.tpl.html +++ b/ui/src/app/edge/edge-card.tpl.html @@ -18,6 +18,6 @@
{{vm.item.type}}
{{vm.item.additionalInfo.description}}
-
{{'edge.assignedToCustomer' | translate}} '{{vm.item.assignedCustomer.title}}'
+
{{'edge.assigned-to-customer' | translate}} '{{vm.item.assignedCustomer.title}}'
{{'edge.public' | translate}}
diff --git a/ui/src/app/edge/edge-fieldset.tpl.html b/ui/src/app/edge/edge-fieldset.tpl.html index 34ed7bfe07..759e53e164 100644 --- a/ui/src/app/edge/edge-fieldset.tpl.html +++ b/ui/src/app/edge/edge-fieldset.tpl.html @@ -31,14 +31,14 @@ data-clipboard-text="{{edge.id.id}}" ng-show="!isEdit" class="md-raised"> - edge.copyId + edge.copy-id - +