Commit 7545660bf6dc22fda2d7b125c3e08d671d1bd803
Exists in
master
and in
1 other branch
Merge branch 'master' of git.ucsd.edu:110swag/flashy-frontend
Showing 12 changed files Inline Diff
config.js
View file @
7545660
angular.module('flashy', [ | 1 | 1 | angular.module('flashy', [ | |
'flashy.LoginController', | 2 | 2 | 'flashy.LoginController', | |
'flashy.RootController', | 3 | 3 | 'flashy.RootController', | |
'flashy.FeedController', | 4 | 4 | 'flashy.FeedController', | |
'flashy.DeckController', | 5 | 5 | 'flashy.DeckController', | |
'flashy.ClassAddController', | 6 | 6 | 'flashy.ClassAddController', | |
'flashy.ClassDropController', | 7 | |||
'flashy.RequestResetController', | 8 | 7 | 'flashy.RequestResetController', | |
'flashy.StudyController', | 9 | 8 | 'flashy.StudyController', | |
'flashy.UserService', | 10 | 9 | 'flashy.UserService', | |
'flashy.FlashcardDirective', | 11 | 10 | 'flashy.FlashcardDirective', | |
'flashy.FlashcardFactory', | 12 | 11 | 'flashy.FlashcardFactory', | |
'flashy.ResetPasswordController', | 13 | 12 | 'flashy.ResetPasswordController', | |
'flashy.VerifyEmailController', | 14 | 13 | 'flashy.VerifyEmailController', | |
'flashy.CardListController', | 15 | 14 | 'flashy.CardListController', | |
'flashy.HelpController', | 16 | 15 | 'flashy.HelpController', | |
'flashy.SettingsController', | 17 | 16 | 'flashy.SettingsController', | |
'ngCookies']). | 18 | 17 | 'ngCookies']). | |
config(function($stateProvider, $urlRouterProvider, $resourceProvider, $httpProvider, $locationProvider) { | 19 | 18 | config(function($stateProvider, $urlRouterProvider, $resourceProvider, $httpProvider, $locationProvider) { | |
'use strict'; | 20 | 19 | 'use strict'; | |
$httpProvider.defaults.withCredentials = true; | 21 | 20 | $httpProvider.defaults.withCredentials = true; | |
$httpProvider.defaults.xsrfCookieName = 'csrftoken'; | 22 | 21 | $httpProvider.defaults.xsrfCookieName = 'csrftoken'; | |
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; | 23 | 22 | $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; | |
$resourceProvider.defaults.stripTrailingSlashes = false; | 24 | 23 | $resourceProvider.defaults.stripTrailingSlashes = false; | |
var arrayMethods = Object.getOwnPropertyNames(Array.prototype); | 25 | 24 | var arrayMethods = Object.getOwnPropertyNames(Array.prototype); | |
arrayMethods.forEach(attachArrayMethodsToNodeList); | 26 | 25 | arrayMethods.forEach(attachArrayMethodsToNodeList); | |
function attachArrayMethodsToNodeList(methodName) { | 27 | 26 | function attachArrayMethodsToNodeList(methodName) { | |
if (methodName !== 'length') { | 28 | 27 | if (methodName !== 'length') { | |
NodeList.prototype[methodName] = Array.prototype[methodName]; | 29 | 28 | NodeList.prototype[methodName] = Array.prototype[methodName]; | |
} | 30 | 29 | } | |
} | 31 | 30 | } | |
32 | 31 | |||
$httpProvider.interceptors.push(function($q, $rootScope) { | 33 | 32 | $httpProvider.interceptors.push(function($q, $rootScope) { | |
return { | 34 | 33 | return { | |
'responseError': function(rejection) { // need a better redirect | 35 | 34 | 'responseError': function(rejection) { // need a better redirect | |
if (rejection.status >= 500) { | 36 | 35 | if (rejection.status >= 500) { | |
console.log('got error'); | 37 | 36 | console.log('got error'); | |
console.log(rejection); | 38 | 37 | console.log(rejection); | |
$rootScope.$broadcast('server_error', rejection); | 39 | 38 | $rootScope.$broadcast('server_error', rejection); | |
} | 40 | 39 | } | |
if (rejection.status == 403) { | 41 | 40 | if (rejection.status == 403) { | |
console.log(rejection); | 42 | 41 | console.log(rejection); | |
if (rejection.data && rejection.data.detail == 'Please verify your email before continuing') { | 43 | 42 | if (rejection.data && rejection.data.detail == 'Please verify your email before continuing') { | |
UserService.showLockedMessage(); | 44 | 43 | UserService.showLockedMessage(); | |
UserService.logout(); | 45 | 44 | UserService.logout(); | |
} | 46 | 45 | } | |
} | 47 | 46 | } | |
if (rejection.status == 429) { | 48 | 47 | if (rejection.status == 429) { | |
console.log(rejection); | 49 | 48 | console.log(rejection); | |
Materialize.toast('Your enthusiasm is appreciated, but we ask that you slow down a little!', 4000); | 50 | 49 | Materialize.toast('Your enthusiasm is appreciated, but we ask that you slow down a little!', 4000); | |
} | 51 | 50 | } | |
return $q.reject(rejection); | 52 | 51 | return $q.reject(rejection); | |
} | 53 | 52 | } | |
}; | 54 | 53 | }; | |
}); | 55 | 54 | }); | |
$locationProvider.html5Mode(true); | 56 | 55 | $locationProvider.html5Mode(true); | |
$urlRouterProvider.otherwise('/404'); | 57 | 56 | $urlRouterProvider.otherwise('/404'); | |
var auth_resolve = { | 58 | 57 | var auth_resolve = { | |
authorize: function($q, $rootScope, $state, $stateParams, UserService) { | 59 | 58 | authorize: function($q, $rootScope, $state, $stateParams, UserService) { | |
console.log('do we need to authorize a user for', $rootScope.nextState.name); | 60 | 59 | console.log('do we need to authorize a user for', $rootScope.nextState.name); | |
if (UserService.noAuthRequired($rootScope.nextState)) { | 61 | 60 | if (UserService.noAuthRequired($rootScope.nextState)) { | |
console.log('no auth required for', $rootScope.nextState.name); | 62 | 61 | console.log('no auth required for', $rootScope.nextState.name); | |
return UserService.getUserData(); | 63 | 62 | return UserService.getUserData(); | |
} | 64 | 63 | } | |
console.log('resolving user before continuing to ' + $rootScope.nextState.name); | 65 | 64 | console.log('resolving user before continuing to ' + $rootScope.nextState.name); | |
var redirectAsNeeded = function() { | 66 | 65 | var redirectAsNeeded = function() { | |
if (!UserService.isLoggedIn()) { | 67 | 66 | if (!UserService.isLoggedIn()) { | |
console.log(UserService.getUserData()); | 68 | 67 | console.log(UserService.getUserData()); | |
console.log('making the user log in'); | 69 | 68 | console.log('making the user log in'); | |
$state.go('login'); | 70 | 69 | $state.go('login'); | |
} | 71 | 70 | } | |
if (!UserService.authorizedFor($rootScope.nextState, $rootScope.nextStateParams)) { | 72 | 71 | if (!UserService.authorizedFor($rootScope.nextState, $rootScope.nextStateParams)) { | |
console.log('user not authorized for ' + $rootScope.nextState.name); | 73 | 72 | console.log('user not authorized for ' + $rootScope.nextState.name); | |
$state.go('addclass'); | 74 | 73 | $state.go('addclass'); | |
} | 75 | 74 | } | |
}; | 76 | 75 | }; | |
if (UserService.isResolved()) return redirectAsNeeded(); | 77 | 76 | if (UserService.isResolved()) return redirectAsNeeded(); | |
return UserService.getUserData().then(redirectAsNeeded); | 78 | 77 | return UserService.getUserData().then(redirectAsNeeded); | |
} | 79 | 78 | } | |
}; | 80 | 79 | }; | |
$stateProvider. | 81 | 80 | $stateProvider. | |
state('login', { | 82 | 81 | state('login', { | |
resolve: auth_resolve, | 83 | 82 | resolve: auth_resolve, | |
url: '/login', | 84 | 83 | url: '/login', | |
templateUrl: 'templates/login.html', | 85 | 84 | templateUrl: 'templates/login.html', | |
controller: 'LoginController' | 86 | 85 | controller: 'LoginController' | |
}). | 87 | 86 | }). | |
state('root', { | 88 | 87 | state('root', { | |
resolve: auth_resolve, | 89 | 88 | resolve: auth_resolve, | |
url: '/', | 90 | 89 | url: '/', | |
controller: 'RootController' | 91 | 90 | controller: 'RootController' | |
}). | 92 | 91 | }). | |
state('feed', { | 93 | 92 | state('feed', { | |
resolve: auth_resolve, | 94 | 93 | resolve: auth_resolve, | |
url: '/feed/{sectionId}', | 95 | 94 | url: '/feed/{sectionId}', | |
templateUrl: 'templates/feed.html', | 96 | 95 | templateUrl: 'templates/feed.html', | |
controller: 'FeedController' | 97 | 96 | controller: 'FeedController' | |
}). | 98 | 97 | }). | |
state('cardlist', { | 99 | 98 | state('cardlist', { | |
resolve: auth_resolve, | 100 | 99 | resolve: auth_resolve, | |
url: '/cards/{sectionId}', | 101 | 100 | url: '/cards/{sectionId}', | |
templateUrl: 'templates/cardlist.html', | 102 | 101 | templateUrl: 'templates/cardlist.html', | |
controller: 'CardListController' | 103 | 102 | controller: 'CardListController' | |
}). | 104 | 103 | }). | |
state('addclass', { | 105 | 104 | state('addclass', { | |
resolve: auth_resolve, | 106 | 105 | resolve: auth_resolve, | |
url: '/addclass', | 107 | 106 | url: '/addclass', | |
templateUrl: 'templates/addclass.html', | 108 | 107 | templateUrl: 'templates/addclass.html', | |
controller: 'ClassAddController' | 109 | 108 | controller: 'ClassAddController' | |
}). | 110 | |||
state('dropclass', { | 111 | |||
resolve: auth_resolve, | 112 | |||
url: '/settings/dropclass', | 113 | |||
templateUrl: 'templates/dropclass.html', | 114 | |||
controller: 'ClassDropController' | 115 | |||
}). | 116 | 109 | }). | |
state('deck', { | 117 | 110 | state('deck', { | |
resolve: auth_resolve, | 118 | 111 | resolve: auth_resolve, | |
url: '/deck/{sectionId}', | 119 | 112 | url: '/deck/{sectionId}', | |
templateUrl: 'templates/deck.html', | 120 | 113 | templateUrl: 'templates/deck.html', | |
controller: 'DeckController' | 121 | 114 | controller: 'DeckController' | |
}). | 122 | 115 | }). | |
state('study', { | 123 | 116 | state('study', { | |
resolve: auth_resolve, | 124 | 117 | resolve: auth_resolve, | |
url: '/study', | 125 | 118 | url: '/study', | |
templateUrl: 'templates/study.html', | 126 | 119 | templateUrl: 'templates/study.html', | |
controller: 'StudyController' | 127 | 120 | controller: 'StudyController' | |
}). | 128 | 121 | }). | |
state('flashcard', { | 129 | 122 | state('flashcard', { | |
resolve: auth_resolve, | 130 | 123 | resolve: auth_resolve, | |
url: '/flashcard', | 131 | 124 | url: '/flashcard', | |
templateUrl: 'templates/flashcard.html', | 132 | 125 | templateUrl: 'templates/flashcard.html', | |
controller: 'FlashcardController' | 133 | 126 | controller: 'FlashcardController' | |
}). | 134 | 127 | }). | |
state('settings', { | 135 | 128 | state('settings', { | |
resolve: auth_resolve, | 136 | 129 | resolve: auth_resolve, | |
url: '/settings', | 137 | 130 | url: '/settings', | |
templateUrl: 'templates/settings.html', | 138 | 131 | templateUrl: 'templates/settings.html', | |
controller: 'SettingsController' | 139 | 132 | controller: 'SettingsController' | |
}). | 140 | 133 | }). | |
state('requestpasswordreset', { | 141 | 134 | state('requestpasswordreset', { | |
url: '/requestpasswordreset', | 142 | 135 | url: '/requestpasswordreset', | |
templateUrl: 'templates/requestpasswordreset.html', | 143 | 136 | templateUrl: 'templates/requestpasswordreset.html', | |
controller: 'RequestResetController' | 144 | 137 | controller: 'RequestResetController' | |
}). | 145 | 138 | }). | |
state('resetpassword', { | 146 | 139 | state('resetpassword', { | |
url: '/resetpassword/{uid}/{token}', | 147 | 140 | url: '/resetpassword/{uid}/{token}', | |
templateUrl: 'templates/resetpassword.html', | 148 | 141 | templateUrl: 'templates/resetpassword.html', | |
controller: 'ResetPasswordController' | 149 | 142 | controller: 'ResetPasswordController' | |
}). | 150 | 143 | }). | |
state('verifyemail', { | 151 | 144 | state('verifyemail', { | |
url: '/verifyemail/{key}', | 152 | 145 | url: '/verifyemail/{key}', | |
templateUrl: 'templates/verifyemail.html', | 153 | 146 | templateUrl: 'templates/verifyemail.html', | |
controller: 'VerifyEmailController' | 154 | 147 | controller: 'VerifyEmailController' | |
}). | 155 | 148 | }). | |
state('404', { | 156 | 149 | state('404', { | |
url: '/404', | 157 | 150 | url: '/404', | |
template: "<h1>This page doesn't exist!</h1>" | 158 | 151 | template: "<h1>This page doesn't exist!</h1>" | |
}). | 159 | 152 | }). | |
state('help', { | 160 | 153 | state('help', { | |
resolve: auth_resolve, | 161 | 154 | resolve: auth_resolve, | |
url: '/help', | 162 | 155 | url: '/help', | |
templateUrl: 'templates/help.html', | 163 | 156 | templateUrl: 'templates/help.html', | |
controller: 'HelpController' | 164 | 157 | controller: 'HelpController' | |
}); | 165 | 158 | }); | |
}). | 166 | 159 | }). | |
run(function($rootScope, $state, $stateParams, $location, UserService) { | 167 | 160 | run(function($rootScope, $state, $stateParams, $location, UserService) { | |
$rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { | 168 | 161 | $rootScope.$on('$stateChangeError', function(event, toState, toParams, fromState, fromParams, error) { | |
console.log('failed to change state: ' + error); | 169 | 162 | console.log('failed to change state: ' + error); | |
$state.go('login'); | 170 | 163 | $state.go('login'); | |
}); | 171 | 164 | }); | |
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { | 172 | 165 | $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) { | |
$rootScope.nextState = toState; | 173 | 166 | $rootScope.nextState = toState; | |
$rootScope.nextStateParams = toParams; | 174 | 167 | $rootScope.nextStateParams = toParams; | |
console.log('changing state to', toState); | 175 | 168 | console.log('changing state to', toState); | |
if (['feed', 'deck', 'cardlist'].indexOf(toState.name) >= 0) { | 176 | 169 | if (['feed', 'deck', 'cardlist'].indexOf(toState.name) >= 0) { | |
localStorage.setItem('last_state', toState.name); | 177 | 170 | localStorage.setItem('last_state', toState.name); | |
localStorage.setItem('last_state_params', JSON.stringify(toParams)); | 178 | 171 | localStorage.setItem('last_state_params', JSON.stringify(toParams)); | |
} | 179 | 172 | } | |
}); | 180 | 173 | }); |
home.html
View file @
7545660
<!DOCTYPE html> | 1 | 1 | <!DOCTYPE html> | |
<html ng-app="flashy"> | 2 | 2 | <html ng-app="flashy"> | |
<base href="/app/"> | 3 | 3 | <base href="/app/"> | |
<head> | 4 | 4 | <head> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> | 5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/> | |
<link rel="stylesheet" | 6 | 6 | <link rel="stylesheet" | |
href="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.css"> | 7 | 7 | href="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.css"> | |
<link rel="shortcut icon" href="flashy.ico"> | 8 | 8 | <link rel="shortcut icon" href="flashy.ico"> | |
9 | 9 | |||
<link rel="stylesheet" href="styles/flashier.css"/> | 10 | 10 | <link rel="stylesheet" href="styles/flashier.css"/> | |
<link rel="stylesheet" href="styles/flashy.css"/> | 11 | 11 | <link rel="stylesheet" href="styles/flashy.css"/> | |
<link rel="manifest" href="manifest.json"> | 12 | 12 | <link rel="manifest" href="manifest.json"> | |
<link | 13 | 13 | <link | |
href='https://fonts.googleapis.com/css?family=Satisfy|Titillium+Web:400,200,200italic,300,600,700,900,700italic,600italic,400italic,300italic' | 14 | 14 | href='https://fonts.googleapis.com/css?family=Satisfy|Titillium+Web:400,200,200italic,300,600,700,900,700italic,600italic,400italic,300italic' | |
rel='stylesheet' type='text/css'> | 15 | 15 | rel='stylesheet' type='text/css'> | |
<title>Flashy</title> | 16 | 16 | <title>Flashy</title> | |
</head> | 17 | 17 | </head> | |
<body ng-controller="RootController"> | 18 | 18 | <body ng-controller="RootController"> | |
<header> | 19 | 19 | <header> | |
<nav> | 20 | 20 | <nav> | |
<div class="nav-wrapper"> | 21 | 21 | <div class="nav-wrapper"> | |
<a ng-show="UserService.isLoggedIn()" href="#" data-activates="mobile-demo" | 22 | 22 | <a ng-show="UserService.isLoggedIn()" href="#" data-activates="mobile-demo" | |
class="left button-collapse hide-on-med-and-up"><i | 23 | 23 | class="left button-collapse hide-on-med-and-up"><i | |
class="mdi-navigation-menu"></i></a> | 24 | 24 | class="mdi-navigation-menu"></i></a> | |
25 | 25 | |||
<!-- User's classes dropdown --> | 26 | 26 | <!-- User's classes dropdown --> | |
<ul id="classDropdown" class="dropdown-content"> | 27 | 27 | <ul id="classDropdown" class="dropdown-content"> | |
<li ui-sref-active="active" ng-repeat="section in UserService.getUserData().sections"> | 28 | 28 | <li ui-sref-active="active" ng-repeat="section in UserService.getUserData().sections"> | |
<a ui-sref="feed({sectionId:section.id})">{{section.short_name}}</a> | 29 | 29 | <a ui-sref="feed({sectionId:section.id})">{{section.short_name}}</a> | |
</li> | 30 | 30 | </li> | |
<li class="divider"></li> | 31 | 31 | <li class="divider"></li> | |
<li><a ui-sref="addclass">Add Class</a></li> | 32 | 32 | <li><a ui-sref="addclass">Add Class</a></li> | |
</ul> | 33 | 33 | </ul> | |
<ul ng-show="UserService.isLoggedIn()" class="left hide-on-small-and-down"> | 34 | 34 | <ul ng-show="UserService.isLoggedIn()" class="left hide-on-small-and-down"> | |
<li><a style="font-size:20px; font-weight:700;" class="dropdown-button ng-cloak hide-on-small-and-down" | 35 | 35 | <li><a style="font-size:20px; font-weight:700;" class="dropdown-button ng-cloak hide-on-small-and-down" | |
href="#!" id="class-list" | 36 | 36 | href="#!" id="class-list" | |
data-activates="classDropdown" data-beloworigin="true">{{currentSection.id?currentSection.short_name:"Classes"}}<i | 37 | 37 | data-activates="classDropdown" data-beloworigin="true">{{currentSection.id?currentSection.short_name:"Classes"}}<i | |
class="mdi-navigation-arrow-drop-down right"></i></a></li> | 38 | 38 | class="mdi-navigation-arrow-drop-down right"></i></a></li> | |
<li ng-show="currentSection.id" ui-sref-active="active"><a ui-sref="feed({sectionId:currentSection.id})" | 39 | 39 | <li ng-show="currentSection.id" ui-sref-active="active"><a ui-sref="feed({sectionId:currentSection.id})" | |
class="tooltipped" | 40 | 40 | class="tooltipped" | |
data-position="bottom" | 41 | 41 | data-position="bottom" | |
data-delay="50" data-tooltip="Feed"><i | 42 | 42 | data-delay="50" data-tooltip="Feed"><i | |
class="mdi-action-view-module"></i></a></li> | 43 | 43 | class="mdi-action-view-module"></i></a></li> | |
<li ng-show="currentSection.id" ui-sref-active="active" id="class-list"><a ui-sref="deck({sectionId:currentSection.id})" | 44 | 44 | <li ng-show="currentSection.id" ui-sref-active="active" id="class-list"><a ui-sref="deck({sectionId:currentSection.id})" | |
class="tooltipped" | 45 | 45 | class="tooltipped" | |
data-position="bottom" | 46 | 46 | data-position="bottom" | |
data-delay="50" data-tooltip="Deck"><i | 47 | 47 | data-delay="50" data-tooltip="Deck"><i | |
class="mdi-action-view-carousel"></i></a></li> | 48 | 48 | class="mdi-action-view-carousel"></i></a></li> | |
<li ng-show="currentSection.id" ui-sref-active="active"><a ui-sref="cardlist({sectionId:currentSection.id})" | 49 | 49 | <li ng-show="currentSection.id" ui-sref-active="active"><a ui-sref="cardlist({sectionId:currentSection.id})" | |
class="tooltipped" | 50 | 50 | class="tooltipped" | |
data-position="bottom" | 51 | 51 | data-position="bottom" | |
data-delay="50" data-tooltip="Card List"><i | 52 | 52 | data-delay="50" data-tooltip="Card List"><i | |
class="mdi-action-view-list"></i></a></li> | 53 | 53 | class="mdi-action-view-list"></i></a></li> | |
</ul> | 54 | 54 | </ul> | |
<a href="#" class="brand-logo center">Flashy</a> | 55 | 55 | <a href="#" class="brand-logo center">Flashy</a> | |
56 | 56 | |||
<ul ng-show="UserService.isLoggedIn()" ng-cloak id="nav-mobile" class="right hide-on-small-and-down"> | 57 | 57 | <ul ng-show="UserService.isLoggedIn()" ng-cloak id="nav-mobile" class="right hide-on-small-and-down"> | |
58 | 58 | |||
<li ui-sref-active="active"><a ui-sref="study" class="tooltipped" data-position="bottom" data-delay="50" | 59 | 59 | <li ui-sref-active="active"><a ui-sref="study" class="tooltipped" data-position="bottom" data-delay="50" | |
data-tooltip="Study"> | 60 | 60 | data-tooltip="Study"> | |
<i class="tiny mdi-action-pageview"></i></a></li> | 61 | 61 | <i class="tiny mdi-action-pageview"></i></a></li> | |
62 | 62 | |||
<!-- Settings Dropdown --> | 63 | 63 | <!-- Settings Dropdown --> | |
<ul id="settingsDropdown" class="dropdown-content"> | 64 | 64 | <ul id="settingsDropdown" class="dropdown-content"> | |
65 | 65 | |||
66 | 66 | |||
</ul> | 67 | 67 | </ul> | |
68 | 68 | |||
<li ui-sref-active="active"><a ui-sref="help"><i class="tiny mdi-action-help tooltipped" | 69 | 69 | <li ui-sref-active="active"><a ui-sref="help"><i class="tiny mdi-action-help tooltipped" | |
data-position="bottom" | 70 | 70 | data-position="bottom" | |
data-delay="50" data-tooltip="Help"></i></a></li> | 71 | 71 | data-delay="50" data-tooltip="Help"></i></a></li> | |
<li ui-sref-active="active"><a ui-sref="settings"><i data-position="bottom" data-delay="50" | 72 | 72 | <li ui-sref-active="active"><a ui-sref="settings"><i data-position="bottom" data-delay="50" | |
data-tooltip="Settings" | 73 | 73 | data-tooltip="Settings" | |
class="mdi-action-settings tooltipped"></i></a></li> | 74 | 74 | class="mdi-action-settings tooltipped"></i></a></li> | |
<li><a ng-click="logout()" ui-sref="login"><i data-position="bottom" data-delay="50" data-tooltip="Logout" | 75 | 75 | <li><a ng-click="logout()" ui-sref="login"><i data-position="bottom" data-delay="50" data-tooltip="Logout" | |
class="mdi-content-forward tooltipped"></i></a></li> | 76 | 76 | class="mdi-content-forward tooltipped"></i></a></li> | |
77 | 77 | |||
78 | 78 | |||
</ul> | 79 | 79 | </ul> | |
80 | 80 | |||
<!-- Slide-in side-nav for small screens --> | 81 | 81 | <!-- Slide-in side-nav for small screens --> | |
<ul ng-show="UserService.isLoggedIn()" class="side-nav" id="mobile-demo"> | 82 | 82 | <ul ng-show="UserService.isLoggedIn()" class="side-nav" id="mobile-demo"> | |
<span ng-show="currentSection.id"> | 83 | 83 | <span ng-show="currentSection.id"> | |
<li ui-sref-active="active"><a ui-sref="feed({sectionId:currentSection.id})"> | 84 | 84 | <li ui-sref-active="active"><a ui-sref="feed({sectionId:currentSection.id})"> | |
<i class="mdi-action-view-module left"></i> | 85 | 85 | <i class="mdi-action-view-module left"></i> | |
Feed</a> | 86 | 86 | Feed</a> | |
</li> | 87 | 87 | </li> | |
<li ui-sref-active="active"><a ui-sref="deck({sectionId:currentSection.id})"> | 88 | 88 | <li ui-sref-active="active"><a ui-sref="deck({sectionId:currentSection.id})"> | |
<i class="mdi-action-view-carousel left"> </i> | 89 | 89 | <i class="mdi-action-view-carousel left"> </i> | |
Deck | 90 | 90 | Deck | |
</a> | 91 | 91 | </a> | |
</li> | 92 | 92 | </li> | |
<li ui-sref-active="active"><a ui-sref="cardlist({sectionId:currentSection.id})"> | 93 | 93 | <li ui-sref-active="active"><a ui-sref="cardlist({sectionId:currentSection.id})"> | |
<i class="mdi-action-view-list left"></i> | 94 | 94 | <i class="mdi-action-view-list left"></i> | |
Card List | 95 | 95 | Card List | |
</a> | 96 | 96 | </a> | |
</li> | 97 | 97 | </li> | |
<hr> | 98 | 98 | <hr> | |
</span> | 99 | 99 | </span> | |
<!-- Collapsible menu for all the User's classes --> | 100 | 100 | <!-- Collapsible menu for all the User's classes --> | |
<ul class="collapsible" data-collapsible="accordion" > | 101 | 101 | <ul class="collapsible" data-collapsible="accordion" > | |
<li class="bold"> | 102 | 102 | <li class="bold"> | |
<a class="collapsible-header black-text"> | 103 | 103 | <a class="collapsible-header black-text"> | |
Classes | 104 | 104 | Classes | |
<i class="mdi-navigation-arrow-drop-down right"></i> | 105 | 105 | <i class="mdi-navigation-arrow-drop-down right"></i> | |
</a> | 106 | 106 | </a> | |
</li> | 107 | 107 | </li> | |
<div class="collapsible-body" style="display: block"> | 108 | 108 | <div class="collapsible-body" style="display: block"> | |
<ul> | 109 | 109 | <ul> | |
<li ui-sref-active="active" ng-repeat="section in UserService.getUserData().sections"> | 110 | 110 | <li ui-sref-active="active" ng-repeat="section in UserService.getUserData().sections"> | |
<a class="class bold" ui-sref="feed({sectionId:section.id})">{{section.short_name}}</a> | 111 | 111 | <a class="class bold" ui-sref="feed({sectionId:section.id})">{{section.short_name}}</a> | |
</li> | 112 | 112 | </li> | |
<hr> | 113 | 113 | <hr> | |
<li><a ui-sref="addclass"><i class="tiny mdi-content-add">Add Class</i></a></li> | 114 | 114 | <li><a ui-sref="addclass"><i class="tiny mdi-content-add">Add Class</i></a></li> | |
</ul> | 115 | 115 | </ul> | |
</div> | 116 | 116 | </div> | |
</ul> | 117 | 117 | </ul> | |
<li><a ui-sref="study">Study</a></li> | 118 | 118 | <li><a ui-sref="study">Study</a></li> | |
<li><a ui-sref="settings">Settings</a></li> | 119 | 119 | <li><a ui-sref="settings">Settings</a></li> | |
<li><a ng-click="logout()">Logout</a></li> | 120 | 120 | <li><a ng-click="logout()">Logout</a></li> | |
</ul> | 121 | 121 | </ul> | |
</div> | 122 | 122 | </div> | |
</nav> | 123 | 123 | </nav> | |
124 | 124 | |||
</header> | 125 | 125 | </header> | |
126 | 126 | |||
127 | 127 | |||
<!-- Menu Bar --> | 128 | 128 | <!-- Menu Bar --> | |
<main ui-view></main> | 129 | 129 | <main ui-view></main> | |
130 | 130 | |||
131 | 131 | |||
<!--<footer class="page-footer">--> | 132 | 132 | <!--<footer class="page-footer">--> | |
<!--<div class="footer-copyright">--> | 133 | 133 | <!--<div class="footer-copyright">--> | |
<!--<div class="container">--> | 134 | 134 | <!--<div class="container">--> | |
<!--© 2015 Team Swag--> | 135 | 135 | <!--© 2015 Team Swag--> | |
<!--<a class="grey-text text-lighten-4 right" id="contact" href="mailto:halp@flashy.cards">Concerns? Contact us by--> | 136 | 136 | <!--<a class="grey-text text-lighten-4 right" id="contact" href="mailto:halp@flashy.cards">Concerns? Contact us by--> | |
<!--email!</a>--> | 137 | 137 | <!--email!</a>--> | |
<!--</div>--> | 138 | 138 | <!--</div>--> | |
139 | 139 | |||
<!--</div>--> | 140 | 140 | <!--</div>--> | |
<!--</footer>--> | 141 | 141 | <!--</footer>--> | |
142 | 142 | |||
</body> | 143 | 143 | </body> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script> | 144 | 144 | <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script> | |
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.14/angular-ui-router.js"></script> | 145 | 145 | <script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.14/angular-ui-router.js"></script> | |
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-cookies.js"></script> | 146 | 146 | <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-cookies.js"></script> | |
<script src="//code.jquery.com/jquery-2.1.4.min.js"></script> | 147 | 147 | <script src="//code.jquery.com/jquery-2.1.4.min.js"></script> | |
<script type="text/javascript" src="scripts/materialize.js"></script> | 148 | 148 | <script type="text/javascript" src="scripts/materialize.js"></script> | |
<script type="text/javascript" src="scripts/jquery.collapsible.js"></script> | 149 | 149 | <script type="text/javascript" src="scripts/jquery.collapsible.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.js"></script> | 150 | 150 | <script src="https://ajax.googleapis.com/ajax/libs/angular_material/0.9.0/angular-material.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script> | 151 | 151 | <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-animate.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script> | 152 | 152 | <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-aria.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-resource.min.js"></script> | 153 | 153 | <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-resource.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-sanitize.js"></script> | 154 | 154 | <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-sanitize.js"></script> | |
<script src="static/js/angular-websocket.js"></script> | 155 | 155 | <script src="static/js/angular-websocket.js"></script> | |
<script src="static/js/angular-contenteditable.js"></script> | 156 | 156 | <script src="static/js/angular-contenteditable.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.4/angular-filter.js"></script> | 157 | 157 | <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.4/angular-filter.js"></script> | |
158 | 158 | |||
159 | 159 | |||
<script src="config.js"></script> | 160 | 160 | <script src="config.js"></script> | |
161 | 161 | |||
<script src="scripts/FlashcardFactory.js"></script> | 162 | 162 | <script src="scripts/FlashcardFactory.js"></script> | |
<script src="scripts/DeckFactory.js"></script> | 163 | 163 | <script src="scripts/DeckFactory.js"></script> | |
164 | 164 |
scripts/CardGridController.js
View file @
7545660
angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSocket', 'flashy.DeckFactory']).CardGridController = | 1 | 1 | angular.module('flashy.CardGridController', ['ui.router', 'ngAnimate', 'ngWebSocket', 'flashy.DeckFactory']).CardGridController = | |
function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, $interval, UserService, Flashcard, Deck) { | 2 | 2 | function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, $interval, UserService, Flashcard, Deck) { | |
3 | sectionId = parseInt($stateParams.sectionId); | |||
$scope.cards = []; // all cards | 3 | 4 | $scope.cards = []; // all cards | |
$scope.cardCols = []; // organized data | 4 | 5 | $scope.cardCols = []; // organized data | |
$scope.cardColsShow = []; // displayed data | 5 | 6 | $scope.cardColsShow = []; // displayed data | |
$scope.numCols = 0; | 6 | 7 | $scope.numCols = 0; | |
$scope.cardTable = {}; // look up table of cards: {'colNum':col, 'obj':card} | 7 | 8 | $scope.section = $rootScope.SectionResource.get({sectionId: sectionId}); | |
$scope.sectionId = parseInt($stateParams.sectionId); | 8 | 9 | $scope.deck = new Deck(sectionId, { | |
$scope.section = $rootScope.SectionResource.get({sectionId: $scope.sectionId}); | 9 | |||
$scope.deck = new Deck($scope.sectionId, { | 10 | |||
cardHideCallback: function(card) { | 11 | 10 | cardHideCallback: function(card) { | |
$scope.hideCardFromGrid(card); | 12 | 11 | $scope.hideCardFromGrid(card); | |
} | 13 | 12 | } | |
}); | 14 | 13 | }); | |
15 | 14 | |||
$scope.showGrid = false; | 16 | 15 | $scope.showGrid = false; | |
//$scope.moveQueue = []; // queue of flashcard objects | 17 | 16 | //$scope.moveQueue = []; // queue of flashcard objects | |
$rootScope.currentSection = $scope.section; | 18 | 17 | $rootScope.currentSection = $scope.section; | |
19 | 18 | |||
$scope.refreshColumnWidth = function() { | 20 | 19 | $scope.refreshColumnWidth = function() { | |
avail = $window.innerWidth - 17; | 21 | 20 | avail = $window.innerWidth - 17; | |
width = Math.floor(avail / Math.floor(avail / 250)); | 22 | 21 | width = Math.floor(avail / Math.floor(avail / 250)); | |
$('.cardColumn').css({ | 23 | 22 | $('.cardColumn').css({ | |
width: width + 'px', | 24 | 23 | width: width + 'px', | |
'font-size': 100 * width / 250 + '%' | 25 | 24 | 'font-size': 100 * width / 250 + '%' | |
}); | 26 | 25 | }); | |
$('.cardColumn .card.flashy').css({ | 27 | 26 | $('.cardColumn .card.flashy').css({ | |
width: width - 12 + 'px', | 28 | 27 | width: width - 12 + 'px', | |
height: (width * 3 / 5) + 'px' | 29 | 28 | height: (width * 3 / 5) + 'px' | |
}); | 30 | 29 | }); | |
}; | 31 | 30 | }; | |
$scope.refreshLayout = function() { | 32 | 31 | $scope.refreshLayout = function() { | |
numCols = Math.max(1, Math.floor(($window.innerWidth - 17) / 250)); | 33 | 32 | numCols = Math.max(1, Math.floor(($window.innerWidth - 17) / 250)); | |
34 | 33 | |||
// check if we actually need to refresh the whole layout | 35 | 34 | // check if we actually need to refresh the whole layout | |
if (numCols == $scope.numCols) return $scope.refreshColumnWidth(); | 36 | 35 | if (numCols == $scope.numCols) return $scope.refreshColumnWidth(); | |
$scope.numCols = numCols; | 37 | 36 | $scope.numCols = numCols; | |
console.log('refreshing layout for ' + numCols + ' columns'); | 38 | 37 | console.log('refreshing layout for ' + numCols + ' columns'); | |
$scope.cardCols = []; | 39 | 38 | $scope.cardCols = []; | |
var cols = []; | 40 | 39 | var cols = []; | |
for (var i = 0; i < numCols; i++) cols.push([]); | 41 | 40 | for (var i = 0; i < numCols; i++) cols.push([]); | |
var n = 0; | 42 | 41 | var n = 0; | |
$scope.cards.forEach(function(card, j) { | 43 | 42 | $scope.cards.forEach(function(card, j) { | |
card.colNum = n++ % numCols; | 44 | 43 | card.colNum = n++ % numCols; | |
cols[card.colNum].push(card); | 45 | 44 | cols[card.colNum].push(card); | |
}); | 46 | 45 | }); | |
for (i in cols) $scope.updateColRanks(cols[i]); | 47 | 46 | for (i in cols) $scope.updateColRanks(cols[i]); | |
console.log(cols); | 48 | 47 | console.log(cols); | |
return $timeout(function() { | 49 | 48 | return $timeout(function() { | |
$scope.cardCols = cols; | 50 | 49 | $scope.cardCols = cols; | |
$timeout($scope.refreshColumnWidth); | 51 | 50 | $timeout($scope.refreshColumnWidth); | |
}); | 52 | 51 | }); | |
53 | 52 | |||
}; | 54 | 53 | }; | |
55 | 54 | |||
angular.element($window).bind('resize', $scope.refreshLayout); | 56 | 55 | angular.element($window).bind('resize', $scope.refreshLayout); | |
57 | 56 | |||
$scope.addCardToGrid = function(card) { | 58 | 57 | $scope.addCardToGrid = function(card) { | |
var colNum = 0; | 59 | 58 | var colNum = 0; | |
var lowestCol = $scope.cardCols[0]; | 60 | 59 | var lowestCol = $scope.cardCols[0]; | |
var lowestColNum = 0; | 61 | 60 | var lowestColNum = 0; | |
while (colNum < $scope.numCols) { | 62 | 61 | while (colNum < $scope.numCols) { | |
if ($scope.cardCols[colNum].length == 0) { | 63 | 62 | if ($scope.cardCols[colNum].length == 0) { | |
lowestCol = $scope.cardCols[colNum]; | 64 | 63 | lowestCol = $scope.cardCols[colNum]; | |
break; | 65 | 64 | break; | |
} else if ($scope.cardCols[colNum].length < lowestCol.length) { | 66 | 65 | } else if ($scope.cardCols[colNum].length < lowestCol.length) { | |
lowestCol = $scope.cardCols[colNum]; | 67 | 66 | lowestCol = $scope.cardCols[colNum]; | |
lowestColNum = colNum; | 68 | 67 | lowestColNum = colNum; | |
lowestColLen = $scope.cardCols[colNum].length; | 69 | 68 | lowestColLen = $scope.cardCols[colNum].length; | |
} | 70 | 69 | } | |
colNum++; | 71 | 70 | colNum++; | |
} | 72 | 71 | } | |
console.log(card); | 73 | 72 | console.log(card); | |
$scope.cards.push(data); | 74 | 73 | $scope.cards.push(data); | |
lowestCol.unshift(card); | 75 | 74 | lowestCol.unshift(card); | |
card.colNum = lowestColNum; | 76 | 75 | card.colNum = lowestColNum; | |
$scope.updateColRanks(lowestCol); | 77 | 76 | $scope.updateColRanks(lowestCol); | |
$timeout($scope.refreshColumnWidth); | 78 | 77 | $timeout($scope.refreshColumnWidth); | |
79 | 78 | |||
}; | 80 | 79 | }; | |
81 | 80 | |||
$scope.updateColRanks = function(col) { | 82 | 81 | $scope.updateColRanks = function(col) { | |
for (i in col) | 83 | 82 | for (i in col) | |
col[i].colRank = parseInt(i); | 84 | 83 | col[i].colRank = parseInt(i); | |
}; | 85 | 84 | }; | |
86 | 85 | |||
$scope.hideCardFromGrid = function(card) { | 87 | 86 | $scope.hideCardFromGrid = function(card) { | |
console.log('hiding', card); | 88 | 87 | console.log('hiding', card); | |
$scope.cardCols[card.colNum].splice(card.colRank, 1); | 89 | 88 | $scope.cardCols[card.colNum].splice(card.colRank, 1); | |
$scope.updateColRanks($scope.cardCols[card.colNum]); | 90 | 89 | $scope.updateColRanks($scope.cardCols[card.colNum]); | |
console.log($scope.cardCols); | 91 | 90 | console.log($scope.cardCols); | |
}; | 92 | 91 | }; | |
93 | 92 |
scripts/CardListController.js
View file @
7545660
angular.module('flashy.CardListController', ['ui.router', 'angular.filter', 'ngSanitize']). | 1 | 1 | angular.module('flashy.CardListController', ['ui.router', 'angular.filter', 'ngSanitize', 'flashy.DeckFactory']). | |
controller('CardListController', function($scope, $rootScope, $state, $http, $stateParams, Flashcard) { | 2 | 2 | controller('CardListController', function($scope, $rootScope, $state, $http, $stateParams, Flashcard, Deck) { | |
// cards array | 3 | 3 | // cards array | |
sectionId = $stateParams.sectionId; | 4 | 4 | sectionId = parseInt($stateParams.sectionId); | |
5 | $scope.deck = new Deck(sectionId, { | |||
6 | cardPullCallback: function(card) { | |||
7 | Materialize.toast('Pulled!', 3000); | |||
8 | }, | |||
9 | cardUnpullCallback: function(card) { | |||
10 | Materialize.toast('Unpulled!', 3000); | |||
11 | }, | |||
12 | cardHideCallback: function(card) { | |||
13 | card.is_hidden = true; | |||
14 | Materialize.toast('Hidden!', 3000); | |||
15 | }, | |||
16 | cardUnhideCallback: function(card) { | |||
17 | card.is_hidden = false; | |||
18 | Materialize.toast('Unhidden!', 3000); | |||
19 | } | |||
20 | }); | |||
$rootScope.currentSection = $rootScope.SectionResource.get({sectionId: sectionId}); | 5 | 21 | $rootScope.currentSection = $rootScope.SectionResource.get({sectionId: sectionId}); | |
$scope.cards = []; | 6 | 22 | $scope.cards = []; | |
7 | 23 | |||
$http.get('/api/sections/' + sectionId + '/flashcards/?hidden=yes'). | 8 | 24 | $http.get('/api/sections/' + sectionId + '/flashcards/?hidden=yes'). | |
success(function(data) { | 9 | 25 | success(function(data) { | |
for (i in data) $scope.cards[data[i].id] = new Flashcard(data[i], $scope.cards); | 10 | 26 | for (i in data) $scope.cards[data[i].id] = new Flashcard(data[i], $scope.deck); | |
}). | 11 | 27 | }). | |
error(function(err) { | 12 | 28 | error(function(err) { | |
console.log('pulling feed failed'); | 13 | 29 | console.log('pulling feed failed'); | |
}); | 14 | 30 | }); | |
15 | 31 | |||
$scope.viewFeed = function() { | 16 | |||
$state.go('feed', {sectionId: sectionId}); | 17 | |||
console.log('go to feed'); | 18 | |||
}; | 19 | |||
20 | ||||
21 | ||||
// unhide card | 22 | |||
$scope.unhide = function(card) { | 23 | |||
$http.post('/api/flashcards/' + card.id + '/unhide/'). | 24 | |||
success(function(data) { | 25 | |||
console.log(card.text + ' unhidden'); | 26 | |||
27 | ||||
// locally change hidden | 28 | |||
card.is_hidden = false; | 29 | |||
Materialize.toast('Unhidden', 3000, 'rounded'); | 30 | |||
}). | 31 | |||
error(function(err) { | 32 | |||
console.log('no unhide for you'); | 33 | |||
}); | 34 | |||
}; | 35 | |||
36 | ||||
// hide card | 37 | |||
$scope.hide = function(card) { | 38 | |||
$http.post('/api/flashcards/' + card.id + '/hide/'). | 39 | |||
success(function(data) { | 40 | |||
console.log(card.text + ' hidden'); | 41 | |||
42 | ||||
// locally change hidden | 43 | |||
card.is_hidden = true; | 44 | |||
Materialize.toast('Hidden', 3000, 'rounded'); | 45 | |||
}). | 46 | |||
error(function(err) { | 47 | |||
console.log('no hide for you'); | 48 | |||
}); | 49 | |||
}; | 50 | |||
51 | ||||
// pull card | 52 | |||
$scope.pull = function(card) { | 53 | |||
$http.post('/api/flashcards/' + card.id + '/pull/'). | 54 | |||
success(function(data) { | 55 | |||
console.log(card.text + ' pulled'); | 56 | |||
57 | ||||
// locally change boolean for display purposes | 58 | |||
card.is_in_deck = true; | 59 | |||
Materialize.toast('Added to Your Deck', 3000, 'rounded'); | 60 | |||
}). | 61 | |||
error(function(err) { | 62 | |||
console.log('no pull for you'); | 63 | |||
}); | 64 | |||
}; | 65 | |||
66 | ||||
// unpull card | 67 | |||
$scope.unpull = function(card) { | 68 | |||
$http.post('/api/flashcards/' + card.id + '/unpull/'). | 69 | |||
success(function(data) { | 70 | |||
console.log(card.text + ' unpulled'); | 71 | |||
72 | ||||
// local change for display purposes | 73 | |||
card.is_in_deck = false; | 74 | |||
Materialize.toast('Removed from Your Deck', 3000, 'rounded'); | 75 | |||
}). | 76 | |||
error(function(err) { | 77 | |||
console.log('no unpull for you'); | 78 | |||
}); | 79 | |||
}; | 80 | |||
81 | ||||
// flag/report card | 82 | 32 | // flag/report card | |
$scope.flag = function(card) { | 83 | 33 | $scope.flag = function(card) { | |
$http.post('/api/flashcards/' + card.id + '/report/'). | 84 | 34 | $http.post('/api/flashcards/' + card.id + '/report/'). | |
success(function(data) { | 85 | 35 | success(function(data) { | |
console.log(card.text + ' reported'); | 86 | 36 | console.log(card.text + ' reported'); | |
87 | ||||
// local change for display purposes | 88 | |||
Materialize.toast('Card Flagged', 3000, 'rounded'); | 89 | |||
}). | 90 | 37 | }). | |
error(function(err) { | 91 | 38 | error(function(err) { | |
console.log('no flag for you'); | 92 | 39 | console.log('no flag for you'); | |
}); | 93 | 40 | }); | |
}; | 94 | 41 | }; | |
95 | 42 | |||
// toggle button text from show to hide | 96 | 43 | // toggle button text from show to hide | |
$(function() { | 97 | 44 | $(function() { | |
$('#showHidden').click(function() { | 98 | 45 | $('#showHidden').click(function() { | |
$(this).text(function(i, text) { | 99 | 46 | $(this).text(function(i, text) { | |
return text === 'Show Hidden' ? 'Hide Hidden' : 'Show Hidden'; | 100 | 47 | return text === 'Show Hidden' ? 'Hide Hidden' : 'Show Hidden'; | |
}); | 101 | 48 | }); | |
}); | 102 | 49 | }); | |
}); | 103 | 50 | }); | |
104 | 51 | |||
$scope.$on('$destroy', function() { | 105 | 52 | $scope.$on('$destroy', function() { | |
$rootScope.currentSection = {}; | 106 | 53 | $rootScope.currentSection = {}; | |
$(document).off('keydown'); | 107 | 54 | $(document).off('keydown'); | |
}); | 108 | 55 | }); | |
109 | 56 | |||
$(document).ready(function() { | 110 | 57 | $(document).ready(function() { | |
$('.tooltipped').tooltip({delay: 50}); | 111 | 58 | $('.tooltipped').tooltip({delay: 50}); | |
112 | 59 | |||
//back to top | 113 | 60 | //back to top | |
var offset = 300; | 114 | 61 | var offset = 300; | |
var duration = 300; | 115 | 62 | var duration = 300; | |
$(window).scroll(function() { | 116 | 63 | $(window).scroll(function() { | |
if ($(this).scrollTop() > offset) { | 117 | 64 | if ($(this).scrollTop() > offset) { | |
$('.back-to-top').fadeIn(duration); | 118 | 65 | $('.back-to-top').fadeIn(duration); | |
} else { | 119 | 66 | } else { | |
$('.back-to-top').fadeOut(duration); | 120 | 67 | $('.back-to-top').fadeOut(duration); | |
} | 121 | 68 | } | |
}); | 122 | 69 | }); | |
123 | 70 | |||
$('.back-to-top').click(function(event) { | 124 | 71 | $('.back-to-top').click(function(event) { | |
event.preventDefault(); | 125 | 72 | event.preventDefault(); | |
$('html, body').animate({scrollTop: 0}, duration); | 126 | 73 | $('html, body').animate({scrollTop: 0}, duration); | |
return false; | 127 | 74 | return false; | |
}); | 128 | 75 | }); | |
}); | 129 | 76 | }); | |
130 | 77 | |||
// to display day of the week badges | 131 | 78 | // to display day of the week badges | |
$scope.dayofweek = function(item) { | 132 | 79 | $scope.dayofweek = function(item) { | |
var date = new Date(item.material_date); | 133 | 80 | var date = new Date(item.material_date); | |
return ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][date.getDay()]; | 134 | 81 | return ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'][date.getDay()]; | |
}; | 135 | 82 | }; | |
136 | 83 | |||
// checkbox filter | 137 | 84 | // checkbox filter | |
$scope.filter = { | 138 | 85 | $scope.filter = { | |
'week1': true, | 139 | 86 | 'week1': true, | |
'week2': true, | 140 | 87 | 'week2': true, | |
'week3': true, | 141 | 88 | 'week3': true, | |
'week4': true, | 142 | 89 | 'week4': true, | |
'week5': true, | 143 | 90 | 'week5': true, | |
'week6': true, | 144 | 91 | 'week6': true, | |
'week7': true, | 145 | 92 | 'week7': true, | |
'week8': true, | 146 | 93 | 'week8': true, | |
'week9': true, | 147 | 94 | 'week9': true, | |
'week10': true, | 148 | 95 | 'week10': true, | |
}; | 149 | 96 | }; | |
150 | 97 | |||
$scope.filterByDate = function(item) { | 151 | 98 | $scope.filterByDate = function(item) { | |
var week = item.material_week_num; | 152 | 99 | var week = item.material_week_num; | |
return (week == 1 && $scope.filter['week1']) || | 153 | 100 | return (week == 1 && $scope.filter['week1']) || | |
(week == 2 && $scope.filter['week2']) || | 154 | 101 | (week == 2 && $scope.filter['week2']) || | |
(week == 3 && $scope.filter['week3']) || | 155 | 102 | (week == 3 && $scope.filter['week3']) || | |
(week == 4 && $scope.filter['week4']) || | 156 | 103 | (week == 4 && $scope.filter['week4']) || | |
(week == 5 && $scope.filter['week5']) || | 157 | 104 | (week == 5 && $scope.filter['week5']) || | |
(week == 6 && $scope.filter['week6']) || | 158 | 105 | (week == 6 && $scope.filter['week6']) || | |
(week == 7 && $scope.filter['week7']) || | 159 | 106 | (week == 7 && $scope.filter['week7']) || | |
(week == 8 && $scope.filter['week8']) || | 160 | 107 | (week == 8 && $scope.filter['week8']) || | |
(week == 9 && $scope.filter['week9']) || | 161 | 108 | (week == 9 && $scope.filter['week9']) || | |
(week == 10 && $scope.filter['week10']); | 162 | 109 | (week == 10 && $scope.filter['week10']); | |
}; | 163 | 110 | }; | |
111 | $scope.$on('$destroy', function() { | |||
112 | $scope.deck.cleanup(); | |||
113 | Flashcard.cleanup(); | |||
114 | }); | |||
164 | 115 | |||
} | 165 | 116 | } | |
). | 166 | 117 | ). | |
filter('displayCard', function($sce) { | 167 | 118 | filter('displayCard', function($sce) { |
scripts/ClassDropController.js
View file @
7545660
angular.module('flashy.ClassDropController', ['ui.router']). | 1 | File was deleted | ||
controller('ClassDropController', function($rootScope, $resource, $scope, $state, $http, UserService) { | 2 | |||
$scope.hi = 'hi'; | 3 | |||
$rootScope.SectionResource = $resource('/api/sections/:sectionId/'); | 4 | |||
$rootScope.currentSection = {}; | 5 | |||
$rootScope.UserService = UserService; | 6 | |||
7 | ||||
$scope.dropClass = function(section) { | 8 | |||
$http.post('/api/sections/' + section.id + '/drop/'). | 9 | |||
success(function(data) { | 10 | |||
console.log(section.short_name + ' dropped'); | 11 | |||
12 | ||||
Materialize.toast('Dropped', 3000, 'rounded'); | 13 | |||
}). | 14 | |||
error(function(err) { | 15 | |||
console.log('no drop for you'); | 16 | |||
}); | 17 |
scripts/DeckFactory.js
View file @
7545660
angular.module('flashy.DeckFactory', ['ui.router', 'flashy.FlashcardFactory', 'ngWebSocket']). | 1 | 1 | angular.module('flashy.DeckFactory', ['ui.router', 'flashy.FlashcardFactory', 'ngWebSocket']). | |
factory('Deck', function ($http, $rootScope, $state, $websocket, Flashcard, UserService) { | 2 | 2 | factory('Deck', function ($http, $rootScope, $state, $websocket, Flashcard, UserService) { | |
3 | 3 | |||
var Deck = function (sectionId, callbacks) { | 4 | 4 | var Deck = function (sectionId, callbacks) { | |
if (!UserService.isInSection(sectionId)) { | 5 | 5 | if (!UserService.isInSection(sectionId)) { | |
console.log('user is not enrolled in ' + sectionId); | 6 | 6 | console.log('user is not enrolled in ' + sectionId); | |
$state.go('addclass'); | 7 | 7 | $state.go('addclass'); | |
} | 8 | 8 | } | |
obj = this; | 9 | 9 | obj = this; | |
this.cards = []; | 10 | 10 | this.cards = []; | |
this.section = $rootScope.SectionResource.get({sectionId: sectionId}); | 11 | 11 | this.section = $rootScope.SectionResource.get({sectionId: sectionId}); | |
12 | 12 | |||
this.ws = $websocket($rootScope.ws_host + '/ws/deck/' + sectionId + '?subscribe-user'); | 13 | 13 | this.ws = $websocket($rootScope.ws_host + '/ws/deck/' + sectionId + '?subscribe-user'); | |
this.contains = function (id) { | 14 | 14 | this.contains = function (id) { | |
return this.cards[id]; | 15 | 15 | return this.cards[id]; | |
}; | 16 | 16 | }; | |
17 | 17 | |||
this.ws.onMessage(function (message) { | 18 | 18 | this.ws.onMessage(function (message) { | |
data = JSON.parse(message.data); | 19 | 19 | data = JSON.parse(message.data); | |
console.log('message', data); | 20 | 20 | console.log('message', data); | |
card = new Flashcard(data.flashcard); | 21 | 21 | card = new Flashcard(data.flashcard); | |
if (data.event_type == 'card_pulled') { | 22 | 22 | if (data.event_type == 'card_pulled') { | |
obj.cards[card.id] = card; | 23 | 23 | obj.cards[card.id] = card; | |
if (callbacks.cardPullCallback) callbacks.cardPullCallback(card); | 24 | 24 | if (callbacks.cardPullCallback) callbacks.cardPullCallback(card); | |
} | 25 | 25 | } | |
if (data.event_type == 'card_unpulled') { | 26 | 26 | if (data.event_type == 'card_unpulled') { | |
obj.cards[card.id] = undefined; | 27 | 27 | obj.cards[card.id] = undefined; | |
if (callbacks.cardUnpullCallback) callbacks.cardUnpullCallback(card); | 28 | 28 | if (callbacks.cardUnpullCallback) callbacks.cardUnpullCallback(card); | |
} | 29 | 29 | } | |
if (data.event_type == 'card_hidden') { | 30 | 30 | if (data.event_type == 'card_hidden') { | |
if (callbacks.cardHideCallback) callbacks.cardHideCallback(card); | 31 | 31 | if (callbacks.cardHideCallback) callbacks.cardHideCallback(card); | |
} | 32 | 32 | } | |
33 | if (data.event_type == 'card_unhidden') { | |||
34 | if (callbacks.cardUnhideCallback) callbacks.cardUnhideCallback(card); | |||
35 | } | |||
}); | 33 | 36 | }); | |
this.deckPromise = $http.get('/api/sections/' + sectionId + '/deck/').success(function (data) { | 34 | 37 | this.deckPromise = $http.get('/api/sections/' + sectionId + '/deck/').success(function (data) { | |
for (i in data) obj.cards[data[i].id] = new Flashcard(data[i], obj); | 35 | 38 | for (i in data) obj.cards[data[i].id] = new Flashcard(data[i], obj); | |
console.log("got user's deck", data); | 36 | 39 | console.log("got user's deck", data); | |
}); | 37 | 40 | }); | |
this.cleanup = function () { | 38 | 41 | this.cleanup = function () { | |
this.ws.close(); | 39 | 42 | this.ws.close(); | |
}; | 40 | 43 | }; | |
this.forEach = this.cards.forEach; | 41 | 44 | this.forEach = this.cards.forEach; |
scripts/FeedController.js
View file @
7545660
angular.module('flashy.FeedController', | 1 | 1 | angular.module('flashy.FeedController', | |
['ui.router', | 2 | 2 | ['ui.router', | |
'ngAnimate', | 3 | 3 | 'ngAnimate', | |
'ngWebSocket', | 4 | 4 | 'ngWebSocket', | |
'contenteditable', | 5 | 5 | 'contenteditable', | |
'flashy.DeckFactory']).controller('FeedController', | 6 | 6 | 'flashy.DeckFactory']).controller('FeedController', | |
function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, $interval, UserService, Flashcard, Deck) { | 7 | 7 | function($scope, $rootScope, $state, $http, $window, $timeout, $stateParams, $websocket, $interval, UserService, Flashcard, Deck) { | |
angular.module('flashy.CardGridController').CardGridController.apply(this, arguments); | 8 | 8 | angular.module('flashy.CardGridController').CardGridController.apply(this, arguments); | |
9 | 9 | |||
(function drawCols() { | 10 | 10 | (function drawCols() { | |
$interval(function() { | 11 | 11 | $interval(function() { | |
if ($scope.cardColsShow != $scope.cardCols) { | 12 | 12 | if ($scope.cardColsShow != $scope.cardCols) { | |
$scope.cardColsShow = $scope.cardCols; | 13 | 13 | $scope.cardColsShow = $scope.cardCols; | |
console.log('interval'); | 14 | 14 | console.log('interval'); | |
} | 15 | 15 | } | |
}, 1000); | 16 | 16 | }, 1000); | |
}()); | 17 | 17 | }()); | |
18 | 18 | |||
$scope.updateCardScore = function(card) { | 19 | 19 | $scope.updateCardScore = function(card) { | |
console.log($scope.cardCols, card); | 20 | 20 | console.log($scope.cardCols, card); | |
// if no colNum is attached, then this doesn't exist on the feed yet | 21 | 21 | // if no colNum is attached, then this doesn't exist on the feed yet | |
if (!card.colNum) return; | 22 | 22 | if (!card.colNum) return; | |
$scope.cardCols[card.colNum].sort(function(a, b) { | 23 | 23 | $scope.cardCols[card.colNum].sort(function(a, b) { | |
return b.score - a.score; | 24 | 24 | return b.score - a.score; | |
}); | 25 | 25 | }); | |
$scope.updateColRanks($scope.cardCols[card.colNum]); | 26 | 26 | $scope.updateColRanks($scope.cardCols[card.colNum]); | |
}; | 27 | 27 | }; | |
28 | 28 | |||
$scope.feed_ws = $websocket($scope.ws_host + '/ws/feed/' + $scope.sectionId + '?subscribe-broadcast'); | 29 | 29 | $scope.feed_ws = $websocket($scope.ws_host + '/ws/feed/' + sectionId + '?subscribe-broadcast'); | |
$scope.feed_ws.onMessage(function(e) { | 30 | 30 | $scope.feed_ws.onMessage(function(e) { | |
data = JSON.parse(e.data); | 31 | 31 | data = JSON.parse(e.data); | |
console.log('message', data); | 32 | 32 | console.log('message', data); | |
if (data.event_type == 'new_card') { | 33 | 33 | if (data.event_type == 'new_card') { | |
$scope.addCardToGrid(new Flashcard(data.flashcard, $scope.deck)); | 34 | 34 | $scope.addCardToGrid(new Flashcard(data.flashcard, $scope.deck)); | |
} else if (data.event_type == 'score_change') { | 35 | 35 | } else if (data.event_type == 'score_change') { | |
card = new Flashcard(data.flashcard); | 36 | 36 | card = new Flashcard(data.flashcard); | |
card.score = data.flashcard.score; | 37 | 37 | card.score = data.flashcard.score; | |
$scope.updateCardScore(card); | 38 | 38 | $scope.updateCardScore(card); | |
} | 39 | 39 | } | |
}); | 40 | 40 | }); | |
41 | 41 | |||
$scope.pushCard = function() { | 42 | 42 | $scope.pushCard = function() { | |
var myCard = { | 43 | 43 | var myCard = { | |
// we can't trim this string because it'd mess up the blanks. Something to fix. | 44 | 44 | // we can't trim this string because it'd mess up the blanks. Something to fix. | |
'text': $('#new-card-input').text(), | 45 | 45 | 'text': $('#new-card-input').text(), | |
'mask': $scope.newCardBlanks, | 46 | 46 | 'mask': $scope.newCardBlanks, | |
section: $scope.section.id | 47 | 47 | section: $scope.section.id | |
}; | 48 | 48 | }; | |
if (myCard.text == '') { | 49 | 49 | if (myCard.text == '') { | |
console.log('blank flashcard not pushed:' + myCard.text); | 50 | 50 | console.log('blank flashcard not pushed:' + myCard.text); | |
return closeNewCard(); | 51 | 51 | return closeNewCard(); | |
} | 52 | 52 | } | |
$http.post('/api/flashcards/', myCard). | 53 | 53 | $http.post('/api/flashcards/', myCard). | |
success(function(data) { | 54 | 54 | success(function(data) { | |
console.log('flashcard pushed: ' + myCard.text); | 55 | 55 | console.log('flashcard pushed: ' + myCard.text); | |
if (!UserService.hasVerifiedEmail()) { | 56 | 56 | if (!UserService.hasVerifiedEmail()) { | |
Materialize.toast("<p>Thanks for contributing! However, others won't see your card until you verify your email address<p>", 4000); | 57 | 57 | Materialize.toast("<p>Thanks for contributing! However, others won't see your card until you verify your email address<p>", 4000); | |
} | 58 | 58 | } | |
}); | 59 | 59 | }); | |
return $scope.closeNewCardModal(); | 60 | 60 | return $scope.closeNewCardModal(); | |
}; | 61 | 61 | }; | |
62 | 62 | |||
/* Key bindings for the whole feed window. Hotkey it up! */ | 63 | 63 | /* Key bindings for the whole feed window. Hotkey it up! */ | |
var listenForC = true; | 64 | 64 | var listenForC = true; | |
65 | 65 | |||
// Need to pass these options into openmodal and leanmodal, | 66 | 66 | // Need to pass these options into openmodal and leanmodal, | |
// otherwise the ready handler doesn't get called | 67 | 67 | // otherwise the ready handler doesn't get called | |
68 | 68 | |||
modal_options = { | 69 | 69 | modal_options = { | |
dismissible: true, // Modal can be dismissed by clicking outside of the modal | 70 | 70 | dismissible: true, // Modal can be dismissed by clicking outside of the modal | |
opacity: 0, // Opacity of modal background | 71 | 71 | opacity: 0, // Opacity of modal background | |
in_duration: 300, // Transition in duration | 72 | 72 | in_duration: 300, // Transition in duration | |
out_duration: 200, // Transition out duration | 73 | 73 | out_duration: 200, // Transition out duration | |
ready: function() { | 74 | 74 | ready: function() { | |
$('#new-card-input').focus(); | 75 | 75 | $('#new-card-input').focus(); | |
document.execCommand('selectAll', false, null); | 76 | 76 | document.execCommand('selectAll', false, null); | |
} | 77 | 77 | } | |
}; | 78 | 78 | }; | |
79 | 79 | |||
$(document).keydown(function(e) { | 80 | 80 | $(document).keydown(function(e) { | |
var keyed = e.which; | 81 | 81 | var keyed = e.which; | |
if (keyed == 67 && listenForC) { // "c" for compose | 82 | 82 | if (keyed == 67 && listenForC) { // "c" for compose | |
$scope.openNewCardModal(); | 83 | 83 | $scope.openNewCardModal(); | |
e.preventDefault(); | 84 | 84 | e.preventDefault(); | |
return false; | 85 | 85 | return false; | |
} else if (keyed == 27) { // clear on ESC | 86 | 86 | } else if (keyed == 27) { // clear on ESC | |
$scope.closeNewCardModal(); | 87 | 87 | $scope.closeNewCardModal(); | |
} | 88 | 88 | } | |
}); | 89 | 89 | }); | |
90 | 90 | |||
$scope.openNewCardModal = function() { | 91 | 91 | $scope.openNewCardModal = function() { | |
$('#newCard').openModal(modal_options); | 92 | 92 | $('#newCard').openModal(modal_options); | |
listenForC = false; | 93 | 93 | listenForC = false; | |
$('#new-card-input').html('Write a flashcard!'); | 94 | 94 | $('#new-card-input').html('Write a flashcard!'); | |
}; | 95 | 95 | }; | |
96 | 96 | |||
$scope.closeNewCardModal = function() { | 97 | 97 | $scope.closeNewCardModal = function() { | |
listenForC = true; | 98 | 98 | listenForC = true; | |
$('#new-card-input').html('').blur(); | 99 | 99 | $('#new-card-input').html('').blur(); | |
$('#newCard').closeModal(modal_options); | 100 | 100 | $('#newCard').closeModal(modal_options); | |
}; | 101 | 101 | }; | |
102 | 102 | |||
$('.tooltipped').tooltip({delay: 50}); | 103 | 103 | $('.tooltipped').tooltip({delay: 50}); | |
// the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered | 104 | 104 | // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered | |
$('.modal-trigger').leanModal(modal_options); | 105 | 105 | $('.modal-trigger').leanModal(modal_options); | |
$('#new-card-input').on('keydown', function(e) { | 106 | 106 | $('#new-card-input').on('keydown', function(e) { | |
if (e.which == 13) { | 107 | 107 | if (e.which == 13) { | |
e.preventDefault(); | 108 | 108 | e.preventDefault(); | |
if ($scope.submit_enabled) { | 109 | 109 | if ($scope.submit_enabled) { | |
$scope.pushCard(); | 110 | 110 | $scope.pushCard(); | |
listenForC = true; | 111 | 111 | listenForC = true; | |
} | 112 | 112 | } | |
return false; | 113 | 113 | return false; | |
} else { | 114 | 114 | } else { | |
115 | 115 | |||
} | 116 | 116 | } | |
}); | 117 | 117 | }); | |
$('button#blank-selected').click(function() { | 118 | 118 | $('button#blank-selected').click(function() { | |
console.log(window.getSelection()); | 119 | 119 | console.log(window.getSelection()); | |
document.execCommand('bold'); | 120 | 120 | document.execCommand('bold'); | |
}); | 121 | 121 | }); | |
$scope.newCardBlanks = []; | 122 | 122 | $scope.newCardBlanks = []; | |
$scope.refreshNewCardInput = function() { | 123 | 123 | $scope.refreshNewCardInput = function() { | |
$scope.newCardText = $('#new-card-input').text(); | 124 | 124 | $scope.newCardText = $('#new-card-input').text(); | |
$scope.submit_enabled = $scope.newCardText.length >= 5 && $scope.newCardText.length <= 160; | 125 | 125 | $scope.submit_enabled = $scope.newCardText.length >= 5 && $scope.newCardText.length <= 160; | |
var i = 0; | 126 | 126 | var i = 0; | |
$scope.newCardBlanks = []; | 127 | 127 | $scope.newCardBlanks = []; | |
$('#new-card-input')[0].childNodes.forEach(function(node) { | 128 | 128 | $('#new-card-input')[0].childNodes.forEach(function(node) { | |
node = $(node)[0]; | 129 | 129 | node = $(node)[0]; | |
if (node.tagName == 'B') { | 130 | 130 | if (node.tagName == 'B') { | |
var text = $(node).text(); | 131 | 131 | var text = $(node).text(); | |
var leftspaces = 0, rightspaces = 0; | 132 | 132 | var leftspaces = 0, rightspaces = 0; | |
// awful way to find the first non-space character from the left or the right. thanks.js | 133 | 133 | // awful way to find the first non-space character from the left or the right. thanks.js | |
while (text[leftspaces] == ' ' || text[leftspaces] == '\xa0') leftspaces++; | 134 | 134 | while (text[leftspaces] == ' ' || text[leftspaces] == '\xa0') leftspaces++; | |
while (text[text.length - 1 - rightspaces] == ' ' || text[text.length - 1 - rightspaces] == '\xa0') rightspaces++; | 135 | 135 | while (text[text.length - 1 - rightspaces] == ' ' || text[text.length - 1 - rightspaces] == '\xa0') rightspaces++; | |
console.log(leftspaces, text.length); | 136 | 136 | console.log(leftspaces, text.length); | |
if (leftspaces != text.length) $scope.newCardBlanks.push([i + leftspaces, i + text.length - rightspaces]); | 137 | 137 | if (leftspaces != text.length) $scope.newCardBlanks.push([i + leftspaces, i + text.length - rightspaces]); | |
i += text.length; | 138 | 138 | i += text.length; | |
} else if (!node.data) { | 139 | 139 | } else if (!node.data) { | |
i += $(node).text().length; | 140 | 140 | i += $(node).text().length; | |
} else { | 141 | 141 | } else { | |
i += node.data.length; | 142 | 142 | i += node.data.length; | |
} | 143 | 143 | } | |
}); | 144 | 144 | }); | |
$scope.newCardBlanks.sort(function(a, b) { | 145 | 145 | $scope.newCardBlanks.sort(function(a, b) { | |
return a[0] - b[0]; | 146 | 146 | return a[0] - b[0]; | |
}); | 147 | 147 | }); | |
i = 0; | 148 | 148 | i = 0; | |
newtext = ''; | 149 | 149 | newtext = ''; | |
$scope.newCardBlanks.forEach(function(blank) { | 150 | 150 | $scope.newCardBlanks.forEach(function(blank) { | |
newtext += $scope.newCardText.slice(i, blank[0]); | 151 | 151 | newtext += $scope.newCardText.slice(i, blank[0]); | |
newtext += '<b>' + $scope.newCardText.slice(blank[0], blank[1]) + '</b>'; | 152 | 152 | newtext += '<b>' + $scope.newCardText.slice(blank[0], blank[1]) + '</b>'; | |
i = blank[1]; | 153 | 153 | i = blank[1]; | |
}); | 154 | 154 | }); | |
newtext += $scope.newCardText.slice(i); | 155 | 155 | newtext += $scope.newCardText.slice(i); | |
//$scope.newCardFormattedText = newtext; | 156 | 156 | //$scope.newCardFormattedText = newtext; | |
}; | 157 | 157 | }; | |
$scope.shuffleCards = function() { | 158 | 158 | $scope.shuffleCards = function() { | |
$timeout(function() { | 159 | 159 | $timeout(function() { | |
(function(o) { | 160 | 160 | (function(o) { | |
for (var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); | 161 | 161 | for (var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x); | |
return o; | 162 | 162 | return o; | |
})($scope.cardCols[0]); | 163 | 163 | })($scope.cardCols[0]); | |
}); | 164 | 164 | }); | |
}; | 165 | 165 | }; | |
$scope.$on('$destroy', function() { | 166 | 166 | $scope.$on('$destroy', function() { | |
$scope.feed_ws.close(); | 167 | 167 | $scope.feed_ws.close(); | |
}); | 168 | 168 | }); | |
return $http.get('/api/sections/' + $scope.sectionId + '/feed/'). | 169 | 169 | return $http.get('/api/sections/' + sectionId + '/feed/'). | |
success(function(data) { | 170 | 170 | success(function(data) { | |
console.log(data); | 171 | 171 | console.log(data); | |
$scope.cards = data.map(function(card) { | 172 | 172 | $scope.cards = data.map(function(card) { |
scripts/FlashcardFactory.js
View file @
7545660
angular.module('flashy.FlashcardFactory', ['ui.router']). | 1 | 1 | angular.module('flashy.FlashcardFactory', ['ui.router']). | |
factory('Flashcard', function ($http) { | 2 | 2 | factory('Flashcard', function ($http) { | |
var FlashcardCache = []; | 3 | 3 | var FlashcardCache = []; | |
4 | var Deck = null; | |||
var Flashcard = function (data, deck) { | 4 | 5 | var Flashcard = function (data, deck) { | |
if (typeof data == 'number') return FlashcardCache[data]; | 5 | 6 | if (typeof data == 'number') return FlashcardCache[data]; | |
if (FlashcardCache[data.id]) return FlashcardCache[data.id]; | 6 | 7 | if (FlashcardCache[data.id]) return FlashcardCache[data.id]; | |
if (deck) this.deck = deck; | 7 | 8 | if (!Deck && deck) Deck = deck; | |
for (var k in data) this[k] = data[k]; | 8 | 9 | for (var k in data) this[k] = data[k]; | |
this.textPieces = []; | 9 | 10 | this.textPieces = []; | |
this.mask.sort(function (a, b) { | 10 | 11 | this.mask.sort(function (a, b) { | |
return a[0] - b[0]; | 11 | 12 | return a[0] - b[0]; | |
}); | 12 | 13 | }); | |
var i = 0; | 13 | 14 | var i = 0; | |
this.mask.forEach(function (blank) { | 14 | 15 | this.mask.forEach(function (blank) { | |
this.textPieces.push({text: this.text.slice(i, blank[0])}); | 15 | 16 | this.textPieces.push({text: this.text.slice(i, blank[0])}); | |
this.textPieces.push({text: this.text.slice(blank[0], blank[1]), blank: true}); | 16 | 17 | this.textPieces.push({text: this.text.slice(blank[0], blank[1]), blank: true}); | |
i = blank[1]; | 17 | 18 | i = blank[1]; | |
}, this); | 18 | 19 | }, this); | |
this.textPieces.push({text: this.text.slice(i)}); | 19 | 20 | this.textPieces.push({text: this.text.slice(i)}); | |
this.formatted_text = ''; | 20 | 21 | this.formatted_text = ''; | |
for (i in this.textPieces) { | 21 | 22 | for (i in this.textPieces) { | |
p = this.textPieces[i]; | 22 | 23 | p = this.textPieces[i]; | |
this.formatted_text += p.blank ? '<b>' + p.text + '</b>' : p.text; | 23 | 24 | this.formatted_text += p.blank ? '<b>' + p.text + '</b>' : p.text; | |
} | 24 | 25 | } | |
FlashcardCache[this.id] = this; | 25 | 26 | FlashcardCache[this.id] = this; | |
}; | 26 | 27 | }; | |
27 | 28 | |||
Flashcard.prototype.isInDeck = function () { | 28 | 29 | Flashcard.prototype.isInDeck = function () { | |
return !(typeof this.deck.contains(this.id) === 'undefined'); | 29 | 30 | return !(typeof Deck.contains(this.id) === 'undefined'); | |
}; | 30 | 31 | }; | |
Flashcard.prototype.pullUnpull = function () { | 31 | 32 | Flashcard.prototype.pullUnpull = function () { | |
if (this.isInDeck()) this.unpull(); | 32 | 33 | if (this.isInDeck()) this.unpull(); | |
else this.pull(); | 33 | 34 | else this.pull(); | |
}; | 34 | 35 | }; | |
Flashcard.prototype.pull = function () { | 35 | 36 | Flashcard.prototype.pull = function () { | |
if (this.isInDeck()) return console.log('Not pulling', this.id, "because it's already in deck"); | 36 | 37 | if (this.isInDeck()) return console.log('Not pulling', this.id, "because it's already in deck"); | |
return $http.post('/api/flashcards/' + this.id + '/pull/'); | 37 | 38 | return $http.post('/api/flashcards/' + this.id + '/pull/'); | |
}; | 38 | 39 | }; | |
Flashcard.prototype.unpull = function () { | 39 | 40 | Flashcard.prototype.unpull = function () { | |
if (!this.isInDeck()) return console.log('Not unpulling', this.id, "because it's not in deck"); | 40 | 41 | if (!this.isInDeck()) return console.log('Not unpulling', this.id, "because it's not in deck"); | |
return $http.post('/api/flashcards/' + this.id + '/unpull/'); | 41 | 42 | return $http.post('/api/flashcards/' + this.id + '/unpull/'); | |
}; | 42 | 43 | }; | |
Flashcard.prototype.hide = function () { | 43 | 44 | Flashcard.prototype.hide = function () { | |
return $http.post('/api/flashcards/' + this.id + '/hide/'); | 44 | 45 | return $http.post('/api/flashcards/' + this.id + '/hide/'); | |
46 | }; | |||
47 | Flashcard.prototype.unhide = function () { | |||
48 | return $http.post('/api/flashcards/' + this.id + '/unhide/'); | |||
49 | }; | |||
50 | Flashcard.cleanup = function () { | |||
51 | Deck = null; | |||
52 | FlashcardCache = []; | |||
}; | 45 | 53 | }; | |
46 | 54 | |||
return Flashcard; | 47 | 55 | return Flashcard; | |
}); | 48 | 56 | }); |
scripts/SettingsController.js
View file @
7545660
angular.module('flashy.SettingsController', ['ui.router']). | 1 | 1 | angular.module('flashy.SettingsController', ['ui.router']). | |
2 | 2 | |||
controller('SettingsController', function($scope, $http) { | 3 | 3 | controller('SettingsController', function($rootScope, $resource, $scope, $state, $http, UserService) { | |
$scope.changePassword = function(oldPassword, newPassword, confirmedNewPassword) { | 4 | 4 | $scope.error = false; | |
5 | $scope.success = false; | |||
6 | $scope.mismatch = false; | |||
7 | $scope.unacceptable = false; | |||
5 | 8 | |||
9 | $scope.changePassword = function(oldPassword, newPassword, confirmedNewPassword) { | |||
10 | console.log('in change password'); | |||
11 | ||||
12 | $http.patch('/api/me/', { | |||
13 | 'old_password': oldPassword, | |||
14 | 'new_password': newPassword | |||
15 | }). | |||
16 | success(function(data) { | |||
17 | ||||
18 | console.log('password successfully changes'); | |||
19 | ||||
20 | }). | |||
21 | error(function(data) { | |||
22 | console.log('not changed'); | |||
23 | }); | |||
24 | ||||
25 | ||||
}; | 6 | 26 | }; | |
27 | ||||
28 | $rootScope.SectionResource = $resource('/api/sections/:sectionId/'); | |||
29 | $rootScope.currentSection = {}; | |||
30 | $rootScope.UserService = UserService; | |||
31 | ||||
32 | $scope.dropClass = function(section) { | |||
33 | $http.post('/api/sections/' + section.id + '/drop/'). | |||
34 | success(function(data) { | |||
35 | console.log(section.short_name + ' dropped'); | |||
36 | ||||
37 | Materialize.toast('Dropped', 3000, 'rounded'); | |||
38 | }). | |||
39 | error(function(err) { | |||
40 | console.log('no drop for you'); | |||
41 | }); | |||
42 | }; | |||
43 | ||||
44 | ||||
45 | ||||
console.log('checking to see if chrome'); | 7 | 46 | console.log('checking to see if chrome'); | |
47 | ||||
if (!chrome) { | 8 | 48 | if (!chrome) { | |
49 | pushSwitch.disabled = true; | |||
return; | 9 | 50 | return; | |
} | 10 | 51 | } | |
52 | ||||
console.log('chrome'); | 11 | 53 | console.log('chrome'); | |
12 | 54 | |||
console.log('executing things outside of module'); | 13 | 55 | console.log('executing things outside of module'); | |
var PUSH_SERVER_URL = '/api/subscribe/'; | 14 | 56 | var PUSH_SERVER_URL = '/api/subscribe/'; | |
57 | var UNPUSH_SERVER_URL = '/api/unsubscribe/'; | |||
15 | 58 | |||
function onPushSubscription(pushSubscription) { | 16 | 59 | function onPushSubscription(pushSubscription) { | |
console.log('pushSubscription = ', pushSubscription.endpoint); | 17 | 60 | console.log('pushSubscription = ', pushSubscription.endpoint); | |
// Here we would normally send the endpoint | 18 | 61 | // Here we would normally send the endpoint | |
// and subscription ID to our server. | 19 | 62 | // and subscription ID to our server. | |
// In this demo we just use send these values to | 20 | 63 | // In this demo we just use send these values to | |
// our server via XHR which sends a push message. | 21 | 64 | // our server via XHR which sends a push message. | |
22 | 65 | |||
var endpoint = pushSubscription.endpoint; | 23 | 66 | var endpoint = pushSubscription.endpoint; | |
var subscriptionId = pushSubscription.subscriptionId; | 24 | 67 | var subscriptionId = pushSubscription.subscriptionId; | |
25 | 68 | |||
console.log('registration_id: ', subscriptionId); | 26 | 69 | console.log('registration_id: ', subscriptionId); | |
$http.post(PUSH_SERVER_URL, {'registration_id': subscriptionId}); | 27 | 70 | $http.post(PUSH_SERVER_URL, {'registration_id': subscriptionId}); | |
} | 28 | 71 | } | |
29 | 72 | |||
73 | function removeSubscription(pushSubscription) { | |||
74 | console.log('removing subscription'); | |||
75 | console.log('pushSubscription endpoint = ', pushSubscription.endpoint); | |||
76 | ||||
77 | var subscriptionId = pushSubscription.subscriptionId; | |||
78 | ||||
79 | console.log('registration_id: ', subscriptionId); | |||
80 | $http.post(UNPUSH_SERVER_URL, {'registration_id': subscriptionId}); | |||
81 | } | |||
82 | ||||
function subscribeDevice() { | 30 | 83 | function subscribeDevice() { | |
// We need the service worker registration to access the push manager | 31 | 84 | // We need the service worker registration to access the push manager | |
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | 32 | 85 | navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | |
serviceWorkerRegistration.pushManager.subscribe() | 33 | 86 | serviceWorkerRegistration.pushManager.subscribe() | |
.then(onPushSubscription) | 34 | 87 | .then(onPushSubscription) | |
.catch(function(e) { | 35 | 88 | .catch(function(e) { | |
console.log('Error in subscribing'); | 36 | 89 | console.log('Error in subscribing'); | |
// Check for a permission prompt issue | 37 | 90 | // Check for a permission prompt issue | |
if ('permissions' in navigator) { | 38 | 91 | if ('permissions' in navigator) { | |
navigator.permissions.query({name: 'push', userVisibleOnly: true}) | 39 | 92 | navigator.permissions.query({name: 'push', userVisibleOnly: true}) | |
.then(function(permissionStatus) { | 40 | 93 | .then(function(permissionStatus) { | |
console.log('subscribe() Error: Push permission status = ', | 41 | 94 | console.log('subscribe() Error: Push permission status = ', | |
permissionStatus); | 42 | 95 | permissionStatus); | |
if (permissionStatus.status === 'denied') { | 43 | 96 | if (permissionStatus.status === 'denied') { | |
97 | pushSwitch.checked = false; | |||
98 | pushSwitch.disabled = true; | |||
// The user blocked the permission prompt | 44 | 99 | // The user blocked the permission prompt | |
console.log('Ooops Notifications are Blocked', | 45 | 100 | console.log('Ooops Notifications are Blocked', | |
'Unfortunately you just permanently blocked notifications. ' + | 46 | 101 | 'Unfortunately you just permanently blocked notifications. ' + | |
'Please unblock / allow them to switch on push ' + | 47 | 102 | 'Please unblock / allow them to switch on push ' + | |
'notifications.'); | 48 | 103 | 'notifications.'); | |
} else { | 49 | 104 | } else { | |
105 | pushSwitch.checked = false; | |||
console.log('Ooops Push Couldn\'t Register', | 50 | 106 | console.log('Ooops Push Couldn\'t Register', | |
'<p>When we tried to ' + | 51 | 107 | '<p>When we tried to ' + | |
'get the subscription ID for GCM, something went wrong,' + | 52 | 108 | 'get the subscription ID for GCM, something went wrong,' + | |
' not sure why.</p>' + | 53 | 109 | ' not sure why.</p>' + | |
'<p>Have you defined "gcm_sender_id" and ' + | 54 | 110 | '<p>Have you defined "gcm_sender_id" and ' + | |
'"gcm_user_visible_only" in the manifest?</p>' + | 55 | 111 | '"gcm_user_visible_only" in the manifest?</p>' + | |
'<p>Error message: ' + | 56 | 112 | '<p>Error message: ' + | |
e.message + | 57 | 113 | e.message + | |
'</p>'); | 58 | 114 | '</p>'); | |
} | 59 | 115 | } | |
}).catch(function(err) { | 60 | 116 | }).catch(function(err) { | |
117 | pushSwitch.checked = false; | |||
console.log('Ooops Push Couldn\'t Register', | 61 | 118 | console.log('Ooops Push Couldn\'t Register', | |
'<p>When we tried to ' + | 62 | 119 | '<p>When we tried to ' + | |
'get the subscription ID for GCM, something went wrong, not ' + | 63 | 120 | 'get the subscription ID for GCM, something went wrong, not ' + | |
'sure why.</p>' + | 64 | 121 | 'sure why.</p>' + | |
'<p>Have you defined "gcm_sender_id" and ' + | 65 | 122 | '<p>Have you defined "gcm_sender_id" and ' + | |
'"gcm_user_visible_only" in the manifest?</p>' + | 66 | 123 | '"gcm_user_visible_only" in the manifest?</p>' + | |
'<p>Error message: ' + | 67 | 124 | '<p>Error message: ' + | |
err.message + | 68 | 125 | err.message + | |
'</p>'); | 69 | 126 | '</p>'); | |
}); | 70 | 127 | }); | |
} else { | 71 | 128 | } else { | |
// Use notification permission to do something | 72 | 129 | // Use notification permission to do something | |
if (Notification.permission === 'denied') { | 73 | 130 | if (Notification.permission === 'denied') { | |
131 | pushSwitch.disabled = true; | |||
132 | pushSwitch.checked = false; | |||
console.log('Ooops Notifications are Blocked', | 74 | 133 | console.log('Ooops Notifications are Blocked', | |
'Unfortunately you just permanently blocked notifications. ' + | 75 | 134 | 'Unfortunately you just permanently blocked notifications. ' + | |
'Please unblock / allow them to switch on push notifications.'); | 76 | 135 | 'Please unblock / allow them to switch on push notifications.'); | |
} else { | 77 | 136 | } else { | |
137 | pushSwitch.checked = false; | |||
console.log('Ooops Push Couldn\'t Register', | 78 | 138 | console.log('Ooops Push Couldn\'t Register', | |
'<p>When we tried to ' + | 79 | 139 | '<p>When we tried to ' + | |
'get the subscription ID for GCM, something went wrong, not ' + | 80 | 140 | 'get the subscription ID for GCM, something went wrong, not ' + | |
'sure why.</p>' + | 81 | 141 | 'sure why.</p>' + | |
'<p>Have you defined "gcm_sender_id" and ' + | 82 | 142 | '<p>Have you defined "gcm_sender_id" and ' + | |
'"gcm_user_visible_only" in the manifest?</p>' + | 83 | 143 | '"gcm_user_visible_only" in the manifest?</p>' + | |
'<p>Error message: ' + | 84 | 144 | '<p>Error message: ' + | |
e.message + | 85 | 145 | e.message + | |
'</p>'); | 86 | 146 | '</p>'); | |
} | 87 | 147 | } | |
} | 88 | 148 | } | |
}); | 89 | 149 | }); | |
}); | 90 | 150 | }); | |
} | 91 | 151 | } | |
92 | 152 | |||
function unsubscribeDevice() { | 93 | 153 | function unsubscribeDevice() { | |
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | 94 | 154 | navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | |
serviceWorkerRegistration.pushManager.getSubscription().then( | 95 | 155 | serviceWorkerRegistration.pushManager.getSubscription().then( | |
function(pushSubscription) { | 96 | 156 | function(pushSubscription) { | |
// Check we have everything we need to unsubscribe | 97 | 157 | // Check we have everything we need to unsubscribe | |
if (!pushSubscription) { | 98 | 158 | if (!pushSubscription) { | |
159 | pushSwitch.checked = false; | |||
return; | 99 | 160 | return; | |
} | 100 | 161 | } | |
101 | 162 | |||
// TODO: Remove the device details from the server | 102 | 163 | // TODO: Remove the device details from the server | |
// i.e. the pushSubscription.subscriptionId and | 103 | 164 | // i.e. the pushSubscription.subscriptionId and | |
// pushSubscription.endpoint | 104 | 165 | // pushSubscription.endpoint | |
166 | var subscriptionId = pushSubscription.subscriptionId; | |||
105 | 167 | |||
pushSubscription.unsubscribe().then(function(successful) { | 106 | 168 | pushSubscription.unsubscribe().then(function(successful) { | |
console.log('Unsubscribed from push: ', successful); | 107 | 169 | console.log('Unsubscribed from push: ', successful); | |
170 | ||||
if (!successful) { | 108 | 171 | if (!successful) { | |
// The unsubscribe was unsuccessful, but we can | 109 | 172 | // The unsubscribe was unsuccessful, but we can | |
// remove the subscriptionId from our server | 110 | 173 | // remove the subscriptionId from our server | |
// and notifications will stop | 111 | 174 | // and notifications will stop | |
// This just may be in a bad state when the user returns | 112 | 175 | // This just may be in a bad state when the user returns | |
console.error('We were unable to unregister from push'); | 113 | 176 | pushSwitch.checked = true; | |
177 | removeSubscription(pushSubscription); | |||
178 | console.error('We were unable to unregister from push, but we removed'+ | |||
179 | 'registration id from the server'); | |||
} | 114 | 180 | } | |
115 | 181 | |||
}).catch(function(e) { | 116 | 182 | }).catch(function(e) { | |
console.log('Unsubscribtion error: ', e); | 117 | 183 | console.log('Unsubscribtion error: ', e); | |
}); | 118 | 184 | }); | |
}.bind(this)).catch(function(e) { | 119 | 185 | }.bind(this)).catch(function(e) { | |
console.error('Error thrown while revoking push notifications. ' + | 120 | 186 | console.error('Error thrown while revoking push notifications. ' + | |
'Most likely because push was never registered', e); | 121 | 187 | 'Most likely because push was never registered', e); | |
}); | 122 | 188 | }); | |
}); | 123 | 189 | }); | |
} | 124 | 190 | } | |
125 | 191 | |||
function permissionStatusChange(permissionStatus) { | 126 | 192 | function permissionStatusChange(permissionStatus) { | |
console.log('permissionStatusChange = ', permissionStatus); | 127 | 193 | console.log('permissionStatusChange = ', permissionStatus); | |
// If the notification permission is denied, it's a permanent block | 128 | 194 | // If the notification permission is denied, it's a permanent block | |
switch (permissionStatus.status) { | 129 | 195 | switch (permissionStatus.status) { | |
case 'denied': | 130 | 196 | case 'denied': | |
197 | pushSwitch.disabled = true; | |||
console.log('Ooops Push has been Blocked', | 131 | 198 | console.log('Ooops Push has been Blocked', | |
'Unfortunately the user permanently blocked push. Please unblock / ' + | 132 | 199 | 'Unfortunately the user permanently blocked push. Please unblock / ' + | |
'allow them to switch on push notifications.'); | 133 | 200 | 'allow them to switch on push notifications.'); | |
break; | 134 | 201 | break; | |
case 'granted': | 135 | 202 | case 'granted': | |
// Set the state of the push switch | 136 | 203 | // Set the state of the push switch | |
console.log('case granted'); | 137 | 204 | console.log('case granted'); | |
break; | 138 | 205 | break; | |
case 'prompt': | 139 | 206 | case 'prompt': | |
207 | pushSwitch.checked = false; | |||
console.log('case prompt'); | 140 | 208 | console.log('case prompt'); | |
break; | 141 | 209 | break; | |
} | 142 | 210 | } | |
} | 143 | 211 | } | |
144 | 212 | |||
function setUpPushPermission() { | 145 | 213 | function setUpPushPermission() { | |
navigator.permissions.query({name: 'push', userVisibleOnly: true}) | 146 | 214 | navigator.permissions.query({name: 'push', userVisibleOnly: true}) | |
.then(function(permissionStatus) { | 147 | 215 | .then(function(permissionStatus) { | |
// Set the initial state | 148 | 216 | // Set the initial state | |
permissionStatusChange(permissionStatus); | 149 | 217 | permissionStatusChange(permissionStatus); | |
150 | 218 | |||
// Handle Permission State Changes | 151 | 219 | // Handle Permission State Changes | |
permissionStatus.onchange = function() { | 152 | 220 | permissionStatus.onchange = function() { | |
permissionStatusChange(this); | 153 | 221 | permissionStatusChange(this); | |
}; | 154 | 222 | }; | |
155 | 223 | |||
// Check if push is supported and what the current state is | 156 | 224 | // Check if push is supported and what the current state is | |
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | 157 | 225 | navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | |
// Let's see if we have a subscription already | 158 | 226 | // Let's see if we have a subscription already | |
serviceWorkerRegistration.pushManager.getSubscription() | 159 | 227 | serviceWorkerRegistration.pushManager.getSubscription() | |
.then(function(subscription) { | 160 | 228 | .then(function(subscription) { | |
if (!subscription) { | 161 | 229 | if (!subscription) { | |
// NOOP | 162 | 230 | // NOOP | |
return; | 163 | 231 | return; | |
} | 164 | 232 | } | |
165 | 233 | |||
234 | console.log('update current state.'); | |||
// Update the current state with the | 166 | 235 | // Update the current state with the | |
// subscriptionid and endpoint | 167 | 236 | // subscriptionid and endpoint | |
onPushSubscription(subscription); | 168 | 237 | onPushSubscription(subscription); | |
}) | 169 | 238 | }) | |
.catch(function(e) { | 170 | 239 | .catch(function(e) { | |
console.log('An error occured while calling getSubscription()', e); | 171 | 240 | console.log('An error occured while calling getSubscription()', e); | |
}); | 172 | 241 | }); | |
}); | 173 | 242 | }); | |
}).catch(function(err) { | 174 | 243 | }).catch(function(err) { | |
console.log('Ooops Unable to check the permission', | 175 | 244 | console.log('Ooops Unable to check the permission', | |
'Unfortunately the permission for push notifications couldn\'t be ' + | 176 | 245 | 'Unfortunately the permission for push notifications couldn\'t be ' + | |
'checked. Are you on Chrome 43+?'); | 177 | 246 | 'checked. Are you on Chrome 43+?'); | |
}); | 178 | 247 | }); | |
} | 179 | 248 | } | |
180 | 249 | |||
function setUpNotificationPermission() { | 181 | 250 | function setUpNotificationPermission() { | |
// If the notification permission is denied, it's a permanent block | 182 | 251 | console.log('setting notification setting'); | |
if (Notification.permission === 'denied') { | 183 | 252 | ||
console.log('Ooops Notifications are Blocked', | 184 | 253 | if (Notification.permission === 'default') { | |
'Unfortunately notifications are permanently blocked. Please unblock / ' + | 185 | |||
'allow them to switch on push notifications.'); | 186 | |||
return; | 187 | |||
} else if (Notification.permission === 'default') { | 188 | |||
console.log('notification permissions === default'); | 189 | 254 | console.log('notification permissions === default'); | |
return; | 190 | 255 | return; | |
} | 191 | 256 | } | |
192 | 257 | |||
// Check if push is supported and what the current state is | 193 | 258 | // Check if push is supported and what the current state is | |
navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | 194 | 259 | navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) { | |
// Let's see if we have a subscription already | 195 | 260 | // Let's see if we have a subscription already | |
serviceWorkerRegistration.pushManager.getSubscription() | 196 | 261 | serviceWorkerRegistration.pushManager.getSubscription() | |
.then(function(subscription) { | 197 | 262 | .then(function(subscription) { | |
if (!subscription) { | 198 | 263 | if (!subscription) { | |
// NOOP | 199 | 264 | // NOOP | |
console.log('not subscription'); | 200 | 265 | console.log('not subscription'); | |
return; | 201 | 266 | return; | |
} | 202 | 267 | } | |
203 | 268 | |||
// Update the current state with the | 204 | 269 | // Update the current state with the | |
// subscriptionid and endpoint | 205 | 270 | // subscriptionid and endpoint | |
console.log('onpushsubscription should be entered'); | 206 | 271 | console.log('onpushsubscription should be entered'); | |
onPushSubscription(subscription); | 207 | 272 | onPushSubscription(subscription); | |
}) | 208 | 273 | }) | |
.catch(function(e) { | 209 | 274 | .catch(function(e) { | |
console.log('An error occured while calling getSubscription()', e); | 210 | 275 | console.log('An error occured while calling getSubscription()', e); | |
}); | 211 | 276 | }); | |
}); | 212 | 277 | }); | |
} | 213 | 278 | } | |
214 | 279 | |||
// Once the service worker is registered set the initial state | 215 | 280 | // Once the service worker is registered set the initial state | |
function initialiseState() { | 216 | 281 | function initialiseState() { | |
282 | // Check if notifications are supported | |||
283 | if (!('showNotification' in ServiceWorkerRegistration.prototype)) { | |||
284 | console.warn('Notifications aren\'t supported.'); | |||
285 | return; | |||
286 | } | |||
287 | // Check the current Notification permission. | |||
288 | // If its denied, it's a permanent block until the | |||
289 | // user changes the permission | |||
290 | else if (Notification.permission === 'denied') { | |||
291 | console.log('Ooops Notifications are Blocked', | |||
292 | 'Unfortunately notifications are permanently blocked. Please unblock / ' + | |||
293 | 'allow them to switch on push notifications.'); | |||
294 | return; | |||
295 | } | |||
296 | // Check if push messaging is supported | |||
297 | else if (!('PushManager' in window)) { | |||
298 | console.warn('Push messaging isn\'t supported.'); | |||
299 | return; | |||
300 | } | |||
301 | ||||
302 | pushSwitch.disabled = false; | |||
// Is the Permissions API supported | 217 | 303 | // Is the Permissions API supported | |
if ('permissions' in navigator) { | 218 | 304 | if ('permissions' in navigator) { | |
console.log('setting push permissions'); | 219 | 305 | console.log('setting push permissions'); | |
setUpPushPermission(); | 220 | 306 | setUpPushPermission(); | |
return; | 221 | 307 | return; | |
} else { | 222 | 308 | } else { | |
console.log('setting notification permissions'); | 223 | 309 | console.log('setting notification permissions'); | |
setUpNotificationPermission(); | 224 | 310 | setUpNotificationPermission(); | |
} | 225 | 311 | } | |
} | 226 | 312 | } | |
227 | 313 | |||
var enablePushSwitch = $('.js-checkbox'); | 228 | 314 | var enablePushSwitch = $('.js-checkbox'); | |
315 | ||||
316 | var pushSwitch = document.getElementById("notifbox"); | |||
317 | pushSwitch.disabled = true; | |||
318 | ||||
319 | var ua = navigator.userAgent.toLowerCase(); | |||
320 | var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile"); | |||
321 | ||||
322 | if(!isAndroid) { | |||
323 | // Do something! | |||
324 | // Redirect to Android-site? | |||
325 | pushSwitch.disabled = true; | |||
326 | console.log("not android"); | |||
327 | return; | |||
328 | } | |||
329 | ||||
enablePushSwitch.change(function(e) { | 229 | 330 | enablePushSwitch.change(function(e) { | |
console.log('checkbox changed'); | 230 | 331 | console.log('checkbox changed'); | |
if (e.target.checked) { | 231 | 332 | if (e.target.checked) { | |
console.log('subscribing device'); | 232 | 333 | console.log('subscribing device'); | |
subscribeDevice(); | 233 | 334 | subscribeDevice(); | |
} else { | 234 | 335 | } else { | |
console.log('unsubscribing device'); | 235 | 336 | console.log('unsubscribing device'); | |
unsubscribeDevice(); | 236 | 337 | unsubscribeDevice(); | |
} | 237 | 338 | } | |
}); | 238 | 339 | }); |
templates/cardlist.html
View file @
7545660
<body> | 1 | 1 | <body> | |
<div class="row"> | 2 | 2 | <div class="row"> | |
<a class="btn" id="showHidden" ng-click="show = !show" style="margin-top: 15px">Show Hidden</a> | 3 | 3 | <a class="btn" id="showHidden" ng-click="show = !show" style="margin-top: 15px">Show Hidden</a> | |
4 | 4 | |||
<div class="input-field col s6 right"> | 5 | 5 | <div class="input-field col s6 right"> | |
<i class="mdi-action-search prefix"></i> | 6 | 6 | <i class="mdi-action-search prefix"></i> | |
<input id="search" type="text" class="validate" ng-model="searchText"/> | 7 | 7 | <input id="search" type="text" class="validate" ng-model="searchText"/> | |
<label for="search">Search</label> | 8 | 8 | <label for="search">Search</label> | |
</div> | 9 | |||
</div> | 10 | 9 | </div> | |
10 | </div> | |||
11 | 11 | |||
<div class="row"> | 12 | 12 | <div class="row"> | |
<form> | 13 | 13 | <form> | |
<div class="col s12"> | 14 | 14 | <div class="col s12"> | |
<div class="col s2"> | 15 | 15 | <div class="col s2"> | |
<input type="checkbox" class="filled-in" id="weekOneCheck" ng-model="filter['week1']"/> | 16 | 16 | <input type="checkbox" class="filled-in" id="weekOneCheck" ng-model="filter['week1']"/> | |
<label for="weekOneCheck">Week One</label> | 17 | 17 | <label for="weekOneCheck">Week One</label> | |
</div> | 18 | |||
<div class="col s2"> | 19 | |||
<input type="checkbox" class="filled-in" id="weekTwoCheck" ng-model="filter['week2']"/> | 20 | |||
<label for="weekTwoCheck">Week Two</label> | 21 | |||
</div> | 22 | |||
<div class="col s2"> | 23 | |||
<input type="checkbox" class="filled-in" id="weekThreeCheck" ng-model="filter['week3']"/> | 24 | |||
<label for="weekThreeCheck">Week Three</label> | 25 | |||
</div> | 26 | |||
<div class="col s2"> | 27 | |||
<input type="checkbox" class="filled-in" id="weekFourCheck" ng-model="filter['week4']"/> | 28 | |||
<label for="weekFourCheck">Week Four</label> | 29 | |||
</div> | 30 | |||
<div class="col s2"> | 31 | |||
<input type="checkbox" class="filled-in" id="weekFiveCheck" ng-model="filter['week5']"/> | 32 | |||
<label for="weekFiveCheck">Week Five</label> | 33 | |||
</div> | 34 | |||
</div> | 35 | 18 | </div> | |
<div class="col s12"> | 36 | 19 | <div class="col s2"> | |
<div class="col s2"> | 37 | 20 | <input type="checkbox" class="filled-in" id="weekTwoCheck" ng-model="filter['week2']"/> | |
<input type="checkbox" class="filled-in" id="weekSixCheck" ng-model="filter['week6']"/> | 38 | 21 | <label for="weekTwoCheck">Week Two</label> | |
<label for="weekSixCheck">Week Six</label> | 39 | |||
</div> | 40 | |||
<div class="col s2"> | 41 | |||
<input type="checkbox" class="filled-in" id="weekSevenCheck" ng-model="filter['week7']"/> | 42 | |||
<label for="weekSevenCheck">Week Seven</label> | 43 | |||
</div> | 44 | |||
<div class="col s2"> | 45 | |||
<input type="checkbox" class="filled-in" id="weekEightCheck" ng-model="filter['week8']"/> | 46 | |||
<label for="weekEightCheck">Week Eight</label> | 47 | |||
</div> | 48 | |||
<div class="col s2"> | 49 | |||
<input type="checkbox" class="filled-in" id="weekNineCheck" ng-model="filter['week9']"/> | 50 | |||
<label for="weekNineCheck">Week Nine</label> | 51 | |||
</div> | 52 | |||
<div class="col s2"> | 53 | |||
<input type="checkbox" class="filled-in" id="weekTenCheck" ng-model="filter['week10']"/> | 54 | |||
<label for="weekTenCheck">Week Ten</label> | 55 | |||
</div> | 56 | |||
</div> | 57 | 22 | </div> | |
</form> | 58 | 23 | <div class="col s2"> | |
</div> | 59 | 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="col s12"> | |||
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 | 60 | |||
<div class="list" style="padding: 0px 25px"> | 61 | 61 | <div class="list" style="padding: 0px 25px"> | |
<ul class="collection" | 62 | 62 | <ul class="collection" | |
ng-repeat="(weeknum, week_cards) in cards | filter:searchText | filter:filterByDate | groupBy: 'material_week_num'"> | 63 | 63 | ng-repeat="(weeknum, week_cards) in cards | filter:searchText | filter:filterByDate | groupBy: 'material_week_num'"> | |
<li class="collection-header"><h3>Week {{weeknum}}</h3></li> | 64 | 64 | <li class="collection-header"><h3>Week {{weeknum}}</h3></li> | |
<li class="collection-item" ng-click="expand = !expand" ng-repeat="card in week_cards" ng-show="show || !card.is_hidden"> | 65 | 65 | <li class="collection-item" ng-click="expand = !expand" ng-repeat="card in week_cards" | |
<div> | 66 | 66 | ng-show="show || !card.is_hidden"> | |
<span ng-bind-html="card | displayCard"></span> | 67 | 67 | <i ng-show="card.isInDeck()" class="mdi-action-done small green-text"></i> | |
<span class="badge">{{dayofweek(card)}}</span> | 68 | 68 | <span ng-bind-html="card | displayCard"></span> | |
<p class="right-align" ng-show="expand"> | 69 | 69 | <span class="badge">{{dayofweek(card)}}</span> | |
<a href="" class="tooltipped" ng-click="pull(card)" ng-show="!card.is_in_deck" data-position="bottom" data-delay="50" data-tooltip="Add to Deck"> | 70 | |||
<i class="mdi-content-add-circle-outline small"></i></a> | 71 | |||
<a href="" class="tooltipped" ng-click="unpull(card)" ng-show="card.is_in_deck" data-position="bottom" data-delay="50" data-tooltip="Add to Deck"> | 72 | |||
<i class="mdi-content-remove-circle-outline small"></i></a> | 73 | |||
<a href="" class="tooltipped" ng-click="hide(card)" ng-show="!card.is_hidden" data-position="bottom" data-delay="50" data-tooltip="Hide"> | 74 | |||
<i class="mdi-action-visibility-off small"></i></a> | 75 | |||
<a href="" class="tooltipped" ng-click="unhide(card)" ng-show="card.is_hidden" data-position="bottom" data-delay="50" data-tooltip="Unhide"> | 76 | |||
<i class="mdi-action-visibility small"></i></a> | 77 | |||
<a href="" ng-click="flag(card)" data-position="bottom" data-delay="50" data-tooltip="Flag"> | 78 | |||
<i class="mdi-content-flag small"></i></a> | 79 | |||
</p> | 80 | |||
</div> | 81 | |||
</li> | 82 | |||
</ul> | 83 | |||
</div> | 84 | |||
85 | 70 | |||
71 | <p class="right-align" ng-show="expand"> | |||
72 | <a href="" class="tooltipped" ng-click="card.pull()" ng-show="!card.isInDeck()" data-position="bottom" | |||
73 | data-delay="50" data-tooltip="Add to Deck"> | |||
74 | <i class="mdi-content-add-circle-outline small"></i></a> | |||
75 | <a href="" class="tooltipped" ng-click="card.unpull()" ng-show="card.isInDeck()" data-position="bottom" | |||
76 | data-delay="50" data-tooltip="Add to Deck"> | |||
77 | <i class="mdi-content-remove-circle-outline small"></i></a> | |||
78 | <a href="" class="tooltipped" ng-click="card.hide()" ng-show="!card.is_hidden" data-position="bottom" | |||
79 | data-delay="50" data-tooltip="Hide"> | |||
80 | <i class="mdi-action-visibility-off small"></i></a> | |||
81 | <a href="" class="tooltipped" ng-click="card.unhide()" ng-show="card.is_hidden" data-position="bottom" | |||
82 | data-delay="50" data-tooltip="Unhide"> | |||
83 | <i class="mdi-action-visibility small"></i></a> | |||
84 | <a href="" ng-click="flag(card)" data-position="bottom" data-delay="50" data-tooltip="Flag"> | |||
85 | <i class="mdi-content-flag small"></i></a> | |||
86 | </p> | |||
87 | </li> | |||
88 | </ul> | |||
89 | </div> | |||
86 | 90 | |||
<div class="fixed-action-btn back-to-top" style="bottom: 45px; right: 24px; display: none;"> | 87 | 91 | ||
<a class="btn-floating btn-large"> | 88 | 92 | <div class="fixed-action-btn back-to-top" style="bottom: 45px; right: 24px; display: none;"> | |
<i class="mdi-editor-publish medium"></i> | 89 | 93 | <a class="btn-floating btn-large"> | |
</a> | 90 | 94 | <i class="mdi-editor-publish medium"></i> | |
</div> | 91 | 95 | </a> | |
96 | </div> | |||
</body> | 92 | 97 | </body> | |
93 | 98 | |||
templates/dropclass.html
View file @
7545660
<div class="row"> | 1 | File was deleted | ||
<div class="col s8 offset-s2"> | 2 | |||
<div class="card-panel" id="dropClassForm"> | 3 | |||
4 | ||||
<h2>Enrolled Classes</h2> | 5 | |||
<div class="row" style="padding: 0px 25px"> | 6 | |||
<table class="hoverable responsive-table"> | 7 | |||
<thead> | 8 | |||
<tr> | 9 | |||
<th data-field="id">Class</th> | 10 | |||
<th data-field="drop">Drop?</th> | 11 | |||
</tr> | 12 | |||
</thead> | 13 | |||
14 | ||||
<tbody> | 15 | |||
<tr ng-repeat="section in UserService.getUserData().sections"> | 16 | |||
<td> | 17 | |||
<span>{{section.short_name}}</span> | 18 | |||
<p>{{section.long_name}}</p> | 19 | |||
</td> | 20 | |||
<td><a href="" ng-click="dropClass(section)"><i class="mdi-content-clear small"></i></a></td> | 21 | |||
</tr> | 22 | |||
</tbody> | 23 | |||
</table> | 24 | |||
</div> | 25 | |||
</div> | 26 |
templates/settings.html
View file @
7545660
<div class="card" id="resetPasswordForm"> | 1 | 1 | <div class="row"> | |
2 | <div class="col s6 offset-s3"> | |||
3 | <div class="card-panel" id="dropClassForm"> | |||
4 | <h2>Notification Settings</h2> | |||
5 | <!-- | |||
6 | class="js-checkbox" name="notifbox" value="toggle notifs"> --> | |||
7 | <form action="#"> | |||
8 | <input type="checkbox" id = "notifbox" class="js-checkbox" /> | |||
9 | <label for="notifbox">Enable notifications</label> | |||
10 | </form> | |||
11 | </div> | |||
12 | </div> | |||
13 | </div> | |||
2 | 14 | |||
<!-- | 3 | 15 | <div class="row"> | |
class="js-checkbox" name="notifbox" value="toggle notifs"> --> | 4 | 16 | <div class="col s6 offset-s3"> | |
<form action="#"> | 5 | 17 | <div class="card-panel" id="resetPasswordForm"> | |
<input type="checkbox" id = "notifbox" class="js-checkbox" /> | 6 | |||
<label for="notifbox">Check this to enable notifications</label> | 7 | |||
</form> | 8 | |||
9 | 18 | |||
<h2>Change Password</h2> | 10 | 19 | <h2>Change Password</h2> | |
11 | 20 | |||
<div class="row"> | 12 | 21 | <form name="ChangePasswordForm"> | |
<form class="col s12"> | 13 | |||
14 | 22 | |||
<div class="row"> | 15 | 23 | <div class="row"> | |
<div class="input-field col s12"> | 16 | 24 | <div class="input-field col s12"> | |
<input id="password" type="password" ng-model="oldPassword" class="validate"> | 17 | 25 | <input id="password" required type="password" name="oldpw" ng-model="oldPassword" class="validate"> | |
<label for="password">Old Password</label> | 18 | 26 | <label for="password">Old Password</label> | |
27 | </div> | |||
</div> | 19 | 28 | </div> | |
</div> | 20 | |||
21 | 29 | |||
<div class="row"> | 22 | 30 | <div role="alert"> | |
<div class="input-field col s12"> | 23 | 31 | <span class="error" ng-show="ChangePasswordForm.oldpw.$error.required"> | |
<input id="password" type="password" ng-model="newPassword" class="validate"> | 24 | 32 | Required!</span> | |
<label for="password">New Password</label> | 25 | |||
</div> | 26 | 33 | </div> | |
</div> | 27 | |||
28 | 34 | |||
<div class="row"> | 29 | 35 | ||
<div class="input-field col s12"> | 30 | 36 | <div class="row"> | |
<input id="password" type="password" ng-model="confirmedNewPassword" class="validate"> | 31 | 37 | <div class="input-field col s12"> | |
<label for="password">Confirm New Password</label> | 32 | 38 | <input id="password" required ng-minlength=8 type="password" name="newpw" ng-model="newPassword" class="validate"> | |
39 | <label for="password">New Password</label> | |||
40 | </div> | |||
</div> | 33 | 41 | </div> | |
</div> | 34 | 42 | ||
43 | <div role="alert"> | |||
44 | <span class="error" ng-show="ChangePasswordForm.newpw.$error.minlength"> | |||
45 | New password must be at least 8 characters. </span> | |||
46 | </div> | |||
35 | 47 | |||
48 | <div class="row"> | |||
49 | <div class="input-field col s12"> | |||
50 | <input id="password" required ng-minlength=8 compare-to="newpw" type="password" name="confirmpw" ng-model="confirmedNewPassword" class="validate"> | |||
51 | <label for="password">Confirm New Password</label> | |||
52 | </div> | |||
53 | </div> | |||
54 | ||||
55 | <div role="alert"> | |||
56 | <span class="error" ng-show="ChangePasswordForm.confirm.$error.minlength"> | |||
57 | Must be the same as the new password. </span> | |||
58 | </div> | |||
36 | 59 | |||
</form> | 37 | |||
38 | 60 | |||
<a class="waves-effect waves-light btn" id="resetPWButton" | 39 | 61 | </form> | |
ng-click="changePassword(oldPassword, newPassword, confirmedNewPassword)">Reset Password</a> | 40 | 62 | <a class="waves-effect waves-light btn" id="resetPWButton" | |
41 | 63 | ng-click="changePassword(oldPassword, newPassword, confirmedNewPassword)">Change Password</a> | ||
64 | </div> | |||
</div> | 42 | 65 | </div> | |
66 | </div> | |||
67 | ||||
68 | <div class="row"> | |||
69 | <div class="col s6 offset-s3"> | |||
70 | <div class="card-panel" id="dropClassForm"> | |||
71 | ||||
72 | <h2>Enrolled Classes</h2> | |||
73 | <div class="row" style="padding: 0px 25px"> | |||
74 | <table class="hoverable responsive-table"> | |||
75 | <thead> | |||
76 | <tr> | |||
77 | <th data-field="id">Class</th> | |||
78 | <th data-field="drop">Drop?</th> | |||
79 | </tr> | |||
80 | </thead> | |||
81 | ||||
82 | <tbody> | |||
83 | <tr ng-repeat="section in UserService.getUserData().sections"> | |||
84 | <td> | |||
85 | <span>{{section.short_name}}</span> | |||
86 | <p>{{section.long_name}}</p> | |||
87 | </td> | |||
88 | <td><a href="" ng-click="dropClass(section)"><i class="mdi-content-clear small"></i></a></td> | |||
89 | </tr> | |||
90 | </tbody> | |||
91 | </table> | |||
92 | </div> | |||
93 | </div> | |||
94 | </div> | |||
</div> | 43 | 95 | </div> | |
44 | 96 | |||
45 | ||||
46 | ||||