Skip to content

Commit 789c64c

Browse files
committed
Merge pull request #1318 from kingcody/feature/admin-module
Feature: admin module
2 parents 147ee57 + 618461f commit 789c64c

File tree

9 files changed

+46
-34
lines changed

9 files changed

+46
-34
lines changed

Diff for: app/generator.js

+1
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ export default class Generator extends Base {
375375
if(this.filters.uirouter) angModules.push("'ui.router'");
376376
if(this.filters.uibootstrap) angModules.push("'ui.bootstrap'");
377377
if(this.filters.auth) {
378+
angModules.unshift(`'${this.scriptAppName}.admin'`);
378379
angModules.unshift(`'${this.scriptAppName}.auth'`);
379380
angModules.push("'validation.match'");
380381
}

Diff for: app/templates/_package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"grunt-contrib-jshint": "~0.11.2",
5050
"grunt-contrib-uglify": "^0.9.1",
5151
"grunt-contrib-watch": "~0.6.1",<% if (filters.jade) { %>
52-
"grunt-contrib-jade": "^0.15.0",<% } %><% if (filters.less) { %>
52+
"grunt-contrib-jade": "^0.15.0",
53+
"karma-ng-jade2js-preprocessor": "^0.2.0",<% } %><% if (filters.less) { %>
5354
"grunt-contrib-less": "^1.0.0",<% } %><% if(filters.babel) { %>
5455
"karma-babel-preprocessor": "^5.2.1",<% } %>
5556
"grunt-babel": "~5.0.0",
@@ -97,7 +98,6 @@
9798
"karma-firefox-launcher": "~0.1.6",
9899
"karma-script-launcher": "~0.1.0",
99100
"karma-html2js-preprocessor": "~0.1.0",
100-
"karma-ng-jade2js-preprocessor": "^0.2.0",
101101
"karma-chrome-launcher": "~0.2.0",
102102
"requirejs": "~2.1.11",
103103
"karma-requirejs": "~0.2.2",

Diff for: app/templates/client/app/admin(auth)/admin(html).html

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
<div class="container">
44
<p>The delete user and user index api routes are restricted to users with the 'admin' role.</p>
55
<ul class="list-group">
6-
<li class="list-group-item" ng-repeat="user in users">
6+
<li class="list-group-item" ng-repeat="user in admin.users">
77
<strong>{{user.name}}</strong><br>
88
<span class="text-muted">{{user.email}}</span>
9-
<a ng-click="delete(user)" class="trash"><span class="glyphicon glyphicon-trash pull-right"></span></a>
9+
<a ng-click="admin.delete(user)" class="trash"><span class="glyphicon glyphicon-trash pull-right"></span></a>
1010
</li>
1111
</ul>
1212
</div>

Diff for: app/templates/client/app/admin(auth)/admin(jade).jade

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ navbar
33
p
44
| The delete user and user index api routes are restricted to users with the 'admin' role.
55
ul.list-group
6-
li.list-group-item(ng-repeat='user in users')
6+
li.list-group-item(ng-repeat='user in admin.users')
77
strong {{user.name}}
88
br
99
span.text-muted {{user.email}}
10-
a.trash(ng-click='delete(user)')
10+
a.trash(ng-click='admin.delete(user)')
1111
span.glyphicon.glyphicon-trash.pull-right
+16-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
'use strict';
22

3-
angular.module('<%= scriptAppName %>')
4-
.controller('AdminCtrl', function($scope, $http, Auth, User) {
3+
(function() {
54

5+
class AdminController {
6+
7+
constructor(User) {
68
// Use the User $resource to fetch all users
7-
$scope.users = User.query();
9+
this.users = User.query();
10+
}
11+
12+
delete(user) {
13+
user.$remove();
14+
this.users.splice(this.users.indexOf(user), 1);
15+
}
16+
}
17+
18+
angular.module('<%= scriptAppName %>.admin')
19+
.controller('AdminController', AdminController);
820

9-
$scope.delete = function(user) {
10-
User.remove({ id: user._id });
11-
$scope.users.splice(this.$index, 1);
12-
};
13-
});
21+
})();

Diff for: app/templates/client/app/admin(auth)/admin.module.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
angular.module('<%= scriptAppName %>.admin', [
4+
'<%= scriptAppName %>.auth'<% if (filters.ngroute) { %>,
5+
'ngRoute'<% } if (filters.uirouter) { %>,
6+
'ui.router'<% } %>
7+
]);
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
'use strict';
22

3-
angular.module('<%= scriptAppName %>')
3+
angular.module('<%= scriptAppName %>.admin')
44
<% if (filters.ngroute) { %>.config(function($routeProvider) {
55
$routeProvider
66
.when('/admin', {
77
templateUrl: 'app/admin/admin.html',
8-
controller: 'AdminCtrl',
8+
controller: 'AdminController',
9+
controllerAs: 'admin',
910
authenticate: 'admin'
1011
});
11-
});<% } %><% if (filters.uirouter) { %>.config(function($stateProvider) {
12+
});<% } if (filters.uirouter) { %>.config(function($stateProvider) {
1213
$stateProvider
1314
.state('admin', {
1415
url: '/admin',
1516
templateUrl: 'app/admin/admin.html',
16-
controller: 'AdminCtrl',
17+
controller: 'AdminController',
18+
controllerAs: 'admin',
1719
authenticate: 'admin'
1820
});
1921
});<% } %>

Diff for: app/templates/karma.conf.js

+8-15
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,25 @@ module.exports = function(config) {
2222
// endbower<% if (filters.socketio) { %>
2323
'node_modules/socket.io-client/socket.io.js',<% } %>
2424
'client/app/app.js',
25-
'client/app/**/*.js',
26-
'client/components/**/*.js',
27-
'client/app/**/*.jade',
28-
'client/components/**/*.jade',
29-
'client/app/**/*.html',
30-
'client/components/**/*.html'
25+
'client/{app,components}/**/*.module.js',
26+
'client/{app,components}/**/*.js',
27+
'client/{app,components}/**/*.<%= filters.jade ? '{jade,html}' : 'html' %>'
3128
],
3229

