Skip to content

Commit 71f80ce

Browse files
committed
Merge pull request #351 from chester1000/client-coffee-clenup
style(app:client:coffee) client-side cleanup of .coffee files
2 parents eb7d50c + afe6d57 commit 71f80ce

16 files changed

+186
-170
lines changed
+33-33
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
'use strict'
22

3-
angular.module('<%= scriptAppName %>')
4-
<% if(filters.ngroute) { %>.config ($routeProvider) ->
5-
$routeProvider
6-
.when('/login',
7-
templateUrl: 'app/account/login/login.html'
8-
controller: 'LoginCtrl'
9-
)
10-
.when('/signup',
11-
templateUrl: 'app/account/signup/signup.html'
12-
controller: 'SignupCtrl'
13-
)
14-
.when('/settings',
15-
templateUrl: 'app/account/settings/settings.html'
16-
controller: 'SettingsCtrl',
17-
authenticate: true
18-
)<% } %><% if(filters.uirouter) { %>.config ($stateProvider) ->
19-
$stateProvider
20-
.state('login',
21-
url: '/login',
22-
templateUrl: 'app/account/login/login.html'
23-
controller: 'LoginCtrl'
24-
)
25-
.state('signup',
26-
url: '/signup',
27-
templateUrl: 'app/account/signup/signup.html'
28-
controller: 'SignupCtrl'
29-
)
30-
.state('settings',
31-
url: '/settings',
32-
templateUrl: 'app/account/settings/settings.html'
33-
controller: 'SettingsCtrl',
34-
authenticate: true
35-
)<% } %>
3+
angular.module '<%= scriptAppName %>'
4+
<% if(filters.ngroute) { %>.config ($routeProvider) ->
5+
$routeProvider
6+
.when '/login',
7+
templateUrl: 'app/account/login/login.html'
8+
controller: 'LoginCtrl'
9+
10+
.when '/signup',
11+
templateUrl: 'app/account/signup/signup.html'
12+
controller: 'SignupCtrl'
13+
14+
.when '/settings',
15+
templateUrl: 'app/account/settings/settings.html'
16+
controller: 'SettingsCtrl'
17+
authenticate: true
18+
<% } %><% if(filters.uirouter) { %>.config ($stateProvider) ->
19+
$stateProvider
20+
.state 'login',
21+
url: '/login'
22+
templateUrl: 'app/account/login/login.html'
23+
controller: 'LoginCtrl'
24+
25+
.state 'signup',
26+
url: '/signup'
27+
templateUrl: 'app/account/signup/signup.html'
28+
controller: 'SignupCtrl'
29+
30+
.state 'settings',
31+
url: '/settings'
32+
templateUrl: 'app/account/settings/settings.html'
33+
controller: 'SettingsCtrl'
34+
authenticate: true
35+
<% } %>

Diff for: app/templates/client/app/account(auth)/login/login.controller(coffee).coffee

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
'use strict'
22

3-
angular.module('<%= scriptAppName %>').controller 'LoginCtrl', ($scope, Auth, $location, $window) ->
3+
angular.module '<%= scriptAppName %>'
4+
.controller 'LoginCtrl', ($scope, Auth, $location, $window) ->
45
$scope.user = {}
56
$scope.errors = {}
67
$scope.login = (form) ->
78
$scope.submitted = true
89

910
if form.$valid
1011
# Logged in, redirect to home
11-
Auth.login(
12+
Auth.login
1213
email: $scope.user.email
1314
password: $scope.user.password
14-
).then(->
15+
16+
.then ->
1517
$location.path '/'
16-
).catch (err) ->
18+
19+
.catch (err) ->
1720
$scope.errors.other = err.message
1821

1922
$scope.loginOauth = (provider) ->
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
'use strict'
22

3-
angular.module('<%= scriptAppName %>').controller 'SettingsCtrl', ($scope, User, Auth) ->
3+
angular.module '<%= scriptAppName %>'
4+
.controller 'SettingsCtrl', ($scope, User, Auth) ->
45
$scope.errors = {}
56
$scope.changePassword = (form) ->
67
$scope.submitted = true
78

89
if form.$valid
9-
Auth.changePassword($scope.user.oldPassword, $scope.user.newPassword).then(->
10+
Auth.changePassword $scope.user.oldPassword, $scope.user.newPassword
11+
.then ->
1012
$scope.message = 'Password successfully changed.'
11-
).catch ->
13+
14+
.catch ->
1215
form.password.$setValidity 'mongoose', false
1316
$scope.errors.other = 'Incorrect password'
1417
$scope.message = ''

Diff for: app/templates/client/app/account(auth)/signup/signup.controller(coffee).coffee

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
'use strict'
22

