Reorganizes the project with clean MVC structure

This commit is contained in:
2016-02-11 17:04:15 +01:00
parent 143274f369
commit e109e116f5
18 changed files with 187 additions and 219 deletions

17
webapp/js/controllers.js Normal file
View File

@@ -0,0 +1,17 @@
'use strict';
var controllers = angular.module('satbd.satellite.bar.controllers',[
'ui.bootstrap',
'ngAnimate'
]);
controllers.controller('NavBarCtrl',function($scope,$location) {
$scope.isCollapsed = true;
$scope.isActive = function(loc) {
return loc === $location.path();
};
$scope.search = function(searchTerms) {
$location.url('/search?q='+ encodeURIComponent(searchTerms));
}
});

0
webapp/js/route.js Normal file
View File

View File

@@ -1,121 +1,12 @@
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();
});
'use strict';
});
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;
});
});
angular.module('satbd.satellite.bar',[
'ngRoute',
'satbd.satellite.bar.controllers',
'satbd.satellite.bar.views.recents',
'satbd.satellite.bar.views.series',
'satbd.satellite.bar.views.authors',
'satbd.satellite.bar.views.search'
]).config(function($routeProvider) {
$routeProvider.otherwise({redirectTo: '/recents'});
});

View File

@@ -0,0 +1 @@
<h1>Par autheurs </h1>

View File

@@ -0,0 +1,9 @@
'use strict';
angular.module('satbd.satellite.bar.views.authors',[
'ngRoute'
]).config(function($routeProvider) {
$routeProvider.when('/authors', {
templateUrl: 'js/views/authors/authors.html',
});
})

View File

@@ -0,0 +1 @@
<h1> Albums Récents </h1>

View File

@@ -0,0 +1,20 @@
'use strict';
angular.module('satbd.satellite.bar.views.recents',[
'ngRoute'
]).config(function($routeProvider) {
$routeProvider.when('/recents', {
templateUrl: 'js/views/recents/recents.html',
controller: 'RecentsCtrl'
});
}).controller('RecentsCtrl', function( $scope, $http, $log) {
$scope.albumIDs = [];
$http.get('/api/recents')
.success(function(data) {
for (var i=0; i < 10; i++) {
$scope.albumIDs.push(data[i]);
}
}).error(function(err){
$log.error(err);
});
});

View File

@@ -0,0 +1,2 @@
<h1> Votre recherche de '{{ terms }}' n'a pas abouti</h1>
<h3>C'est toujours pas implémenté, couillon</h3>

View File

@@ -0,0 +1,12 @@
'use strict';
angular.module('satbd.satellite.bar.views.search',[
'ngRoute'
]).config(function($routeProvider) {
$routeProvider.when('/search', {
templateUrl: 'js/views/search/search.html',
controller: 'SearchCtrl'
});
}).controller('SearchCtrl', function($scope,$routeParams) {
$scope.terms=$routeParams.q;
});

View File

@@ -0,0 +1 @@
<h1>Par Séries</h1>

View File

@@ -0,0 +1,9 @@
'use strict';
angular.module('satbd.satellite.bar.views.series',[
'ngRoute'
]).config(function($routeProvider) {
$routeProvider.when('/series', {
templateUrl: 'js/views/series/series.html'
});
});