Commit ff2397443a823546dcfd30b2d138b58bc48b8ea2

Authored by Melody
1 parent d9ebbe3d97

Nicer formatting for search

Showing 2 changed files with 5 additions and 7 deletions Inline Diff

scripts/CardListController.js View file @ ff23974
angular.module('flashy.CardListController', ['ui.router']). 1 1 angular.module('flashy.CardListController', ['ui.router']).
controller('CardListController', function($scope, $rootScope, $state, $http, $stateParams) { 2 2 controller('CardListController', function($scope, $rootScope, $state, $http, $stateParams) {
// cards array 3 3 // cards array
sectionId = $stateParams.sectionId; 4 4 sectionId = $stateParams.sectionId;
$rootScope.currentSection = $rootScope.SectionResource.get({sectionId: sectionId}); 5 5 $rootScope.currentSection = $rootScope.SectionResource.get({sectionId: sectionId});
$scope.cards = []; 6 6 $scope.cards = [];
7 7
$http.get('/api/sections/' + sectionId + '/flashcards/'). 8 8 $http.get('/api/sections/' + sectionId + '/flashcards/?hidden=yes').
success(function(data) { 9 9 success(function(data) {
console.log(data); 10 10 console.log(data);
$scope.cards = data; 11 11 $scope.cards = data;
}). 12 12 }).
error(function(err) { 13 13 error(function(err) {
console.log('pulling feed failed'); 14 14 console.log('pulling feed failed');
}); 15 15 });
16 16
$scope.viewFeed = function() { 17 17 $scope.viewFeed = function() {
$state.go('feed', {sectionId: sectionId}); 18 18 $state.go('feed', {sectionId: sectionId});
console.log('go to feed'); 19 19 console.log('go to feed');
}; 20 20 };
21 21
// unhide card (dunno if it works yet) 22 22 // unhide card (dunno if it works yet)
$scope.unhide = function(card) { 23 23 $scope.unhide = function(card) {
$http.post('/api/flashcards/' + card.id + '/unhide/'). 24 24 $http.post('/api/flashcards/' + card.id + '/unhide/').
success(function(data) { 25 25 success(function(data) {
console.log(card.text + ' unhidden'); 26 26 console.log(card.text + ' unhidden');
}). 27 27 }).
error(function(err) { 28 28 error(function(err) {
console.log('no unhide for you'); 29 29 console.log('no unhide for you');
}); 30 30 });
}; 31 31 };
32 32
// toggle button text from show to hide 33 33 // toggle button text from show to hide
$(function() { 34 34 $(function() {
$('#showHidden').click(function() { 35 35 $('#showHidden').click(function() {
$(this).text(function(i, text) { 36 36 $(this).text(function(i, text) {
return text === 'Show Hidden' ? 'Hide Hidden' : 'Show Hidden'; 37 37 return text === 'Show Hidden' ? 'Hide Hidden' : 'Show Hidden';
}); 38 38 });
}); 39 39 });
}); 40 40 });
$scope.$on('$destroy', function() { 41 41 $scope.$on('$destroy', function() {
$rootScope.currentSection = {}; 42 42 $rootScope.currentSection = {};
$(document).off('keydown'); 43 43 $(document).off('keydown');
}); 44 44 });
45 45
// checkbox filter 46 46 // checkbox filter
$scope.filter = { 47 47 $scope.filter = {
'week1': true, 48 48 'week1': true,
'week2': true, 49 49 'week2': true,
'week3': true, 50 50 'week3': true,
'week4': true, 51 51 'week4': true,
'week5': true, 52 52 'week5': true,
'week6': true, 53 53 'week6': true,
'week7': true, 54 54 'week7': true,
'week8': true, 55 55 'week8': true,
'week9': true, 56 56 'week9': true,
'week10': true, 57 57 'week10': true,
}; 58 58 };
59 59
$scope.filterByDate = function(item) { 60 60 $scope.filterByDate = function(item) {
var date = new Date(item.pushed); 61 61 var date = new Date(item.pushed);
return ((date >= new Date('Mar 29, 2015')) && (date <= new Date('Apr 4, 2015')) && $scope.filter['week1']) || 62 62 return ((date >= new Date('Mar 29, 2015')) && (date <= new Date('Apr 4, 2015')) && $scope.filter['week1']) ||
((date >= new Date('Apr 4, 2015')) && (date <= new Date('Apr 11, 2015')) && $scope.filter['week2']) || 63 63 ((date >= new Date('Apr 4, 2015')) && (date <= new Date('Apr 11, 2015')) && $scope.filter['week2']) ||
((date >= new Date('Apr 12, 2015')) && (date <= new Date('Apr 18, 2015')) && $scope.filter['week3']) || 64 64 ((date >= new Date('Apr 12, 2015')) && (date <= new Date('Apr 18, 2015')) && $scope.filter['week3']) ||
((date >= new Date('Apr 19, 2015')) && (date <= new Date('Apr 25, 2015')) && $scope.filter['week4']) || 65 65 ((date >= new Date('Apr 19, 2015')) && (date <= new Date('Apr 25, 2015')) && $scope.filter['week4']) ||
((date >= new Date('Apr 26, 2015')) && (date <= new Date('May 2, 2015')) && $scope.filter['week5']) || 66 66 ((date >= new Date('Apr 26, 2015')) && (date <= new Date('May 2, 2015')) && $scope.filter['week5']) ||
((date >= new Date('May 3, 2015')) && (date <= new Date('May 9, 2015')) && $scope.filter['week6']) || 67 67 ((date >= new Date('May 3, 2015')) && (date <= new Date('May 9, 2015')) && $scope.filter['week6']) ||
((date >= new Date('May 10, 2015')) && (date <= new Date('May 16, 2015')) && $scope.filter['week7']) || 68 68 ((date >= new Date('May 10, 2015')) && (date <= new Date('May 16, 2015')) && $scope.filter['week7']) ||
((date >= new Date('May 17, 2015')) && (date <= new Date('May 23, 2015')) && $scope.filter['week8']) || 69 69 ((date >= new Date('May 17, 2015')) && (date <= new Date('May 23, 2015')) && $scope.filter['week8']) ||
templates/cardlist.html View file @ ff23974
<div class="row"> 1 1 <div class="row">
<a class="btn" id="showHidden" ng-click="show = !show" style="margin-top: 15px">Show Hidden</a> 2 2 <a class="btn" id="showHidden" ng-click="show = !show" style="margin-top: 15px">Show Hidden</a>
<form class="col s6"> 3 3 <div class="input-field col s4 right">
<div class="input-field col s6"> 4
<i class="mdi-action-search prefix"></i> 5 4 <i class="mdi-action-search prefix"></i>
<input id="search" type="text" class="validate" ng-model="searchText"> 6 5 <input id="search" type="text" class="validate" ng-model="searchText"/>
<label for="search">Search</label> 7 6 <label for="search">Search</label>
</div> 8 7 </div>
</form> 9
</div> 10 8 </div>
11 9
<div class="row"> 12 10 <div class="row">
<form> 13 11 <form>
<div class="row"> 14 12 <div class="col s12">
<div class="col s2"> 15 13 <div class="col s2">
<input type="checkbox" class="filled-in" id="weekOneCheck" ng-model="filter['week1']"/> 16 14 <input type="checkbox" class="filled-in" id="weekOneCheck" ng-model="filter['week1']"/>
<label for="weekOneCheck">Week One</label> 17 15 <label for="weekOneCheck">Week One</label>
</div> 18 16 </div>
<div class="col s2"> 19 17 <div class="col s2">
<input type="checkbox" class="filled-in" id="weekTwoCheck" ng-model="filter['week2']"/> 20 18 <input type="checkbox" class="filled-in" id="weekTwoCheck" ng-model="filter['week2']"/>
<label for="weekTwoCheck">Week Two</label> 21 19 <label for="weekTwoCheck">Week Two</label>
</div> 22 20 </div>
<div class="col s2"> 23 21 <div class="col s2">
<input type="checkbox" class="filled-in" id="weekThreeCheck" ng-model="filter['week3']"/> 24 22 <input type="checkbox" class="filled-in" id="weekThreeCheck" ng-model="filter['week3']"/>
<label for="weekThreeCheck">Week Three</label> 25 23 <label for="weekThreeCheck">Week Three</label>
</div> 26 24 </div>
<div class="col s2"> 27 25 <div class="col s2">
<input type="checkbox" class="filled-in" id="weekFourCheck" ng-model="filter['week4']"/> 28 26 <input type="checkbox" class="filled-in" id="weekFourCheck" ng-model="filter['week4']"/>
<label for="weekFourCheck">Week Four</label> 29 27 <label for="weekFourCheck">Week Four</label>
</div> 30 28 </div>
<div class="col s2"> 31 29 <div class="col s2">
<input type="checkbox" class="filled-in" id="weekFiveCheck" ng-model="filter['week5']"/> 32 30 <input type="checkbox" class="filled-in" id="weekFiveCheck" ng-model="filter['week5']"/>
<label for="weekFiveCheck">Week Five</label> 33 31 <label for="weekFiveCheck">Week Five</label>
</div> 34 32 </div>
</div> 35 33 </div>
<div class="row"> 36 34 <div class="col s12">
<div class="col s2"> 37 35 <div class="col s2">
<input type="checkbox" class="filled-in" id="weekSixCheck" ng-model="filter['week6']"/> 38 36 <input type="checkbox" class="filled-in" id="weekSixCheck" ng-model="filter['week6']"/>
<label for="weekSixCheck">Week Six</label> 39 37 <label for="weekSixCheck">Week Six</label>
</div> 40 38 </div>
<div class="col s2"> 41 39 <div class="col s2">
<input type="checkbox" class="filled-in" id="weekSevenCheck" ng-model="filter['week7']"/> 42 40 <input type="checkbox" class="filled-in" id="weekSevenCheck" ng-model="filter['week7']"/>
<label for="weekSevenCheck">Week Seven</label> 43 41 <label for="weekSevenCheck">Week Seven</label>
</div> 44 42 </div>
<div class="col s2"> 45 43 <div class="col s2">
<input type="checkbox" class="filled-in" id="weekEightCheck" ng-model="filter['week8']"/> 46 44 <input type="checkbox" class="filled-in" id="weekEightCheck" ng-model="filter['week8']"/>
<label for="weekEightCheck">Week Eight</label> 47 45 <label for="weekEightCheck">Week Eight</label>
</div> 48 46 </div>
<div class="col s2"> 49 47 <div class="col s2">
<input type="checkbox" class="filled-in" id="weekNineCheck" ng-model="filter['week9']"/> 50 48 <input type="checkbox" class="filled-in" id="weekNineCheck" ng-model="filter['week9']"/>
<label for="weekNineCheck">Week Nine</label> 51 49 <label for="weekNineCheck">Week Nine</label>
</div> 52 50 </div>
<div class="col s2"> 53 51 <div class="col s2">
<input type="checkbox" class="filled-in" id="weekTenCheck" ng-model="filter['week10']"/> 54 52 <input type="checkbox" class="filled-in" id="weekTenCheck" ng-model="filter['week10']"/>
<label for="weekTenCheck">Week Ten</label> 55 53 <label for="weekTenCheck">Week Ten</label>
</div> 56 54 </div>
</div> 57 55 </div>
</form> 58 56 </form>
</div> 59 57 </div>
60 58
<div class="list" style="padding: 0px 15px"> 61 59 <div class="list" style="padding: 0px 15px">
<ul class="collection"> 62 60 <ul class="collection">
<li class="collection-item" ng-repeat="card in cards | filter:searchText | filter:filterByDate" ng-show="show || !card.is_hidden"> 63 61 <li class="collection-item" ng-repeat="card in cards | filter:searchText | filter:filterByDate" ng-show="show || !card.is_hidden">
<div>{{card.text}}<a href="unhide(card)" class="secondary-content" ng-show="card.is_hidden">Unhide</a></div> 64 62 <div>{{card.text}}<a href="unhide(card)" class="secondary-content" ng-show="card.is_hidden">Unhide</a></div>
</li> 65 63 </li>
</ul> 66 64 </ul>
</div> 67 65 </div>
68 66