3-
angular.module('<%= scriptAppName %>').controller 'SignupCtrl', ($scope, Auth, $location, $window) ->
3+
angular.module '<%= scriptAppName %>'
4+
.controller 'SignupCtrl', ($scope, Auth, $location, $window) ->
45
$scope.user = {}
56
$scope.errors = {}
67
$scope.register = (form) ->
78
$scope.submitted = true
89

910
if form.$valid
1011
# Account created, redirect to home
11-
Auth.createUser(
12+
Auth.createUser
1213
name: $scope.user.name
1314
email: $scope.user.email
1415
password: $scope.user.password
15-
).then(->
16+
17+
.then ->
1618
$location.path '/'
1719

18-
).catch (err) ->
20+
.catch (err) ->
1921
err = err.data
2022
$scope.errors = {}
2123

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use strict'
22

3-
angular.module('<%= scriptAppName %>')
4-
<% if(filters.ngroute) { %>.config ($routeProvider) ->
5-
$routeProvider
6-
.when('/admin',
7-
templateUrl: 'app/admin/admin.html'
8-
controller: 'AdminCtrl'
9-
)<% } %><% if(filters.uirouter) { %>.config ($stateProvider) ->
10-
$stateProvider
11-
.state('admin',
12-
url: '/admin',
13-
templateUrl: 'app/admin/admin.html'
14-
controller: 'AdminCtrl'
15-
)<% } %>
3+
angular.module '<%= scriptAppName %>'
4+
<% if(filters.ngroute) { %>.config ($routeProvider) ->
5+
$routeProvider
6+
.when '/admin',
7+
templateUrl: 'app/admin/admin.html'
8+
controller: 'AdminCtrl'
9+
<% } %><% if(filters.uirouter) { %>.config ($stateProvider) ->
10+
$stateProvider
11+
.state 'admin',
12+
url: '/admin'
13+
templateUrl: 'app/admin/admin.html'
14+
controller: 'AdminCtrl'
15+
<% } %>
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
'use strict'
22

3-
angular.module('<%= scriptAppName %>').controller 'AdminCtrl', ($scope, $http, Auth, User) ->
4-
$http.get('/api/users').success (users) ->
3+
angular.module '<%= scriptAppName %>'
4+
.controller 'AdminCtrl', ($scope, $http, Auth, User) ->
5+
6+
$http.get '/api/users'
7+
.success (users) ->
58
$scope.users = users
69

710
$scope.delete = (user) ->
811
User.remove id: user._id
912
angular.forEach $scope.users, (u, i) ->
10-
$scope.users.splice i, 1 if u is user
13+
$scope.users.splice i, 1 if u is user

Diff for: app/templates/client/app/app(coffee).coffee

+34-35
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
'use strict'
22

3-
angular.module('<%= scriptAppName %>', [<%= angularModules %>])
4-
<% if(filters.ngroute) { %>.config (($routeProvider, $locationProvider<% if(filters.auth) { %>, $httpProvider<% } %>) ->
5-
$routeProvider
6-
.otherwise
7-
redirectTo: '/'
3+
angular.module '<%= scriptAppName %>', [<%= angularModules %>]
4+
<% if(filters.ngroute) { %>.config ($routeProvider, $locationProvider<% if(filters.auth) { %>, $httpProvider<% } %>) ->
5+
$routeProvider
6+
.otherwise
7+
redirectTo: '/'
88

9-
$locationProvider.html5Mode true<% if(filters.auth) { %>
10-
$httpProvider.interceptors.push 'authInterceptor'<% } %>
11-
)<% } %><% if(filters.uirouter) { %>.config (($stateProvider, $urlRouterProvider, $locationProvider<% if(filters.auth) { %>, $httpProvider<% } %>) ->
12-
$urlRouterProvider
13-
.otherwise('/')
9+
$locationProvider.html5Mode true<% if(filters.auth) { %>
10+
$httpProvider.interceptors.push 'authInterceptor'<% } %>
11+
<% } %><% if(filters.uirouter) { %>.config ($stateProvider, $urlRouterProvider, $locationProvider<% if(filters.auth) { %>, $httpProvider<% } %>) ->
12+
$urlRouterProvider
13+
.otherwise '/'
1414

15-
$locationProvider.html5Mode true<% if(filters.auth) { %>
16-
$httpProvider.interceptors.push 'authInterceptor'<% } %>
17-
)<% } %><% if(filters.auth) { %>
18-
.factory('authInterceptor', ($rootScope, $q, $cookieStore, $location) ->
19-
# Add authorization token to headers
20-
request: (config) ->
21-
config.headers = config.headers or {}
22-
config.headers.Authorization = 'Bearer ' + $cookieStore.get('token') if $cookieStore.get('token')
23-
config
15+
$locationProvider.html5Mode true<% if(filters.auth) { %>
16+
$httpProvider.interceptors.push 'authInterceptor'<% } %>
17+
<% } %><% if(filters.auth) { %>
18+
.factory 'authInterceptor', ($rootScope, $q, $cookieStore, $location) ->
19+
# Add authorization token to headers
20+
request: (config) ->
21+
config.headers = config.headers or {}
22+
config.headers.Authorization = 'Bearer ' + $cookieStore.get 'token' if $cookieStore.get 'token'
23+
config
2424

25-
# Intercept 401s and redirect you to login
26-
responseError: (response) ->
27-
if response.status is 401
28-
$location.path '/login'
29-
# remove any stale tokens
30-
$cookieStore.remove 'token'
31-
$q.reject response
32-
else
33-
$q.reject response
34-
)
35-
.run (($rootScope, $location, Auth) ->
36-
# Redirect to login if route requires auth and you're not logged in
37-
$rootScope.$on <% if(filters.ngroute) { %>'$routeChangeStart'<% } %><% if(filters.uirouter) { %>'$stateChangeStart'<% } %>, (event, next) ->
38-
Auth.isLoggedInAsync (loggedIn) ->
39-
$location.path "/login" if next.authenticate and not loggedIn
40-
)<% } %>
25+
# Intercept 401s and redirect you to login
26+
responseError: (response) ->
27+
if response.status is 401
28+
$location.path '/login'
29+
# remove any stale tokens
30+
$cookieStore.remove 'token'
31+
32+
$q.reject response
33+
34+
.run ($rootScope, $location, Auth) ->
35+
# Redirect to login if route requires auth and you're not logged in
36+
$rootScope.$on <% if(filters.ngroute) { %>'$routeChangeStart'<% } %><% if(filters.uirouter) { %>'$stateChangeStart'<% } %>, (event, next) ->
37+
Auth.isLoggedInAsync (loggedIn) ->
38+
$location.path "/login" if next.authenticate and not loggedIn
39+
<% } %>

