From 0ca2a332f5cc44fd2daf36732daae61e26dba538 Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Fri, 11 Aug 2017 21:10:53 -0400 Subject: [PATCH 1/5] fix(ts): fix TypeScript errors --- .../account(auth)/login/login.component.js | 3 +- .../account(auth)/signup/signup.component.js | 17 +++--- .../client/app/admin(auth)/admin.component.js | 2 +- templates/app/client/app/app.constants.js | 2 +- templates/app/client/app/app.module.js | 53 ++----------------- .../app/client/app/main/main.component.js | 3 +- .../components/auth(auth)/auth.service.js | 34 ++++++------ .../components/auth(auth)/user.service.js | 28 +++++----- .../components/navbar/navbar.component.js | 4 +- templates/app/client/components/util.js | 4 +- .../server/api/user(auth)/user.controller.js | 2 +- templates/app/tsconfig(ts).json | 10 ++-- 12 files changed, 62 insertions(+), 100 deletions(-) diff --git a/templates/app/client/app/account(auth)/login/login.component.js b/templates/app/client/app/account(auth)/login/login.component.js index 6a2a4fec5..1f6dd0614 100644 --- a/templates/app/client/app/account(auth)/login/login.component.js +++ b/templates/app/client/app/account(auth)/login/login.component.js @@ -34,7 +34,8 @@ export class LoginComponent { errors = {login: undefined}; submitted = false; AuthService; - <%_ if(filters.ngroute) { -%><% } %> + <%_ if(filters.ngroute) { -%> + Router;<% } %> <%_ if(filters.uirouter) { -%> StateService;<% } %> diff --git a/templates/app/client/app/account(auth)/signup/signup.component.js b/templates/app/client/app/account(auth)/signup/signup.component.js index 96f051bc6..142e92715 100644 --- a/templates/app/client/app/account(auth)/signup/signup.component.js +++ b/templates/app/client/app/account(auth)/signup/signup.component.js @@ -2,9 +2,9 @@ import { Component } from '@angular/core'; <%_ if(filters.uirouter) { -%> import { StateService } from 'ui-router-ng2';<% } %> -<%_ if(filters.ngroute) { -%><% } %> +<%_ if(filters.ngroute) { -%> +import { Router } from '@angular/router';<% } %> import { AuthService } from '../../../components/auth/auth.service'; -import {ANGULARCLASS_MATCH_CONTROL_DIRECTIVES} from '@angularclass/match-control'; <%_ if(filters.flow) { -%> type User = { @@ -21,8 +21,7 @@ interface User { @Component({ selector: 'signup', - template: require('./signup.<%=templateExt%>'), - directives: [...ANGULARCLASS_MATCH_CONTROL_DIRECTIVES] + template: require('./signup.<%=templateExt%>') }) export class SignupComponent { user: User = { @@ -33,14 +32,16 @@ export class SignupComponent { errors = {}; submitted = false; AuthService; - <%_ if(filters.ngroute) { -%><% } %> + <%_ if(filters.ngroute) { -%> + Router;<% } %> <%_ if(filters.uirouter) { -%> StateService;<% } %> - static parameters = [AuthService, <% if(filters.ngroute) { %><% } else { %>StateService<% } %>]; - constructor(_AuthService_: AuthService, <% if(filters.ngroute) { %><% } else { %>_StateService_: StateService<% } %>) { + static parameters = [AuthService, <% if(filters.ngroute) { %>Router<% } else { %>StateService<% } %>]; + constructor(_AuthService_: AuthService, <% if(filters.ngroute) { %>router: Router<% } else { %>_StateService_: StateService<% } %>) { this.AuthService = _AuthService_; - <%_ if(filters.ngroute) { -%><% } -%> + <%_ if(filters.ngroute) { -%> + this.Router = router;<% } -%> <%_ if(filters.uirouter) { -%> this.StateService = _StateService_;<% } -%> } diff --git a/templates/app/client/app/admin(auth)/admin.component.js b/templates/app/client/app/admin(auth)/admin.component.js index 738dccbf8..d1c5dbe7c 100644 --- a/templates/app/client/app/admin(auth)/admin.component.js +++ b/templates/app/client/app/admin(auth)/admin.component.js @@ -12,7 +12,7 @@ export class AdminComponent { <%_ } _%> static parameters = [UserService]; - constructor(userService: UserService) { + constructor(<%= private() %>userService: UserService) { this.userService = userService; // Use the user service to fetch all users this.userService.query().subscribe(users => { diff --git a/templates/app/client/app/app.constants.js b/templates/app/client/app/app.constants.js index 39adeaea5..30d84c9e8 100644 --- a/templates/app/client/app/app.constants.js +++ b/templates/app/client/app/app.constants.js @@ -1,6 +1,6 @@ <%_ if(filters.babel) { -%> export default from '../../server/config/environment/shared';<% } %> <%_ if(filters.ts) { -%> -import shared from '../../server/config/environment/shared'; +import shared from '../../server/config/environment/shared.js'; export default shared;<% } %> diff --git a/templates/app/client/app/app.module.js b/templates/app/client/app/app.module.js index 8f0185f82..8e8b6a52c 100644 --- a/templates/app/client/app/app.module.js +++ b/templates/app/client/app/app.module.js @@ -1,54 +1,9 @@ -// import angular from 'angular'; -// // import ngAnimate from 'angular-animate'; -// import ngCookies from 'angular-cookies'; -// import ngResource from 'angular-resource'; -// import ngSanitize from 'angular-sanitize'; -// <%_ if(filters.socketio) { _%> -// import 'angular-socket-io';<% } %> -// <%_ if(filters.ngroute) { _%> -// const ngRoute = require('angular-route');<% } %> -// <%_ if(filters.uirouter) { _%> -// import uiRouter from 'angular-ui-router';<% } %> -// <%_ if(filters.uibootstrap) { _%> -// import uiBootstrap from 'angular-ui-bootstrap';<% } %> -// // import ngMessages from 'angular-messages'; -// <%_ if(filters.auth) { _%> -// // import ngValidationMatch from 'angular-validation-match';<% } %> - -// import {routeConfig} from './app.config'; - -// <%_ if(filters.auth) { _%> -// import _Auth from '../components/auth/auth.module'; -// import account from './account'; -// import admin from './admin';<% } %> -// import navbar from '../components/navbar/navbar.component'; -// import footer from '../components/footer/footer.component'; -// import main from './main/main.component'; -// import constants from './app.constants'; -// import util from '../components/util/util.module'; -// <%_ if(filters.socketio) { _%> -// import socket from '../components/socket/socket.service';<% } %> - -// .config(routeConfig) -// <%_ if(filters.auth) { _%> -// .run(function($rootScope, $location, Auth) { -// 'ngInject'; -// // Redirect to login if route requires auth and you're not logged in -// $rootScope.$on('$stateChangeStart', function(event, next) { -// Auth.isLoggedIn(function(loggedIn) { -// if(next.authenticate && !loggedIn) { -// $location.path('/login'); -// } -// }); -// }); -// })<% } %>; - - import { NgModule, ErrorHandler, Injectable, ApplicationRef, + Provider, } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { @@ -60,9 +15,7 @@ import { import { removeNgStyles, createNewHosts, - disposeOldHosts, createInputTransfer, - restoreInputValues, } from '@angularclass/hmr'; <%_ if (filters.uirouter) { -%> import { UIRouterModule } from 'ui-router-ng2';<% } %> @@ -79,7 +32,7 @@ import { AdminModule } from './admin/admin.module'; import constants from './app.constants'; -let providers = [ +let providers: Provider[] = [ provideAuth({ // Allow using AuthHttp while not logged in noJwtError: true, @@ -134,7 +87,7 @@ const appRoutes: Routes = [ }) export class AppModule { static parameters = [ApplicationRef]; - constructor(appRef/*: ApplicationRef*/) { + constructor(<%= private() %>appRef: ApplicationRef) { this.appRef = appRef; } diff --git a/templates/app/client/app/main/main.component.js b/templates/app/client/app/main/main.component.js index 79d0bdc79..71b12d74b 100644 --- a/templates/app/client/app/main/main.component.js +++ b/templates/app/client/app/main/main.component.js @@ -15,8 +15,7 @@ export class MainComponent implements OnInit<% if(filters.ws) { %>, OnDestroy<% <%_ if(filters.models) { -%> newThing = '';<% } %> - <%_ if(filters.babel) { -%> - static parameters = [Http, SocketService];<% } %> + static parameters = [Http, SocketService]; constructor(<%= private() %>http: Http<% if(filters.ws) { %>, <%= private() %>socketService: SocketService<% } %>) { this.Http = http; <%_ if(filters.ws) { -%> diff --git a/templates/app/client/components/auth(auth)/auth.service.js b/templates/app/client/components/auth(auth)/auth.service.js index 40a28f382..258be54b7 100644 --- a/templates/app/client/components/auth(auth)/auth.service.js +++ b/templates/app/client/components/auth(auth)/auth.service.js @@ -6,7 +6,7 @@ import { Http } from '@angular/http'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/toPromise'; import { safeCb, extractData } from '../util'; -import { userRoles } from '../../app/app.constants'; +import constants from '../../app/app.constants'; // @flow class User { @@ -19,19 +19,19 @@ class User { @Injectable() export class AuthService { - _currentUser: User = {}; + _currentUser: User = new User(); @Output() currentUserChanged = new EventEmitter(true); - userRoles = userRoles || []; + userRoles = constants.userRoles || []; static parameters = [Http, AuthHttp, UserService]; - constructor(_Http_: Http, _AuthHttp_: AuthHttp, _UserService_: UserService) { - this.Http = _Http_; - this.AuthHttp = _AuthHttp_; - this.UserService = _UserService_; + constructor(<%= private() %>http: Http, <%= private() %>authHttp: AuthHttp, <%= private() %>userService: UserService) { + this.Http = http; + this.AuthHttp = authHttp; + this.UserService = userService; if(localStorage.getItem('id_token')) { this.UserService.get().toPromise() - .then(user => { + .then((user: User) => { this.currentUser = user; }) .catch(err => { @@ -48,7 +48,7 @@ export class AuthService { * @param {String} role - role to check against */ static hasRole(userRole, role) { - return userRoles.indexOf(userRole) >= userRoles.indexOf(role); + return constants.userRoles.indexOf(userRole) >= constants.userRoles.indexOf(role); } get currentUser() { @@ -78,7 +78,7 @@ export class AuthService { localStorage.setItem('id_token', res.token); return this.UserService.get().toPromise(); }) - .then(user => { + .then((user: User) => { this.currentUser = user; localStorage.setItem('user', JSON.stringify(user)); safeCb(callback)(null, user); @@ -98,7 +98,7 @@ export class AuthService { logout() { localStorage.removeItem('user'); localStorage.removeItem('id_token'); - this.currentUser = {}; + this.currentUser = new User(); return Promise.resolve(); } @@ -115,7 +115,7 @@ export class AuthService { localStorage.setItem('id_token', data.token); return this.UserService.get().toPromise(); }) - .then(_user => { + .then((_user: User) => { this.currentUser = _user; return safeCb(callback)(null, _user); }) @@ -135,6 +135,7 @@ export class AuthService { */ changePassword(oldPassword, newPassword, callback) { return this.UserService.changePassword({id: this.currentUser._id}, oldPassword, newPassword) + .toPromise() .then(() => safeCb(callback)(null)) .catch(err => safeCb(callback)(err)); } @@ -145,7 +146,7 @@ export class AuthService { * @param {Function} [callback] - function(user) * @return {Promise} */ - getCurrentUser(callback) { + getCurrentUser(callback?) { safeCb(callback)(this.currentUser); return Promise.resolve(this.currentUser); } @@ -161,9 +162,10 @@ export class AuthService { /** * Checks if user is logged in + * @param {function} [callback] * @returns {Promise} */ - isLoggedIn(callback) { + isLoggedIn(callback<% if(filters.ts) { %>?<% } %>) { let is = !!this.currentUser._id; safeCb(callback)(is); return Promise.resolve(is); @@ -180,10 +182,10 @@ export class AuthService { /** * Check if a user is an admin * - * @param {Function|*} callback - optional, function(is) + * @param {Function|*} [callback] - optional, function(is) * @return {Promise} */ - isAdmin(callback) { + isAdmin(callback?) { return this.getCurrentUser().then(user => { var is = user.role === 'admin'; safeCb(callback)(is); diff --git a/templates/app/client/components/auth(auth)/user.service.js b/templates/app/client/components/auth(auth)/user.service.js index 543df3c5a..8782f5132 100644 --- a/templates/app/client/components/auth(auth)/user.service.js +++ b/templates/app/client/components/auth(auth)/user.service.js @@ -10,44 +10,46 @@ import 'rxjs/add/operator/toPromise'; // @flow type UserType = { // TODO: use Mongoose model - name: string; - email: string; + id?: string; + _id?: string; + name?: string; + email?: string; +} + +function handleError(err) { + return Observable.throw(err.json().error || 'Server error'); } @Injectable() export class UserService { static parameters = [AuthHttp]; - constructor(authHttp: AuthHttp) { + constructor(<%= private() %>authHttp: AuthHttp) { this.AuthHttp = authHttp; } - handleError(err) { - Observable.throw(err.json().error || 'Server error'); - } - query(): Observable { return this.AuthHttp.get('/api/users/') .map((res:Response) => res.json()) - .catch(this.handleError); + .catch(handleError); } - get(user = {id: 'me'}): Observable { + get(user: UserType = {id: 'me'}): Observable { return this.AuthHttp.get(`/api/users/${user.id || user._id}`) .map((res:Response) => res.json()) - .catch(this.handleError); + .catch(handleError); } create(user: UserType) { return this.AuthHttp.post('/api/users/', user) .map((res:Response) => res.json()) - .catch(this.handleError); + .catch(handleError); } changePassword(user, oldPassword, newPassword) { return this.AuthHttp.put(`/api/users/${user.id || user._id}/password`, {oldPassword, newPassword}) .map((res:Response) => res.json()) - .catch(this.handleError); + .catch(handleError); } remove(user) { return this.AuthHttp.delete(`/api/users/${user.id || user._id}`) .map(() => user) - .catch(this.handleError); + .catch(handleError); } } diff --git a/templates/app/client/components/navbar/navbar.component.js b/templates/app/client/components/navbar/navbar.component.js index 969d7b2ac..cfa763d0e 100644 --- a/templates/app/client/components/navbar/navbar.component.js +++ b/templates/app/client/components/navbar/navbar.component.js @@ -22,7 +22,7 @@ export class NavbarComponent { <%_ if(filters.auth) { -%> static parameters = [AuthService<% if(filters.uirouter) { %>, StateService<% } else { %>, Router<% } %>]; - constructor(authService: AuthService<% if(filters.uirouter) { %>, stateService: StateService<% } else { %>, router: Router<% } %>) { + constructor(<%= private() %>authService: AuthService<% if(filters.uirouter) { %>, <%= private() %>stateService: StateService<% } else { %>, <%= private() %>router: Router<% } %>) { this.AuthService = authService; <%_ if(filters.uirouter) { -%> this.StateService = stateService;<% } %> @@ -32,7 +32,7 @@ export class NavbarComponent { this.reset(); this.AuthService.currentUserChanged.subscribe(user => { - this.currentuser = user; + this.currentUser = user; this.reset(); }); } diff --git a/templates/app/client/components/util.js b/templates/app/client/components/util.js index 11255b391..61f6c2811 100644 --- a/templates/app/client/components/util.js +++ b/templates/app/client/components/util.js @@ -44,9 +44,9 @@ export function urlParse(url) { * @return {Boolean} - true if url is same origin */ export function isSameOrigin(url, origins) { - url = Util.urlParse(url); + url = urlParse(url); origins = (origins && [].concat(origins)) || []; - origins = origins.map(Util.urlParse); + origins = origins.map(urlParse); origins.push(window.location); origins = origins.filter(function(o) { let hostnameCheck = url.hostname === o.hostname; diff --git a/templates/app/server/api/user(auth)/user.controller.js b/templates/app/server/api/user(auth)/user.controller.js index ae0e960fa..7f0dce8b7 100644 --- a/templates/app/server/api/user(auth)/user.controller.js +++ b/templates/app/server/api/user(auth)/user.controller.js @@ -47,7 +47,7 @@ export function create(req, res) { <% if (filters.mongooseModels) { %>var newUser = new User(req.body); newUser.provider = 'local'; newUser.role = 'user'; - newUser.save()<% } + return newUser.save()<% } if (filters.sequelizeModels) { %>var newUser = User.build(req.body); newUser.setDataValue('provider', 'local'); newUser.setDataValue('role', 'user'); diff --git a/templates/app/tsconfig(ts).json b/templates/app/tsconfig(ts).json index 7fe883d2f..de791d019 100644 --- a/templates/app/tsconfig(ts).json +++ b/templates/app/tsconfig(ts).json @@ -4,16 +4,20 @@ "allowSyntheticDefaultImports": true, "experimentalDecorators": true, "sourceMap": true, - "rootDir": "./client", + "rootDir": "./", "module": "es6", "outDir": ".tmp", "removeComments": false, "target": "es5", "skipLibCheck": true, - "moduleResolution": "node" + "moduleResolution": "node", + "lib": [ + "es2016", + "dom" + ] }, "typeRoots": [ - "node_modules/@types" + "./node_modules/@types/" ], "exclude": [ "node_modules" From da7c11b4ea21c0f2714f2461645c0fdffee0cf6a Mon Sep 17 00:00:00 2001 From: stherrienaspnet Date: Wed, 9 Aug 2017 22:40:06 -0400 Subject: [PATCH 2/5] chore(client): upgade angular --- templates/app/_package.json | 20 +++++++++---------- .../settings/settings.component.js | 20 +++++++++---------- .../app/account(auth)/settings/settings.html | 20 +++++++++---------- templates/app/client/app/app.module.js | 20 +++++++++++++------ 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/templates/app/_package.json b/templates/app/_package.json index 3ca824ff0..ceea38d0a 100644 --- a/templates/app/_package.json +++ b/templates/app/_package.json @@ -54,16 +54,16 @@ "@angularclass/match-control": "^2.0.0", "reflect-metadata": "^0.1.3", "rxjs": "^5.3.0", - "zone.js": "^0.7.2", - "@angular/common": "~2.4.9", - "@angular/compiler": "~2.4.9", - "@angular/core": "~2.4.9", - "@angular/forms": "~2.4.9", - "@angular/http": "~2.4.9", + "zone.js": "^0.8.4", + "@angular/common": "^4.3.3", + "@angular/compiler": "^4.3.3", + "@angular/core": "^4.3.3", + "@angular/forms": "^4.3.3", + "@angular/http": "^4.3.3", + "@angular/platform-browser": "^4.3.3", + "@angular/platform-browser-dynamic": "^4.3.3", + "@angular/router": "^4.3.3", <%#"@angular/material": "^2.0.0-alpha.10",%> - "@angular/platform-browser": "~2.4.9", - "@angular/platform-browser-dynamic": "~2.4.9", - "@angular/router": "^3.4.7", "@angularclass/hmr": "^1.2.1", <%_ if(filters.ts) { -%> "@types/core-js": "^0.9.41", @@ -82,7 +82,7 @@ "@types/webpack": "^2.2.15", <%_ } -%> "angular2-universal": "2.1.0-rc.1", - "angular2-jwt": "^0.1.24", + "angular2-jwt": "^0.1.28", <% if(filters.auth) { %> "angular-validation-match": "^1.9.0",<% } %> <% if(filters.uirouter) { %> diff --git a/templates/app/client/app/account(auth)/settings/settings.component.js b/templates/app/client/app/account(auth)/settings/settings.component.js index e426e94e3..c19ee87aa 100644 --- a/templates/app/client/app/account(auth)/settings/settings.component.js +++ b/templates/app/client/app/account(auth)/settings/settings.component.js @@ -40,16 +40,14 @@ export class SettingsComponent { changePassword(form) { this.submitted = true; - if(form.$valid) { - this.AuthService.changePassword(this.user.oldPassword, this.user.newPassword) - .then(() => { - this.message = 'Password successfully changed.'; - }) - .catch(() => { - form.password.$setValidity('mongoose', false); - this.errors.other = 'Incorrect password'; - this.message = ''; - }); - } + return this.AuthService.changePassword(this.user.oldPassword, this.user.newPassword) + .then(() => { + this.message = 'Password successfully changed.'; + }) + .catch(() => { + // form.password.$setValidity('mongoose', false); + this.errors.other = 'Incorrect password'; + this.message = ''; + }); } } diff --git a/templates/app/client/app/account(auth)/settings/settings.html b/templates/app/client/app/account(auth)/settings/settings.html index eed1686fd..6a33253a6 100644 --- a/templates/app/client/app/account(auth)/settings/settings.html +++ b/templates/app/client/app/account(auth)/settings/settings.html @@ -9,20 +9,19 @@

Change Password

- -

- {{ errors.other }} + +

+ Required

- +

+ [hidden]="newPassword.valid || !submitted"> Password must be at least 3 characters.

@@ -30,12 +29,11 @@

Change Password

- + minlength="3"/>

+ [hidden]="confirmPassword.valid || !submitted"> Passwords must match.

diff --git a/templates/app/client/app/app.module.js b/templates/app/client/app/app.module.js index 8e8b6a52c..3bde844db 100644 --- a/templates/app/client/app/app.module.js +++ b/templates/app/client/app/app.module.js @@ -7,6 +7,7 @@ import { } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { + Http, HttpModule, BaseRequestOptions, RequestOptions, @@ -21,7 +22,7 @@ import { import { UIRouterModule } from 'ui-router-ng2';<% } %> <%_ if (filters.ngroute) { -%> import { RouterModule, Routes } from '@angular/router';<% } %> -import { provideAuth } from 'angular2-jwt'; +import { provideAuth, AuthHttp, AuthConfig } from 'angular2-jwt'; import { AppComponent } from './app.component'; import { MainModule } from './main/main.module'; @@ -32,12 +33,19 @@ import { AdminModule } from './admin/admin.module'; import constants from './app.constants'; -let providers: Provider[] = [ - provideAuth({ - // Allow using AuthHttp while not logged in +export function getAuthHttp(http) { + return new AuthHttp(new AuthConfig({ noJwtError: true, - }) -]; + globalHeaders: [{'Accept': 'application/json'}], + tokenGetter: (() => localStorage.getItem('id_token')), + }), http); +} + +let providers: Provider[] = [{ + provide: AuthHttp, + useFactory: getAuthHttp, + deps: [Http] +}]; if(constants.env === 'development') { @Injectable() From 9ae9fb578ced5a0f8994714dc44bc8da92bde7ac Mon Sep 17 00:00:00 2001 From: stherrienaspnet Date: Thu, 10 Aug 2017 22:46:13 -0400 Subject: [PATCH 3/5] Removed unnecessary component usage --- templates/app/client/__index.html | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/templates/app/client/__index.html b/templates/app/client/__index.html index 8b9dacffe..ccdf4f911 100644 --- a/templates/app/client/__index.html +++ b/templates/app/client/__index.html @@ -25,9 +25,6 @@ ga('send', 'pageview'); - LOADING - - <% if (filters.ngroute) { %><% } %><% if (filters.uirouter) { %>
<% } %> -
+ Loading... From cf1fe47519df8242870df79dd63e1beca7cc2dae Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Sun, 13 Aug 2017 12:40:18 -0400 Subject: [PATCH 4/5] fix(client): fix remaining TS errors --- .../app/client/app/account(auth)/account.module.js | 13 +++++++------ .../app/account(auth)/signup/signup.component.js | 2 +- .../app/client/app/admin(auth)/admin.module.js | 2 +- templates/app/client/app/main/main.component.js | 1 + .../client/components/auth(auth)/auth.service.js | 8 ++++++-- .../client/components/auth(auth)/user.service.js | 4 +++- .../client/components/navbar/navbar.component.js | 9 ++++++--- test/fixtures/.yo-rc.json | 5 ++--- 8 files changed, 27 insertions(+), 17 deletions(-) diff --git a/templates/app/client/app/account(auth)/account.module.js b/templates/app/client/app/account(auth)/account.module.js index 2f047996b..b303eb7eb 100644 --- a/templates/app/client/app/account(auth)/account.module.js +++ b/templates/app/client/app/account(auth)/account.module.js @@ -1,20 +1,21 @@ import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { BrowserModule } from '@angular/platform-browser'; -<%_ if (filters.uirouter) { -%> +<%_ if(filters.uirouter) { -%> import { UIRouterModule } from 'ui-router-ng2';<% } %> -<%_ if (filters.ngroute) { -%> +<%_ if(filters.ngroute) { -%> import { RouterModule, Routes } from '@angular/router';<% } %> <%_ if(filters.oauth) { -%> import { DirectivesModule } from '../../components/directives.module';<% } %> -import { STATES } from './account.routes'; +<%_ if(filters.uirouter) { -%> +import { STATES } from './account.routes';<% } %> import { LoginComponent } from './login/login.component'; import { SettingsComponent } from './settings/settings.component'; import { SignupComponent } from './signup/signup.component'; -<%_ if (filters.ngroute) { -%> +<%_ if(filters.ngroute) { -%> const accountRoutes: Routes = [{ path: 'login', component: LoginComponent, @@ -31,11 +32,11 @@ const accountRoutes: Routes = [{ imports: [ FormsModule, BrowserModule, - <%_ if (filters.uirouter) { -%> + <%_ if(filters.uirouter) { -%> UIRouterModule.forChild({ states: STATES, }),<% } %> - <%_ if (filters.ngroute) { -%> + <%_ if(filters.ngroute) { -%> RouterModule.forChild(accountRoutes),<% } %> <%_ if(filters.oauth) { -%> DirectivesModule,<% } %> diff --git a/templates/app/client/app/account(auth)/signup/signup.component.js b/templates/app/client/app/account(auth)/signup/signup.component.js index 142e92715..74fe2eb8d 100644 --- a/templates/app/client/app/account(auth)/signup/signup.component.js +++ b/templates/app/client/app/account(auth)/signup/signup.component.js @@ -56,7 +56,7 @@ export class SignupComponent { }) .then(() => { // Account created, redirect to home - <% if(filters.ngroute) { %>this.$location.path('/');<% } -%> + <% if(filters.ngroute) { %>this.Router.navigateByUrl('/home');<% } -%> <% if(filters.uirouter) { %>this.StateService.go('main');<% } -%> }) .catch(err => { diff --git a/templates/app/client/app/admin(auth)/admin.module.js b/templates/app/client/app/admin(auth)/admin.module.js index e165f9e41..b9142d7c4 100644 --- a/templates/app/client/app/admin(auth)/admin.module.js +++ b/templates/app/client/app/admin(auth)/admin.module.js @@ -9,7 +9,7 @@ import { AdminComponent } from './admin.component'; <%_ if(filters.uirouter) { -%> import { STATES } from './admin.routes';<% } %> -<%_ if (filters.ngroute) { -%> +<%_ if(filters.ngroute) { -%> const adminRoutes: Routes = [{ path: 'admin', component: AdminComponent, diff --git a/templates/app/client/app/main/main.component.js b/templates/app/client/app/main/main.component.js index 71b12d74b..1944616f9 100644 --- a/templates/app/client/app/main/main.component.js +++ b/templates/app/client/app/main/main.component.js @@ -9,6 +9,7 @@ import { SocketService } from '../../components/socket/socket.service'; styles: [require('./main.<%=styleExt%>')], }) export class MainComponent implements OnInit<% if(filters.ws) { %>, OnDestroy<% } %> { + Http; <%_ if(filters.ws) { -%> SocketService;<% } %> awesomeThings = []; diff --git a/templates/app/client/components/auth(auth)/auth.service.js b/templates/app/client/components/auth(auth)/auth.service.js index 258be54b7..31931abc7 100644 --- a/templates/app/client/components/auth(auth)/auth.service.js +++ b/templates/app/client/components/auth(auth)/auth.service.js @@ -22,6 +22,9 @@ export class AuthService { _currentUser: User = new User(); @Output() currentUserChanged = new EventEmitter(true); userRoles = constants.userRoles || []; + Http; + AuthHttp; + UserService; static parameters = [Http, AuthHttp, UserService]; constructor(<%= private() %>http: Http, <%= private() %>authHttp: AuthHttp, <%= private() %>userService: UserService) { @@ -31,6 +34,7 @@ export class AuthService { if(localStorage.getItem('id_token')) { this.UserService.get().toPromise() + .then(extractData) .then((user: User) => { this.currentUser = user; }) @@ -146,7 +150,7 @@ export class AuthService { * @param {Function} [callback] - function(user) * @return {Promise} */ - getCurrentUser(callback?) { + getCurrentUser(callback<% if(filters.ts) { %>?<% } %>) { safeCb(callback)(this.currentUser); return Promise.resolve(this.currentUser); } @@ -185,7 +189,7 @@ export class AuthService { * @param {Function|*} [callback] - optional, function(is) * @return {Promise} */ - isAdmin(callback?) { + isAdmin(callback<% if(filters.ts) { %>?<% } %>) { return this.getCurrentUser().then(user => { var is = user.role === 'admin'; safeCb(callback)(is); diff --git a/templates/app/client/components/auth(auth)/user.service.js b/templates/app/client/components/auth(auth)/user.service.js index 8782f5132..8520f2115 100644 --- a/templates/app/client/components/auth(auth)/user.service.js +++ b/templates/app/client/components/auth(auth)/user.service.js @@ -22,6 +22,8 @@ function handleError(err) { @Injectable() export class UserService { + AuthHttp; + static parameters = [AuthHttp]; constructor(<%= private() %>authHttp: AuthHttp) { this.AuthHttp = authHttp; @@ -32,7 +34,7 @@ export class UserService { .map((res:Response) => res.json()) .catch(handleError); } - get(user: UserType = {id: 'me'}): Observable { + get(user<% if(filters.ts) { %>: UserType<% } %> = {id: 'me'}): Observable { return this.AuthHttp.get(`/api/users/${user.id || user._id}`) .map((res:Response) => res.json()) .catch(handleError); diff --git a/templates/app/client/components/navbar/navbar.component.js b/templates/app/client/components/navbar/navbar.component.js index cfa763d0e..bfeed3314 100644 --- a/templates/app/client/components/navbar/navbar.component.js +++ b/templates/app/client/components/navbar/navbar.component.js @@ -12,14 +12,17 @@ import { AuthService } from '../auth/auth.service';<% } %> }) export class NavbarComponent { isCollapsed = true; - isLoggedIn; - isAdmin; - currentUser = {}; menu = [{ title: 'Home', <% if(filters.uirouter) { %>'state': 'main'<% } else { %>'link': '/home'<% } %>, }]; + <%_ if(filters.ngroute) { -%> + Router;<% } %> <%_ if(filters.auth) { -%> + isAdmin; + isLoggedIn; + currentUser = {}; + AuthService; static parameters = [AuthService<% if(filters.uirouter) { %>, StateService<% } else { %>, Router<% } %>]; constructor(<%= private() %>authService: AuthService<% if(filters.uirouter) { %>, <%= private() %>stateService: StateService<% } else { %>, <%= private() %>router: Router<% } %>) { diff --git a/test/fixtures/.yo-rc.json b/test/fixtures/.yo-rc.json index bace79b9f..e0d83dd8d 100644 --- a/test/fixtures/.yo-rc.json +++ b/test/fixtures/.yo-rc.json @@ -18,7 +18,7 @@ "flow": false, "html": true, "sass": true, - "uirouter": true, + "ngroute": true, "bootstrap": true, "uibootstrap": true, "ws": true, @@ -41,11 +41,10 @@ "moduleName": "", "modulePrompt": true, "filters": [ - "uirouter", + "ngroute", "mocha", "expect", "should", - "uirouter", "es6", "webpack" ], From 18c86d6c02ee9bac7d299958e3636c9d6c41ae55 Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Sun, 13 Aug 2017 12:51:44 -0400 Subject: [PATCH 5/5] test(client): fix client test import --- templates/app/spec.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/templates/app/spec.js b/templates/app/spec.js index ba731f735..0cf207a88 100644 --- a/templates/app/spec.js +++ b/templates/app/spec.js @@ -21,9 +21,12 @@ testsContext('./components/oauth-buttons/oauth-buttons.component.spec.<%= script <%_ } -%> import { TestBed, getTestBed } from '@angular/core/testing'; -import browser from '@angular/platform-browser-dynamic/testing'; +import { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting, +} from '@angular/platform-browser-dynamic/testing'; -TestBed.initTestEnvironment(browser.BrowserDynamicTestingModule, browser.platformBrowserDynamicTesting()); +TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()); <%_ if (filters.mocha) { -%> var hook = new Mocha.Hook('Modified Angular beforeEach Hook', function() {