Browse Source

Added manage customer edges

pull/2818/head
Volodymyr Babak 7 years ago
parent
commit
f35c115665
  1. 37
      ui/src/app/api/dashboard.service.js
  2. 37
      ui/src/app/api/edge.service.js
  3. 21
      ui/src/app/customer/customer.controller.js
  4. 6
      ui/src/app/dashboard/dashboard-fieldset.tpl.html
  5. 50
      ui/src/app/dashboard/dashboards.controller.js
  6. 3
      ui/src/app/dashboard/dashboards.tpl.html
  7. 2
      ui/src/app/dashboard/index.js
  8. 69
      ui/src/app/dashboard/manage-assigned-edges.controller.js
  9. 51
      ui/src/app/dashboard/manage-assigned-edges.tpl.html
  10. 2
      ui/src/app/edge/edge-card.tpl.html
  11. 4
      ui/src/app/edge/edge-fieldset.tpl.html
  12. 2
      ui/src/app/edge/edge.directive.js
  13. 34
      ui/src/app/locale/locale.constant-en_US.json

37
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;
}
}

37
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;

21
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});
}
}

6
ui/src/app/dashboard/dashboard-fieldset.tpl.html

@ -31,6 +31,12 @@
<md-button ng-click="onUnassignFromCustomer({event: $event})"
ng-show="!isEdit && dashboardScope === 'customer' && customerId != dashboard.publicCustomerId"
class="md-raised md-primary">{{ 'dashboard.unassign-from-customer' | translate }}</md-button>
<!--<md-button ng-click="onManageAssignedEdges({event: $event})"-->
<!--ng-show="!isEdit && dashboardScope === 'tenant'"-->
<!--class="md-raised md-primary">{{ 'dashboard.manage-assigned-edges' | translate }}</md-button>-->
<!--<md-button ng-click="onUnassignFromEdge({event: $event})"-->
<!--ng-show="!isEdit && dashboardScope === 'customer' && customerId != dashboard.publicCustomerId"-->
<!--class="md-raised md-primary">{{ 'dashboard.unassign-from-customer' | translate }}</md-button>-->
<md-button ng-click="onDeleteDashboard({event: $event})"
ng-show="!isEdit && dashboardScope === 'tenant'"
class="md-raised md-primary">{{ 'dashboard.delete' | translate }}</md-button>

50
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 () {
});
}
}

3
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)"></tb-dashboard-details>
on-delete-dashboard="vm.grid.deleteItem(event, vm.grid.detailsConfig.currentItem)"
on-manage-assigned-edges="vm.manageAssignedEdges(event, vm.grid.detailsConfig.currentItem)"></tb-dashboard-details>
</md-tab>
<md-tab ng-if="!vm.grid.detailsConfig.isDetailsEditMode && vm.grid.isTenantAdmin()" md-on-select="vm.grid.triggerResize()" label="{{ 'audit-log.audit-logs' | translate }}">
<tb-audit-log-table flex entity-type="vm.types.entityType.dashboard"

2
ui/src/app/dashboard/index.js

