Skip to content

Commit

Permalink
fix problem with importing deviceType dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
TyrManuZ committed May 2, 2018
1 parent ba79ca9 commit d95cd1b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Mac
.DS_Store

# C8Y builds
build
_build_for_deploy
Expand Down
23 changes: 18 additions & 5 deletions plugins/dashboardUtils/modals/dashboardImportConfig.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@
var datapoints = device.datapoints.join(', ');
device.help = 'Used in the following widgets: ' + widgets + '; Used for the following datapoints: ' + datapoints;
});
console.log(devices);

var dashboard = vm.resolve.dashboard;

if ($routeParams.deviceId) {
getDeviceType().then(function(result) {
vm.deviceType=result;
});
}

_.assign(vm, {
devices,
rootId,
Expand All @@ -52,12 +57,20 @@
back
});

function replaceDeviceIds() {
_.forEach(devices, function(device) {
dashboard.dashboard = _.replace(dashboard.dashboard, new RegExp("{{" + device.value + "}}", "g"), device.selectedDevice.id);
function getDeviceType() {
return c8yInventory.detail($routeParams.deviceId).then(function(result) {
return result.data.type;
});
}

function replaceDeviceIds() {
if (dashboard.manifest.type != 'deviceType') {
_.forEach(devices, function(device) {
dashboard.dashboard = _.replace(dashboard.dashboard, new RegExp("{{" + device.value + "}}", "g"), device.selectedDevice.id);
});
}
}

function setDashboardType(dashboard) {
// Now convert JSON string to object
dashboard.dashboard = angular.fromJson(dashboard.dashboard);
Expand All @@ -69,7 +82,7 @@
fragment = 'c8y_Dashboard!device!' + $routeParams.deviceId;
dashboard.dashboard[fragment] = {};
} else if (dashboard.manifest.type == 'deviceType') {
fragment = 'c8y_Dashboard!type!' + dashboard.dashboard.c8y_Dashboard.deviceType;
fragment = 'c8y_Dashboard!type!' + vm.deviceType;
dashboard.dashboard[fragment] = {};
}
return dashboard;
Expand Down
18 changes: 16 additions & 2 deletions plugins/dashboardUtils/modals/dashboardImportConfig.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@ <h3 translate>Import dashboard</h3>

<div class="modal-body container">
<form class="col-md-4 col-md-offset-1" name="setDevicesForm">
<div ng-repeat="device in vm.resolve.dashboard.manifest.devices">
<div ng-show="vm.dashboard.manifest.type == 'deviceType'">
<label>
Device type
</label>
<input
class="form-control"
name="deviceType"
ng-required="vm.dashboard.manifest.type == 'deviceType'"
ng-model="vm.deviceType"
>
</div>
<div
ng-show="vm.dashboard.manifest.type != 'deviceType'"
ng-repeat="device in vm.resolve.dashboard.manifest.devices"
>
<label>
{{device.value | translate}}
</label>
Expand All @@ -29,7 +43,7 @@ <h3 translate>Import dashboard</h3>
class="form-control"
ng-hide="true"
name="{{device.value}}"
required
ng-required="vm.dashboard.manifest.type != 'deviceType'"
ng-model="device.selectedDevice.id"
>
</div>
Expand Down

0 comments on commit d95cd1b

Please sign in to comment.