Improve devices attributes table.

This commit is contained in:
Igor Kulikov 2017-04-26 21:39:42 +03:00
parent 02202c217f
commit dcefde00f0
2 changed files with 19 additions and 9 deletions

View File

@ -72,7 +72,7 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS
scope.$watch("deviceId", function(newVal, prevVal) { scope.$watch("deviceId", function(newVal, prevVal) {
if (newVal && !angular.equals(newVal, prevVal)) { if (newVal && !angular.equals(newVal, prevVal)) {
scope.resetFilter(); scope.resetFilter();
scope.getDeviceAttributes(); scope.getDeviceAttributes(false, true);
} }
}); });
@ -81,7 +81,7 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS
scope.mode = 'default'; scope.mode = 'default';
scope.query.search = null; scope.query.search = null;
scope.selectedAttributes = []; scope.selectedAttributes = [];
scope.getDeviceAttributes(); scope.getDeviceAttributes(false, true);
} }
}); });
@ -117,15 +117,25 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS
} }
} }
scope.getDeviceAttributes = function(forceUpdate) { scope.onReorder = function() {
scope.getDeviceAttributes(false, false);
}
scope.onPaginate = function() {
scope.getDeviceAttributes(false, false);
}
scope.getDeviceAttributes = function(forceUpdate, reset) {
if (scope.attributesDeferred) { if (scope.attributesDeferred) {
scope.attributesDeferred.resolve(); scope.attributesDeferred.resolve();
} }
if (scope.deviceId && scope.attributeScope) { if (scope.deviceId && scope.attributeScope) {
scope.attributes = { if (reset) {
count: 0, scope.attributes = {
data: [] count: 0,
}; data: []
};
}
scope.checkSubscription(); scope.checkSubscription();
scope.attributesDeferred = deviceService.getDeviceAttributes(scope.deviceId, scope.attributeScope.value, scope.attributesDeferred = deviceService.getDeviceAttributes(scope.deviceId, scope.attributeScope.value,
scope.query, function(attributes, update, apply) { scope.query, function(attributes, update, apply) {

View File

@ -126,7 +126,7 @@
</md-toolbar> </md-toolbar>
<md-table-container ng-show="mode!='widget'"> <md-table-container ng-show="mode!='widget'">
<table md-table md-row-select multiple="" ng-model="selectedAttributes" md-progress="attributesDeferred.promise"> <table md-table md-row-select multiple="" ng-model="selectedAttributes" md-progress="attributesDeferred.promise">
<thead md-head md-order="query.order" md-on-reorder="getDeviceAttributes"> <thead md-head md-order="query.order" md-on-reorder="onReorder">
<tr md-row> <tr md-row>
<th md-column md-order-by="lastUpdateTs"><span>Last update time</span></th> <th md-column md-order-by="lastUpdateTs"><span>Last update time</span></th>
<th md-column md-order-by="key"><span>Key</span></th> <th md-column md-order-by="key"><span>Key</span></th>
@ -147,7 +147,7 @@
</md-table-container> </md-table-container>
<md-table-pagination ng-show="mode!='widget'" md-limit="query.limit" md-limit-options="[5, 10, 15]" <md-table-pagination ng-show="mode!='widget'" md-limit="query.limit" md-limit-options="[5, 10, 15]"
md-page="query.page" md-total="{{attributes.count}}" md-page="query.page" md-total="{{attributes.count}}"
md-on-paginate="getDeviceAttributes" md-page-select> md-on-paginate="onPaginate" md-page-select>
</md-table-pagination> </md-table-pagination>
<ul flex rn-carousel ng-if="mode==='widget'" class="widgets-carousel" <ul flex rn-carousel ng-if="mode==='widget'" class="widgets-carousel"
rn-carousel-index="widgetsCarousel.index" rn-carousel-index="widgetsCarousel.index"