thingsboard-aplcache

Merge pull request #108 from thingsboard/feature/TB-48 TB-48:

4/17/2017 2:00:02 PM

Details

diff --git a/ui/src/app/dashboard/dashboard-card.tpl.html b/ui/src/app/dashboard/dashboard-card.tpl.html
index 9cb8a4b..9f6cd00 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.
 
 -->
-<div class="tb-small" ng-if="item &&
-            item.customerId.id != parentCtl.types.id.nullUid &&
-            parentCtl.dashboardsScope === 'tenant'" translate>dashboard.assignedToCustomer</div>
+<div class="tb-small" ng-show="vm.isAssignedToCustomer()">{{'dashboard.assignedToCustomer' | translate}} '{{vm.customerTitle}}'</div>
+
diff --git a/ui/src/app/dashboard/dashboards.controller.js b/ui/src/app/dashboard/dashboards.controller.js
index b006d95..3ef96a7 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 83dc850..dc74c76 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 4a054e2..4de12bb 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;