Skip to content

Simple search functionality #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions css/notes.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@
padding-left: 2px;
}

#app-navigation li .nav-entry {
display: block;
width: 100%;
line-height: 44px;
min-height: 44px;
padding: 0 12px;
overflow: hidden;
box-sizing: border-box;
white-space: nowrap;
text-overflow: ellipsis;
color: #000;
opacity: .57;
}

#app-navigation li:hover .nav-entry,
#app-navigation li:focus .nav-entry {
opacity: 1;
}

#app-navigation #note-add:hover span,
#app-navigation #note-add:focus span {
display: inline;
Expand Down Expand Up @@ -52,6 +71,25 @@
opacity: 1 !important;
}

.note-search span {
background-position: 0 center;
background-origin: content-box;
}

.note-search input {
width: 100%;
padding-left: 20px;
background-color: transparent;
border: none;
border-radius: 0;
}

.note-search input:active,
.note-search input:focus,
.note-search input:hover {
border-bottom: 1px solid grey;
}

.tooltip {
text-shadow: none;
text-transform: none;
Expand Down
2 changes: 2 additions & 0 deletions js/app/controllers/appcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ app.controller('AppController', function ($scope, $location, is) {
$location.path('/notes/' + lastViewedNote);
}
};

$scope.search = '';
});
14 changes: 14 additions & 0 deletions js/app/filters/and.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* filter by multiple words (AND operation)
*/
app.filter('and', ['$filter', function ($filter) {
'use strict';
return function (items, searchString) {
var searchValues = searchString.split(' ');
var filtered = items;
for(var i in searchValues) {
filtered = $filter('filter')(filtered, searchValues[i]);
}
return filtered;
};
}]);
2 changes: 1 addition & 1 deletion js/public/app.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/public/app.min.js.map

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions js/tests/unit/filters/andfilterSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
describe('and filter', function() {
'use strict';

var result;
var $filter;

beforeEach(module('Notes'));

beforeEach(inject(function(_$filter_) {
$filter = _$filter_;
}));


it ('should do nothing if search string is empty', function() {
result = $filter('and')([], '');
expect(result).toEqual([]);

result = $filter('and')(['a', 'lot', 'of', 'strings'], '');
expect(result).toEqual(['a', 'lot', 'of', 'strings']);
});

it ('should match single words', function() {
result = $filter('and')(['a', 'ad', 'multiple words'], 'd');
expect(result).toEqual(['ad', 'multiple words']);
});

it ('should math multiple words', function() {
result = $filter('and')(['a b c', 'a c e', 'a d'], 'a c');
expect(result).toEqual(['a b c', 'a c e']);
});

it ('should return nothing if nothing matches', function() {
result = $filter('and')(['brown fox jumps over the lazy dog'], 'quick');
expect(result).toEqual([]);
});
});
12 changes: 11 additions & 1 deletion templates/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@

<div id="app-navigation" ng-controller="NotesController">
<ul>
<li class="note-search">
<span class="nav-entry icon-search">
<input type="text" ng-model="search" />
</span>
</li>
<!-- new note button -->
<li id="note-add" ng-click="create()"
oc-click-focus="{ selector: '#app-content textarea' }">
<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 filteredNotes = (notes| and:search | orderBy:['-favorite','-modified'])"
ng-class="{ active: note.id == route.noteId }">
<a href="#/notes/{{ note.id }}">
{{ note.title | noteTitle }}
Expand All @@ -61,6 +66,11 @@
ng-class="{'icon-starred': note.favorite}"></button>
</span>
</li>
<li ng-hide="filteredNotes.length">
<span class="nav-entry">
<?php p($l->t('No notes found')); ?>
</span>
</li>

</ul>
</div>
Expand Down