2016-12-01 11:40:28 +02:00
|
|
|
/*
|
2017-01-09 23:11:09 +02:00
|
|
|
* Copyright © 2016-2017 The Thingsboard Authors
|
2016-12-01 11:40:28 +02:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
/* eslint-disable import/no-unresolved, import/default */
|
|
|
|
|
|
|
|
|
|
import addDeviceTemplate from './add-device.tpl.html';
|
|
|
|
|
import deviceCard from './device-card.tpl.html';
|
|
|
|
|
import assignToCustomerTemplate from './assign-to-customer.tpl.html';
|
|
|
|
|
import addDevicesToCustomerTemplate from './add-devices-to-customer.tpl.html';
|
|
|
|
|
import deviceCredentialsTemplate from './device-credentials.tpl.html';
|
|
|
|
|
|
|
|
|
|
/* eslint-enable import/no-unresolved, import/default */
|
|
|
|
|
|
|
|
|
|
/*@ngInject*/
|
2017-04-23 18:04:55 +03:00
|
|
|
export function DeviceCardController(types) {
|
2017-04-17 19:07:32 +03:00
|
|
|
|
|
|
|
|
var vm = this;
|
|
|
|
|
|
|
|
|
|
vm.types = types;
|
|
|
|
|
|
|
|
|
|
vm.isAssignedToCustomer = function() {
|
2017-04-17 19:59:03 +03:00
|
|
|
if (vm.item && vm.item.customerId && vm.parentCtl.devicesScope === 'tenant' &&
|
2017-04-23 18:04:55 +03:00
|
|
|
vm.item.customerId.id != vm.types.id.nullUid && !vm.item.assignedCustomer.isPublic) {
|
2017-04-17 19:07:32 +03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-23 18:04:55 +03:00
|
|
|
vm.isPublic = function() {
|
|
|
|
|
if (vm.item && vm.item.assignedCustomer && vm.parentCtl.devicesScope === 'tenant' && vm.item.assignedCustomer.isPublic) {
|
|
|
|
|
return true;
|
2017-04-17 19:07:32 +03:00
|
|
|
}
|
2017-04-23 18:04:55 +03:00
|
|
|
return false;
|
|
|
|
|
}
|
2017-04-17 19:07:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*@ngInject*/
|
2017-04-23 18:04:55 +03:00
|
|
|
export function DeviceController(userService, deviceService, customerService, $state, $stateParams, $document, $mdDialog, $q, $translate, types) {
|
2016-12-01 11:40:28 +02:00
|
|
|
|
|
|
|
|
var customerId = $stateParams.customerId;
|
|
|
|
|
|
|
|
|
|
var deviceActionsList = [];
|
|
|
|
|
|
|
|
|
|
var deviceGroupActionsList = [];
|
|
|
|
|
|
|
|
|
|
var vm = this;
|
|
|
|
|
|
|
|
|
|
vm.types = types;
|
|
|
|
|
|
|
|
|
|
vm.deviceGridConfig = {
|
|
|
|
|
deleteItemTitleFunc: deleteDeviceTitle,
|
|
|
|
|
deleteItemContentFunc: deleteDeviceText,
|
|
|
|
|
deleteItemsTitleFunc: deleteDevicesTitle,
|
|
|
|
|
deleteItemsActionTitleFunc: deleteDevicesActionTitle,
|
|
|
|
|
deleteItemsContentFunc: deleteDevicesText,
|
|
|
|
|
|
|
|
|
|
saveItemFunc: saveDevice,
|
|
|
|
|
|
|
|
|
|
getItemTitleFunc: getDeviceTitle,
|
|
|
|
|
|
2017-04-17 19:07:32 +03:00
|
|
|
itemCardController: 'DeviceCardController',
|
2016-12-01 11:40:28 +02:00
|
|
|
itemCardTemplateUrl: deviceCard,
|
2017-03-15 18:55:50 +02:00
|
|
|
parentCtl: vm,
|
2016-12-01 11:40:28 +02:00
|
|
|
|
|
|
|
|
actionsList: deviceActionsList,
|
|
|
|
|
groupActionsList: deviceGroupActionsList,
|
|
|
|
|
|
|
|
|
|
onGridInited: gridInited,
|
|
|
|
|
|
|
|
|
|
addItemTemplateUrl: addDeviceTemplate,
|
|
|
|
|
|
|
|
|
|
addItemText: function() { return $translate.instant('device.add-device-text') },
|
|
|
|
|
noItemsText: function() { return $translate.instant('device.no-devices-text') },
|
|
|
|
|
itemDetailsText: function() { return $translate.instant('device.device-details') },
|
|
|
|
|
isDetailsReadOnly: isCustomerUser,
|
|
|
|
|
isSelectionEnabled: function () {
|
|
|
|
|
return !isCustomerUser();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (angular.isDefined($stateParams.items) && $stateParams.items !== null) {
|
|
|
|
|
vm.deviceGridConfig.items = $stateParams.items;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (angular.isDefined($stateParams.topIndex) && $stateParams.topIndex > 0) {
|
|
|
|
|
vm.deviceGridConfig.topIndex = $stateParams.topIndex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vm.devicesScope = $state.$current.data.devicesType;
|
|
|
|
|
|
|
|
|
|
vm.assignToCustomer = assignToCustomer;
|
2017-04-23 18:04:55 +03:00
|
|
|
vm.makePublic = makePublic;
|
2016-12-01 11:40:28 +02:00
|
|
|
vm.unassignFromCustomer = unassignFromCustomer;
|
|
|
|
|
vm.manageCredentials = manageCredentials;
|
|
|
|
|
|
|
|
|
|
initController();
|
|
|
|
|
|
|
|
|
|
function initController() {
|
|
|
|
|
var fetchDevicesFunction = null;
|
|
|
|
|
var deleteDeviceFunction = null;
|
|
|
|
|
var refreshDevicesParamsFunction = null;
|
|
|
|
|
|
|
|
|
|
var user = userService.getCurrentUser();
|
|
|
|
|
|
|
|
|
|
if (user.authority === 'CUSTOMER_USER') {
|
|
|
|
|
vm.devicesScope = 'customer_user';
|
|
|
|
|
customerId = user.customerId;
|
|
|
|
|
}
|
2017-04-23 18:04:55 +03:00
|
|
|
if (customerId) {
|
|
|
|
|
vm.customerDevicesTitle = $translate.instant('customer.devices');
|
|
|
|
|
customerService.getShortCustomerInfo(customerId).then(
|
|
|
|
|
function success(info) {
|
|
|
|
|
if (info.isPublic) {
|
|
|
|
|
vm.customerDevicesTitle = $translate.instant('customer.public-devices');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
|
|
|
|
|
if (vm.devicesScope === 'tenant') {
|
|
|
|
|
fetchDevicesFunction = function (pageLink) {
|
2017-04-23 18:04:55 +03:00
|
|
|
return deviceService.getTenantDevices(pageLink, true);
|
2016-12-01 11:40:28 +02:00
|
|
|
};
|
|
|
|
|
deleteDeviceFunction = function (deviceId) {
|
|
|
|
|
return deviceService.deleteDevice(deviceId);
|
|
|
|
|
};
|
|
|
|
|
refreshDevicesParamsFunction = function() {
|
|
|
|
|
return {"topIndex": vm.topIndex};
|
|
|
|
|
};
|
|
|
|
|
|
2017-04-23 18:04:55 +03:00
|
|
|
deviceActionsList.push({
|
|
|
|
|
onAction: function ($event, item) {
|
|
|
|
|
makePublic($event, item);
|
|
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('action.share') },
|
|
|
|
|
details: function() { return $translate.instant('device.make-public') },
|
|
|
|
|
icon: "share",
|
|
|
|
|
isEnabled: function(device) {
|
|
|
|
|
return device && (!device.customerId || device.customerId.id === types.id.nullUid);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
deviceActionsList.push(
|
|
|
|
|
{
|
|
|
|
|
onAction: function ($event, item) {
|
|
|
|
|
assignToCustomer($event, [ item.id.id ]);
|
|
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('action.assign') },
|
|
|
|
|
details: function() { return $translate.instant('device.assign-to-customer') },
|
|
|
|
|
icon: "assignment_ind",
|
|
|
|
|
isEnabled: function(device) {
|
|
|
|
|
return device && (!device.customerId || device.customerId.id === types.id.nullUid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
deviceActionsList.push(
|
|
|
|
|
{
|
|
|
|
|
onAction: function ($event, item) {
|
2017-04-23 18:04:55 +03:00
|
|
|
unassignFromCustomer($event, item, false);
|
2016-12-01 11:40:28 +02:00
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('action.unassign') },
|
|
|
|
|
details: function() { return $translate.instant('device.unassign-from-customer') },
|
|
|
|
|
icon: "assignment_return",
|
|
|
|
|
isEnabled: function(device) {
|
2017-04-23 18:04:55 +03:00
|
|
|
return device && device.customerId && device.customerId.id !== types.id.nullUid && !device.assignedCustomer.isPublic;
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2017-04-23 18:04:55 +03:00
|
|
|
deviceActionsList.push({
|
|
|
|
|
onAction: function ($event, item) {
|
|
|
|
|
unassignFromCustomer($event, item, true);
|
|
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('action.unshare') },
|
|
|
|
|
details: function() { return $translate.instant('device.make-private') },
|
|
|
|
|
icon: "reply",
|
|
|
|
|
isEnabled: function(device) {
|
|
|
|
|
return device && device.customerId && device.customerId.id !== types.id.nullUid && device.assignedCustomer.isPublic;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
deviceActionsList.push(
|
|
|
|
|
{
|
|
|
|
|
onAction: function ($event, item) {
|
|
|
|
|
manageCredentials($event, item);
|
|
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('device.credentials') },
|
|
|
|
|
details: function() { return $translate.instant('device.manage-credentials') },
|
|
|
|
|
icon: "security"
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
deviceActionsList.push(
|
|
|
|
|
{
|
|
|
|
|
onAction: function ($event, item) {
|
|
|
|
|
vm.grid.deleteItem($event, item);
|
|
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('action.delete') },
|
|
|
|
|
details: function() { return $translate.instant('device.delete') },
|
|
|
|
|
icon: "delete"
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
deviceGroupActionsList.push(
|
|
|
|
|
{
|
|
|
|
|
onAction: function ($event, items) {
|
|
|
|
|
assignDevicesToCustomer($event, items);
|
|
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('device.assign-devices') },
|
|
|
|
|
details: function(selectedCount) {
|
|
|
|
|
return $translate.instant('device.assign-devices-text', {count: selectedCount}, "messageformat");
|
|
|
|
|
},
|
|
|
|
|
icon: "assignment_ind"
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
deviceGroupActionsList.push(
|
|
|
|
|
{
|
|
|
|
|
onAction: function ($event) {
|
|
|
|
|
vm.grid.deleteItems($event);
|
|
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('device.delete-devices') },
|
|
|
|
|
details: deleteDevicesActionTitle,
|
|
|
|
|
icon: "delete"
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (vm.devicesScope === 'customer' || vm.devicesScope === 'customer_user') {
|
|
|
|
|
fetchDevicesFunction = function (pageLink) {
|
2017-04-23 18:04:55 +03:00
|
|
|
return deviceService.getCustomerDevices(customerId, pageLink, true);
|
2016-12-01 11:40:28 +02:00
|
|
|
};
|
|
|
|
|
deleteDeviceFunction = function (deviceId) {
|
|
|
|
|
return deviceService.unassignDeviceFromCustomer(deviceId);
|
|
|
|
|
};
|
|
|
|
|
refreshDevicesParamsFunction = function () {
|
|
|
|
|
return {"customerId": customerId, "topIndex": vm.topIndex};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (vm.devicesScope === 'customer') {
|
|
|
|
|
deviceActionsList.push(
|
|
|
|
|
{
|
|
|
|
|
onAction: function ($event, item) {
|
2017-04-23 18:04:55 +03:00
|
|
|
unassignFromCustomer($event, item, false);
|
2016-12-01 11:40:28 +02:00
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('action.unassign') },
|
|
|
|
|
details: function() { return $translate.instant('device.unassign-from-customer') },
|
2017-04-23 18:04:55 +03:00
|
|
|
icon: "assignment_return",
|
|
|
|
|
isEnabled: function(device) {
|
|
|
|
|
return device && !device.assignedCustomer.isPublic;
|
|
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
}
|
|
|
|
|
);
|
2017-04-23 18:04:55 +03:00
|
|
|
deviceActionsList.push(
|
|
|
|
|
{
|
|
|
|
|
onAction: function ($event, item) {
|
|
|
|
|
unassignFromCustomer($event, item, true);
|
|
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('action.unshare') },
|
|
|
|
|
details: function() { return $translate.instant('device.make-private') },
|
|
|
|
|
icon: "reply",
|
|
|
|
|
isEnabled: function(device) {
|
|
|
|
|
return device && device.assignedCustomer.isPublic;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
deviceActionsList.push(
|
|
|
|
|
{
|
|
|
|
|
onAction: function ($event, item) {
|
|
|
|
|
manageCredentials($event, item);
|
|
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('device.credentials') },
|
|
|
|
|
details: function() { return $translate.instant('device.manage-credentials') },
|
|
|
|
|
icon: "security"
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
deviceGroupActionsList.push(
|
|
|
|
|
{
|
|
|
|
|
onAction: function ($event, items) {
|
|
|
|
|
unassignDevicesFromCustomer($event, items);
|
|
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('device.unassign-devices') },
|
|
|
|
|
details: function(selectedCount) {
|
|
|
|
|
return $translate.instant('device.unassign-devices-action-title', {count: selectedCount}, "messageformat");
|
|
|
|
|
},
|
|
|
|
|
icon: "assignment_return"
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
vm.deviceGridConfig.addItemAction = {
|
|
|
|
|
onAction: function ($event) {
|
|
|
|
|
addDevicesToCustomer($event);
|
|
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('device.assign-devices') },
|
|
|
|
|
details: function() { return $translate.instant('device.assign-new-device') },
|
|
|
|
|
icon: "add"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if (vm.devicesScope === 'customer_user') {
|
|
|
|
|
deviceActionsList.push(
|
|
|
|
|
{
|
|
|
|
|
onAction: function ($event, item) {
|
|
|
|
|
manageCredentials($event, item);
|
|
|
|
|
},
|
|
|
|
|
name: function() { return $translate.instant('device.credentials') },
|
|
|
|
|
details: function() { return $translate.instant('device.view-credentials') },
|
|
|
|
|
icon: "security"
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
vm.deviceGridConfig.addItemAction = {};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vm.deviceGridConfig.refreshParamsFunc = refreshDevicesParamsFunction;
|
|
|
|
|
vm.deviceGridConfig.fetchItemsFunc = fetchDevicesFunction;
|
|
|
|
|
vm.deviceGridConfig.deleteItemFunc = deleteDeviceFunction;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteDeviceTitle(device) {
|
|
|
|
|
return $translate.instant('device.delete-device-title', {deviceName: device.name});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteDeviceText() {
|
|
|
|
|
return $translate.instant('device.delete-device-text');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteDevicesTitle(selectedCount) {
|
|
|
|
|
return $translate.instant('device.delete-devices-title', {count: selectedCount}, 'messageformat');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteDevicesActionTitle(selectedCount) {
|
|
|
|
|
return $translate.instant('device.delete-devices-action-title', {count: selectedCount}, 'messageformat');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteDevicesText () {
|
|
|
|
|
return $translate.instant('device.delete-devices-text');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function gridInited(grid) {
|
|
|
|
|
vm.grid = grid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getDeviceTitle(device) {
|
|
|
|
|
return device ? device.name : '';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveDevice (device) {
|
|
|
|
|
return deviceService.saveDevice(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function isCustomerUser() {
|
|
|
|
|
return vm.devicesScope === 'customer_user';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function assignToCustomer($event, deviceIds) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
var pageSize = 10;
|
|
|
|
|
customerService.getCustomers({limit: pageSize, textSearch: ''}).then(
|
|
|
|
|
function success(_customers) {
|
|
|
|
|
var customers = {
|
|
|
|
|
pageSize: pageSize,
|
|
|
|
|
data: _customers.data,
|
|
|
|
|
nextPageLink: _customers.nextPageLink,
|
|
|
|
|
selection: null,
|
|
|
|
|
hasNext: _customers.hasNext,
|
|
|
|
|
pending: false
|
|
|
|
|
};
|
|
|
|
|
if (customers.hasNext) {
|
|
|
|
|
customers.nextPageLink.limit = pageSize;
|
|
|
|
|
}
|
|
|
|
|
$mdDialog.show({
|
|
|
|
|
controller: 'AssignDeviceToCustomerController',
|
|
|
|
|
controllerAs: 'vm',
|
|
|
|
|
templateUrl: assignToCustomerTemplate,
|
|
|
|
|
locals: {deviceIds: deviceIds, customers: customers},
|
|
|
|
|
parent: angular.element($document[0].body),
|
|
|
|
|
fullscreen: true,
|
|
|
|
|
targetEvent: $event
|
|
|
|
|
}).then(function () {
|
|
|
|
|
vm.grid.refreshList();
|
|
|
|
|
}, function () {
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function fail() {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function addDevicesToCustomer($event) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
var pageSize = 10;
|
2017-04-23 18:04:55 +03:00
|
|
|
deviceService.getTenantDevices({limit: pageSize, textSearch: ''}, false).then(
|
2016-12-01 11:40:28 +02:00
|
|
|
function success(_devices) {
|
|
|
|
|
var devices = {
|
|
|
|
|
pageSize: pageSize,
|
|
|
|
|
data: _devices.data,
|
|
|
|
|
nextPageLink: _devices.nextPageLink,
|
|
|
|
|
selections: {},
|
|
|
|
|
selectedCount: 0,
|
|
|
|
|
hasNext: _devices.hasNext,
|
|
|
|
|
pending: false
|
|
|
|
|
};
|
|
|
|
|
if (devices.hasNext) {
|
|
|
|
|
devices.nextPageLink.limit = pageSize;
|
|
|
|
|
}
|
|
|
|
|
$mdDialog.show({
|
|
|
|
|
controller: 'AddDevicesToCustomerController',
|
|
|
|
|
controllerAs: 'vm',
|
|
|
|
|
templateUrl: addDevicesToCustomerTemplate,
|
|
|
|
|
locals: {customerId: customerId, devices: devices},
|
|
|
|
|
parent: angular.element($document[0].body),
|
|
|
|
|
fullscreen: true,
|
|
|
|
|
targetEvent: $event
|
|
|
|
|
}).then(function () {
|
|
|
|
|
vm.grid.refreshList();
|
|
|
|
|
}, function () {
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
function fail() {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function assignDevicesToCustomer($event, items) {
|
|
|
|
|
var deviceIds = [];
|
|
|
|
|
for (var id in items.selections) {
|
|
|
|
|
deviceIds.push(id);
|
|
|
|
|
}
|
|
|
|
|
assignToCustomer($event, deviceIds);
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-23 18:04:55 +03:00
|
|
|
function unassignFromCustomer($event, device, isPublic) {
|
2016-12-01 11:40:28 +02:00
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
2017-04-23 18:04:55 +03:00
|
|
|
var title;
|
|
|
|
|
var content;
|
|
|
|
|
var label;
|
|
|
|
|
if (isPublic) {
|
|
|
|
|
title = $translate.instant('device.make-private-device-title', {deviceName: device.name});
|
|
|
|
|
content = $translate.instant('device.make-private-device-text');
|
|
|
|
|
label = $translate.instant('device.make-private');
|
|
|
|
|
} else {
|
|
|
|
|
title = $translate.instant('device.unassign-device-title', {deviceName: device.name});
|
|
|
|
|
content = $translate.instant('device.unassign-device-text');
|
|
|
|
|
label = $translate.instant('device.unassign-device');
|
|
|
|
|
}
|
2016-12-01 11:40:28 +02:00
|
|
|
var confirm = $mdDialog.confirm()
|
|
|
|
|
.targetEvent($event)
|
2017-04-23 18:04:55 +03:00
|
|
|
.title(title)
|
|
|
|
|
.htmlContent(content)
|
|
|
|
|
.ariaLabel(label)
|
2016-12-01 11:40:28 +02:00
|
|
|
.cancel($translate.instant('action.no'))
|
|
|
|
|
.ok($translate.instant('action.yes'));
|
|
|
|
|
$mdDialog.show(confirm).then(function () {
|
|
|
|
|
deviceService.unassignDeviceFromCustomer(device.id.id).then(function success() {
|
|
|
|
|
vm.grid.refreshList();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function unassignDevicesFromCustomer($event, items) {
|
|
|
|
|
var confirm = $mdDialog.confirm()
|
|
|
|
|
.targetEvent($event)
|
|
|
|
|
.title($translate.instant('device.unassign-devices-title', {count: items.selectedCount}, 'messageformat'))
|
|
|
|
|
.htmlContent($translate.instant('device.unassign-devices-text'))
|
|
|
|
|
.ariaLabel($translate.instant('device.unassign-device'))
|
|
|
|
|
.cancel($translate.instant('action.no'))
|
|
|
|
|
.ok($translate.instant('action.yes'));
|
|
|
|
|
$mdDialog.show(confirm).then(function () {
|
|
|
|
|
var tasks = [];
|
|
|
|
|
for (var id in items.selections) {
|
|
|
|
|
tasks.push(deviceService.unassignDeviceFromCustomer(id));
|
|
|
|
|
}
|
|
|
|
|
$q.all(tasks).then(function () {
|
|
|
|
|
vm.grid.refreshList();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-23 18:04:55 +03:00
|
|
|
function makePublic($event, device) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
var confirm = $mdDialog.confirm()
|
|
|
|
|
.targetEvent($event)
|
|
|
|
|
.title($translate.instant('device.make-public-device-title', {deviceName: device.name}))
|
|
|
|
|
.htmlContent($translate.instant('device.make-public-device-text'))
|
|
|
|
|
.ariaLabel($translate.instant('device.make-public'))
|
|
|
|
|
.cancel($translate.instant('action.no'))
|
|
|
|
|
.ok($translate.instant('action.yes'));
|
|
|
|
|
$mdDialog.show(confirm).then(function () {
|
|
|
|
|
deviceService.makeDevicePublic(device.id.id).then(function success() {
|
|
|
|
|
vm.grid.refreshList();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 11:40:28 +02:00
|
|
|
function manageCredentials($event, device) {
|
|
|
|
|
if ($event) {
|
|
|
|
|
$event.stopPropagation();
|
|
|
|
|
}
|
|
|
|
|
$mdDialog.show({
|
|
|
|
|
controller: 'ManageDeviceCredentialsController',
|
|
|
|
|
controllerAs: 'vm',
|
|
|
|
|
templateUrl: deviceCredentialsTemplate,
|
|
|
|
|
locals: {deviceId: device.id.id, isReadOnly: isCustomerUser()},
|
|
|
|
|
parent: angular.element($document[0].body),
|
|
|
|
|
fullscreen: true,
|
|
|
|
|
targetEvent: $event
|
|
|
|
|
}).then(function () {
|
|
|
|
|
}, function () {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|