Showed dashboards based on edge assignment

This commit is contained in:
Volodymyr Babak 2019-10-22 21:04:23 +03:00
parent 0cca90ff21
commit 4327f4d3a6
3 changed files with 28 additions and 7 deletions

View File

@ -78,7 +78,7 @@ function EntityService($http, $q, $filter, $translate, $log, userService, device
$log.error('Get Alarm Entity is not implemented!'); $log.error('Get Alarm Entity is not implemented!');
break; break;
case types.entityType.edge: case types.entityType.edge:
promise = edgeService.getEdge(entityId, true, config); promise = edgeService.getEdge(entityId, config);
break; break;
} }
return promise; return promise;

View File

@ -14,10 +14,11 @@
* limitations under the License. * limitations under the License.
*/ */
/*@ngInject*/ /*@ngInject*/
export default function AddDashboardsToEdgeController(dashboardService, $mdDialog, $q, edgeId, dashboards) { export default function AddDashboardsToEdgeController(dashboardService, types, $mdDialog, $q, edgeId, edgeCustomerId, dashboards) {
var vm = this; var vm = this;
vm.types = types;
vm.dashboards = dashboards; vm.dashboards = dashboards;
vm.searchText = ''; vm.searchText = '';
@ -52,7 +53,13 @@ export default function AddDashboardsToEdgeController(dashboardService, $mdDialo
fetchMoreItems_: function () { fetchMoreItems_: function () {
if (vm.dashboards.hasNext && !vm.dashboards.pending) { if (vm.dashboards.hasNext && !vm.dashboards.pending) {
vm.dashboards.pending = true; vm.dashboards.pending = true;
dashboardService.getTenantDashboards(vm.dashboards.nextPageLink).then( var fetchDashboardsPromise;
if (edgeCustomerId === vm.types.id.nullUid) {
fetchDashboardsPromise = dashboardService.getTenantDashboards(vm.dashboards.nextPageLink);
} else {
fetchDashboardsPromise = dashboardService.getCustomerDashboards(edgeCustomerId, vm.dashboards.nextPageLink);
}
fetchDashboardsPromise.then(
function success(dashboards) { function success(dashboards) {
vm.dashboards.data = vm.dashboards.data.concat(dashboards.data); vm.dashboards.data = vm.dashboards.data.concat(dashboards.data);
vm.dashboards.nextPageLink = dashboards.nextPageLink; vm.dashboards.nextPageLink = dashboards.nextPageLink;

View File

@ -57,8 +57,8 @@ export function DashboardCardController(types) {
} }
/*@ngInject*/ /*@ngInject*/
export function DashboardsController(userService, dashboardService, customerService, importExport, types, export function DashboardsController(userService, dashboardService, customerService, importExport, edgeService,
$state, $stateParams, $mdDialog, $document, $q, $translate) { $state, $stateParams, $mdDialog, $document, $q, $translate, types) {
var customerId = $stateParams.customerId; var customerId = $stateParams.customerId;
var edgeId = $stateParams.edgeId; var edgeId = $stateParams.edgeId;
@ -159,6 +159,13 @@ export function DashboardsController(userService, dashboardService, customerServ
if (edgeId) { if (edgeId) {
vm.edgeDashboardsTitle = $translate.instant('edge.dashboards'); vm.edgeDashboardsTitle = $translate.instant('edge.dashboards');
edgeService.getEdge(edgeId).then(
function success(edge) {
if (edge.customerId) {
vm.edgeCustomerId = edge.customerId;
}
}
)
} }
if (vm.dashboardsScope === 'tenant') { if (vm.dashboardsScope === 'tenant') {
@ -769,7 +776,14 @@ export function DashboardsController(userService, dashboardService, customerServ
$event.stopPropagation(); $event.stopPropagation();
} }
var pageSize = 10; var pageSize = 10;
dashboardService.getTenantDashboards({limit: pageSize, textSearch: ''}).then( var fetchDashboardsPromise;
if (vm.edgeCustomerId.id === vm.types.id.nullUid) {
fetchDashboardsPromise = dashboardService.getTenantDashboards({limit: pageSize, textSearch: ''});
} else {
fetchDashboardsPromise = dashboardService.getCustomerDashboards(vm.edgeCustomerId.id, {limit: pageSize, textSearch: ''});
}
fetchDashboardsPromise.then(
function success(_dashboards) { function success(_dashboards) {
var dashboards = { var dashboards = {
pageSize: pageSize, pageSize: pageSize,
@ -787,7 +801,7 @@ export function DashboardsController(userService, dashboardService, customerServ
controller: 'AddDashboardsToEdgeController', controller: 'AddDashboardsToEdgeController',
controllerAs: 'vm', controllerAs: 'vm',
templateUrl: addDashboardsToEdgeTemplate, templateUrl: addDashboardsToEdgeTemplate,
locals: {edgeId: edgeId, dashboards: dashboards}, locals: {edgeId: edgeId, edgeCustomerId: vm.edgeCustomerId.id, dashboards: dashboards},
parent: angular.element($document[0].body), parent: angular.element($document[0].body),
fullscreen: true, fullscreen: true,
targetEvent: $event targetEvent: $event