Diff for: app/templates/client/app/main/main(coffee).coffee

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
'use strict'
22

3-
angular.module('<%= scriptAppName %>')
4-
<% if(filters.ngroute) { %>.config ($routeProvider) ->
5-
$routeProvider
6-
.when('/',
7-
templateUrl: 'app/main/main.html'
8-
controller: 'MainCtrl'
9-
)<% } %><% if(filters.uirouter) { %>.config ($stateProvider) ->
10-
$stateProvider
11-
.state('main',
12-
url: '/',
13-
templateUrl: 'app/main/main.html'
14-
controller: 'MainCtrl'
15-
)<% } %>
3+
angular.module '<%= scriptAppName %>'
4+
<% if(filters.ngroute) { %>.config ($routeProvider) ->
5+
$routeProvider
6+
.when '/',
7+
templateUrl: 'app/main/main.html'
8+
controller: 'MainCtrl'
9+
<% } %><% if(filters.uirouter) { %>.config ($stateProvider) ->
10+
$stateProvider
11+
.state 'main',
12+
url: '/'
13+
templateUrl: 'app/main/main.html'
14+
controller: 'MainCtrl'
15+
<% } %>

Diff for: app/templates/client/app/main/main.controller(coffee).coffee

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

3-
angular.module('<%= scriptAppName %>').controller 'MainCtrl', ($scope, $http<% if(filters.socketio) { %>, socket<% } %>) ->
3+
angular.module '<%= scriptAppName %>'
4+
.controller 'MainCtrl', ($scope, $http<% if(filters.socketio) { %>, socket<% } %>) ->
45
$scope.awesomeThings = []
56

67
$http.get('/api/things').success (awesomeThings) ->

Diff for: app/templates/client/app/main/main.controller.spec(coffee).coffee

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
describe 'Controller: MainCtrl', ->
44

55
# load the controller's module
6-
beforeEach module('<%= scriptAppName %>')<% if(filters.socketio) {%>
7-
beforeEach module('socketMock')<% } %>
6+
beforeEach module '<%= scriptAppName %>' <% if(filters.socketio) {%>
7+
beforeEach module 'socketMock' <% } %>
88

99
MainCtrl = undefined
1010
scope = undefined
1111
$httpBackend = undefined
1212

1313
# Initialize the controller and a mock scope
14-
beforeEach inject((_$httpBackend_, $controller, $rootScope) ->
14+
beforeEach inject (_$httpBackend_, $controller, $rootScope) ->
1515
$httpBackend = _$httpBackend_
1616
$httpBackend.expectGET('/api/things').respond [
1717
'HTML5 Boilerplate'
@@ -20,10 +20,8 @@ describe 'Controller: MainCtrl', ->
2020
'Express'
2121
]
2222
scope = $rootScope.$new()
23-
MainCtrl = $controller('MainCtrl',
23+
MainCtrl = $controller 'MainCtrl',
2424
$scope: scope
25-
)
26-
)
2725

2826
it 'should attach a list of things to the scope', ->
2927
$httpBackend.flush()

0 commit comments

Comments
 (0)