Skip to content

Commit

Permalink
Merge branch 'release/1.0.0-rc.22'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gery Hirschfeld committed Jul 17, 2015
2 parents bfce0f8 + d75751d commit 2c7c616
Show file tree
Hide file tree
Showing 39 changed files with 631 additions and 298 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.0.0-rc.22 / 2015-07-17
==================

* Added TypeScript Pull-Request


1.0.0-rc.21 / 2015-07-02
==================

Expand Down
10 changes: 7 additions & 3 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,15 @@ var HirschGenerator = yeoman.generators.Base.extend({
scaffoldFolders: function() {
this.mkdir('src');
this.mkdir('src/app');
this.mkdir('src/app/common/services');
this.mkdir('src/app/common/directives');
this.mkdir('src/app/common/templates');
this.mkdir('src/app/common/decorators');
this.mkdir('src/app/common/directives');
this.mkdir('src/app/common/filters');
this.mkdir('src/app/common/models');
this.mkdir('src/app/common/services');
this.mkdir('src/app/common/services/converters');
this.mkdir('src/app/common/services/rest');
this.mkdir('src/app/common/templates');
this.mkdir('src/app/common/util');
this.mkdir('src/app/common/views');
this.mkdir('src/app/core');
this.mkdir('src/assets');
Expand Down
3 changes: 0 additions & 3 deletions app/templates/_tsd.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
"angularjs/angular-cookies.d.ts": {
"commit": "c50b111ded0a3a18b87b5abffea3150d6aca94da"
},
"restangular/restangular.d.ts": {
"commit": "c50b111ded0a3a18b87b5abffea3150d6aca94da"
},
"jquery/jquery.d.ts": {
"commit": "c50b111ded0a3a18b87b5abffea3150d6aca94da"
},
Expand Down
2 changes: 1 addition & 1 deletion app/templates/_tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"indent": [true, 2],
"label-position": true,
"label-undefined": true,
"max-line-length": [true, 140],
"max-line-length": [true, 200],
"no-arg": true,
"no-bitwise": true,
"no-console": [true,
Expand Down
24 changes: 24 additions & 0 deletions app/templates/src/app-ts/common/util/lazy.ts
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 app/templates/src/app-ts/common/views/abstractController.ts

This file was deleted.

55 changes: 51 additions & 4 deletions app/templates/src/app-ts/core/router/router.config.ts
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);
}
12 changes: 0 additions & 12 deletions app/templates/src/app-ts/core/router/router.constants.ts

This file was deleted.

31 changes: 31 additions & 0 deletions app/templates/src/app-ts/core/router/router.middleware.auth.ts
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);
}
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);
}
9 changes: 3 additions & 6 deletions app/templates/src/app-ts/core/router/router.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ module <%= prompts.prefix %>.core.router {
export var Namespace = '<%= prompts.prefix %>.core.router';

export var ID = {
RouterService: `${Namespace}.RouterService`,
APP_ROUTER_PRIVATE_ROUTES: `${Namespace}.APP_ROUTER_PRIVATE_ROUTES`
RouterService: `${Namespace}.RouterService`
};

angular
.module(Namespace, [
'ui.router',
'ui.router.router',
'ui.router.state',

`${Namespace}.RouterConstants`,

`${Namespace}.RouterConfig`,
ID.RouterService,
`${Namespace}.Router`
ID.RouterService
]);
}
Loading

0 comments on commit 2c7c616

Please sign in to comment.