Skip to content

Commit 58729b4

Browse files
committed
add AppController, search-snippets filter
1 parent 68956ec commit 58729b4

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/controllers/AppController.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* global angular */
2+
angular.module('codexen')
3+
.controller('AppController', function ($scope) {
4+
5+
})

src/filters/search-snippets.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* global angular */
2+
angular.module('codexen')
3+
.filter('searchSnippets', function ($filter) {
4+
return function (input, needle) {
5+
if (!angular.isString(needle)) return input
6+
if (needle.match(/^#./)) {
7+
var name = needle.match(/^#(.+)/)[1]
8+
return input.filter(function (snippet) {
9+
return snippet.Tags.some(function (tag) {
10+
return tag.name.match(new RegExp(name))
11+
})
12+
})
13+
}
14+
else return $filter('filter')(input, needle)
15+
}
16+
})

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919

2020
</head>
21-
<body>
21+
<body ng-controller="AppController as app">
2222
<div side-nav id="side-view"></div>
2323
<div ui-view name="main-view" id="main-view"></div>
2424

src/tpls/states/snippets.list.tpl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h4>
2626
<a ui-sref="auth.signin" class="btn btn-default"><i class="fa fa-signin"></i> Sign In</a>
2727
</li>
2828

29-
<li ng-repeat="snippet in vm.snippets | filter:vm.search" ui-sref="snippets.detail({id:snippet.id})" ui-sref-active="active">
29+
<li ng-repeat="snippet in vm.snippets | searchSnippets:vm.search" ui-sref="snippets.detail({id:snippet.id})" ui-sref-active="active">
3030
<div class="media">
3131
<div class="media-left">
3232
<img width="25" height="25" class="img-circle" src="http://www.gravatar.com/avatar/ea0b6ad1c11700120d1af08810caa19d" alt="" />

0 commit comments

Comments
 (0)