remove $scope watch

This commit is contained in:
Mads Rasmussen
2016-11-14 20:20:03 +01:00
parent addad5b7dc
commit 1f3d305a55
2 changed files with 36 additions and 9 deletions

View File

@@ -37,6 +37,10 @@
vm.trashFilter = trashFilter;
vm.changeSortOrder = changeSortOrder;
vm.setSortProperty = setSortProperty;
vm.setContentType = setContentType;
vm.setFilterProperty = setFilterProperty;
vm.setFilterTerm = setFilterTerm;
vm.changeConstraintValue = changeConstraintValue;
function onInit() {
@@ -54,6 +58,8 @@
.then(function (conditions) {
vm.conditions = conditions;
});
throttledFunc();
}
@@ -61,6 +67,7 @@
vm.contentPickerOverlay = {
view: "contentpicker",
show: true,
submitButtonLabel: "Insert",
submit: function(model) {
var selectedNodeId = model.selection[0].id;
@@ -73,6 +80,8 @@
delete query.source.id;
}
throttledFunc();
vm.contentPickerOverlay.show = false;
vm.contentPickerOverlay = null;
},
@@ -105,6 +114,7 @@
} else {
query.sort.direction = "ascending";
}
throttledFunc();
}
function setSortProperty(query, property) {
@@ -114,20 +124,37 @@
} else {
query.sort.direction = "ascending";
}
throttledFunc();
}
function setContentType(contentType) {
vm.query.contentType = contentType;
throttledFunc();
}
function setFilterProperty(filter, property) {
filter.property = property;
throttledFunc();
}
function setFilterTerm(filter, term) {
filter.term = term;
throttledFunc();
}
function changeConstraintValue() {
throttledFunc();
}
var throttledFunc = _.throttle(function () {
templateQueryResource.postTemplateQuery(vm.query)
.then(function (response) {
$scope.model.result = response;
});
}, 200);
$scope.$watch("vm.query", function (value) {
throttledFunc();
}, true);
onInit();

View File

@@ -15,7 +15,7 @@
<ul class="dropdown-menu">
<li ng-repeat="contentType in vm.contentTypes">
<a href ng-click="vm.query.contentType = contentType">{{contentType.name}}</a>
<a href ng-click="vm.setContentType(contentType)">{{contentType.name}}</a>
</li>
</ul>
@@ -44,7 +44,7 @@
<ul class="dropdown-menu">
<li ng-repeat="property in vm.properties">
<a href ng-click="filter.property = property">
<a href ng-click="vm.setFilterProperty(filter, property)">
{{property.name}}
</a>
</li>
@@ -59,14 +59,14 @@
</a>
<ul class="dropdown-menu">
<li ng-repeat="term in vm.getPropertyOperators(filter.property)">
<a href ng-click="filter.term = term">
<a href ng-click="vm.setFilterTerm(filter, term)">
{{term.name}}
</a>
</li>
</ul>
</div>
<input type="text" ng-if="filter.term" style="width:90px;" ng-model="filter.constraintValue" />
<input type="text" ng-if="filter.term" style="width:90px;" ng-model="filter.constraintValue" ng-change="vm.changeConstraintValue()" />
<a href ng-click="vm.addFilter(vm.query)">
<i class="icon-add"></i>