Skip to content

scaffold done, routes completed, views not working yet. #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MONGODB_URI='mongodb://localhost/cfgram-backend'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you always gitignore your .env files.

NODE_ENV='testing'
APP_SECRET='coolsecret'
PORT=3000
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
build/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
* each view should have its own controller
* the `/#/` view should be the default landing page
* the landing page markup should contain `<signup>` and `<login>` components
* Create an auth service with for making `http` requests to the `slugram-backend` application
* Create an auth service for making `http` requests to the `slugram-backend` application
* this should have contain methods for sign up and sign in routes
* this should have methods to `get` and `delete` a token from local storage
* Create a sign up component
Expand Down
7 changes: 7 additions & 0 deletions app/config/log-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

module.exports = ['$logProvider', logConfig];

function logConfig($logProvider) {
$logProvider.debugEnabled(__DEBUG__);
};
41 changes: 41 additions & 0 deletions app/config/router-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';
module.exports = ['$stateProvider', '$urlRouterProvider', routerConfig];

function routerConfig($stateProvider, $urlRouterProvider) {
$urlRouterProvider.when('', '/home');
$urlRouterProvider.when('/', '/join#signup');
$urlRouterProvider.when('/signup', '/join#signup');
$urlRouterProvider.when('/login', '/join#login');

let routes = [
{
name: 'home',
url: '/home',
template: require('../view/home/home.html'),
controller: 'HomeController',
controllerAs: 'homeCtrl',
},
{
name: 'landing',
url: '/join',
template: require('../view/landing/landing.html'),
controller: 'LandingController',
controllerAs: 'landingCtrl'
},
{
name: 'signup',
url:'/signup',
template: require('../view/signup/signup.html'),
controller: 'SignupController',
controllerAs: 'signupCtrl',
},
{
name: 'login',
url: '/login',
template: require('../view/landing/landing.html'),
controller: 'LoginController',
controllerAs: 'loginCtrl'
}
];
routes.forEach($stateProvider.state);
}
27 changes: 27 additions & 0 deletions app/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const path = require('path');
const camelcase = require('camelcase');
const pascalcase = require('pascalcase');
const angular = require('angular');
const uiRouter = require('@uirouter/angularjs');

// require('./scss/main.scss');

const cfgram = angular.module('cfgram', ['ui.router']);

let context = require.context('./config/', true, /\.js$/);
context.keys().forEach(key => {
cfgram.config(context(key));
});

context = require.context('./view/', true, /\.js$/);
context.keys().forEach(key => {
cfgram.controller(pascalcase(path.basename(key, '.js')), context(key));
});

ontext = require.context('./service/', true, /\.js$/);
context.keys().forEach(key => cfgram.service(camelcase(path.basename(key, '.js')), context(key)));

