Merge pull request #2255 from matakuka/search_filter

Added search filtering by category (fixes #2019, fixes #2239)
This commit is contained in:
Emanuel Schütze 2016-08-25 17:53:55 +02:00 committed by GitHub
commit 6efbe7b210
4 changed files with 99 additions and 23 deletions

View File

@ -944,40 +944,89 @@ angular.module('OpenSlidesApp.core.site', [
.controller('SearchBarCtrl', [ .controller('SearchBarCtrl', [
'$scope', '$scope',
'$state', '$state',
function ($scope, $state) { '$sanitize',
$scope.search = function(query) { function ($scope, $state, $sanitize) {
$scope.query = ''; $scope.search = function() {
var query = _.escape($scope.querybar);
$scope.querybar = '';
$state.go('search', {q: query}); $state.go('search', {q: query});
}; };
} }
]) ])
// Search Controller // Search Controller
.controller('SearchCtrl', [ .controller('SearchCtrl', [
'$scope', '$scope',
'$http', '$http',
'$stateParams', '$stateParams',
'$location',
'$sanitize',
'DS', 'DS',
function ($scope, $http, $stateParams, DS) { function ($scope, $http, $stateParams, $location, $sanitize, DS) {
$scope.fullword = false;
$scope.filterAgenda = true;
$scope.filterMotion = true;
$scope.filterAssignment = true;
$scope.filterUser = true;
$scope.filterMedia = true;
// search function // search function
$scope.search = function(query) { $scope.search = function() {
$http.get('/core/search_api/?q=' + query).then(function(success) { var query = _.escape($scope.query);
var elements = success.data.elements; if (query !== '') {
$scope.results = []; var lastquery = query;
angular.forEach(elements, function(element) { // attach asterisks if search is not for full words only
DS.find(element.collection, element.id).then(function(data) { if (!$scope.fullword) {
data.urlState = element.collection.replace('/','.')+'.detail'; if (query.charAt(0) != '*'){
data.urlParam = {id: element.id}; query = "*" + query;
$scope.results.push(data); }
if (query.charAt(query.length - 1) != '*'){
query = query + "*";
}
}
$scope.query = lastquery;
$http.get('/core/search_api/?q=' + query).then(function(success) {
$scope.results = [];
var elements = success.data.elements;
angular.forEach(elements, function(element) {
DS.find(element.collection, element.id).then(function(data) {
data.urlState = element.collection.replace('/','.')+'.detail';
data.urlParam = {id: element.id};
$scope.results.push(data);
});
}); });
}); });
}); $location.url('/search/?q=' + lastquery);
}
}; };
// run search with get parameter from url //get search string from parameters submitted from outside the scope
if ($stateParams.q) { if ($stateParams.q) {
$scope.search($stateParams.q);
$scope.query = $stateParams.q; $scope.query = $stateParams.q;
$scope.search();
} }
// returns element if part of the current search selection
$scope.filterresult = function() {
return function(result) {
if ($scope.filterUser && result.urlState == 'users.user.detail') {
return result;
}
if ($scope.filterMotion && result.urlState == 'motions.motion.detail') {
return result;
}
if ($scope.filterAgenda && result.urlState == 'core.customslide.detail') {
return result;
}
if ($scope.filterAssignment && result.urlState == 'assignments.assignment.detail') {
return result;
}
if ($scope.filterMedia && result.urlState== 'mediafiles.mediafile.detail') {
return result;
}
return;
};
};
} }
]) ])

View File

@ -139,9 +139,9 @@
</ul> </ul>
<!-- Search bar --> <!-- Search bar -->
<div class="searchbar pull-right" ng-controller="SearchBarCtrl"> <div class="searchbar pull-right" ng-controller="SearchBarCtrl">
<form ng-submit="search(query); closeMenu()"> <form ng-submit="search(); closeMenu()">
<div class="input-group"> <div class="input-group">
<input ng-model="query" class="form-control" type="text" placeholder="{{ 'Search' | translate}}"> <input ng-model="querybar" class="form-control" type="text" placeholder="{{ 'Search' | translate}}">
<span class="input-group-btn"> <span class="input-group-btn">
<button type="submit" class="btn btn-default"> <button type="submit" class="btn btn-default">
<i class="fa fa-search"></i> <i class="fa fa-search"></i>

View File

@ -5,16 +5,43 @@
</div> </div>
<div class="details"> <div class="details">
<form class="input-group" ng-submit="search(query)"> <form class="input-group" ng-submit="search()">
<input type="text" ng-model="query" class="form-control"> <input type="text" ng-model="query" class="form-control">
<span class="input-group-btn"> <span class="input-group-btn">
<button type="submit" class="btn btn-default" translate>Search</button> <button type="submit" class="btn btn-default" translate>Search</button>
</span> </span>
</form> </form>
<div class="searchfilter spacer-top">
<label class="checkbox-inline">
<input type="checkbox" ng-model="filterAgenda">
<translate>Agenda items</translate>
</label>
<label class="checkbox-inline">
<input type="checkbox" ng-model="filterMotion">
<translate>Motions</translate>
</label>
<label class="checkbox-inline">
<input type="checkbox" ng-model="filterAssignment">
<translate>Elections</translate>
</label>
<label class="checkbox-inline">
<input type="checkbox" ng-model="filterUser">
<translate>Participants</translate>
</label>
<label class="checkbox-inline">
<input type="checkbox" ng-model="filterMedia">
<translate>Files</translate>
</label>
<div>
<label class="checkbox-inline">
<input type="checkbox" ng-model="fullword" ng-change="search()">
<translate>Only whole words</translate>
</label>
</div>
</div>
<div class="searchresults spacer-top-lg"> <div class="searchresults spacer-top-lg">
<ol ng-show="results"> <ol ng-show="results">
<li ng-repeat="result in results"> <li ng-repeat="result in results | filter:filterresult()">
<a ng-if="!result.mediafileUrl" ui-sref="{{ result.urlState }}({{ result.urlParam }})"> <a ng-if="!result.mediafileUrl" ui-sref="{{ result.urlState }}({{ result.urlParam }})">
{{ result.getSearchResultName() }} {{ result.getSearchResultName() }}
</a> </a>
@ -24,6 +51,6 @@
<br> <br>
<span class="grey">{{ result.getSearchResultSubtitle() | translate }}</span> <span class="grey">{{ result.getSearchResultSubtitle() | translate }}</span>
</ol> </ol>
<p ng-show="!results" translate>No results.</p> <p ng-show="!results || results.length == 0" translate>No results.</p>
</div> </div>
</div> </div>

View File

@ -8,7 +8,7 @@
<form name="mediafileForm" ng-submit="save(mediafile)"> <form name="mediafileForm" ng-submit="save(mediafile)">
<!-- file --> <!-- file -->
<div class="form-group"> <div class="form-group">
<label for="inputTitle" translate>File *</label> <label for="inputTitle"><translate>File</translate>*</label>
<!-- create view: show file select field --> <!-- create view: show file select field -->
<input ng-if="!mediafile.id" type="file" ngf-select ng-model="mediafile.newFile" required> <input ng-if="!mediafile.id" type="file" ngf-select ng-model="mediafile.newFile" required>
<!-- update view: show filename only --> <!-- update view: show filename only -->