From afc6df1d4d7ad0afb6f38c998f058b22b486bee6 Mon Sep 17 00:00:00 2001 From: Nate Stuyvesant Date: Wed, 1 Feb 2017 00:04:15 -0500 Subject: [PATCH 1/7] fix app: prevent excess sync()s when seeding db Change app.js to seed database in promise chain before startServer, move seeding conditional to seed.js and wrap in function. --- templates/app/server/app.js | 7 +- templates/app/server/config/seed(models).js | 125 ++++++++++---------- 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/templates/app/server/app.js b/templates/app/server/app.js index 7dbbcba9f..ba25f0b5d 100644 --- a/templates/app/server/app.js +++ b/templates/app/server/app.js @@ -10,6 +10,7 @@ mongoose.Promise = require('bluebird');<% } %><% if (filters.sequelize) { %> import sqldb from './sqldb';<% } %> import config from './config/environment'; import http from 'http'; +<% if(filters.models) { %>import seedDatabaseIfNeeded from './config/seed';<% } %> <% if (filters.mongoose) { %> // Connect to MongoDB mongoose.connect(config.mongo.uri, config.mongo.options); @@ -17,11 +18,6 @@ mongoose.connection.on('error', function(err) { console.error('MongoDB connection error: ' + err); process.exit(-1); // eslint-disable-line no-process-exit }); -<% } %><% if(filters.models) { %> -// Populate databases with sample data -if(config.seedDB) { - require('./config/seed'); -} <% } %> // Setup server var app = express(); @@ -43,6 +39,7 @@ function startServer() { <% if(filters.sequelize) { %> sqldb.sequelize.sync() .then(startServer) +<% if(filters.models) { %> .then(seedDatabaseIfNeeded)<% } %> .catch(function(err) { console.log('Server failed to start due to error: %s', err); }); diff --git a/templates/app/server/config/seed(models).js b/templates/app/server/config/seed(models).js index 627aa5a36..cd4f07d33 100644 --- a/templates/app/server/config/seed(models).js +++ b/templates/app/server/config/seed(models).js @@ -6,67 +6,70 @@ 'use strict';<% if (filters.mongooseModels) { %> import Thing from '../api/thing/thing.model';<% if (filters.auth) { %> import User from '../api/user/user.model';<% } %><% } %><% if (filters.sequelizeModels) { %> -import sqldb from '../sqldb'; -var Thing = sqldb.Thing;<% if (filters.auth) { %> -var User = sqldb.User;<% } %><% } %> +import sqldb from '../sqldb';<% } %> +import config from './environment/'; -<% if (filters.mongooseModels) { %>Thing.find({}).remove()<% } - if (filters.sequelizeModels) { %>Thing.sync() - .then(() => { - return Thing.destroy({ where: {} }); - })<% } %> - .then(() => { - <% if (filters.mongooseModels) { %>Thing.create({<% } - if (filters.sequelizeModels) { %>Thing.bulkCreate([{<% } %> - name: 'Development Tools', - info: 'Integration with popular tools such as Webpack, Gulp, Babel, TypeScript, Karma, ' - + 'Mocha, ESLint, Node Inspector, Livereload, Protractor, Pug, ' - + 'Stylus, Sass, and Less.' - }, { - name: 'Server and Client integration', - info: 'Built with a powerful and fun stack: MongoDB, Express, ' - + 'AngularJS, and Node.' - }, { - name: 'Smart Build System', - info: 'Build system ignores `spec` files, allowing you to keep ' - + 'tests alongside code. Automatic injection of scripts and ' - + 'styles into your index.html' - }, { - name: 'Modular Structure', - info: 'Best practice client and server structures allow for more ' - + 'code reusability and maximum scalability' - }, { - name: 'Optimized Build', - info: 'Build process packs up your templates as a single JavaScript ' - + 'payload, minifies your scripts/css/images, and rewrites asset ' - + 'names for caching.' - }, { - name: 'Deployment Ready', - info: 'Easily deploy your app to Heroku or Openshift with the heroku ' - + 'and openshift subgenerators' - <% if (filters.mongooseModels) { %>});<% } - if (filters.sequelizeModels) { %>}]);<% } %> - }); +export default function seedDatabaseIfNeeded() { + if(config.seedDB) { + <% if (filters.sequelizeModels) { %>let Thing = sqldb.Thing;<% if (filters.auth) { %> + let User = sqldb.User;<% } %><% } %> + + <% if (filters.mongooseModels) { %>Thing.find({}).remove()<% } + if (filters.sequelizeModels) { %>return Thing.destroy({ where: {} })<% } %> + .then(() => { + <% if (filters.mongooseModels) { %>Thing.create({<% } + if (filters.sequelizeModels) { %>return Thing.bulkCreate([{<% } %> + name: 'Development Tools', + info: 'Integration with popular tools such as Webpack, Gulp, Babel, TypeScript, Karma, ' + + 'Mocha, ESLint, Node Inspector, Livereload, Protractor, Pug, ' + + 'Stylus, Sass, and Less.' + }, { + name: 'Server and Client integration', + info: 'Built with a powerful and fun stack: MongoDB, Express, ' + + 'AngularJS, and Node.' + }, { + name: 'Smart Build System', + info: 'Build system ignores `spec` files, allowing you to keep ' + + 'tests alongside code. Automatic injection of scripts and ' + + 'styles into your index.html' + }, { + name: 'Modular Structure', + info: 'Best practice client and server structures allow for more ' + + 'code reusability and maximum scalability' + }, { + name: 'Optimized Build', + info: 'Build process packs up your templates as a single JavaScript ' + + 'payload, minifies your scripts/css/images, and rewrites asset ' + + 'names for caching.' + }, { + name: 'Deployment Ready', + info: 'Easily deploy your app to Heroku or Openshift with the heroku ' + + 'and openshift subgenerators' + <% if (filters.mongooseModels) { %>});<% } + if (filters.sequelizeModels) { %>}]);<% } %> + }) + .then(() => console.log('finished populating things')) + .catch(err => console.log('error populating things', err)); <% if (filters.auth) { %> -<% if (filters.mongooseModels) { %>User.find({}).remove()<% } - if (filters.sequelizeModels) { %>User.sync() - .then(() => User.destroy({ where: {} }))<% } %> - .then(() => { - <% if (filters.mongooseModels) { %>User.create({<% } - if (filters.sequelizeModels) { %>User.bulkCreate([{<% } %> - provider: 'local', - name: 'Test User', - email: 'test@example.com', - password: 'test' - }, { - provider: 'local', - role: 'admin', - name: 'Admin', - email: 'admin@example.com', - password: 'admin' - <% if (filters.mongooseModels) { %>})<% } - if (filters.sequelizeModels) { %>}])<% } %> - .then(() => { - console.log('finished populating users'); + <% if (filters.mongooseModels) { %>User.find({}).remove()<% } + if (filters.sequelizeModels) { %>User.destroy({ where: {} })<% } %> + .then(() => { + <% if (filters.mongooseModels) { %>User.create({<% } + if (filters.sequelizeModels) { %>return User.bulkCreate([{<% } %> + provider: 'local', + name: 'Test User', + email: 'test@example.com', + password: 'test' + }, { + provider: 'local', + role: 'admin', + name: 'Admin', + email: 'admin@example.com', + password: 'admin' + <% if (filters.mongooseModels) { %>})<% } + if (filters.sequelizeModels) { %>}])<% } %> + .then(() => console.log('finished populating users')) + .catch(err => console.log('error populating users', err));<% } %> }); - });<% } %> + } +} From 42ec90a543ac2dd40001fa5fb6a239b924f39af1 Mon Sep 17 00:00:00 2001 From: Nate Stuyvesant Date: Wed, 1 Feb 2017 00:13:50 -0500 Subject: [PATCH 2/7] fix (app): prevent excess sync() calls during db seed Previously, .sync() was being called once in server/config/seed.js and once during sqldb.sequelize.sync() in server/app.js. As a result, duplicate queries were being sent to the database if the tables needed to be defined causing an error when it tries to define constraints a second time (like for an identity column). Seed.js is wrapped in a function and contains the conditional to determine whether to seed the database. This makes it easy to include in the promise chain under sqldb.sequelize.sync(). --- templates/app/server/app.js | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/app/server/app.js b/templates/app/server/app.js index ba25f0b5d..82d630da5 100644 --- a/templates/app/server/app.js +++ b/templates/app/server/app.js @@ -44,6 +44,7 @@ sqldb.sequelize.sync() console.log('Server failed to start due to error: %s', err); }); <% } else { %> +seedDatabaseIfNeeded(); setImmediate(startServer); <% } %> // Expose app From d0fad3ef876f0d0d43eb1c7271e7b1387b657e71 Mon Sep 17 00:00:00 2001 From: Nate Stuyvesant Date: Wed, 1 Feb 2017 00:23:13 -0500 Subject: [PATCH 3/7] fix (app): prevent excess sync() calls during seed Previously, .sync() was being called once in server/config/seed.js and once during sqldb.sequelize.sync() in server/app.js. As a result, duplicate queries were being sent to the database if the tables needed to be defined causing an error when it tries to define constraints a second time (like for an identity column). Seed.js is wrapped in a function and contains the conditional to determine whether to seed the database. This makes it easy to include in the promise chain under sqldb.sequelize.sync(). --- templates/app/server/app.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/app/server/app.js b/templates/app/server/app.js index 82d630da5..88b97fb0f 100644 --- a/templates/app/server/app.js +++ b/templates/app/server/app.js @@ -37,14 +37,14 @@ function startServer() { }); } <% if(filters.sequelize) { %> -sqldb.sequelize.sync() +sqldb.sequelize.sync()<% if(filters.models) { %> + .then(seedDatabaseIfNeeded)<% } %> .then(startServer) -<% if(filters.models) { %> .then(seedDatabaseIfNeeded)<% } %> .catch(function(err) { console.log('Server failed to start due to error: %s', err); }); -<% } else { %> -seedDatabaseIfNeeded(); +<% } else { %><% if(filters.models) { %> +seedDatabaseIfNeeded();<% } %> setImmediate(startServer); <% } %> // Expose app From 9473d8158481b304868ccce2e8e393abf78b0d5e Mon Sep 17 00:00:00 2001 From: Nate Stuyvesant Date: Sun, 5 Feb 2017 12:45:26 -0500 Subject: [PATCH 4/7] refactor(admin): convert to component Previously, admin was implemented as a loosely coupled controller. Converting it to a full component makes it consistent with main and generated components. --- src/test/get-expected-files.js | 2 +- .../app/client/app/admin(auth)/admin(html).html | 4 ++-- .../app/client/app/admin(auth)/admin(pug).pug | 4 ++-- .../app/client/app/admin(auth)/admin.component.js | 14 ++++++++++++++ .../app/client/app/admin(auth)/admin.controller.js | 7 +++++-- .../app/client/app/admin(auth)/admin.routes.js | 8 ++------ templates/app/client/app/admin(auth)/index.js | 13 ------------- templates/app/client/app/app.js | 2 +- 8 files changed, 27 insertions(+), 27 deletions(-) create mode 100644 templates/app/client/app/admin(auth)/admin.component.js delete mode 100644 templates/app/client/app/admin(auth)/index.js diff --git a/src/test/get-expected-files.js b/src/test/get-expected-files.js index 70b4bfc9c..000ce03fa 100644 --- a/src/test/get-expected-files.js +++ b/src/test/get-expected-files.js @@ -176,7 +176,7 @@ export function app(options) { 'client/app/account/signup/signup.' + markup, 'client/app/account/signup/index.' + script, 'client/app/account/signup/signup.controller.' + script, - 'client/app/admin/index.' + script, + 'client/app/admin/admin.component.' + script, 'client/app/admin/admin.' + markup, 'client/app/admin/admin.' + stylesheet, 'client/app/admin/admin.controller.' + script, diff --git a/templates/app/client/app/admin(auth)/admin(html).html b/templates/app/client/app/admin(auth)/admin(html).html index cbbe68a40..be4ab13e0 100644 --- a/templates/app/client/app/admin(auth)/admin(html).html +++ b/templates/app/client/app/admin(auth)/admin(html).html @@ -1,12 +1,12 @@

The delete user and user index api routes are restricted to users with the 'admin' role.

    -
  • +
  • - +
diff --git a/templates/app/client/app/admin(auth)/admin(pug).pug b/templates/app/client/app/admin(auth)/admin(pug).pug index 7da628335..bd77ccbb9 100644 --- a/templates/app/client/app/admin(auth)/admin(pug).pug +++ b/templates/app/client/app/admin(auth)/admin(pug).pug @@ -2,9 +2,9 @@ p | The delete user and user index api routes are restricted to users with the 'admin' role. ul.list-group - li.list-group-item(ng-repeat='user in admin.users') + li.list-group-item(ng-repeat='user in $ctrl.users') strong {{user.name}} br span.text-muted {{user.email}} - a.trash(ng-click='admin.delete(user)') + a.trash(ng-click='$ctrl.delete(user)') span.glyphicon.glyphicon-trash.pull-right diff --git a/templates/app/client/app/admin(auth)/admin.component.js b/templates/app/client/app/admin(auth)/admin.component.js new file mode 100644 index 000000000..527a8c6db --- /dev/null +++ b/templates/app/client/app/admin(auth)/admin.component.js @@ -0,0 +1,14 @@ +'use strict'; +import angular from 'angular';<% if (filters.uirouter) { %> +import uiRouter from 'angular-ui-router';<% } %> +import routes from './admin.routes'; +import AdminController from './admin.controller'; + +export default angular.module('<%= scriptAppName %>.admin', ['<%= scriptAppName %>.auth'<% if (filters.ngroute) { %>, + 'ngRoute'<% } if (filters.uirouter) { %>, uiRouter<% } %>]) + .config(routes) + .component('admin', { + template: require('./admin.<%= templateExt %>'), + controller: AdminController + }) + .name; diff --git a/templates/app/client/app/admin(auth)/admin.controller.js b/templates/app/client/app/admin(auth)/admin.controller.js index afb2e557b..be9341450 100644 --- a/templates/app/client/app/admin(auth)/admin.controller.js +++ b/templates/app/client/app/admin(auth)/admin.controller.js @@ -7,8 +7,11 @@ export default class AdminController { <%_ } _%> /*@ngInject*/ constructor(User) { - // Use the User $resource to fetch all users - this.users = User.query(); + this.User = User; + } + + $onInit() { + this.users = this.User.query(); // Fetch all users } delete(user) { diff --git a/templates/app/client/app/admin(auth)/admin.routes.js b/templates/app/client/app/admin(auth)/admin.routes.js index 24114892e..6b04e3b74 100644 --- a/templates/app/client/app/admin(auth)/admin.routes.js +++ b/templates/app/client/app/admin(auth)/admin.routes.js @@ -5,9 +5,7 @@ export default function routes($routeProvider) { 'ngInject'; $routeProvider .when('/admin', { - template: require('./admin.<%= templateExt %>'), - controller: 'AdminController', - controllerAs: 'admin', + template: '', authenticate: 'admin' }); };<% } %> @@ -17,9 +15,7 @@ export default function routes($stateProvider) { $stateProvider .state('admin', { url: '/admin', - template: require('./admin.<%= templateExt %>'), - controller: 'AdminController', - controllerAs: 'admin', + template: '', authenticate: 'admin' }); };<% } %> diff --git a/templates/app/client/app/admin(auth)/index.js b/templates/app/client/app/admin(auth)/index.js deleted file mode 100644 index 72422ea8f..000000000 --- a/templates/app/client/app/admin(auth)/index.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; -import angular from 'angular'; -import routes from './admin.routes'; -import AdminController from './admin.controller'; - -export default angular.module('<%= scriptAppName %>.admin', [ - '<%= scriptAppName %>.auth'<% if (filters.ngroute) { %>, - 'ngRoute'<% } if (filters.uirouter) { %>, - 'ui.router'<% } %> -]) - .config(routes) - .controller('AdminController', AdminController) - .name; diff --git a/templates/app/client/app/app.js b/templates/app/client/app/app.js index 2937399dd..f5c751288 100644 --- a/templates/app/client/app/app.js +++ b/templates/app/client/app/app.js @@ -22,7 +22,7 @@ import {routeConfig} from './app.config'; <%_ if(filters.auth) { _%> import _Auth from '../components/auth/auth.module'; import account from './account'; -import admin from './admin';<% } %> +import admin from './admin/admin.component';<% } %> import navbar from '../components/navbar/navbar.component'; import footer from '../components/footer/footer.component'; import main from './main/main.component'; From f6da78f5e12512e305b9220c1e44390fd75aef39 Mon Sep 17 00:00:00 2001 From: Nate Stuyvesant Date: Sun, 5 Feb 2017 23:21:14 -0500 Subject: [PATCH 5/7] fix(server:seed): user seed not executing For projects with auth=Y, users were not being populated for those using Sequelize because of the return on Think.bulkCreate. The return was changed to a Sequelize.Promise.all so that all the promises are properly managed. --- templates/app/server/config/seed(models).js | 115 ++++++++++---------- 1 file changed, 56 insertions(+), 59 deletions(-) diff --git a/templates/app/server/config/seed(models).js b/templates/app/server/config/seed(models).js index cd4f07d33..9310a6346 100644 --- a/templates/app/server/config/seed(models).js +++ b/templates/app/server/config/seed(models).js @@ -6,70 +6,67 @@ 'use strict';<% if (filters.mongooseModels) { %> import Thing from '../api/thing/thing.model';<% if (filters.auth) { %> import User from '../api/user/user.model';<% } %><% } %><% if (filters.sequelizeModels) { %> -import sqldb from '../sqldb';<% } %> +import { Thing<% if (filters.auth) { %>, User<% } %> } from '../sqldb';<% if (filters.auth) { %> +import Sequelize from 'sequelize';<% } %><% } %> import config from './environment/'; export default function seedDatabaseIfNeeded() { if(config.seedDB) { - <% if (filters.sequelizeModels) { %>let Thing = sqldb.Thing;<% if (filters.auth) { %> - let User = sqldb.User;<% } %><% } %> - <% if (filters.mongooseModels) { %>Thing.find({}).remove()<% } - if (filters.sequelizeModels) { %>return Thing.destroy({ where: {} })<% } %> - .then(() => { - <% if (filters.mongooseModels) { %>Thing.create({<% } - if (filters.sequelizeModels) { %>return Thing.bulkCreate([{<% } %> - name: 'Development Tools', - info: 'Integration with popular tools such as Webpack, Gulp, Babel, TypeScript, Karma, ' - + 'Mocha, ESLint, Node Inspector, Livereload, Protractor, Pug, ' - + 'Stylus, Sass, and Less.' - }, { - name: 'Server and Client integration', - info: 'Built with a powerful and fun stack: MongoDB, Express, ' - + 'AngularJS, and Node.' - }, { - name: 'Smart Build System', - info: 'Build system ignores `spec` files, allowing you to keep ' - + 'tests alongside code. Automatic injection of scripts and ' - + 'styles into your index.html' - }, { - name: 'Modular Structure', - info: 'Best practice client and server structures allow for more ' - + 'code reusability and maximum scalability' - }, { - name: 'Optimized Build', - info: 'Build process packs up your templates as a single JavaScript ' - + 'payload, minifies your scripts/css/images, and rewrites asset ' - + 'names for caching.' - }, { - name: 'Deployment Ready', - info: 'Easily deploy your app to Heroku or Openshift with the heroku ' - + 'and openshift subgenerators' - <% if (filters.mongooseModels) { %>});<% } - if (filters.sequelizeModels) { %>}]);<% } %> - }) - .then(() => console.log('finished populating things')) - .catch(err => console.log('error populating things', err)); -<% if (filters.auth) { %> + if (filters.sequelizeModels) { %>return <% if (filters.auth) { %>Sequelize.Promise.all([ + <% } %>Thing.destroy({ where: {} })<% } %> + .then(() =><% if (filters.mongooseModels) { %> { + Thing.create({<% } if (filters.sequelizeModels) { %> + Thing.bulkCreate([{<% } %> + name: 'Development Tools', + info: 'Integration with popular tools such as Webpack, Gulp, Babel, TypeScript, Karma, ' + + 'Mocha, ESLint, Node Inspector, Livereload, Protractor, Pug, ' + + 'Stylus, Sass, and Less.' + }, { + name: 'Server and Client integration', + info: 'Built with a powerful and fun stack: MongoDB, Express, ' + + 'AngularJS, and Node.' + }, { + name: 'Smart Build System', + info: 'Build system ignores `spec` files, allowing you to keep ' + + 'tests alongside code. Automatic injection of scripts and ' + + 'styles into your index.html' + }, { + name: 'Modular Structure', + info: 'Best practice client and server structures allow for more ' + + 'code reusability and maximum scalability' + }, { + name: 'Optimized Build', + info: 'Build process packs up your templates as a single JavaScript ' + + 'payload, minifies your scripts/css/images, and rewrites asset ' + + 'names for caching.' + }, { + name: 'Deployment Ready', + info: 'Easily deploy your app to Heroku or Openshift with the heroku ' + + 'and openshift subgenerators' + }<% if (filters.sequelizeModels) { %>]<% } %>)<% if (filters.mongooseModels) { %>; + }<% } %>) + .then(() => console.log('seeded things'))<% if (filters.sequelizeModels && filters.auth) { %>,<% } if (filters.auth) { %> <% if (filters.mongooseModels) { %>User.find({}).remove()<% } - if (filters.sequelizeModels) { %>User.destroy({ where: {} })<% } %> - .then(() => { - <% if (filters.mongooseModels) { %>User.create({<% } - if (filters.sequelizeModels) { %>return User.bulkCreate([{<% } %> - provider: 'local', - name: 'Test User', - email: 'test@example.com', - password: 'test' - }, { - provider: 'local', - role: 'admin', - name: 'Admin', - email: 'admin@example.com', - password: 'admin' - <% if (filters.mongooseModels) { %>})<% } - if (filters.sequelizeModels) { %>}])<% } %> - .then(() => console.log('finished populating users')) - .catch(err => console.log('error populating users', err));<% } %> - }); + if (filters.sequelizeModels) { %> User.destroy({ where: {} })<% } %> + .then(() =><% if (filters.mongooseModels) { %> {<% } %> + <% if (filters.mongooseModels) { %>User.create({<% } + if (filters.sequelizeModels) { %>User.bulkCreate([{<% } %> + provider: 'local', + name: 'Test User', + email: 'test@example.com', + password: 'test' + }, { + provider: 'local', + role: 'admin', + name: 'Admin', + email: 'admin@example.com', + password: 'admin' + }<% if (filters.mongooseModels) { %>); + })<% } + if (filters.sequelizeModels) { %>])<% } %> + .then(() => console.log('seeded users'))<% if (filters.sequelizeModels) { %>)]) + .then(() => console.log('seeded database'))<% } %><% } %> + <% if (filters.sequelizeModels && !filters.auth) { %> <% } %><% if (filters.mongooseModels) { %> <% } %>.catch(err => console.log('Seeding error: ', err)); } } From f938a24a2d1884e75bd533e2c93883f2735cd6db Mon Sep 17 00:00:00 2001 From: Nate Stuyvesant Date: Tue, 7 Feb 2017 21:47:42 -0500 Subject: [PATCH 6/7] refactor(admin): convert to component Previously, admin was implemented as a loosely coupled controller. Converting it to a full component makes it consistent with main and generated components. --- src/test/get-expected-files.js | 1 - .../client/app/admin(auth)/admin.component.js | 21 ++++++++++++++++++- .../app/admin(auth)/admin.controller.js | 21 ------------------- 3 files changed, 20 insertions(+), 23 deletions(-) delete mode 100644 templates/app/client/app/admin(auth)/admin.controller.js diff --git a/src/test/get-expected-files.js b/src/test/get-expected-files.js index 000ce03fa..f76d97491 100644 --- a/src/test/get-expected-files.js +++ b/src/test/get-expected-files.js @@ -179,7 +179,6 @@ export function app(options) { 'client/app/admin/admin.component.' + script, 'client/app/admin/admin.' + markup, 'client/app/admin/admin.' + stylesheet, - 'client/app/admin/admin.controller.' + script, 'client/app/admin/admin.routes.' + script, 'client/components/auth/auth.module.' + script, 'client/components/auth/auth.service.' + script, diff --git a/templates/app/client/app/admin(auth)/admin.component.js b/templates/app/client/app/admin(auth)/admin.component.js index 527a8c6db..4d17dde66 100644 --- a/templates/app/client/app/admin(auth)/admin.component.js +++ b/templates/app/client/app/admin(auth)/admin.component.js @@ -2,7 +2,26 @@ import angular from 'angular';<% if (filters.uirouter) { %> import uiRouter from 'angular-ui-router';<% } %> import routes from './admin.routes'; -import AdminController from './admin.controller'; + +export class AdminController { + <%_ if(filters.ts || filters.flow) { _%> + users: Object[]; + + <%_ } _%> + /*@ngInject*/ + constructor(User) { + this.User = User; + } + + $onInit() { + this.users = this.User.query(); // Fetch all users + } + + delete(user) { + user.$remove(); + this.users.splice(this.users.indexOf(user), 1); + } +} export default angular.module('<%= scriptAppName %>.admin', ['<%= scriptAppName %>.auth'<% if (filters.ngroute) { %>, 'ngRoute'<% } if (filters.uirouter) { %>, uiRouter<% } %>]) diff --git a/templates/app/client/app/admin(auth)/admin.controller.js b/templates/app/client/app/admin(auth)/admin.controller.js deleted file mode 100644 index be9341450..000000000 --- a/templates/app/client/app/admin(auth)/admin.controller.js +++ /dev/null @@ -1,21 +0,0 @@ -'use strict'; - -export default class AdminController { - <%_ if(filters.ts || filters.flow) { _%> - users: Object[]; - - <%_ } _%> - /*@ngInject*/ - constructor(User) { - this.User = User; - } - - $onInit() { - this.users = this.User.query(); // Fetch all users - } - - delete(user) { - user.$remove(); - this.users.splice(this.users.indexOf(user), 1); - } -} From c4cb5618d264ed6991f705829487c92be129b902 Mon Sep 17 00:00:00 2001 From: Nate Stuyvesant Date: Tue, 21 Mar 2017 22:47:35 -0400 Subject: [PATCH 7/7] undo(server:seed): user seed not executing --- templates/app/server/config/seed(models).js | 115 ++++++++++---------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/templates/app/server/config/seed(models).js b/templates/app/server/config/seed(models).js index 9310a6346..cd4f07d33 100644 --- a/templates/app/server/config/seed(models).js +++ b/templates/app/server/config/seed(models).js @@ -6,67 +6,70 @@ 'use strict';<% if (filters.mongooseModels) { %> import Thing from '../api/thing/thing.model';<% if (filters.auth) { %> import User from '../api/user/user.model';<% } %><% } %><% if (filters.sequelizeModels) { %> -import { Thing<% if (filters.auth) { %>, User<% } %> } from '../sqldb';<% if (filters.auth) { %> -import Sequelize from 'sequelize';<% } %><% } %> +import sqldb from '../sqldb';<% } %> import config from './environment/'; export default function seedDatabaseIfNeeded() { if(config.seedDB) { + <% if (filters.sequelizeModels) { %>let Thing = sqldb.Thing;<% if (filters.auth) { %> + let User = sqldb.User;<% } %><% } %> + <% if (filters.mongooseModels) { %>Thing.find({}).remove()<% } - if (filters.sequelizeModels) { %>return <% if (filters.auth) { %>Sequelize.Promise.all([ - <% } %>Thing.destroy({ where: {} })<% } %> - .then(() =><% if (filters.mongooseModels) { %> { - Thing.create({<% } if (filters.sequelizeModels) { %> - Thing.bulkCreate([{<% } %> - name: 'Development Tools', - info: 'Integration with popular tools such as Webpack, Gulp, Babel, TypeScript, Karma, ' - + 'Mocha, ESLint, Node Inspector, Livereload, Protractor, Pug, ' - + 'Stylus, Sass, and Less.' - }, { - name: 'Server and Client integration', - info: 'Built with a powerful and fun stack: MongoDB, Express, ' - + 'AngularJS, and Node.' - }, { - name: 'Smart Build System', - info: 'Build system ignores `spec` files, allowing you to keep ' - + 'tests alongside code. Automatic injection of scripts and ' - + 'styles into your index.html' - }, { - name: 'Modular Structure', - info: 'Best practice client and server structures allow for more ' - + 'code reusability and maximum scalability' - }, { - name: 'Optimized Build', - info: 'Build process packs up your templates as a single JavaScript ' - + 'payload, minifies your scripts/css/images, and rewrites asset ' - + 'names for caching.' - }, { - name: 'Deployment Ready', - info: 'Easily deploy your app to Heroku or Openshift with the heroku ' - + 'and openshift subgenerators' - }<% if (filters.sequelizeModels) { %>]<% } %>)<% if (filters.mongooseModels) { %>; - }<% } %>) - .then(() => console.log('seeded things'))<% if (filters.sequelizeModels && filters.auth) { %>,<% } if (filters.auth) { %> + if (filters.sequelizeModels) { %>return Thing.destroy({ where: {} })<% } %> + .then(() => { + <% if (filters.mongooseModels) { %>Thing.create({<% } + if (filters.sequelizeModels) { %>return Thing.bulkCreate([{<% } %> + name: 'Development Tools', + info: 'Integration with popular tools such as Webpack, Gulp, Babel, TypeScript, Karma, ' + + 'Mocha, ESLint, Node Inspector, Livereload, Protractor, Pug, ' + + 'Stylus, Sass, and Less.' + }, { + name: 'Server and Client integration', + info: 'Built with a powerful and fun stack: MongoDB, Express, ' + + 'AngularJS, and Node.' + }, { + name: 'Smart Build System', + info: 'Build system ignores `spec` files, allowing you to keep ' + + 'tests alongside code. Automatic injection of scripts and ' + + 'styles into your index.html' + }, { + name: 'Modular Structure', + info: 'Best practice client and server structures allow for more ' + + 'code reusability and maximum scalability' + }, { + name: 'Optimized Build', + info: 'Build process packs up your templates as a single JavaScript ' + + 'payload, minifies your scripts/css/images, and rewrites asset ' + + 'names for caching.' + }, { + name: 'Deployment Ready', + info: 'Easily deploy your app to Heroku or Openshift with the heroku ' + + 'and openshift subgenerators' + <% if (filters.mongooseModels) { %>});<% } + if (filters.sequelizeModels) { %>}]);<% } %> + }) + .then(() => console.log('finished populating things')) + .catch(err => console.log('error populating things', err)); +<% if (filters.auth) { %> <% if (filters.mongooseModels) { %>User.find({}).remove()<% } - if (filters.sequelizeModels) { %> User.destroy({ where: {} })<% } %> - .then(() =><% if (filters.mongooseModels) { %> {<% } %> - <% if (filters.mongooseModels) { %>User.create({<% } - if (filters.sequelizeModels) { %>User.bulkCreate([{<% } %> - provider: 'local', - name: 'Test User', - email: 'test@example.com', - password: 'test' - }, { - provider: 'local', - role: 'admin', - name: 'Admin', - email: 'admin@example.com', - password: 'admin' - }<% if (filters.mongooseModels) { %>); - })<% } - if (filters.sequelizeModels) { %>])<% } %> - .then(() => console.log('seeded users'))<% if (filters.sequelizeModels) { %>)]) - .then(() => console.log('seeded database'))<% } %><% } %> - <% if (filters.sequelizeModels && !filters.auth) { %> <% } %><% if (filters.mongooseModels) { %> <% } %>.catch(err => console.log('Seeding error: ', err)); + if (filters.sequelizeModels) { %>User.destroy({ where: {} })<% } %> + .then(() => { + <% if (filters.mongooseModels) { %>User.create({<% } + if (filters.sequelizeModels) { %>return User.bulkCreate([{<% } %> + provider: 'local', + name: 'Test User', + email: 'test@example.com', + password: 'test' + }, { + provider: 'local', + role: 'admin', + name: 'Admin', + email: 'admin@example.com', + password: 'admin' + <% if (filters.mongooseModels) { %>})<% } + if (filters.sequelizeModels) { %>}])<% } %> + .then(() => console.log('finished populating users')) + .catch(err => console.log('error populating users', err));<% } %> + }); } }