diff --git a/www/js/controllers/market-controllers.js b/www/js/controllers/market-controllers.js index e0e7d37437ac16f52eeb061cf1292021a0026126..f543ced4591861d032660db7a4930b73b4d061cc 100644 --- a/www/js/controllers/market-controllers.js +++ b/www/js/controllers/market-controllers.js @@ -55,6 +55,14 @@ angular.module('cesium.market.controllers', ['cesium.services']) function MarketCategoryModalController($scope, Market, $state, $ionicModal) { $scope.categoryModal = null; + $scope.categories = { + all: null, + search: { + text: '', + results: {}, + options: false + } + }; // category lookup modal $ionicModal.fromTemplateUrl('templates/market/modal_category.html', { @@ -66,10 +74,13 @@ function MarketCategoryModalController($scope, Market, $state, $ionicModal) { }); $scope.openCategoryModal = function() { + // load categories Market.category.all() .then(function(categories){ - $scope.categories = categories; + $scope.categories.search.text = ''; + $scope.categories.search.results = categories; + $scope.categories.all = categories; $scope.categoryModal.show(); }); }; @@ -83,6 +94,31 @@ function MarketCategoryModalController($scope, Market, $state, $ionicModal) { console.log('Category ' + cat.name + 'selected. Method selectCategory(cat) not overwritten.'); $scope.closeCategoryModal(); }; + + $scope.searchCategoryChanged = function() { + $scope.categories.search.text = $scope.categories.search.text.toLowerCase(); + if ($scope.categories.search.text.length > 1) { + $scope.doSearchCategory($scope.categories.search.text); + } + else { + $scope.categories.search.results = $scope.categories.all; + } + }; + + $scope.doSearchCategory = function(text) { + $scope.search.looking = true; + + $scope.categories.search.results = $scope.categories.all.reduce(function(result, cat) { + if (cat.parent != null + && cat.parent != "undefined" + && cat.name.toLowerCase().search(text) != -1) { + return result.concat(cat); + } + return result; + }, []); + + $scope.categories.search.looking = false; + }; } function MarketLookupController($scope, Market, $state, $ionicModal) { diff --git a/www/js/controllers/registry-controllers.js b/www/js/controllers/registry-controllers.js index 719c75a0fe87c052c4b18a7c1860d713b67804a7..376b5cd7c3f6968ca37e58cef9d1b5c275649647 100644 --- a/www/js/controllers/registry-controllers.js +++ b/www/js/controllers/registry-controllers.js @@ -55,6 +55,14 @@ angular.module('cesium.registry.controllers', ['cesium.services']) function RegistryCategoryModalController($scope, Registry, $state, $ionicModal) { $scope.categoryModal = null; + $scope.categories = { + all: null, + search: { + text: '', + results: {}, + options: false + } + }; // category lookup modal $ionicModal.fromTemplateUrl('templates/registry/modal_category.html', { @@ -69,7 +77,9 @@ function RegistryCategoryModalController($scope, Registry, $state, $ionicModal) // load categories Registry.category.all() .then(function(categories){ - $scope.categories = categories; + $scope.categories.search.text = ''; + $scope.categories.search.results = categories; + $scope.categories.all = categories; $scope.categoryModal.show(); }); }; @@ -83,6 +93,31 @@ function RegistryCategoryModalController($scope, Registry, $state, $ionicModal) console.log('Category ' + cat.name + 'selected. Method selectCategory(cat) not overwritten.'); $scope.closeCategoryModal(); }; + + $scope.searchCategoryChanged = function() { + $scope.categories.search.text = $scope.categories.search.text.toLowerCase(); + if ($scope.categories.search.text.length > 1) { + $scope.doSearchCategory($scope.categories.search.text); + } + else { + $scope.categories.search.results = $scope.categories.all; + } + }; + + $scope.doSearchCategory = function(text) { + $scope.search.looking = true; + + $scope.categories.search.results = $scope.categories.all.reduce(function(result, cat) { + if (cat.parent != null + && cat.parent != "undefined" + && cat.name.toLowerCase().search(text) != -1) { + return result.concat(cat); + } + return result; + }, []); + + $scope.categories.search.looking = false; + }; } function RegistryLookupController($scope, Registry, $state, $ionicModal) { diff --git a/www/js/services/market-services.js b/www/js/services/market-services.js index c4203383b04d2c33f8b41a47221e76b8d2820eac..53fc215cc134bdaaa87fd753b14e55838b87e573 100644 --- a/www/js/services/market-services.js +++ b/www/js/services/market-services.js @@ -198,7 +198,9 @@ angular.module('cesium.market.services', ['ngResource', 'cesium.services', 'cesi empty: emptyHit }, category: { - all: getCategories + all: getCategories, + searchText: getResource('http://' + server + '/market/category/_search?q=:search'), + search: postResource('http://' + server + '/market/category/_search?pretty') }, record: { get: getResource('http://' + server + '/market/record/:id'), diff --git a/www/templates/market/modal_category.html b/www/templates/market/modal_category.html index 0d9042bbabfab62b84dfdc608c2052fc068b0149..700e6f5399bc79a0d3136390cb4a768d84dba000 100644 --- a/www/templates/market/modal_category.html +++ b/www/templates/market/modal_category.html @@ -8,14 +8,14 @@ <div class="list"> <label class="item item-input"> <i class="icon ion-search placeholder-icon"></i> - <input type="text" placeholder="Search" ng-model="search.text" ng-change="searchChanged()"> + <input type="text" placeholder="Search" ng-model="categories.search.text" ng-change="searchCategoryChanged()"> </label> - <label class="item center" ng-if="search.looking"> + <label class="item center" ng-if="modal.categories.search.looking"> <ion-spinner icon="android"></ion-spinner> </label> - <a class="item" ng-repeat="found in categories" ng-class="{'item-divider': (found.parent==null)}" href="#" ng-click="selectCategory(found)"> + <a class="item" ng-repeat="found in categories.search.results" ng-class="{'item-divider': (found.parent==null)}" href="#" ng-click="selectCategory(found)"> <h2 ng-bind-html="found.name"></h2> </a> </div> diff --git a/www/templates/registry/modal_category.html b/www/templates/registry/modal_category.html index b3d7c2ba7cb1a729c64ee56f934447f54d1efa72..d36d3f8fa710d078dfbf77cb9650a8fa8b563512 100644 --- a/www/templates/registry/modal_category.html +++ b/www/templates/registry/modal_category.html @@ -8,14 +8,14 @@ <div class="list"> <label class="item item-input"> <i class="icon ion-search placeholder-icon"></i> - <input type="text" placeholder="Search" ng-model="search.text" ng-change="searchChanged()"> + <input type="text" placeholder="Search" ng-model="categories.search.text" ng-change="searchCategoryChanged()"> </label> - <label class="item center" ng-if="search.looking"> + <label class="item center" ng-if="categories.search.looking"> <ion-spinner icon="android"></ion-spinner> </label> - <a class="item" ng-repeat="found in categories" ng-class="{'item-divider': (found.parent==null)}" href="#" ng-click="selectCategory(found)"> + <a class="item" ng-repeat="found in categories.search.results" ng-class="{'item-divider': (found.parent==null)}" href="#" ng-click="selectCategory(found)"> <h2 ng-bind-html="found.name" class="item-category"></h2> </a> </div>