context = require.context('./component/', true, /\.js$/);
context.keys().forEach(key => cfgram.component(camelcase(path.basename(key, '.js')), context(key)));
12 changes: 12 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body ng-app="routesApp">
<main>
<ui-view></ui-view>
</main>
</body>
</html>
48 changes: 48 additions & 0 deletions app/npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'test-watch' ]
2 info using npm@3.10.10
3 info using node@v6.10.0
4 verbose run-script [ 'pretest-watch', 'test-watch', 'posttest-watch' ]
5 info lifecycle 26-angular-routing@1.0.0~pretest-watch: 26-angular-routing@1.0.0
6 silly lifecycle 26-angular-routing@1.0.0~pretest-watch: no script for pretest-watch, continuing
7 info lifecycle 26-angular-routing@1.0.0~test-watch: 26-angular-routing@1.0.0
8 verbose lifecycle 26-angular-routing@1.0.0~test-watch: unsafe-perm in lifecycle true
9 verbose lifecycle 26-angular-routing@1.0.0~test-watch: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;C:\Users\Isak Swearingen\CodeFellows\401\lab_isak\26-angular-routing\node_modules\.bin;C:\Users\Isak Swearingen\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\local\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\bin;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Users\Isak Swearingen\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files\Intel\WiFi\bin;C:\Program Files\Common Files\Intel\WirelessCommon;C:\Program Files\nodejs;C:\Program Files\Git\cmd;C:\Program Files\PuTTY;C:\Users\Isak Swearingen\AppData\Local\atom\bin;C:\Users\Isak Swearingen\AppData\Local\Microsoft\WindowsApps;C:\Users\Isak Swearingen\AppData\Roaming\npm;C:\Program Files\Heroku\bin;C:\Program Files\MongoDB\Server\3.4\bin;C:\Program Files\Git\usr\bin\vendor_perl;C:\Program Files\Git\usr\bin\core_perl
10 verbose lifecycle 26-angular-routing@1.0.0~test-watch: CWD: C:\Users\Isak Swearingen\CodeFellows\401\lab_isak\26-angular-routing
11 silly lifecycle 26-angular-routing@1.0.0~test-watch: Args: [ '/d /s /c', 'karma' ]
12 silly lifecycle 26-angular-routing@1.0.0~test-watch: Returned: code: 1 signal: null
13 info lifecycle 26-angular-routing@1.0.0~test-watch: Failed to exec test-watch script
14 verbose stack Error: 26-angular-routing@1.0.0 test-watch: `karma`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:255:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:877:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid 26-angular-routing@1.0.0
16 verbose cwd C:\Users\Isak Swearingen\CodeFellows\401\lab_isak\26-angular-routing\app
17 error Windows_NT 10.0.14393
18 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test-watch"
19 error node v6.10.0
20 error npm v3.10.10
21 error code ELIFECYCLE
22 error 26-angular-routing@1.0.0 test-watch: `karma`
22 error Exit status 1
23 error Failed at the 26-angular-routing@1.0.0 test-watch script 'karma'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the 26-angular-routing package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error karma
23 error You can get information on how to open an issue for this project with:
23 error npm bugs 26-angular-routing
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls 26-angular-routing
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
Empty file added app/scss/main.scss
Empty file.
94 changes: 94 additions & 0 deletions app/service/auth-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
'use strict';

module.exports = [
'$q',
'$log',
'$http',
'$window',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to pass in authService in here

function($q, $log, $http, $window, authService) {
$log.debug('authService');

let service = {};
let token = null;

function setToken(_token) {
$log.debug('authService.setToken()');

if(!_token) return $q.reject(new Error('Token Does Not Exist'));
$window.localStorage.setItem('token', _token);
token = _token;

return $q.resolve(token);
}

service.getToken = function() {
$log.debug('authService.getToken()');

if(token) return $q.resolve(token);
token = $window.localStorage.getItem('token');
if(token) return $q.resolve(token);

return $q.reject(new Error('Token not found.'));
};

service.logout = function() {
$log.debug('authService.logout()');

$window.localStorage.removeItem('token');
token = null;

return $q.resolve();
};

service.deleteToken = function() {
$log.debug('authService.deleteToken()');

if(token) $window.localStorage.removeItem('token');
token = null;

return $q.resolve();
};

service.signup = function(user) {
$log.debug('authService.signup()');

let url = `${__API_URL__}/api/signup`;
let config = {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
};

return $http.post(url, user, config)
.then(res => {
$log.log('success', res.data);
})
.catch(err => {
$log.error('failure', err);
});
};

service.signin = function(user) {
$log.debug('authService.signin()');

let url = `${__API_URL__}/api/signin`;
let config = {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
};

return $http.get(url, user, config)
.then(res => {
$log.log('success', res.data);
})
.catch(err => {
$log.error('failure', err);
});
};

return service;
}
];
50 changes: 50 additions & 0 deletions app/test/controller-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const angular = require('angular');
require('angular-mocks');

