From ad92e7c574caf9a35a4543dda450f43087a9986b Mon Sep 17 00:00:00 2001 From: stherrienaspnet Date: Tue, 20 Jun 2017 20:24:29 -0400 Subject: [PATCH 01/14] 32 typescript errors remaining --- .../client/app/admin(auth)/admin.component.js | 2 +- templates/app/client/app/app.module.js | 2 +- .../app/client/app/main/main.component.js | 8 ++++---- .../components/auth(auth)/auth.service.js | 20 +++++++++---------- .../components/auth(auth)/user.service.js | 14 ++++++------- .../components/navbar/navbar.component.js | 18 ++++++++--------- templates/app/client/components/util.js | 2 +- 7 files changed, 33 insertions(+), 33 deletions(-) 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.module.js b/templates/app/client/app/app.module.js index 33eda9b50..2c83da10b 100644 --- a/templates/app/client/app/app.module.js +++ b/templates/app/client/app/app.module.js @@ -113,7 +113,7 @@ if(constants.env === 'development') { }) 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..5e23f9582 100644 --- a/templates/app/client/app/main/main.component.js +++ b/templates/app/client/app/main/main.component.js @@ -18,13 +18,13 @@ export class MainComponent implements OnInit<% if(filters.ws) { %>, OnDestroy<% <%_ if(filters.babel) { -%> static parameters = [Http, SocketService];<% } %> constructor(<%= private() %>http: Http<% if(filters.ws) { %>, <%= private() %>socketService: SocketService<% } %>) { - this.Http = http; + this.http = http; <%_ if(filters.ws) { -%> this.SocketService = socketService;<% } %> } ngOnInit() { - this.Http.get('/api/things') + this.http.get('/api/things') .map(res => { return res.json(); }) @@ -46,7 +46,7 @@ export class MainComponent implements OnInit<% if(filters.ws) { %>, OnDestroy<% let text = this.newThing; this.newThing = ''; - return this.Http.post('/api/things', { name: text }) + return this.http.post('/api/things', { name: text }) .map(res => res.json()) .catch(err => Observable.throw(err.json().error || 'Server error')) .subscribe(thing => { @@ -56,7 +56,7 @@ export class MainComponent implements OnInit<% if(filters.ws) { %>, OnDestroy<% } deleteThing(thing) { - return this.Http.delete(`/api/things/${thing._id}`) + return this.http.delete(`/api/things/${thing._id}`) .map(res => res.json()) .catch(err => Observable.throw(err.json().error || 'Server error')) .subscribe(() => { diff --git a/templates/app/client/components/auth(auth)/auth.service.js b/templates/app/client/components/auth(auth)/auth.service.js index a99cf9366..66fadc12f 100644 --- a/templates/app/client/components/auth(auth)/auth.service.js +++ b/templates/app/client/components/auth(auth)/auth.service.js @@ -24,13 +24,13 @@ export class AuthService { userRoles = 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() + this.userService.get().toPromise() .then(user => { this.currentUser = user; }) @@ -68,7 +68,7 @@ export class AuthService { * @return {Promise} */ login({email, password}, callback) { - return this.Http.post('/auth/local', { + return this.http.post('/auth/local', { email, password }) @@ -76,7 +76,7 @@ export class AuthService { .then(extractData) .then(res => { localStorage.setItem('id_token', res.token); - return this.UserService.get().toPromise(); + return this.userService.get().toPromise(); }) .then(user => { this.currentUser = user; @@ -110,10 +110,10 @@ export class AuthService { * @return {Promise} */ createUser(user, callback) { - return this.UserService.create(user).toPromise() + return this.userService.create(user).toPromise() .then(data => { localStorage.setItem('id_token', data.token); - return this.UserService.get().toPromise(); + return this.userService.get().toPromise(); }) .then(_user => { this.currentUser = _user; @@ -134,7 +134,7 @@ export class AuthService { * @return {Promise} */ changePassword(oldPassword, newPassword, callback) { - return this.UserService.changePassword({id: this.currentUser._id}, oldPassword, newPassword) + return this.userService.changePassword({id: this.currentUser._id}, oldPassword, newPassword) .then(() => safeCb(callback)(null)) .catch(err => safeCb(callback)(err)); } diff --git a/templates/app/client/components/auth(auth)/user.service.js b/templates/app/client/components/auth(auth)/user.service.js index 543df3c5a..fdfe71c71 100644 --- a/templates/app/client/components/auth(auth)/user.service.js +++ b/templates/app/client/components/auth(auth)/user.service.js @@ -17,8 +17,8 @@ type UserType = { @Injectable() export class UserService { static parameters = [AuthHttp]; - constructor(authHttp: AuthHttp) { - this.AuthHttp = authHttp; + constructor(<%= private() %>authHttp: AuthHttp) { + this.authHttp = authHttp; } handleError(err) { @@ -26,27 +26,27 @@ export class UserService { } query(): Observable { - return this.AuthHttp.get('/api/users/') + return this.authHttp.get('/api/users/') .map((res:Response) => res.json()) .catch(this.handleError); } get(user = {id: 'me'}): Observable { - return this.AuthHttp.get(`/api/users/${user.id || user._id}`) + return this.authHttp.get(`/api/users/${user.id || user._id}`) .map((res:Response) => res.json()) .catch(this.handleError); } create(user: UserType) { - return this.AuthHttp.post('/api/users/', user) + return this.authHttp.post('/api/users/', user) .map((res:Response) => res.json()) .catch(this.handleError); } changePassword(user, oldPassword, newPassword) { - return this.AuthHttp.put(`/api/users/${user.id || user._id}/password`, {oldPassword, newPassword}) + return this.authHttp.put(`/api/users/${user.id || user._id}/password`, {oldPassword, newPassword}) .map((res:Response) => res.json()) .catch(this.handleError); } remove(user) { - return this.AuthHttp.delete(`/api/users/${user.id || user._id}`) + return this.authHttp.delete(`/api/users/${user.id || user._id}`) .map(() => user) .catch(this.handleError); } diff --git a/templates/app/client/components/navbar/navbar.component.js b/templates/app/client/components/navbar/navbar.component.js index a1e4608fb..aa4a4588e 100644 --- a/templates/app/client/components/navbar/navbar.component.js +++ b/templates/app/client/components/navbar/navbar.component.js @@ -20,34 +20,34 @@ export class NavbarComponent { <%_ if(filters.auth) { -%> static parameters = [AuthService<% if(filters.uirouter) { %>, StateService<% } %>]; - constructor(authService: AuthService<% if(filters.uirouter) { %>, stateService: StateService<% } %>) { - this.AuthService = authService; - this.StateService = stateService; + constructor(<%= private() %>authService: AuthService<% if(filters.uirouter) { %>, <%= private() %>stateService: StateService<% } %>) { + this.authService = authService; + this.stateService = stateService; this.reset(); - this.AuthService.currentUserChanged.subscribe(user => { + this.authService.currentUserChanged.subscribe(user => { this.currentuser = user; this.reset(); }) } reset() { - this.AuthService.isLoggedIn().then(is => { + this.authService.isLoggedIn().then(is => { this.isLoggedIn = is; }); - this.AuthService.isAdmin().then(is => { + this.authService.isAdmin().then(is => { this.isAdmin = is; }); - this.AuthService.getCurrentUser().then(user => { + this.authService.getCurrentUser().then(user => { this.currentUser = user; }); } logout() { - let promise = this.AuthService.logout(); + let promise = this.authService.logout(); <%_ if (filters.uirouter) { -%> - this.StateService.go('login');<% } -%> + this.stateService.go('login');<% } -%> <%_ if (filters.ngroute) { -%><% } -%> return promise; }<% } -%> diff --git a/templates/app/client/components/util.js b/templates/app/client/components/util.js index 11255b391..e0ab22c37 100644 --- a/templates/app/client/components/util.js +++ b/templates/app/client/components/util.js @@ -44,7 +44,7 @@ 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.push(window.location); From 8dbc4cd9fcd629b8790f880960eda47f0ab75b7b Mon Sep 17 00:00:00 2001 From: stherrienaspnet Date: Sat, 8 Jul 2017 16:17:46 -0400 Subject: [PATCH 02/14] 14 typescript errors remaining --- templates/app/client/app/app.constants.js | 2 +- .../components/auth(auth)/auth.service.js | 23 ++++++++++--------- .../components/auth(auth)/user.service.js | 8 ++++--- .../components/navbar/navbar.component.js | 2 +- templates/app/client/components/util.js | 2 +- templates/app/tsconfig(ts).json | 8 +++++-- 6 files changed, 26 insertions(+), 19 deletions(-) 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/components/auth(auth)/auth.service.js b/templates/app/client/components/auth(auth)/auth.service.js index 66fadc12f..f7aa16fb1 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,9 +19,9 @@ 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(<%= private() %>http: Http, <%= private() %>authHttp: AuthHttp, <%= private() %>userService: UserService) { @@ -31,7 +31,7 @@ export class AuthService { 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(); } @@ -145,7 +145,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 +161,10 @@ export class AuthService { /** * Checks if user is logged in + * @param {function} [callback] * @returns {Promise} */ - isLoggedIn(callback) { + isLoggedIn(callback?) { let is = this.currentUser.hasOwnProperty('role'); safeCb(callback)(is); return Promise.resolve(is); @@ -180,10 +181,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 fdfe71c71..4fc47a0af 100644 --- a/templates/app/client/components/auth(auth)/user.service.js +++ b/templates/app/client/components/auth(auth)/user.service.js @@ -10,8 +10,10 @@ import 'rxjs/add/operator/toPromise'; // @flow type UserType = { // TODO: use Mongoose model - name: string; - email: string; + id?: string; + _id?: string; + name?: string; + email?: string; } @Injectable() @@ -30,7 +32,7 @@ export class UserService { .map((res:Response) => res.json()) .catch(this.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); diff --git a/templates/app/client/components/navbar/navbar.component.js b/templates/app/client/components/navbar/navbar.component.js index aa4a4588e..6a8147c04 100644 --- a/templates/app/client/components/navbar/navbar.component.js +++ b/templates/app/client/components/navbar/navbar.component.js @@ -27,7 +27,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 e0ab22c37..61f6c2811 100644 --- a/templates/app/client/components/util.js +++ b/templates/app/client/components/util.js @@ -46,7 +46,7 @@ export function urlParse(url) { export function isSameOrigin(url, origins) { 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/tsconfig(ts).json b/templates/app/tsconfig(ts).json index 7fe883d2f..9b902599a 100644 --- a/templates/app/tsconfig(ts).json +++ b/templates/app/tsconfig(ts).json @@ -4,13 +4,17 @@ "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" From bf905b74608fcb82b9661b5f8bf17755328eb94a Mon Sep 17 00:00:00 2001 From: stherrienaspnet Date: Sat, 8 Jul 2017 16:58:31 -0400 Subject: [PATCH 03/14] 14 typescript errors remaining, fixed missing brackets --- templates/app/client/components/auth(auth)/auth.service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/app/client/components/auth(auth)/auth.service.js b/templates/app/client/components/auth(auth)/auth.service.js index f7aa16fb1..fed714605 100644 --- a/templates/app/client/components/auth(auth)/auth.service.js +++ b/templates/app/client/components/auth(auth)/auth.service.js @@ -31,7 +31,7 @@ export class AuthService { if(localStorage.getItem('id_token')) { this.userService.get().toPromise() - .then(user:User => { + .then((user:User) => { this.currentUser = user; }) .catch(err => { @@ -78,7 +78,7 @@ export class AuthService { localStorage.setItem('id_token', res.token); return this.userService.get().toPromise(); }) - .then(user: User => { + .then((user: User) => { this.currentUser = user; localStorage.setItem('user', JSON.stringify(user)); safeCb(callback)(null, user); From c1f3a17b2f599cd16e580d3e65780e5ead2f3c4c Mon Sep 17 00:00:00 2001 From: stherrienaspnet Date: Tue, 25 Jul 2017 21:26:01 -0400 Subject: [PATCH 04/14] fixed typescript issues only tests issues remaining --- .../account(auth)/signup/signup.component.js | 4 +- templates/app/client/app/app.module.js | 51 +------------------ .../app/client/app/main/main.component.js | 3 +- .../components/auth(auth)/auth.service.js | 4 +- .../components/auth(auth)/user.service.js | 18 +++---- templates/app/tsconfig(ts).json | 2 +- 6 files changed, 16 insertions(+), 66 deletions(-) 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..750ecc354 100644 --- a/templates/app/client/app/account(auth)/signup/signup.component.js +++ b/templates/app/client/app/account(auth)/signup/signup.component.js @@ -4,7 +4,6 @@ import { Component } from '@angular/core'; import { StateService } from 'ui-router-ng2';<% } %> <%_ if(filters.ngroute) { -%><% } %> import { AuthService } from '../../../components/auth/auth.service'; -import {ANGULARCLASS_MATCH_CONTROL_DIRECTIVES} from '@angularclass/match-control'; <%_ if(filters.flow) { -%> type User = { @@ -21,8 +20,7 @@ interface User { @Component({ selector: 'signup', - template: require('./signup.<%=templateExt%>'), - directives: [...ANGULARCLASS_MATCH_CONTROL_DIRECTIVES] + template: require('./signup.<%=templateExt%>') }) export class SignupComponent { user: User = { diff --git a/templates/app/client/app/app.module.js b/templates/app/client/app/app.module.js index 2c83da10b..e9f86d75c 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';<% } %> @@ -76,7 +29,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, diff --git a/templates/app/client/app/main/main.component.js b/templates/app/client/app/main/main.component.js index 5e23f9582..541cebab6 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 fed714605..27c9ed06d 100644 --- a/templates/app/client/components/auth(auth)/auth.service.js +++ b/templates/app/client/components/auth(auth)/auth.service.js @@ -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); }) @@ -134,7 +134,7 @@ export class AuthService { * @return {Promise} */ changePassword(oldPassword, newPassword, callback) { - return this.userService.changePassword({id: this.currentUser._id}, oldPassword, newPassword) + return this.userService.changePassword({id: this.currentUser._id}, oldPassword, newPassword).toPromise() .then(() => safeCb(callback)(null)) .catch(err => safeCb(callback)(err)); } diff --git a/templates/app/client/components/auth(auth)/user.service.js b/templates/app/client/components/auth(auth)/user.service.js index 4fc47a0af..d6126e5e3 100644 --- a/templates/app/client/components/auth(auth)/user.service.js +++ b/templates/app/client/components/auth(auth)/user.service.js @@ -16,6 +16,10 @@ type UserType = { email?: string; } +function handleError(err) { + return Observable.throw(err.json().error || 'Server error'); +} + @Injectable() export class UserService { static parameters = [AuthHttp]; @@ -23,33 +27,29 @@ export class UserService { 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: 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/tsconfig(ts).json b/templates/app/tsconfig(ts).json index 9b902599a..de791d019 100644 --- a/templates/app/tsconfig(ts).json +++ b/templates/app/tsconfig(ts).json @@ -17,7 +17,7 @@ ] }, "typeRoots": [ - "node_modules/@types" + "./node_modules/@types/" ], "exclude": [ "node_modules" From 0b6ada3f1f7930a6a8526a68d0f08a942d8db3a3 Mon Sep 17 00:00:00 2001 From: Andrew Koroluk Date: Thu, 27 Jul 2017 14:41:35 -0400 Subject: [PATCH 05/14] stash --- templates/app/client/__index.html | 4 +-- templates/app/client/app/app.component.js | 2 +- templates/app/client/app/app.module.js | 31 ++++++++++++++++--- .../client/components/directives.module.js | 10 ++++-- .../components/navbar/navbar.component.js | 5 +-- .../app/client/components/navbar/navbar.html | 2 +- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/templates/app/client/__index.html b/templates/app/client/__index.html index c934094a7..8b9dacffe 100644 --- a/templates/app/client/__index.html +++ b/templates/app/client/__index.html @@ -1,9 +1,9 @@ + - Angular Full-Stack Generator @@ -27,7 +27,7 @@ LOADING - <% if (filters.ngroute) { %>
<% } %><% if (filters.uirouter) { %>
<% } %> + <% if (filters.ngroute) { %><% } %><% if (filters.uirouter) { %>
<% } %>
diff --git a/templates/app/client/app/app.component.js b/templates/app/client/app/app.component.js index 0a4f290ce..7acc50c2a 100644 --- a/templates/app/client/app/app.component.js +++ b/templates/app/client/app/app.component.js @@ -3,7 +3,7 @@ import { Component } from '@angular/core'; @Component({ selector: 'app', template: ` - + <% if (filters.ngroute) { %><% } %><% if (filters.uirouter) { %><% } %>
` }) export class AppComponent {} diff --git a/templates/app/client/app/app.module.js b/templates/app/client/app/app.module.js index 33eda9b50..58137cc47 100644 --- a/templates/app/client/app/app.module.js +++ b/templates/app/client/app/app.module.js @@ -66,13 +66,16 @@ import { } from '@angularclass/hmr'; <%_ if (filters.uirouter) { -%> import { UIRouterModule } from 'ui-router-ng2';<% } %> +<%_ if (filters.ngroute) { -%> +import { RouterModule, Routes } from '@angular/router';<% } %> import { provideAuth } from 'angular2-jwt'; import { AppComponent } from './app.component'; import { MainModule } from './main/main.module'; +import { MainComponent } from './main/main.component'; import { DirectivesModule } from '../components/directives.module'; -import { AccountModule } from './account/account.module'; -import { AdminModule } from './admin/admin.module'; +//import { AccountModule } from './account/account.module'; +//import { AdminModule } from './admin/admin.module'; import constants from './app.constants'; @@ -95,16 +98,34 @@ if(constants.env === 'development') { providers.push({ provide: RequestOptions, useClass: HttpOptions }); } +const appRoutes: Routes = [ + //{ path: 'crisis-center', component: CrisisListComponent }, + //{ path: 'hero/:id', component: HeroDetailComponent }, + { + path: 'home', + component: MainComponent, + data: { title: 'Home' } + }, + { path: '', + redirectTo: '/home', + pathMatch: 'full' + }, + //{ path: '**', component: PageNotFoundComponent } +]; + @NgModule({ providers, imports: [ BrowserModule, HttpModule, - UIRouterModule.forRoot(), + <%_ if (filters.uirouter) { -%> + UIRouterModule.forRoot(),<% } %> + <%_ if (filters.ngroute) { -%> + RouterModule.forRoot(appRoutes, { enableTracing: true }),<% } %> MainModule, DirectivesModule, - AccountModule, - AdminModule, + //AccountModule, + //AdminModule, ], declarations: [ AppComponent, diff --git a/templates/app/client/components/directives.module.js b/templates/app/client/components/directives.module.js index e67c223b8..6b3e1bfbb 100644 --- a/templates/app/client/components/directives.module.js +++ b/templates/app/client/components/directives.module.js @@ -1,6 +1,9 @@ import { NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; -import { UIRouterModule } from 'ui-router-ng2'; +<%_ if (filters.uirouter) { -%> +import { UIRouterModule } from 'ui-router-ng2';<% } %> +<%_ if (filters.ngroute) { -%> +import { RouterModule, Routes } from '@angular/router';<% } %> import { CollapseModule } from 'ng2-bootstrap'; import { AuthModule } from './auth/auth.module'; @@ -13,7 +16,10 @@ import { OauthButtonsComponent } from './oauth-buttons/oauth-buttons.component'; @NgModule({ imports: [ CommonModule, - UIRouterModule.forChild(), + <%_ if (filters.uirouter) { -%> + UIRouterModule.forChild(),<% } %> + <%_ if (filters.ngroute) { -%> + RouterModule.forChild(),<% } %> CollapseModule, AuthModule, ], diff --git a/templates/app/client/components/navbar/navbar.component.js b/templates/app/client/components/navbar/navbar.component.js index a1e4608fb..ad0998c57 100644 --- a/templates/app/client/components/navbar/navbar.component.js +++ b/templates/app/client/components/navbar/navbar.component.js @@ -1,6 +1,6 @@ import { Component } from '@angular/core'; <%_ if (filters.auth) { -%> - <%_ if (filters.uirouter) { -%> +<%_ if (filters.uirouter) { -%> import { StateService } from 'ui-router-ng2';<% } %> import { AuthService } from '../auth/auth.service';<% } %> @@ -22,7 +22,8 @@ export class NavbarComponent { static parameters = [AuthService<% if(filters.uirouter) { %>, StateService<% } %>]; constructor(authService: AuthService<% if(filters.uirouter) { %>, stateService: StateService<% } %>) { this.AuthService = authService; - this.StateService = stateService; + <%_ if (filters.uirouter) { -%> + this.StateService = stateService;<% } %> this.reset(); diff --git a/templates/app/client/components/navbar/navbar.html b/templates/app/client/components/navbar/navbar.html index 2b4284e55..2be85d3b8 100644 --- a/templates/app/client/components/navbar/navbar.html +++ b/templates/app/client/components/navbar/navbar.html @@ -12,7 +12,7 @@