Commit e086f832fbc08c42c5988f6c72da7224691edd9c

Authored by Andrew Buss
1 parent e0b8e710fc

Added a few views. Logout still broken

Showing 7 changed files with 114 additions and 116 deletions Side-by-side Diff

1 1 angular.module('flashy', ['flashy.controller'])
2 2  
3   -.config(['$stateProvider', '$urlRouterProvider',
4   - function ($stateProvider, $urlRouterProvider) {
  3 + .config(['$stateProvider', '$urlRouterProvider',
  4 + function ($stateProvider, $urlRouterProvider) {
5 5  
6   - $urlRouterProvider.otherwise('/home');
  6 + $urlRouterProvider.otherwise('/home');
7 7  
8   - $stateProvider.
9   - state('home', {
10   - url: '/home',
11   - templateUrl: 'home.html',
12   - controller: 'HomeController'
13   - }).
  8 + $stateProvider.
  9 + state('home', {
  10 + url: '/home',
  11 + templateUrl: 'home.html',
  12 + controller: 'HomeController'
  13 + }).
  14 + state('login', {
  15 + url: '/login',
  16 + templateUrl: 'templates/login_form.html',
  17 + controller: 'LoginController'
  18 + }).
  19 + state('logout', {
  20 + url: '/logout',
  21 + templateUrl: 'templates/logout.html',
  22 + controller: 'LogoutController'
  23 + }).
  24 + state('dashboard', {
  25 + url: '/dashboard',
  26 + templateUrl: 'templates/dashboard.html',
  27 + controller: 'DashboardController'
  28 + }).
  29 + state('dashboard.feed', {
  30 + url: '/feed',
  31 + templateUrl: 'templates/feed.html',
  32 + controller: 'FeedController'
  33 + })
14 34  
15   - state('dashboard', {
16   - url: '/dashboard',
17   - templateUrl: 'templates/dashboard.html',
18   - controller: 'DashboardController'
19   - })
20   -
21   -}]);
  35 + }]);
