Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Feature/nested states #9

Merged
merged 2 commits into from
Jun 30, 2015
Merged
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
29 changes: 25 additions & 4 deletions app/account/account.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,33 @@

$stateProvider
.state('login', {
url: '/login',
templateUrl: 'account/login/login.html'
parent: 'root',
url: '/login?next',
data: {
title: 'Login'
},
views: {
'container@': {
templateUrl: 'account/login/login.html',
controller: 'LoginController'
},
'footer@': {
// no footer
template: ''
}
}
})
.state('register', {
url: '/register',
templateUrl: 'account/register/register.html'
url: '/register?next',
data: {
title: "Join"
},
views: {
'container@': {
templateUrl: 'account/register/register.html',
controller: 'RegisterController'
}
}
});

$urlRouterProvider.otherwise('/login');
Expand Down
18 changes: 16 additions & 2 deletions app/account/login/login.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@

angular.module('tc.account').controller('LoginController', LoginController);

LoginController.$inject = [];
LoginController.$inject = ['$log', '$state', '$stateParams', 'auth', '$location'];

function LoginController() {
function LoginController($log, $state, $stateParams, auth, $location) {
var vm = this;
vm.name = 'login';

// check if the user is already logged in
if (auth.isAuthenticated()) {
// redirect to next if exists else dashboard
if ($stateParams.next) {
$log.debug('Redirecting: ' + $stateParams.next);
$log.debug($location.path());
$location.path($stateParams.next);
} else {
// FIXME
$state.go('sample.child1');
}
}

}
})();
70 changes: 70 additions & 0 deletions app/blocks/exception/exception-handler.provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Include in index.html so that app level exceptions are handled.
// Exclude from testRunner.html which should run exactly what it wants to run
(function () {
'use strict';

angular
.module('blocks.exception')
.provider('exceptionHandler', exceptionHandlerProvider)
.config(config);

/**
* Must configure the exception handling
* @return {[type]}
*/
function exceptionHandlerProvider() {
/* jshint validthis:true */
this.config = {
appErrorPrefix: undefined
};

this.configure = function (appErrorPrefix) {
this.config.appErrorPrefix = appErrorPrefix;
};

this.$get = function () {
return {config: this.config};
};
}

config.$inject = ['$provide'];

/**
* Configure by setting an optional string value for appErrorPrefix.
* Accessible via config.appErrorPrefix (via config value).
* @param {[type]} $provide
* @return {[type]}
* @ngInject
*/
function config($provide) {
$provide.decorator('$exceptionHandler', extendExceptionHandler);
}

extendExceptionHandler.$inject = ['$delegate', 'exceptionHandler', 'logger'];

/**
* Extend the $exceptionHandler service to also display a toast.
* @param {Object} $delegate
* @param {Object} exceptionHandler
* @param {Object} logger
* @return {Function} the decorated $exceptionHandler service
*/
function extendExceptionHandler($delegate, exceptionHandler, logger) {
return function (exception, cause) {
var appErrorPrefix = exceptionHandler.config.appErrorPrefix || '';
var errorData = {exception: exception, cause: cause};
exception.message = appErrorPrefix + exception.message;
$delegate(exception, cause);
/**
* Could add the error to a service's collection,
* add errors to $rootScope, log errors to remote web server,
* or log locally. Or throw hard. It is entirely up to you.
* throw exception;
*
* @example
* throw { message: 'error message we added' };
*/
logger.error(exception.message, errorData);
};
}
})();
67 changes: 67 additions & 0 deletions app/blocks/exception/exception-handler.provider.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/* jshint -W117, -W030 */
describe('blocks.exception', function () {
var exceptionHandlerProvider;
var mocks = {
errorMessage: 'fake error',
prefix: '[TEST]: '
};

beforeEach(function () {
bard.inject('$rootScope');
});

bard.verifyNoOutstandingHttpRequests();

describe('$exceptionHandler', function () {
it('should have a dummy test', inject(function () {
expect(true).to.equal(true);
}));

it('should be defined', inject(function ($exceptionHandler) {
expect($exceptionHandler).to.be.defined;
}));

it('should have configuration', inject(function ($exceptionHandler) {
expect($exceptionHandler.config).to.be.defined;
}));

// describe('with appErrorPrefix', function () {
// beforeEach(function () {
// exceptionHandlerProvider.configure(mocks.prefix);
// });

// it('should have exceptionHandlerProvider defined', inject(function () {
// expect(exceptionHandlerProvider).to.be.defined;
// }));

// it('should have appErrorPrefix defined', inject(function () {
// expect(exceptionHandlerProvider.$get().config.appErrorPrefix).to.be.defined;
// }));

// it('should have appErrorPrefix set properly', inject(function () {
// expect(exceptionHandlerProvider.$get().config.appErrorPrefix)
// .to.equal(mocks.prefix);
// }));

// it('should throw an error when forced', inject(function () {
// expect(functionThatWillThrow).to.throw();
// }));

// it('manual error is handled by decorator', function () {
// var exception;
// exceptionHandlerProvider.configure(mocks.prefix);
// try {
// $rootScope.$apply(functionThatWillThrow);
// }
// catch (ex) {
// exception = ex;
// expect(ex.message).to.equal(mocks.prefix + mocks.errorMessage);
// }
// });
// });
});

function functionThatWillThrow() {
throw new Error(mocks.errorMessage);
}
});
23 changes: 23 additions & 0 deletions app/blocks/exception/exception.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
(function () {
'use strict';

angular
.module('blocks.exception')
.factory('exception', exception);

exception.$inject = ['logger'];

/* @ngInject */
function exception(logger) {
var service = {
catcher: catcher
};
return service;

function catcher(message) {
return function (reason) {
logger.error(message, reason);
};
}
}
})();
5 changes: 5 additions & 0 deletions app/blocks/exception/exception.module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(function () {
'use strict';

angular.module('blocks.exception', ['blocks.logger']);
})();
43 changes: 43 additions & 0 deletions app/blocks/logger/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
(function () {
'use strict';

angular
.module('blocks.logger')
.factory('logger', logger);

logger.$inject = ['$log'];

/* @ngInject */
function logger($log) {
var service = {
showToasts: false,

error: error,
info: info,
success: success,
warning: warning,

// straight to console; bypass toastr
log: $log.log
};

return service;
/////////////////////

function error(message, data, title) {
$log.error('Error: ' + message, data);
}

function info(message, data, title) {
$log.info('Info: ' + message, data);
}

function success(message, data, title) {
$log.info('Success: ' + message, data);
}

function warning(message, data, title) {
$log.warn('Warning: ' + message, data);
}
}
}());
5 changes: 5 additions & 0 deletions app/blocks/logger/logger.module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(function () {
'use strict';

angular.module('blocks.logger', []);
})();
37 changes: 31 additions & 6 deletions app/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ html

