-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/hirsch88/generator-hirsch …
…into develop
- Loading branch information
Showing
37 changed files
with
624 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/// <reference path="../../../../typings/tsd.d.ts"/> | ||
|
||
module <%= prompts.prefix %>.common.util { | ||
'use strict'; | ||
|
||
export class Lazy<T> { | ||
private instance: T; | ||
|
||
constructor(private factory: () => T) { } | ||
|
||
get isCreated() { | ||
return !!this.instance; | ||
} | ||
|
||
get value() { | ||
return this.instance || (this.instance = this.factory()); | ||
} | ||
|
||
reset = () => { | ||
this.instance = undefined; | ||
return this; | ||
} | ||
} | ||
} |
13 changes: 0 additions & 13 deletions
13
app/templates/src/app-ts/common/views/abstractController.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,61 @@ | ||
/// <reference path="../../../../typings/tsd.d.ts"/> | ||
|
||
/** | ||
* Extension for 3rd party type definition file. | ||
*/ | ||
declare module angular.ui { | ||
interface IState { | ||
includes?(name: string): void; | ||
} | ||
} | ||
|
||
module <%= prompts.prefix %>.core.router { | ||
|
||
var routerConfig = ($urlRouterProvider: ng.ui.IUrlRouterProvider) => { | ||
$urlRouterProvider.otherwise('/home'); | ||
// this variable is to prevent an issue with the default routes; | ||
// if the initial request to the application is for an invalid route | ||
// the default route rule triggers multiple times (once during a state | ||
// transition). This causes the actual state transition to be superseded. | ||
// By capturing a variable inside the module scope, we can make the | ||
// default route handler ignore invalid route requests during routing | ||
var stateChangeCountingSemaphore = 0; | ||
var checkSemaphore = (fn: () => string) => stateChangeCountingSemaphore > 0 ? undefined : fn(); | ||
|
||
var routerConfig = ($urlRouterProvider: ng.ui.IUrlRouterProvider, $stateProvider: ng.ui.IStateProvider) => { | ||
$urlRouterProvider.otherwise(() => checkSemaphore(() => `/home`)); | ||
|
||
// We decorate the 'includes' to extract all states that would match | ||
// a $state.includes() test for each state, and extend the state | ||
// object with a function that can be used to check whether a given | ||
// state is included in the list. This is then used inside the router | ||
// pipeline to check whether a given middleware is applicable for a | ||
// routing request | ||
$stateProvider.decorator('includes', (state, parent): any => { | ||
var result = parent(state); | ||
var includeNames = Object.keys(result); | ||
|
||
// state is actually a wrapper object, so we unwrap it | ||
state = state['self']; | ||
|
||
state.includes = name => includeNames.some(s => s === name); | ||
|
||
return result; | ||
}); | ||
}; | ||
|
||
routerConfig.$inject = ['$urlRouterProvider', '$stateProvider']; | ||
|
||
var run = ($rootScope: ng.IRootScopeService, routerService: IRouterService) => { | ||
$rootScope.$on('$stateChangeStart', (evt, ...rest: any[]) => { | ||
stateChangeCountingSemaphore += 1; | ||
rest.unshift(evt.preventDefault.bind(evt)); | ||
routerService.startPipeline.apply(null, rest).finally(() => stateChangeCountingSemaphore -= 1); | ||
}); | ||
}; | ||
|
||
routerConfig.$inject = ['$urlRouterProvider']; | ||
run.$inject = ['$rootScope', ID.RouterService]; | ||
|
||
angular | ||
.module(`${Namespace}.RouterConfig`, []) | ||
.config(routerConfig); | ||
.config(routerConfig) | ||
.run(run); | ||
} |
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
app/templates/src/app-ts/core/router/router.middleware.auth.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/// <reference path="../../../../typings/tsd.d.ts" /> | ||
|
||
module <%= prompts.prefix %>.core.router { | ||
'use strict'; | ||
|
||
var run = (logger: util.ILoggerFactory, $timeout: ng.ITimeoutService, routerService: IRouterService) => { | ||
var log = logger('Auth middleware'); | ||
|
||
var authMiddleware: IRouterMiddleware = (actions, context) => { | ||
if (context.toState.data && context.toState.data.requiresSession) { | ||
// TODO: check if user has session | ||
return $timeout(() => { ; }, 1000).then(() => { | ||
log.debug('Redirecting to login page...'); | ||
return actions.redirect('public.login'); | ||
}); | ||
} else { | ||
return actions.next(); | ||
} | ||
}; | ||
|
||
routerService.addMiddleware(authMiddleware, 'auth'); | ||
}; | ||
|
||
run.$inject = [util.ID.LoggerFactory, '$timeout', ID.RouterService]; | ||
|
||
angular | ||
.module(`${Namespace}.RouterMiddlewareAuth`, [ | ||
util.ID.LoggerFactory | ||
]) | ||
.run(run); | ||
} |
24 changes: 24 additions & 0 deletions
24
app/templates/src/app-ts/core/router/router.middleware.errorHandling.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/// <reference path="../../../../typings/tsd.d.ts" /> | ||
|
||
module <%= prompts.prefix %>.core.router { | ||
'use strict'; | ||
|
||
var run = ($q: ng.IQService, routerService: IRouterService, logger: util.ILoggerFactory) => { | ||
var log = logger('ErrorHandling middleware'); | ||
|
||
var errorHandlingMiddleware: IRouterMiddleware = a => a.next().catch(err => { | ||
log.error(err); | ||
return $q.reject(err); | ||
}); | ||
|
||
routerService.addMiddleware(errorHandlingMiddleware, 'errorHandling'); | ||
}; | ||
|
||
run.$inject = ['$q', ID.RouterService, util.ID.LoggerFactory]; | ||
|
||
angular | ||
.module(`${Namespace}.RouterMiddlewareErrorHandling`, [ | ||
util.ID.LoggerFactory | ||
]) | ||
.run(run); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.