From 7702f0350719d4dde628ff910a32621bfe7c5c36 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Mon, 17 Apr 2017 19:59:03 +0300 Subject: [PATCH] TB-48: Show assigned customer title in dashboard card. --- ui/src/app/dashboard/dashboard-card.tpl.html | 5 ++- ui/src/app/dashboard/dashboards.controller.js | 31 ++++++++++++++++++- ui/src/app/dashboard/index.js | 3 +- ui/src/app/device/device.controller.js | 4 +-- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/ui/src/app/dashboard/dashboard-card.tpl.html b/ui/src/app/dashboard/dashboard-card.tpl.html index 9cb8a4bd81..9f6cd00b7a 100644 --- a/ui/src/app/dashboard/dashboard-card.tpl.html +++ b/ui/src/app/dashboard/dashboard-card.tpl.html @@ -15,6 +15,5 @@ limitations under the License. --> -
dashboard.assignedToCustomer
+
{{'dashboard.assignedToCustomer' | translate}} '{{vm.customerTitle}}'
+ diff --git a/ui/src/app/dashboard/dashboards.controller.js b/ui/src/app/dashboard/dashboards.controller.js index b006d95981..3ef96a7198 100644 --- a/ui/src/app/dashboard/dashboards.controller.js +++ b/ui/src/app/dashboard/dashboards.controller.js @@ -23,7 +23,35 @@ import addDashboardsToCustomerTemplate from './add-dashboards-to-customer.tpl.ht /* eslint-enable import/no-unresolved, import/default */ /*@ngInject*/ -export default function DashboardsController(userService, dashboardService, customerService, importExport, types, $scope, $controller, +export function DashboardCardController($scope, types, customerService) { + + var vm = this; + + vm.types = types; + + vm.isAssignedToCustomer = function() { + if (vm.item && vm.item.customerId && vm.parentCtl.dashboardsScope === 'tenant' && + vm.item.customerId.id != vm.types.id.nullUid) { + return true; + } + return false; + } + + $scope.$watch('vm.item', + function() { + if (vm.isAssignedToCustomer()) { + customerService.getCustomerTitle(vm.item.customerId.id).then( + function success(title) { + vm.customerTitle = title; + } + ); + } + } + ); +} + +/*@ngInject*/ +export function DashboardsController(userService, dashboardService, customerService, importExport, types, $scope, $controller, $state, $stateParams, $mdDialog, $document, $q, $translate) { var customerId = $stateParams.customerId; @@ -58,6 +86,7 @@ export default function DashboardsController(userService, dashboardService, cust clickItemFunc: openDashboard, getItemTitleFunc: getDashboardTitle, + itemCardController: 'DashboardCardController', itemCardTemplateUrl: dashboardCard, parentCtl: vm, diff --git a/ui/src/app/dashboard/index.js b/ui/src/app/dashboard/index.js index 83dc850c6d..dc74c76ed4 100644 --- a/ui/src/app/dashboard/index.js +++ b/ui/src/app/dashboard/index.js @@ -35,7 +35,7 @@ import thingsboardItemBuffer from '../services/item-buffer.service'; import thingsboardImportExport from '../import-export'; import DashboardRoutes from './dashboard.routes'; -import DashboardsController from './dashboards.controller'; +import {DashboardsController, DashboardCardController} from './dashboards.controller'; import DashboardController from './dashboard.controller'; import DeviceAliasesController from './device-aliases.controller'; import AliasesDeviceSelectPanelController from './aliases-device-select-panel.controller'; @@ -68,6 +68,7 @@ export default angular.module('thingsboard.dashboard', [ ]) .config(DashboardRoutes) .controller('DashboardsController', DashboardsController) + .controller('DashboardCardController', DashboardCardController) .controller('DashboardController', DashboardController) .controller('DeviceAliasesController', DeviceAliasesController) .controller('AliasesDeviceSelectPanelController', AliasesDeviceSelectPanelController) diff --git a/ui/src/app/device/device.controller.js b/ui/src/app/device/device.controller.js index 4a054e2896..4de12bb3a4 100644 --- a/ui/src/app/device/device.controller.js +++ b/ui/src/app/device/device.controller.js @@ -31,7 +31,7 @@ export function DeviceCardController($scope, types, customerService) { vm.types = types; vm.isAssignedToCustomer = function() { - if (vm.item && vm.item.customerId && vm.parentCtl.devicesScope === 'tenant', + if (vm.item && vm.item.customerId && vm.parentCtl.devicesScope === 'tenant' && vm.item.customerId.id != vm.types.id.nullUid) { return true; } @@ -40,7 +40,7 @@ export function DeviceCardController($scope, types, customerService) { $scope.$watch('vm.item', function() { - if (vm.item && vm.item.customerId && vm.item.customerId.id != vm.types.id.nullUid) { + if (vm.isAssignedToCustomer()) { customerService.getCustomerTitle(vm.item.customerId.id).then( function success(title) { vm.customerTitle = title;