body(ng-app="topcoder", ng-controller="TopcoderController as main", ng-strict-di)

include ./layout/header/sidebar.jade

include ./layout/header/header.jade
//- include ./layout/header/header.jade
div(ui-view="header")

//- include ./layout/header/sidebar.jade
div(ui-view="sidebar")


.view-container(ng-class="{slided: main.sidebarActive}")
div(ui-view, ng-class="$state.current.name")
div(ui-view="container", ng-class="$state.current.name")

include ./layout/footer/footer.jade
//- include ./layout/footer/footer.jade
div(ui-view="footer")

// build:js js/vendor.js
//- bower:js
Expand All @@ -60,13 +65,18 @@ html
script(src="topcoder.constants.js")
script(src="topcoder.controller.js")
script(src="topcoder.interceptors.js")
script(src="topcoder.routes.js")
script(src="account/account.module.js")
script(src="layout/layout.module.js")
script(src="peer-review/peer-review.module.js")
script(src="filters/local-time.filter.js")
script(src="sample/sample.module.js")
script(src="blocks/exception/exception.module.js")
script(src="blocks/logger/logger.module.js")
script(src="account/account.routes.js")
script(src="filters/local-time.filter.js")
script(src="peer-review/peer-review.routes.js")
script(src="peer-review/slideable.directive.js")
script(src="sample/sample.routes.js")
script(src="services/api.service.js")
script(src="services/auth.service.js")
script(src="services/authtoken.service.js")
Expand All @@ -78,12 +88,27 @@ html
script(src="services/user.service.js")
script(src="account/login/login.controller.js")
script(src="account/register/register.controller.js")
script(src="blocks/exception/exception-handler.provider.js")
script(src="blocks/exception/exception.js")
script(src="blocks/logger/logger.js")
script(src="bower_components/lodash/lodash.js")
script(src="bower_components/lodash/lodash.min.js")
script(src="bower_components/angular/angular.js")
script(src="bower_components/angular/angular.min.js")
script(src="bower_components/angular/index.js")
script(src="bower_components/restangular/Gruntfile.js")
script(src="bower_components/restangular/karma.conf.js")
script(src="bower_components/restangular/karma.underscore.conf.js")
script(src="layout/header/header.controller.js")
script(src="peer-review/completed-review/completed-review.controller.js")
script(src="peer-review/edit-review/edit-review.controller.js")
script(src="peer-review/readOnlyScorecard/readOnlyScorecard.controller.js")
script(src="peer-review/review-status/review-status.controller.js")
script(src="peer-review/review-status/review-status.filter.js")
script(src="peer-review/edit-review/edit-review.controller.js")
script(src="bower_components/restangular/dist/restangular.js")
script(src="bower_components/restangular/dist/restangular.min.js")
script(src="bower_components/restangular/test/restangularSpec.js")
script(src="bower_components/restangular/src/restangular.js")
//- endinject

// inject:templates.js
Expand Down
Loading