3330
preprocessors: {
34-
'**/*.jade': 'ng-jade2js',
35-
'**/*.html': 'html2js',<% if(filters.babel) { %>
31+
'**/*.html': 'html2js'<% if (filters.jade) { %>,
32+
'**/*.jade': 'ng-jade2js'<% } if (filters.babel) { %>,
3633
'client/{app,components}/**/*.js': 'babel'<% } %>
3734
},
3835

3936
ngHtml2JsPreprocessor: {
4037
stripPrefix: 'client/'
41-
},
38+
},<% if (filters.jade) { %>
4239

4340
ngJade2JsPreprocessor: {
4441
stripPrefix: 'client/'
45-
},
42+
},<% } if (filters.babel) { %>
4643

47-
<% if(filters.babel) { %>
4844
babelPreprocessor: {
4945
options: {
5046
sourceMap: 'inline'
@@ -55,8 +51,7 @@ module.exports = function(config) {
5551
sourceFileName: function (file) {
5652
return file.originalPath;
5753
}
58-
},
59-
<% } %>
54+
},<% } %>
6055

6156
// list of files / patterns to exclude
6257
exclude: [],
@@ -80,7 +75,6 @@ module.exports = function(config) {
8075
// enable / disable watching file and executing tests whenever any file changes
8176
autoWatch: false,
8277

83-
8478
// Start these browsers, currently available:
8579
// - Chrome
8680
// - ChromeCanary
@@ -91,7 +85,6 @@ module.exports = function(config) {
9185
// - IE (only Windows)
9286
browsers: ['PhantomJS'],
9387

94-
9588
// Continuous Integration mode
9689
// if true, it capture browsers, run tests and exit
9790
singleRun: false

Diff for: test/test-file-creation.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ describe('angular-fullstack generator', function () {
267267
'client/app/account/signup/signup.controller.' + script,
268268
'client/app/admin/admin.' + markup,
269269
'client/app/admin/admin.' + stylesheet,
270-
'client/app/admin/admin.' + script,
270+
'client/app/admin/admin.module.' + script,
271+
'client/app/admin/admin.router.' + script,
271272
'client/app/admin/admin.controller.' + script,
272273
'client/components/auth/auth.module.' + script,
273274
'client/components/auth/auth.service.' + script,

0 commit comments

Comments
 (0)