Commit d9ebbe3d97afc5daad64e86dad26f3c2067adc5b

Authored by Rachel Lee

Merge branch 'master' of https://git.ucsd.edu/110swag/flashy-frontend

Showing 2 changed files Inline Diff

scripts/CardListController.js View file @ d9ebbe3
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/').
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
46 // checkbox filter
47 $scope.filter = {
48 'week1': true,
49 'week2': true,
50 'week3': true,
51 'week4': true,
52 'week5': true,
53 'week6': true,
54 'week7': true,
55 'week8': true,
56 'week9': true,
57 'week10': true,
58 };
59
60 $scope.filterByDate = function(item) {
61 var date = new Date(item.pushed);
62 return ((date >= new Date('Mar 29, 2015')) && (date <= new Date('Apr 4, 2015')) && $scope.filter['week1']) ||
63 ((date >= new Date('Apr 4, 2015')) && (date <= new Date('Apr 11, 2015')) && $scope.filter['week2']) ||
64 ((date >= new Date('Apr 12, 2015')) && (date <= new Date('Apr 18, 2015')) && $scope.filter['week3']) ||
65 ((date >= new Date('Apr 19, 2015')) && (date <= new Date('Apr 25, 2015')) && $scope.filter['week4']) ||
66 ((date >= new Date('Apr 26, 2015')) && (date <= new Date('May 2, 2015')) && $scope.filter['week5']) ||
67 ((date >= new Date('May 3, 2015')) && (date <= new Date('May 9, 2015')) && $scope.filter['week6']) ||
68 ((date >= new Date('May 10, 2015')) && (date <= new Date('May 16, 2015')) && $scope.filter['week7']) ||
69 ((date >= new Date('May 17, 2015')) && (date <= new Date('May 23, 2015')) && $scope.filter['week8']) ||
70 ((date >= new Date('May 24, 2015')) && (date <= new Date('May 30, 2015')) && $scope.filter['week9']) ||
templates/cardlist.html View file @ d9ebbe3
<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>
3 <form class="col s6">
4 <div class="input-field col s6">
5 <i class="mdi-action-search prefix"></i>
6 <input id="search" type="text" class="validate" ng-model="searchText">
7 <label for="search">Search</label>
8 </div>
9 </form>
</div> 3 10 </div>
4 11
12 <div class="row">
13 <form>
14 <div class="row">
15 <div class="col s2">
16 <input type="checkbox" class="filled-in" id="weekOneCheck" ng-model="filter['week1']"/>
17 <label for="weekOneCheck">Week One</label>
18 </div>
19 <div class="col s2">
20 <input type="checkbox" class="filled-in" id="weekTwoCheck" ng-model="filter['week2']"/>
21 <label for="weekTwoCheck">Week Two</label>
22 </div>
23 <div class="col s2">
24 <input type="checkbox" class="filled-in" id="weekThreeCheck" ng-model="filter['week3']"/>
25 <label for="weekThreeCheck">Week Three</label>
26 </div>
27 <div class="col s2">
28 <input type="checkbox" class="filled-in" id="weekFourCheck" ng-model="filter['week4']"/>
29 <label for="weekFourCheck">Week Four</label>
30 </div>
31 <div class="col s2">
32 <input type="checkbox" class="filled-in" id="weekFiveCheck" ng-model="filter['week5']"/>
33 <label for="weekFiveCheck">Week Five</label>
34 </div>
35 </div>
36 <div class="row">
37 <div class="col s2">
38 <input type="checkbox" class="filled-in" id="weekSixCheck" ng-model="filter['week6']"/>
39 <label for="weekSixCheck">Week Six</label>
40 </div>
41 <div class="col s2">
42 <input type="checkbox" class="filled-in" id="weekSevenCheck" ng-model="filter['week7']"/>
43 <label for="weekSevenCheck">Week Seven</label>
44 </div>
45 <div class="col s2">
46 <input type="checkbox" class="filled-in" id="weekEightCheck" ng-model="filter['week8']"/>
47 <label for="weekEightCheck">Week Eight</label>
48 </div>
49 <div class="col s2">
50 <input type="checkbox" class="filled-in" id="weekNineCheck" ng-model="filter['week9']"/>
51 <label for="weekNineCheck">Week Nine</label>
52 </div>
53 <div class="col s2">
54 <input type="checkbox" class="filled-in" id="weekTenCheck" ng-model="filter['week10']"/>
55 <label for="weekTenCheck">Week Ten</label>
56 </div>
57 </div>
58 </form>
59 </div>
60
<div class="list" style="padding: 0px 15px"> 5 61 <div class="list" style="padding: 0px 15px">
<ul class="collection"> 6 62 <ul class="collection">
<li class="collection-item" ng-repeat="card in cards" ng-show="show || !card.is_hidden"> 7 63 <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> 8 64 <div>{{card.text}}<a href="unhide(card)" class="secondary-content" ng-show="card.is_hidden">Unhide</a></div>
</li> 9 65 </li>
</ul> 10 66 </ul>
</div> 11 67 </div>