Commit f71cb843b14b75c821f998ad76aeb376d9511677

Authored by Andrew Buss
1 parent 6f48f3a680

tweaks; email verification nagging

Showing 5 changed files with 54 additions and 42 deletions Side-by-side Diff

scripts/FeedController.js View file @ f71cb84
1 1 angular.module('flashy.FeedController', ['ui.router']).
2   - controller('FeedController', function($scope, $rootScope, $stateParams, $state, $http) {
  2 + controller('FeedController', function($scope, $rootScope, $stateParams, $state, $http, UserService) {
3 3 console.log('Hello from feed');
4 4 sectionId = $stateParams.sectionId;
5 5 $rootScope.currentSection = $rootScope.SectionResource.get({sectionId: sectionId});
... ... @@ -19,7 +19,10 @@
19 19 };
20 20 ws.onmessage = function(e) {
21 21 console.log('got websocket message ' + e.data);
22   - $scope.refreshCards();
  22 + data = JSON.parse(e.data);
  23 + if (data.event_type == 'new_card') {
  24 + addCardToFeed(data.flashcard);
  25 + }
23 26 };
24 27 ws.onerror = function(e) {
25 28 console.error(e);
26 29  
27 30  
... ... @@ -32,18 +35,17 @@
32 35 success(function(data) {
33 36 console.log(data);
34 37 $scope.cards = data;
  38 +
35 39 }).
36 40 error(function(err) {
37 41 console.log('pulling feed failed');
38 42 });
39 43  
40   - $scope.viewDeck = function() {
41   - $state.go('deck', {sectionId: sectionId});
42   - console.log('go to deck');
  44 + var addCardToFeed = function(card) {
  45 + $scope.cards.unshift(card);
43 46 };
44 47  
45 48 $scope.pushCard = function() {
46   - var pushed = new Date(Date.now());
47 49 var i = 0;
48 50 var blanks = [];
49 51 $('#new-card-input')[0].childNodes.forEach(function(node) {
50 52  
51 53  
52 54  
53 55  
... ... @@ -61,41 +63,32 @@
61 63 text = $('#new-card-input').text();
62 64 var myCard = {
63 65 'text': text,
64   - 'material_date': pushed,
65 66 'mask': blanks,
66 67 section: sectionId
67 68 };
68 69 $http.post('/api/flashcards/', myCard).
69 70 success(function(data) {
70   - console.log('pushed a card!');
71   - listenForC = true;
  71 + console.log('flashcard push succeeded');
  72 + if (!UserService.hasVerifiedEmail()) {
  73 + Materialize.toast("<p>Thanks for contributing! However, others won't see your card until you verify your email address<p>", 4000);
  74 + }
72 75 }).
73 76 error(function(error) {
74 77 console.log('something went wrong pushing a card!');
75 78 });
76   -
  79 + listenForC = true;
77 80 $('#new-card-input').html('');
78 81 };
79 82  
80   - $scope.refreshCards = function() {
81   - $http.get('/api/sections/' + sectionId + '/feed/').
82   - success(function(data) {
83   - console.log(data);
84   - $scope.cards = data;
  83 + $http.get('/api/sections/' + sectionId + '/feed/').
  84 + success(function(data) {
  85 + console.log(data);
  86 + $scope.cards = data;
  87 + }).
  88 + error(function(err) {
  89 + console.log("couldn't get cards!");
  90 + });
85 91  
86   - /*if (data.length == 0) {
87   - return true;
88   - } else {
89   - return false;
90   - }*/
91   -
92   - console.log('success in refresh cards...');
93   - }).
94   - error(function(err) {
95   - console.log('refresh fail');
96   - });
97   - };
98   -
99 92 /* Key bindings for the whole feed window. Hotkey it up! */
100 93 var listenForC = true;
101 94  
... ... @@ -137,6 +130,7 @@
137 130 var selected_start = 0;
138 131 var selected_end = 0;
139 132 $(document).ready(function() {
  133 + $('.tooltipped').tooltip({delay: 50});
140 134 // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
141 135 $('.modal-trigger').leanModal(modal_options);
142 136 $('#new-card-input').on('keydown', function(e) {
scripts/LoginController.js View file @ f71cb84
... ... @@ -17,7 +17,6 @@
17 17 if (angular.isDefined($scope.returnToState))
18 18 $state.go($scope.returnToState.name, $scope.returnToStateParams);
19 19 else $state.go('addclass');
20   - console.log(data);
21 20 }).
22 21 error(function(data, status, header, config) {
23 22 if (data.detail) { // assume 'invalid email or pass'
... ... @@ -32,7 +31,7 @@
32 31 'password': password
33 32 })).
34 33 success(function(data) {
35   - console.log(data);
  34 + UserService.login(data);
36 35 if (angular.isDefined($scope.returnToState))
37 36 $state.go($scope.returnToState.name, $scope.returnToStateParams);
38 37 else $state.go('addclass');
scripts/UserService.js View file @ f71cb84
... ... @@ -22,7 +22,13 @@
22 22 };
23 23 this.login = function(data) {
24 24 _user = data;
  25 + if (!data.is_confirmed) {
  26 + Materialize.toast('Please verify your email address!', 4000);
  27 + }
25 28 deferred.resolve(data);
  29 + };
  30 + this.hasVerifiedEmail = function() {
  31 + return this.isResolved() && _user.is_confirmed;
26 32 };
27 33 this.logout = function() {
28 34 _user = false;
styles/flashy.css View file @ f71cb84
... ... @@ -236,9 +236,11 @@
236 236 nav {
237 237 background-color: #d2143f !important;
238 238 }
239   -main{
240   - min-height:145px;
  239 +
  240 +main {
  241 + min-height: 145px;
241 242 }
  243 +
242 244 .side-nav .collapsible-body {
243 245 width: 100%;
244 246 }
245 247  
... ... @@ -279,11 +281,19 @@
279 281 /*#sidenav-overlay {
280 282 background-color: rgba(0, 0, 0, 0) !important;
281 283 }*/
282   -.card-content{
283   - width:100%;
  284 +.card-content {
  285 + width: 100%;
284 286 }
285 287  
286   -.valign-wrapper{
287   - height:100%;
  288 +.valign-wrapper {
  289 + height: 100%;
  290 +}
  291 +
  292 +.toast {
  293 + height:100px;
  294 + width: 300px;
  295 + line-height: 20px;
  296 + max-height: 100px;
  297 + word-wrap: normal;
288 298 }
templates/feed.html View file @ f71cb84
1   -
2 1 <div class="row">
3 2 <div ng-repeat="card in cards">
4 3 <flashcard flashcard-obj="card" refresh="refreshCards()"/>
... ... @@ -9,7 +8,8 @@
9 8  
10 9 <!--Lil plus button in corner-->
11 10 <div class="fixed-action-btn" style="bottom: 96px; right: 24px;">
12   - <a data-target="newCard" class="btn-floating btn-large modal-trigger" href="#newCard">
  11 + <a data-target="newCard" class="btn-floating btn-large modal-trigger tooltipped" href="#newCard" data-position="left" data-delay="50"
  12 + data-tooltip="(C)ompose">
13 13 <i class="large mdi-content-add"></i>
14 14 </a>
15 15 </div>
16 16  
17 17  
... ... @@ -19,16 +19,19 @@
19 19 <div class="modal-content">
20 20 <div class="input-field">
21 21 <!--<label id="newCardSign" for="newCard">New Flashcard Text</label>-->
22   - <div id="new-card-input" contenteditable>
  22 + <div id="new-card-input" contenteditable style="outline:0px solid transparent;">
23 23  
24 24 </div>
25 25 </div>
26 26 </div>
27 27 <div class="modal-footer">
28   - <button class="btn modal-close" type="submit" ng-click="pushCard()">Submit
29   - <i class="mdi-content-send right"></i>
  28 + <button class="btn modal-close tooltipped" type="submit" ng-click="pushCard()" data-position="left" data-delay="50"
  29 + data-tooltip="Enter">Submit
  30 + <i class="mdi-hardware-keyboard-return right"></i>
30 31 </button>
31   - <button id="blank-selected" style="float:left" class="btn">Blank Selected Text</button>
  32 + <button id="blank-selected" style="float:left" class="btn tooltipped" data-position="right" data-delay="50"
  33 + data-tooltip="Ctrl-B">Blank Selected Text
  34 + </button>
32 35 </div>
33 36 </form>
34 37 </div>