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 Inline Diff

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