Implements a search

This commit is contained in:
2016-02-15 18:24:27 +01:00
parent 0170bf99ad
commit e9e1adf089
6 changed files with 117 additions and 9 deletions

View File

@@ -1,2 +1,23 @@
<h1> Votre recherche de '{{ terms }}' n'a pas abouti</h1>
<h3>C'est toujours pas implémenté, couillon</h3>
<h3 class="text-center"> Votre recherche '{{terms}}' à donné {{response.total_hits}} résultats en {{inSecond(response.took)}} s</h3>
<div class="row" ng-repeat="h in allHits">
<div class="col-xs-5 col-sm-3 album" >
<album album-id="h.id" ratio="0.95"> </album>
</div>
<div class="col-xs-7 col-sm-9 search-result">
<div class="search-score"> {{h.fields['ref']}} <span class="badge">Score: {{round4Dec(h.score)}} </span></div>
<h4> {{h.fields['série']}} - {{h.fields['titre']}} </h4>
<hr/>
<ul class="hidden-xs">
<li ng-repeat="(field,fragments) in h.fragments"><label>{{field}}</label>:
<ul>
<li ng-repeat="f in fragments" ng-bind-html="trustedFragment(f)"></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="row text-center" in-view="$inview&&loadMore()" ng-if="scrollMore">
Chargement ...
</div>

View File

@@ -1,12 +1,56 @@
'use strict';
angular.module('satbd.satellite.bar.views.search',[
'ngRoute'
'ngRoute',
'ngSanitize',
'satbd.satellite.bar.services',
'satbd.satellite.bar.components.album',
'angular-inview'
]).config(function($routeProvider) {
$routeProvider.when('/search', {
templateUrl: 'js/views/search/search.html',
controller: 'SearchCtrl'
});
}).controller('SearchCtrl', function($scope,$routeParams) {
}).controller('SearchCtrl', function($scope,$routeParams,$log,$sce,albumService) {
$scope.terms=$routeParams.q;
$scope.scrollMore = false;
$scope.allHits = [];
$scope.pushHits = function (response) {
for ( var i = 0; i < response.hits.length; i++ ) {
$scope.allHits.push(response.hits[i]);
}
// stop scrolling if we have all hits
$scope.scrollMore = $scope.allHits.length < response.total_hits;
};
albumService.search($scope.terms).then( function(data) {
$scope.response = data;
$scope.pushHits(data);
});
$scope.loadMore = function () {
if ( !$scope.scrollMore || $scope.allHits.length >= $scope.response.total_hits) {
$scope.scrollMore = false;
$log.info('Done scrolling results');
return;
}
$log.info('Scrolling more results');
albumService.search($scope.terms,$scope.allHits.length).then( function(data) {
$scope.pushHits(data);
});
};
$scope.inSecond= function(bleveValue) {
return bleveValue / 1e6;
}
$scope.trustedFragment = function(f) {
return $sce.trustAsHtml(f);
}
$scope.round4Dec = function(value) {
return Math.round(value * 10000) / 10000;
}
});