Skip to content

Commit 1227d89

Browse files
committed
fixes owncloud#368 and owncloud#176: Added fulltext search to notes
1 parent 9cf8d8f commit 1227d89

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,6 @@ nbproject
6767

6868
# Generated from .drone.star
6969
.drone.yml
70+
js/package-lock.json
71+
js/public/app.min.js
72+
js/public/app.min.js.map

js/app/controllers/notescontroller.js

+42-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,45 @@ app.controller('NotesController', function($routeParams, $scope, $location,
4343
});
4444
};
4545

46-
});
46+
var searchform = $('.searchbox');
47+
var searchbox = $('#searchbox');
48+
49+
initSearch();
50+
51+
function initSearch() {
52+
$scope.queryString = searchbox.val().trim();
53+
54+
/** Conduct the search when there is a pause in typing in text */
55+
var checkQueryChange = _.debounce(function() {
56+
if ($scope.queryString != searchbox.val().trim()) {
57+
onEnterSearchString();
58+
}
59+
}, 250);
60+
searchbox.bind('propertychange change keyup input paste', checkQueryChange);
61+
62+
/** Handle clearing the searchbox. This has to be registered to the parent form
63+
* of the #searchbox element.
64+
*/
65+
searchform.on('reset', function() {
66+
setQueryString('');
67+
});
68+
69+
/** Run search when enter pressed within the searchbox */
70+
searchbox.bind('keydown', function (event) {
71+
if (event.which === 13) {
72+
onEnterSearchString();
73+
}
74+
});
75+
}
76+
77+
function onEnterSearchString() {
78+
setQueryString(searchbox.val().trim());
79+
}
80+
81+
function setQueryString(query) {
82+
$scope.$apply(() => {
83+
$scope.queryString = query;
84+
});
85+
}
86+
87+
});

js/app/filters/noteFilter.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
app.filter('noteFilter', function() {
2+
'use strict';
3+
return function (items, searchString) {
4+
if (!searchString || searchString.length == 0)
5+
return items;
6+
7+
var regex = new RegExp(searchString, 'i');
8+
return items.filter(x => x.title.match(regex) || x.content.match(regex));
9+
};
10+
});

templates/main.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<a href='#'>+ <span><?php p($l->t('New note')); ?></span></a>
4242
</li>
4343
<!-- notes list -->
44-
<li ng-repeat="note in notes|orderBy:['-favorite','-modified']"
44+
<li ng-repeat="note in notes|orderBy:['-favorite','-modified']|noteFilter:queryString"
4545
ng-class="{ active: note.id == route.noteId }">
4646
<a href="#/notes/{{ note.id }}">
4747
{{ note.title | noteTitle }}
@@ -67,4 +67,7 @@
6767
<div id="app-content" ng-class="{loading: is.loading}">
6868
<div id="app-content-container" ng-view></div>
6969
</div>
70+
71+
<!-- Show search button in header -->
72+
<div id="searchresults" class="hidden" data-appfilter="notes"></div>
7073
</div>

0 commit comments

Comments
 (0)