Commit fcda9ffd202c5776281cd13f912e56c42671ce49

Authored by Tetranoir
1 parent 3c77a71a36

feed controller attempt at organizing by score (in progress, non breaky vers); t…

…ried to get verifyemail speshul authentication measures (none), hit a road block with http.interceptor

Showing 6 changed files with 61 additions and 23 deletions Side-by-side Diff

... ... @@ -53,7 +53,11 @@
53 53 $urlRouterProvider.otherwise('/404');
54 54 var auth_resolve = {
55 55 authorize: function($q, $state, $stateParams, UserService) {
56   - console.log('resolving user before continuing');
  56 + if (UserService.noAuthRequired($state)) {
  57 + console.log('no auth state ' + $state.name);
  58 + return $state.go(state.name);
  59 + }
  60 + console.log('resolving user before continuing for ' + $state.name);
57 61 var redirectAsNeeded = function() {
58 62 if (!UserService.isLoggedIn()) {
59 63 console.log(UserService.getUserData());
... ... @@ -61,6 +65,7 @@
61 65 $state.go('login');
62 66 }
63 67 if (!UserService.authorizedFor($state, $stateParams)) {
  68 + console.log('user not authorized for ' + $state.name);
64 69 $state.go('addclass');
65 70 }
66 71 };
... ... @@ -138,7 +143,6 @@
138 143 controller: 'ResetPasswordController'
139 144 }).
140 145 state('verifyemail', {
141   - resolve: auth_resolve,
142 146 url: '/verifyemail/{key}',
143 147 templateUrl: 'templates/verifyemail.html',
144 148 controller: 'VerifyEmailController'
scripts/FeedController.js View file @ fcda9ff
... ... @@ -11,8 +11,8 @@
11 11 $scope.cards = false;
12 12 $scope.cardCols = []; // organized data
13 13 $scope.numCols = 0;
  14 + $scope.cardTable = {}; // look up table of cards, {'colNum':col, 'obj':card}
14 15  
15   -
16 16 function calculate_cols() {
17 17 var avail = $window.innerWidth - 17;
18 18 return Math.max(1, Math.floor(avail / 250));
... ... @@ -42,6 +42,7 @@
42 42 for (i = 0; i < $scope.numCols; i++) cols.push([]);
43 43 $scope.cards.forEach(function(card, i) {
44 44 cols[i % $scope.numCols].push(card);
  45 + $scope.cardTable[card.id] = {'colNum':i % $scope.numCols, 'obj':card};
45 46 });
46 47 // wait until the next digest cycle to update cardCols
47 48  
48 49  
49 50  
50 51  
51 52  
52 53  
53 54  
54 55  
55 56  
... ... @@ -70,46 +71,68 @@
70 71  
71 72 $scope.add = function(card) {
72 73 var colNum = 0;
73   - var lowestCol = {};
74   - var lowestColLen = Infinity;
  74 + var lowestCol = $scope.cardCols[0];
  75 + var lowestColNum = 0;
75 76 while (colNum < $scope.numCols) {
76 77 if ($scope.cardCols[colNum].length == 0) {
77 78 lowestCol = $scope.cardCols[colNum];
78 79 break;
79   - } else if ($scope.cardCols[colNum].length < lowestColLen) {
  80 + } else if ($scope.cardCols[colNum].length < lowestCol.length) {
80 81 lowestCol = $scope.cardCols[colNum];
  82 + lowestColNum = colNum;
81 83 lowestColLen = $scope.cardCols[colNum].length;
82 84 }
83 85 colNum++;
84 86 }
85   - /*if (colNum == $scope.numCols) {
86   - colNum = Math.floor(Math.random() * $scope.numCols);
87   - }
88   - console.log('adding card to column ' + colNum);*/
89 87 console.log(card);
90 88 $scope.cards.push(data);
91 89 $timeout(function() {
92 90 lowestCol.unshift(card);
  91 + $scope.cardTable[card.id] = {'colNum':lowestColNum, 'obj':card};
93 92 $timeout($scope.refreshColumnWidth);
94 93 });
95 94 };
  95 +
  96 + $scope.sortAdd = function(card, array) {
  97 + console.log('sort add');
  98 + array.forEach(function(ele, i, ary) {
  99 + if (ele.score <= card.score) {
  100 + ary.splice(i, 0, card);
  101 + return;
  102 + }
  103 + });
  104 + };
96 105  
97 106 $scope.hide = function(card) {
98 107 console.log('hiding card');
99 108 var found = -1;
100   - for (i = 0; i < $scope.cardCols.length; i++) {
101   - found = $scope.cardCols[i].indexOf(card);
102   - if (found != -1) {
103   - $timeout(function() {
104   - console.log('card to hide, found');
105   - });
106   - $scope.cardCols[i].splice(found, 1);
107   - return;
108   - }
109   - }
  109 + col = $scope.cardTable[card.id].colNum;
  110 + found = $scope.cardCols[col].indexOf(card);
  111 + if (found != -1) {
  112 + $scope.cardCols[col].splice(found, 1);
  113 + console.log('card hidden');
  114 + return col;
  115 + }
110 116 console.log('Error finding card to hide:');
111 117 console.log(card);
  118 + return -1;
112 119 };
  120 +
  121 + $scope.update = function(id, new_score) { // NOT WORKING
  122 + /*card = $scope.cardTable[id].obj;
  123 + if (new_score == card.score) {
  124 + console.log('score same, no update required');
  125 + return;
  126 + }
  127 + console.log('updating');
  128 + card.score = new_score;
  129 + console.log(card);
  130 +
  131 + col = $scope.hide(card)
  132 + if (col != -1) {
  133 + $scope.sortAdd(card, $scope.cardCols[col]);
  134 + }*/
  135 + };
113 136  
114 137 var loc = window.location, new_uri;
115 138 if (loc.protocol === 'https:') {
116 139  
117 140  
... ... @@ -124,12 +147,13 @@
124 147 console.log('websocket connected');
125 148 };
126 149 ws.onmessage = function(e) {
  150 + data = JSON.parse(e.data);
127 151 console.log('got websocket message ' + e.data);
128   - data = JSON.parse(e.data);
  152 + console.log(data);
129 153 if (data.event_type == 'new_card') {
130 154 $scope.add(data.flashcard);
131 155 } else if (data.event_type == 'score_change') {
132   - //
  156 + $scope.update(data.flashcard_id, data.new_score);
133 157 }
134 158 };
135 159 ws.onerror = function(e) {
scripts/FlashcardDirective.js View file @ fcda9ff
... ... @@ -12,6 +12,7 @@
12 12 link: function(scope, element) {
13 13 /* Handles width of the card */
14 14 scope.textPieces = [];
  15 +
15 16 scope.flashcard.mask.sort(function(a, b) {
16 17 return a[0] - b[0];
17 18 });
scripts/UserService.js View file @ fcda9ff
... ... @@ -66,6 +66,12 @@
66 66 }
67 67 return true;
68 68 };
  69 + this.noAuthRequired = function(state) {
  70 + if (['verifyemail'].indexOf(state.name) >= 0) {
  71 + return true;
  72 + }
  73 + return false;
  74 + }
69 75 this.resendConfirmationEmail = function() {
70 76 if (!this.isLoggedIn()) return console.log("Can't request resending a confirmation email since the user is not logged in.");
71 77 console.log('Requesting resend of confirmation email');
templates/feed.html View file @ fcda9ff
... ... @@ -5,7 +5,7 @@
5 5 <div class="indeterminate"></div>
6 6 </div>
7 7 <div class="cardColumn" ng-repeat="col in cardCols">
8   - <div class="repeated-card" ng-repeat="card in col">
  8 + <div class="repeated-card" ng-repeat="card in col track by $index">
9 9 <flashcard flashcard-obj="card" refresh="hide(card)"/>
10 10 </div>
11 11 </div>
templates/flashcard.html View file @ fcda9ff
... ... @@ -29,5 +29,8 @@
29 29 <div ng-show="flashcard.is_in_deck" class="green-text" style="position:absolute; top:0px;right:0px">
30 30 <div class="center-me"><i class="mdi-action-done small"></i></div>
31 31 </div>
  32 + <div style="position:absolute; bottom:0px; right:5px">
  33 + <span class="center-me">score:{{flashcard.score}}</span>
  34 + </div>
32 35 </div>