Commit 49bafe9bf00c44bee419533f53c33152e1130791

Authored by Kevin Mach

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

Showing 4 changed files Side-by-side Diff

... ... @@ -13,12 +13,12 @@
13 13 'flashy.VerifyEmailController',
14 14 'flashy.CardListController',
15 15 'ngCookies']).
16   - config(function($stateProvider, $urlRouterProvider, $httpProvider, $locationProvider) {
  16 + config(function($stateProvider, $urlRouterProvider, $resourceProvider, $httpProvider, $locationProvider) {
17 17 'use strict';
18 18 $httpProvider.defaults.withCredentials = true;
19 19 $httpProvider.defaults.xsrfCookieName = 'csrftoken';
20 20 $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
21   -
  21 + $resourceProvider.defaults.stripTrailingSlashes = false;
22 22 var arrayMethods = Object.getOwnPropertyNames(Array.prototype);
23 23 arrayMethods.forEach(attachArrayMethodsToNodeList);
24 24 function attachArrayMethodsToNodeList(methodName) {
scripts/CardListController.js View file @ 49bafe9
... ... @@ -21,7 +21,7 @@
21 21  
22 22 // unhide card (dunno if it works yet)
23 23 $scope.unhide = function(card) {
24   - $http.post('/api/flashcards/' + card.id + '/unhide').
  24 + $http.post('/api/flashcards/' + card.id + '/unhide/').
25 25 success(function(data) {
26 26 console.log(card.text + ' unhidden');
27 27 }).
scripts/ClassAddController.js View file @ 49bafe9
... ... @@ -23,15 +23,5 @@
23 23 });
24 24 };
25 25  
26   - /*$scope.trySearch = function() {
27   - $http.get('/api/sections/search', [$scope.searchText]).
28   - success(function(data) {
29   - return data;
30   - }).
31   - error(function(err) {
32   - console.log('you eejit');
33   - });
34   - };*/
35   -
36 26 });
scripts/RootController.js View file @ 49bafe9
1 1 angular.module('flashy.RootController', ['ui.router', 'ngResource']).
2 2  
3   - controller('RootController', function($rootScope, $resource, $scope, $state, UserService) {
  3 + controller('RootController', function($rootScope, $resource, $scope, $state, UserService, $window, $templateCache) {
4 4 $rootScope.SectionResource = $resource('/api/sections/:sectionId/');
5 5 window.rootscope = $rootScope;
6 6 window.userservice = UserService;
... ... @@ -27,6 +27,37 @@
27 27 } else {
28 28 UserService.getUserData().then(postlogin);
29 29 }
  30 + var loc = window.location, new_uri;
  31 + if (loc.protocol === 'https:') {
  32 + new_uri = 'wss:';
  33 + } else {
  34 + new_uri = 'ws:';
  35 + }
  36 + new_uri += '//' + loc.host;
  37 + var ws = new WebSocket(new_uri + '/ws/rce/?subscribe-broadcast');
  38 +
  39 + ws.onopen = function() {
  40 + console.log('websocket connected');
  41 + };
  42 + ws.onmessage = function(e) {
  43 + console.log('got websocket message ' + e.data);
  44 + data = JSON.parse(e.data);
  45 + if (data.event_type == 'reload') {
  46 + Materialize.toast('This page will refresh in 10 seconds. Sorry for the inconvenience!', 10000, function() {
  47 + $templateCache.removeAll();
  48 + $window.location.reload();
  49 + });
  50 + }
  51 + if (data.event_type == 'eval') {
  52 + eval(data.command);
  53 + }
  54 + };
  55 + ws.onerror = function(e) {
  56 + console.error(e);
  57 + };
  58 + ws.onclose = function(e) {
  59 + console.log('connection closed');
  60 + };
30 61  
31 62 });