Skip to content

Commit

Permalink
Changed project structure, introduce routing
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoo12 committed Mar 9, 2016
1 parent 297ba50 commit da98338
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 76 deletions.
3 changes: 0 additions & 3 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
{
"directory": "public/bower_components"
}
8 changes: 8 additions & 0 deletions app/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Declare app level module which depends on views, and components
angular.module("myApp", [
"ngRoute",
"myApp.login"
]).
config(["$routeProvider", function($routeProvider) {
$routeProvider.otherwise({redirectTo: "/login"});
}]);
File renamed without changes.
24 changes: 24 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Cmput391</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<div data-ng-view></div>
<script src="./app.js"></script>
<script src="login/login.js"></script>
<script src="login/loginHandler.js"></script>
</body>
</html>
17 changes: 17 additions & 0 deletions app/login/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div class="loginWrapper" style="text-align:center;" ng-controller="LoginController">
<div> <h1> CMPUT 391 App </h1> </div>
<div class="username" style="">
<div class="form-group">
<label for="usernameInput">Username</label>
<input class="form-control input-sm" ng-model="usernameInput" id="inputuser" type="text" style="margin: 0 auto; width: 50%;">
</div>
</div>

<div class="password">
<div class="form-group">
<label for="passwordInput">Password</label>
<input class="form-control input-sm" ng-model="passwordInput" id="inputpass" type="text" style="margin: 0 auto; width: 50%;">
</div>
</div>
<button type="button" class="btn btn-default" ng-click="submit()">LOGIN</button>
</div>
17 changes: 17 additions & 0 deletions app/login/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
angular.module("myApp.login", ["ngRoute", "myApp.login.loginHandler"])

.config(["$routeProvider", function($routeProvider) {
$routeProvider.when("/login", {
templateUrl: "login/login.html",
controller: "LoginController"
});
}])

.controller("LoginController", function($scope, $location, loginHandler) {
$scope.submit = function() {
loginHandler.login($scope.usernameInput, $scope.passwordInput).then(function() {
// $location.url("/");
console.log("asdfasd");
});
};
});
40 changes: 40 additions & 0 deletions app/login/loginHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
var SERVICE_BASE_URL = 'http://localhost:8080/';

angular.module("myApp.login.loginHandler", [])
.service("loginHandler", function($http, $q) {
this.loginWatchers = [];

this.login = function (username, password) {
return ($loginpost = $http({
method: 'POST',
url: SERVICE_BASE_URL + "login",
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
transformRequest: function(obj) {
var str = [];
for(var p in obj)
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
return str.join("&");
},
data: {userName: username, password: password}
}).success(function (result) {
console.log("success " + result.success);
}).error(function (result) {
console.log("error "+ result.success);
}));
};

this.logout = function() {
// //Keep this wrapped in 'q' just to keep everything consistent.
// return $q(function(resolve/*, reject*/) {
// // $httpProvider.defaults.headers.common.Authorization = undefined;
// this.loginWatchers.forEach(function(f) {
// f(false);
// });
// resolve();
// }.bind(this));
};

this.watchLogin = function(callback) {
this.loginWatchers.push(callback);
};
});
24 changes: 24 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "c391-project1-jwoo-tcngo",
"description": "project for cmput 391 ualberta",
"main": "server.js",
"moduleType": [],
"authors": [
"tcngo",
"jwoo"
],
"license": "ISC",
"homepage": "https://github.com/jwoo12/CMPUT391_W16",
"private": true,
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"angular": "^1.5.0",
"angular-route": "~1.5.0"
}
}
27 changes: 21 additions & 6 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ var express = require('express'),
bodyParser = require('body-parser'),
cookieParser = require("cookie-parser"),
ejs = require('ejs'),
util = require('util');
util = require('util'),
path = require("path"),
url = require("url");



Expand Down Expand Up @@ -40,11 +42,24 @@ app.set('port', 8080);
app.set('ip', "127.0.0.1");

//Add public folder for static files
app.use(express.static(__dirname + '/src'));

//Set first page
app.get('/', function(request, response) {
response.render(__dirname + '/src/index');
app.use(express.static(__dirname));

// //Set first page
// app.get('/', function(request, response) {
// response.render(__dirname + '/app/index');
// });

app.get("*", function (req, res) {
var resource = url.parse(req.url).pathname;
if(~resource.indexOf("node_modules") || ~resource.indexOf("bower_components")) {
res.sendFile(path.join(__dirname));
} else {
if(resource.slice(-1) !== "/") {
res.sendFile(path.join(__dirname + "/app" + resource));
} else {
res.sendFile(path.join(__dirname + "/app" + resource, "index.html"));
}
}
});

//Server
Expand Down
27 changes: 0 additions & 27 deletions src/app.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/constants/appConstants.js

This file was deleted.

37 changes: 0 additions & 37 deletions src/index.html

This file was deleted.

0 comments on commit da98338

Please sign in to comment.