describe('testing gallery controller', function(){
beforeEach(() => {
angular.mock.module('routesApp');
angular.mock.inject(($rootScope, $controller) => {
this.$rootScope = $rootScope;
this.galleryCtrl = new $controller('GalleryController');
this.galleryCtrl.$onInit();
});
});
afterEach(() => this.$rootScope.$apply());

it('Should have text in the title', () => {
expect(this.galleryCtrl.title).toBe.string;
});
});

describe('testing signup controller', function(){
beforeEach(() => {
angular.mock.module('routesApp');
angular.mock.inject(($rootScope, $controller) => {
this.$rootScope = $rootScope;
this.signupCtrl = new $controller('SignupController');
this.signupCtrl.$onInit();
});
});
afterEach(() => this.$rootScope.$apply());

it('Should have text in the title', () => {
expect(this.signupCtrl.title).toBe.string;
});
});

describe('testing home controller', function(){
beforeEach(() => {
angular.mock.module('routesApp');
angular.mock.inject(($rootScope, $controller) => {
this.$rootScope = $rootScope;
this.homeCtrl = new $controller('HomeController');
this.homeCtrl.$onInit();
});
});
afterEach(() => this.$rootScope.$apply());

it('Should have text in the title', () => {
expect(this.homeCtrl.title).toBe.string;
});
});
3 changes: 3 additions & 0 deletions app/view/home/_home.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
section{
background-color: linear-gradient(#fff, #000, #444, #888);
}
16 changes: 16 additions & 0 deletions app/view/home/home-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

require('./_home.scss');

module.exports = ['$log', function($log){
$log.debug('HomeController');

this.$onInit = () => {
this.title = 'The Home Page, of Derf!!!';

// this.update = function(input) {
// $log.debug('#updateHome');
// return this.say({text: input || 'Home', f: this.current});
// };
};
}];
5 changes: 5 additions & 0 deletions app/view/home/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<section>
<h1>{{ homeCtrl.title }}</h1>
<a href="/#!/signup">Sign Up</a>
<a href="/#!/gallery">Gallery</a>
</section>
Empty file added app/view/landing/_landing.scss
Empty file.
10 changes: 10 additions & 0 deletions app/view/landing/landing-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

require('./_landing.scss');

module.exports = ['$log', '$location', '$rootScope', 'authService', LandingController];

function LandingController($log, $location, authService) {
let url = $location.url();
this.showSignup = url === '/join#signup' || url === '/join';
}
25 changes: 25 additions & 0 deletions app/view/landing/landing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<section class="landing">
<div class="join-container"
ng-if="landingCtrl.showSignup">
<div class="join-inner">
<signup></signup>
<p>Already a member?</p>
<a href="/#!login"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll need to add a '/' before the login.

ng-click="landingCtrl.showSignup=false">
Sign In Here
</a>
</div>
</div>

<div class="join-container"
ng-if="!landingCtrl.showSignup">
<div class="join-inner">
<login></login>
<p>Want to Sign Up?</p>
<a href="/#!/signup"
ng-click="landingCtrl.showSignup=true">
Sign Up Here
</a>
</div>
</div>
</section>
Empty file added app/view/signup/_signup.scss
Empty file.
16 changes: 16 additions & 0 deletions app/view/signup/signup-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const angular = require('angular');

module.exports = ['$log', function($log) {
$log.debug('SignupController');

this.$onInit = () => {
this.title = 'Sign Up';

this.update = function(input) {
$log.debug('#update');
return this.say({text: input || 'SignUp', f: this.current});
};
};
}];
9 changes: 9 additions & 0 deletions app/view/signup/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<section>
<h1>Sign Up</h1>
<form>
<label>Name: <input type="text" ng-model="signupCtrl.text"></label>
<label>Email: <input type="text" ng-model="signupCtrl.email"></label>
<label>Password: <input type="text" ng-model="signupCtrl.password"></label>

</form>
</section>
Empty file added karma.conf.js
Empty file.
Loading