controller.js View file @ e086f83
... ... @@ -3,44 +3,69 @@
3 3 });
4 4  
5 5  
6   -app.controller('HomeController', ['$scope', '$state', function ($scope, $state) {
  6 +app.controller('LoginController', ['$scope', '$state', function ($scope, $state) {
  7 + $.ajaxPrefilter(function (options, originalOptions, jqXHR) {
  8 + options.crossDomain = {
  9 + crossDomain: true
  10 + };
  11 + options.xhrFields = {
  12 + withCredentials: true
  13 + };
  14 + });
  15 + $.postJSON = function (url, data, success, args) {
  16 + args = $.extend({
  17 + url: url,
  18 + type: 'POST',
  19 + data: JSON.stringify(data),
  20 + contentType: 'application/json; charset=utf-8',
  21 + dataType: 'json',
  22 + async: true,
  23 + success: success
  24 + }, args);
  25 + return $.ajax(args);
  26 + };
7 27  
8   - // SIGN UP
9   - $scope.signUp = function (email, username, password) {
10   -
11   - // make server call
12   - console.log('go to dashboard');
13   - $.post('https://flashy.cards/api/users/me',
  28 + $scope.signUp = function (email, password) {
  29 + $.postJSON('https://flashy.cards/api/users/me',
14 30 {"email": email, "password": password},
15 31 function (data, textStatus, jqXHR) {
16 32 console.log(data);
  33 + $scope.$parent.user = data;
  34 + $state.go('dashboard');
17 35 }
18 36 );
19 37  
20   - // if successful, go to dashboard
21   - $state.go('dashboard');
22   -
23 38 };
24 39  
25   -
26   - // LOGIN
27 40 $scope.login = function (email, password) {
28   -
29   - console.log('go to dashboard');
30   - $.post('https://flashy.cards/api/login',
  41 + $.postJSON('https://flashy.cards/api/login',
31 42 {"email": email, "password": password},
32 43 function (data, textStatus, jqXHR) {
33 44 console.log(data);
  45 + $scope.$parent.user = data;
  46 + $state.go('dashboard');
34 47 }
35 48 );
  49 + };
36 50  
37   - $state.go('dashboard');
38 51  
  52 +}]);
39 53  
40   - };
41 54  
  55 +app.controller("HomeController", ['$scope', '$state', function ($scope, $state) {
  56 + $state.go('login');
  57 +}]);
42 58  
  59 +app.controller("FeedController", ['$scope', '$state', function ($scope, $state) {
  60 + console.log("Hello from feed");
43 61 }]);
  62 +
  63 +app.controller("LogoutController", ['$scope', '$state', function ($scope, $state) {
  64 + $.post('https://flashy.cards/api/logout', function () {
  65 + $state.go('home')
  66 + });
  67 +}]);
  68 +
44 69  
45 70 app.controller("DashboardController", function () {
46 71 // This gets really annoying every time I refresh the page :(
1   -.myform {
2   - max-width: 400px;
3   - margin-top: 30px;
4   - margin-bottom: 30px;
  1 +#loginform input {
  2 + margin: 10px;
  3 +}
  4 +
  5 +#loginform {
  6 + max-width: 400px;
  7 + margin: 30px auto;
  8 +}
  9 +
  10 +#sidebar{
  11 + position:absolute;
  12 + top:100px;
  13 + left:0px;
5 14 }
... ... @@ -11,68 +11,11 @@
11 11 <!-- MENU BAR -->
12 12 <nav class="navbar navbar-default">
13 13 <div class="container-fluid">
14   - <button type="button" class="navbar-toggle collapsed"
15   - data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
16   - <span class="sr-only">Toggle navigation</span>
17   - <span class="icon-bar"></span>
18   - <span class="icon-bar"></span>
19   - <span class="icon-bar"></span>
20   - </button>
21   - <a class="navbar-brand" href="#">Flashy</a>
  14 + <a class="navbar-brand" ui-sref="dashboard">Flashy</a>
  15 + <a class="navbar-brand navbar-right" ui-sref="logout">Logout</a>
22 16 </div>
23 17 </nav>
24   -<ui-view>
25   - <div class="container">
26   - <h1 class="text-success heading">Create and share flashcards in real time!</h1>
27   - <blockquote class="pull-left">
28   - <p>The System shall enlighten you.</p>
29   - <small>SWAG</small>
30   - </blockquote>
31   - </div>
32   -
33   - <div class="container">
34   - <!-- REGISTRATION TABS -->
35   - <div class="tabbable">
36   - <ul class="nav nav-tabs">
37   - <li role="presentation" class="active"><a href=""
38   - data-toggle="tab">SIGN UP</a></li>
39   - <li role="presentation"><a href="login" data-toggle="tab">LOGIN</a></li>
40   - </ul>
41   - </div>
42   -
43   - <!-- REGISTRATION TAB PANES -->
44   - <div class="tab-content">
45   - <!-- SIGN UP FORM -->
46   - <div class="tab-pane active myform" id="tab1">
47   - <form>
48   - <div class="form-group">
49   - <input type="email" class="form-control" ng-model="signUpEmail" placeholder="Email"/>
50   - </div>
51   -
52   - <div class="form-group">
53   - <input type="password" class="form-control" ng-model="signUpPassword" placeholder="Password"/>
54   - </div>
55   - <input type="submit" class="btn btn-primary" ng-click="signUp(signUpEmail,signUpPassword)"
56   - value="GET STARTED!"/>
57   - </form>
58   - </div>
59   -
60   - <!-- LOGIN FORM -->
61   - <div class="tab-pane myform" id="tab2">
62   - <form>
63   - <div class="form-group">
64   - <input type="email" class="form-control" ng-model="loginEmail" placeholder="Email"/>
65   - </div>
66   - <div class="form-group">
67   - <input type="password" class="form-control" ng-model="loginPassword" placeholder="Password"/>
68   - </div>
69   - <input type="submit" class="btn btn-primary" ng-click="login(loginEmail, loginPassword)"
70   - value="LOGIN"/>
71   - </form>
72   - </div>
73   - </div>
74   - </div>
75   -</ui-view>
  18 +<div class="container" ui-view></div>
76 19 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script>
77 20 <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.14/angular-ui-router.js"></script>
78 21 <script src="config.js"></script>
templates/dashboard.html View file @ e086f83
1   -<div class="sidebar">
  1 +<div id="sidebar">
2 2 <ul>
3   - <li>CSE 110</li>
  3 + <li class="class-section"><a ui-sref="dashboard.feed">CSE 999</a></li>
  4 + <li class="class-section"><a ui-sref="dashboard.feed">CSE 140LL</a></li>
  5 + <li class="class-section"><a ui-sref="dashboard.feed">Math 20Z</a></li>
  6 + <li class="class-section"><a ui-sref="dashboard.feed">CSE 110</a></li>
4 7 </ul>
  8 +</div>
  9 +<div class="container">
  10 + <ui-view></ui-view>
5 11 </div>
templates/feed.html View file @ e086f83
1   -<!DOCTYPE html>
2   -
3   -<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
4   - <base href="/app/">
5   - <head>
6   - <link rel = "stylesheet" href ="styles/bootstrap-3.3.4-dist/css/bootstrap.css" />
7   - <link rel ="stylesheet" href="styles/feed.css" />
8   - </head>
9   -
10   - <body>
11   - <nav class="navbar navbar-default">
12   - <a class="navbar-brand" href="#">Flashy</a>
13   - </nav>
14   -
15   - Add a class lol
16   - </body>
17   -</html>
  1 +<h2>cards go here or something</h2>
templates/login_form.html View file @ e086f83
  1 +<div class="container">
  2 + <form id="loginform">
  3 + <h1 class="text-success heading">Please Log In</h1>
  4 + <blockquote class="pull-left">
  5 + <p>The System shall enlighten you.</p>
  6 + <small>SWAG</small>
  7 + </blockquote>
  8 + <div>
  9 + <input type="email" class="form-control" ng-model="loginEmail" placeholder="Email"/>
  10 + </div>
  11 + <div class="form-group">
  12 + <input type="password" class="form-control" ng-model="loginPassword" placeholder="Password"/>
  13 + </div>
  14 + <input type="submit" class="btn btn-primary" ng-click="login(loginEmail, loginPassword)" value="LOGIN"/>
  15 + <input type="submit" class="btn btn-primary" ng-click="signUp(loginEmail, loginPassword)" value="REGISTER"/>
  16 + </form>
  17 +</div>