Skip to content

Commit

Permalink
fixes owncloud#368 and owncloud#176: Added fulltext search to notes
Browse files Browse the repository at this point in the history
  • Loading branch information
rstefko committed Jan 21, 2023
1 parent 9cf8d8f commit 1227d89
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ nbproject

# Generated from .drone.star
.drone.yml
js/package-lock.json
js/public/app.min.js
js/public/app.min.js.map
43 changes: 42 additions & 1 deletion js/app/controllers/notescontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,45 @@ app.controller('NotesController', function($routeParams, $scope, $location,
});
};

});
var searchform = $('.searchbox');
var searchbox = $('#searchbox');

initSearch();

function initSearch() {
$scope.queryString = searchbox.val().trim();

/** Conduct the search when there is a pause in typing in text */
var checkQueryChange = _.debounce(function() {
if ($scope.queryString != searchbox.val().trim()) {
onEnterSearchString();
}
}, 250);
searchbox.bind('propertychange change keyup input paste', checkQueryChange);

/** Handle clearing the searchbox. This has to be registered to the parent form
* of the #searchbox element.
*/
searchform.on('reset', function() {
setQueryString('');
});

/** Run search when enter pressed within the searchbox */
searchbox.bind('keydown', function (event) {
if (event.which === 13) {
onEnterSearchString();
}
});
}

function onEnterSearchString() {
setQueryString(searchbox.val().trim());
}

function setQueryString(query) {
$scope.$apply(() => {
$scope.queryString = query;
});
}

});
10 changes: 10 additions & 0 deletions js/app/filters/noteFilter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
app.filter('noteFilter', function() {
'use strict';
return function (items, searchString) {
if (!searchString || searchString.length == 0)
return items;

var regex = new RegExp(searchString, 'i');
return items.filter(x => x.title.match(regex) || x.content.match(regex));
};
});
5 changes: 4 additions & 1 deletion templates/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<a href='#'>+ <span><?php p($l->t('New note')); ?></span></a>
</li>
<!-- notes list -->
<li ng-repeat="note in notes|orderBy:['-favorite','-modified']"
<li ng-repeat="note in notes|orderBy:['-favorite','-modified']|noteFilter:queryString"
ng-class="{ active: note.id == route.noteId }">
<a href="#/notes/{{ note.id }}">
{{ note.title | noteTitle }}
Expand All @@ -67,4 +67,7 @@
<div id="app-content" ng-class="{loading: is.loading}">
<div id="app-content-container" ng-view></div>
</div>

<!-- Show search button in header -->
<div id="searchresults" class="hidden" data-appfilter="notes"></div>
</div>

0 comments on commit 1227d89

Please sign in to comment.