Files
satbd-explorer/webapp/js/satbd.satellite.bar.js

122 lines
3.6 KiB
JavaScript

angular.module('satbd.satellite.bar', ['ui.bootstrap','ngAnimate','ngSanitize']);
angular.module('satbd.satellite.bar').controller('GlobalCtrl', function($scope,$log) {
$scope.location = '';
$scope.isActive = function(location) {
return $scope.location === location
};
$scope.recents = function() {
$scope.location='recents';
$scope.$broadcast('displayRecents')
};
$scope.collections = function() {
$scope.location='collections';
$scope.$broadcast('displayCollections')
};
$scope.authors = function() {
$scope.location='authors';
$scope.$broadcast('displayAuthors')
};
$scope.$on('onSearchQuery', function(event,query) {
if (query.length > 0) {
$scope.location='search';
$scope.$broadcast('displaySearch', query)
}
});
$scope.$on('recentsReady', function(event) {
$scope.recents();
});
});
angular.module('satbd.satellite.bar').controller('NavbarCollapseCtrl', function ($scope, $uibModal) {
$scope.isCollapsed = true;
$scope.openModal = function (size) {
var modalInstance = $uibModal.open({
templateUrl: 'help.html',
controller: 'HelpInstanceCtrl',
size: size,
keyboard: true,
});
};
$scope.searchQuery = '';
$scope.search = function() {
$scope.$emit('onSearchQuery',$scope.searchQuery);
};
});
angular.module('satbd.satellite.bar').controller('HelpInstanceCtrl', function($scope, $uibModalInstance) {
$scope.ok = function () {
$uibModalInstance.close('');
};
});
angular.module('satbd.satellite.bar').controller('RecentCtrl', function($scope, $http,$log) {
$scope.albumIDs = [ ];
$scope.clear = function(event) { $scope.albumIDs = [] };
$scope.$on('displayAuthors', $scope.clear);
$scope.$on('displayCollections', $scope.clear);
$scope.$on('displaySearch', $scope.clear);
$scope.$on('displayRecents', function(event) {
$scope.clear();
$log.info('fetching recent albums');
$http.get('/api/recents').success(function(data){
for (var i = 0; i < 10; i++) {
$scope.albumIDs.push(data[i]);
}
});
});
$scope.$emit('recentsReady')
});
angular.module('satbd.satellite.bar').controller('RecentAlbumCtrl', function($scope, $http) {
$scope.init_by_id = function(id) {
$http.get('api/albums/'+ id).success(function (data) {
$scope.album = data;
});
};
});
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;
});
});
});