@ -42,6 +42,7 @@ import DashboardController from './dashboard.controller';
import DashboardSettingsController from './dashboard-settings.controller';
import AddDashboardsToCustomerController from './add-dashboards-to-customer.controller';
import ManageAssignedCustomersController from './manage-assigned-customers.controller';
import ManageAssignedEdgesController from './manage-assigned-edges.controller';
import AddWidgetController from './add-widget.controller';
import DashboardDirective from './dashboard.directive';
import EditWidgetDirective from './edit-widget.directive';
@ -76,6 +77,7 @@ export default angular.module('thingsboard.dashboard', [
.controller('DashboardSettingsController', DashboardSettingsController)
.controller('AddDashboardsToCustomerController', AddDashboardsToCustomerController)
.controller('ManageAssignedCustomersController', ManageAssignedCustomersController)
.controller('ManageAssignedEdgesController', ManageAssignedEdgesController)
.controller('AddWidgetController', AddWidgetController)
.directive('tbDashboardDetails', DashboardDirective)
.directive('tbEditWidget', EditWidgetDirective)

69
ui/src/app/dashboard/manage-assigned-edges.controller.js

@ -0,0 +1,69 @@
/*
* Copyright © 2016-2019 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.
*/
/*@ngInject*/
export default function ManageAssignedEdgesController($mdDialog, $q, types, dashboardService, actionType, dashboardIds, assignedEdges) {
var vm = this;
vm.types = types;
vm.actionType = actionType;
vm.dashboardIds = dashboardIds;
vm.assignedEdges = assignedEdges;
if (actionType != 'manage') {
vm.assignedEdges = [];
}
if (actionType == 'manage') {
vm.titleText = 'dashboard.manage-assigned-edges';
vm.labelText = 'dashboard.assigned-edges';
vm.actionName = 'action.update';
} else if (actionType == 'assign') {
vm.titleText = 'dashboard.assign-to-edges';
vm.labelText = 'dashboard.assign-to-edges-text';
vm.actionName = 'action.assign';
} else if (actionType == 'unassign') {
vm.titleText = 'dashboard.unassign-from-edges';
vm.labelText = 'dashboard.unassign-from-edges-text';
vm.actionName = 'action.unassign';
}
vm.submit = submit;
vm.cancel = cancel;
function cancel () {
$mdDialog.cancel();
}
function submit () {
var tasks = [];
for (var i=0;i<vm.dashboardIds.length;i++) {
var dashboardId = vm.dashboardIds[i];
var promise;
if (vm.actionType == 'manage') {
promise = dashboardService.updateDashboardEdges(dashboardId, vm.assignedEdges);
} else if (vm.actionType == 'assign') {
promise = dashboardService.addDashboardEdges(dashboardId, vm.assignedEdges);
} else if (vm.actionType == 'unassign') {
promise = dashboardService.removeDashboardEdges(dashboardId, vm.assignedEdges);
}
tasks.push(promise);
}
$q.all(tasks).then(function () {
$mdDialog.hide();
});
}
}

51
ui/src/app/dashboard/manage-assigned-edges.tpl.html

@ -0,0 +1,51 @@
<!--
Copyright © 2016-2019 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.
-->
<md-dialog aria-label="{{ vm.titleText | translate }}" style="width: 600px;">
<form name="theForm" ng-submit="vm.submit()">
<md-toolbar>
<div class="md-toolbar-tools">
<h2 translate>{{vm.titleText}}</h2>
<span flex></span>
<md-button class="md-icon-button" ng-click="vm.cancel()">
<ng-md-icon icon="close" aria-label="{{ 'dialog.close' | translate }}"></ng-md-icon>
</md-button>
</div>
</md-toolbar>
<md-progress-linear class="md-warn" md-mode="indeterminate" ng-disabled="!$root.loading" ng-show="$root.loading"></md-progress-linear>
<span style="min-height: 5px;" flex="" ng-show="!$root.loading"></span>
<md-dialog-content>
<div class="md-dialog-content">
<fieldset>
<span translate>{{vm.labelText}}</span>
<tb-entity-list ng-disabled="$root.loading"
ng-model="vm.assignedEdges"
entity-type="vm.types.entityType.edge"></tb-entity-list>
</fieldset>
</div>
</md-dialog-content>
<md-dialog-actions layout="row">
<span flex></span>
<md-button ng-disabled="$root.loading || !theForm.$dirty || !theForm.$valid" type="submit" class="md-raised md-primary">
{{ vm.actionName | translate }}
</md-button>
<md-button ng-disabled="$root.loading" ng-click="vm.cancel()" style="margin-right:20px;">{{ 'action.cancel' |
translate }}
</md-button>
</md-dialog-actions>
</form>
</md-dialog>

2
ui/src/app/edge/edge-card.tpl.html

@ -18,6 +18,6 @@
<div flex layout="column">
<div style="text-transform: uppercase; padding-bottom: 5px;">{{vm.item.type}}</div>
<div class="tb-card-description">{{vm.item.additionalInfo.description}}</div>
<div style="padding-top: 5px;" class="tb-small" ng-show="vm.isAssignedToCustomer()">{{'edge.assignedToCustomer' | translate}} '{{vm.item.assignedCustomer.title}}'</div>
<div style="padding-top: 5px;" class="tb-small" ng-show="vm.isAssignedToCustomer()">{{'edge.assigned-to-customer' | translate}} '{{vm.item.assignedCustomer.title}}'</div>
<div style="padding-top: 5px;" class="tb-small" ng-show="vm.isPublic()">{{'edge.public' | translate}}</div>
</div>

4
ui/src/app/edge/edge-fieldset.tpl.html

@ -31,14 +31,14 @@
data-clipboard-text="{{edge.id.id}}" ng-show="!isEdit"
class="md-raised">
<md-icon md-svg-icon="mdi:clipboard-arrow-left"></md-icon>
<span translate>edge.copyId</span>
<span translate>edge.copy-id</span>
</md-button>
</div>
<md-content class="md-padding" layout="column">
<md-input-container class="md-block"
ng-show="!isEdit && isAssignedToCustomer && !isPublic && edgeScope === 'tenant'">
<label translate>edge.assignedToCustomer</label>
<label translate>edge.assigned-to-customer</label>
<input ng-model="assignedCustomer.title" disabled>
</md-input-container>
<div class="tb-small" style="padding-bottom: 10px; padding-left: 2px;"

2
ui/src/app/edge/edge.directive.js

@ -49,7 +49,7 @@ export default function EdgeDirective($compile, $templateCache, $translate, $mdD
});
scope.onEdgeIdCopied = function() {
toast.showSuccess($translate.instant('edge.idCopiedMessage'), 750, angular.element(element).parent().parent(), 'bottom left');
toast.showSuccess($translate.instant('edge.id-copied-message'), 750, angular.element(element).parent().parent(), 'bottom left');
};
$compile(element.contents())(scope);

34
ui/src/app/locale/locale.constant-en_US.json

@ -384,6 +384,7 @@
"public-devices": "Public Devices",
"public-assets": "Public Assets",
"public-entity-views": "Public Entity Views",
"public-edges": "Public Edges",
"add": "Add Customer",
"delete": "Delete customer",
"manage-customer-users": "Manage customer users",
@ -392,7 +393,9 @@
"manage-public-devices": "Manage public devices",
"manage-public-dashboards": "Manage public dashboards",
"manage-customer-assets": "Manage customer assets",
"manage-customer-edges": "Manage customer edges",
"manage-public-assets": "Manage public assets",
"manage-public-edges": "Manage public edges",
"add-customer-text": "Add new customer",
"no-customers-text": "No customers found",
"customer-details": "Customer details",
@ -417,7 +420,8 @@
"customer-required": "Customer is required",
"select-default-customer": "Select default customer",
"default-customer": "Default customer",
"default-customer-required": "Default customer is required in order to debug dashboard on Tenant level"
"default-customer-required": "Default customer is required in order to debug dashboard on Tenant level",
"edges": "Customer Edges"
},
"datetime": {
"date-from": "Date from",
@ -564,7 +568,8 @@
"show-details": "Show details",
"hide-details": "Hide details",
"select-state": "Select target state",
"state-controller": "State controller"
"state-controller": "State controller",
"manage-assigned-edges": "Manage assigned edges"
},
"datakey": {
"settings": "Settings",
@ -729,13 +734,32 @@
"description": "Description",
"events": "Events",
"details": "Details",
"copyId": "Copy role Id",
"idCopiedMessage": "Edge Id has been copied to clipboard",
"copy-id": "Copy Edge Id",
"id-copied-message": "Edge Id has been copied to clipboard",
"permissions": "Permissions",
"edge-required": "Edge required",
"edge-type": "Edge type",
"edge-type-required": "Edge type is required.",
"select-edge-type": "Select edge type"
"select-edge-type": "Select edge type",
"assign-to-customer": "Assign to customer",
"assign-to-customer-text": "Please select the customer to assign the edge(s)",
"assign-edge-to-customer": "Assign Edge(s) To Customer",
"assign-edge-to-customer-text": "Please select the edges to assign to the customer",
"assigned-to-customer": "Assigned to customer",
"unassign-from-customer": "Unassign from customer",
"assign-edges-text": "Assign { count, plural, 1 {1 edge} other {# edges} } to customer",
"unassign-edge-title": "Are you sure you want to unassign the edge '{{edgeName}}'?",
"unassign-edge-text": "After the confirmation the edge will be unassigned and won't be accessible by the customer.",
"make-public": "Make edge public",
"make-public-edge-title": "Are you sure you want to make the edge '{{edgeName}}' public?",
"make-public-edge-text": "After the confirmation the edge and all its data will be made public and accessible by others.",
"make-private": "Make edge private",
"public": "Public",
"make-private-edge-title": "Are you sure you want to make the edge '{{edgeName}}' private?",
"make-private-edge-text": "After the confirmation the edge and all its data will be made private and won't be accessible by others.",
"import": "Import edge",
"label": "Label",
"assign-new-edge": "Assign new edge"
},
"error": {
"unable-to-connect": "Unable to connect to the server! Please check your internet connection.",

Loading…
Cancel
Save