Implements the search part

This commit is contained in:
2016-01-26 12:31:03 +01:00
parent 5f2208839d
commit f6a884b188
6 changed files with 100 additions and 15 deletions

View File

@@ -1,6 +1,6 @@
angular.module('satbd.satellite.bar', ['ui.bootstrap','ngAnimate']);
angular.module('satbd.satellite.bar', ['ui.bootstrap','ngAnimate','ngSanitize']);
angular.module('satbd.satellite.bar').controller('GlobalCtrl', function($scope) {
angular.module('satbd.satellite.bar').controller('GlobalCtrl', function($scope,$log) {
$scope.location = '';
$scope.isActive = function(location) {
return $scope.location === location
@@ -21,15 +21,15 @@ angular.module('satbd.satellite.bar').controller('GlobalCtrl', function($scope)
$scope.$broadcast('displayAuthors')
};
$scope.search = function( query ) {
$scope.$on('onSearchQuery', function(event,query) {
$scope.location='search';
$scope.$broadcast('displaySearch', query)
};
});
$scope.$on('recentsReady', function(event) {
$scope.recents();
});
});
angular.module('satbd.satellite.bar').controller('NavbarCollapseCtrl', function ($scope, $uibModal) {
@@ -43,6 +43,11 @@ angular.module('satbd.satellite.bar').controller('NavbarCollapseCtrl', function
});
};
$scope.searchQuery = '';
$scope.search = function() {
$scope.$emit('onSearchQuery',$scope.searchQuery);
};
});
angular.module('satbd.satellite.bar').controller('HelpInstanceCtrl', function($scope, $uibModalInstance) {
@@ -78,3 +83,37 @@ angular.module('satbd.satellite.bar').controller('RecentAlbumCtrl', function($sc
});
};
});
angular.module('satbd.satellite.bar').controller('SearchCtrl', function($scope, $http, $log) {
$scope.showResults = false
$scope.searchResults = null;
$scope.searchResultsJSON = '';
$scope.clear = function () {
$scope.showResults = false;
$scope.searchResults = null;
$scope.searchResultsJSON = '';
};
$scope.$on('displayAuthors', $scope.clear);
$scope.$on('displayCollections', $scope.clear);
$scope.$on('displayRecents', $scope.clear);
$scope.$on('displaySearch', function(event, query) {
$log.info("Submitting query " + query);
$http.post('/api/search', {
"size": 20,
"explain": false,
"highlight":{},
"fields": ["série", "collection","titre","éditeur","ref","description","Note"],
"query": {
"query": query,
}
}).success(function(data) {
$scope.searchResults = data;
$scope.showResults = true;
}).error(function(data, code) {
$log.error("got " + code + " data: " + data);
$scope.showResults = true;
});
});
});