Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into feat/replacing-gulp-node-inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
lirantal committed Oct 13, 2016
2 parents 19145b9 + d824224 commit 83ffc98
Show file tree
Hide file tree
Showing 64 changed files with 424 additions and 304 deletions.
1 change: 1 addition & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"angular-messages": "~1.5.0",
"angular-mocks": "~1.5.0",
"angular-resource": "~1.5.0",
"angular-ui-notification": "~0.2.0",
"angular-ui-router": "~0.2.18",
"bootstrap": "~3.3.6",
"ng-file-upload": "^12.1.0",
Expand Down
4 changes: 3 additions & 1 deletion config/assets/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = {
// bower:css
'public/lib/bootstrap/dist/css/bootstrap.css',
'public/lib/bootstrap/dist/css/bootstrap-theme.css',
'public/lib/ng-img-crop/compile/unminified/ng-img-crop.css'
'public/lib/ng-img-crop/compile/unminified/ng-img-crop.css',
'public/lib/angular-ui-notification/dist/angular-ui-notification.css'
// endbower
],
js: [
Expand All @@ -22,6 +23,7 @@ module.exports = {
'public/lib/angular-messages/angular-messages.js',
'public/lib/angular-mocks/angular-mocks.js',
'public/lib/angular-resource/angular-resource.js',
'public/lib/angular-ui-notification/dist/angular-ui-notification.js',
'public/lib/angular-ui-router/release/angular-ui-router.js',
'public/lib/owasp-password-strength-test/owasp-password-strength-test.js',
// endbower
Expand Down
2 changes: 2 additions & 0 deletions config/assets/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module.exports = {
'public/lib/bootstrap/dist/css/bootstrap.min.css',
'public/lib/bootstrap/dist/css/bootstrap-theme.min.css',
'public/lib/ng-img-crop/compile/minified/ng-img-crop.css',
'public/lib/angular-ui-notification/dist/angular-ui-notification.min.css'
// endbower
],
js: [
Expand All @@ -20,6 +21,7 @@ module.exports = {
'public/lib/angular-messages/angular-messages.min.js',
'public/lib/angular-mocks/angular-mocks.js',
'public/lib/angular-resource/angular-resource.min.js',
'public/lib/angular-ui-notification/dist/angular-ui-notification.min.js',
'public/lib/angular-ui-router/release/angular-ui-router.min.js',
'public/lib/ng-file-upload/ng-file-upload.min.js',
'public/lib/ng-img-crop/compile/minified/ng-img-crop.js',
Expand Down
22 changes: 11 additions & 11 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,29 @@ gulp.task('nodemon-nodebug', function () {
// Watch Files For Changes
gulp.task('watch', function () {
// Start livereload
plugins.livereload.listen();
plugins.refresh.listen();

// Add watch rules
gulp.watch(defaultAssets.server.views).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.server.allJS, ['eslint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.js, ['eslint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.css, ['csslint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.sass, ['sass', 'csslint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.less, ['less', 'csslint']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.server.views).on('change', plugins.refresh.changed);
gulp.watch(defaultAssets.server.allJS, ['eslint']).on('change', plugins.refresh.changed);
gulp.watch(defaultAssets.client.js, ['eslint']).on('change', plugins.refresh.changed);
gulp.watch(defaultAssets.client.css, ['csslint']).on('change', plugins.refresh.changed);
gulp.watch(defaultAssets.client.sass, ['sass', 'csslint']).on('change', plugins.refresh.changed);
gulp.watch(defaultAssets.client.less, ['less', 'csslint']).on('change', plugins.refresh.changed);

if (process.env.NODE_ENV === 'production') {
gulp.watch(defaultAssets.server.gulpConfig, ['templatecache', 'eslint']);
gulp.watch(defaultAssets.client.views, ['templatecache']).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.views, ['templatecache']).on('change', plugins.refresh.changed);
} else {
gulp.watch(defaultAssets.server.gulpConfig, ['eslint']);
gulp.watch(defaultAssets.client.views).on('change', plugins.livereload.changed);
gulp.watch(defaultAssets.client.views).on('change', plugins.refresh.changed);
}
});

// Watch server test files
gulp.task('watch:server:run-tests', function () {
// Start livereload
plugins.livereload.listen();
plugins.refresh.listen();

// Add Server Test file rules
gulp.watch([testAssets.tests.server, defaultAssets.server.allJS], ['test:server']).on('change', function (file) {
Expand All @@ -108,7 +108,7 @@ gulp.task('watch:server:run-tests', function () {
});
});

plugins.livereload.changed();
plugins.refresh.changed();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
})
.state('admin.articles.list', {
url: '',
templateUrl: 'modules/articles/client/views/admin/list-articles.client.view.html',
templateUrl: '/modules/articles/client/views/admin/list-articles.client.view.html',
controller: 'ArticlesAdminListController',
controllerAs: 'vm',
data: {
Expand All @@ -25,7 +25,7 @@
})
.state('admin.articles.create', {
url: '/create',
templateUrl: 'modules/articles/client/views/admin/form-article.client.view.html',
templateUrl: '/modules/articles/client/views/admin/form-article.client.view.html',
controller: 'ArticlesAdminController',
controllerAs: 'vm',
data: {
Expand All @@ -37,7 +37,7 @@
})
.state('admin.articles.edit', {
url: '/:articleId/edit',
templateUrl: 'modules/articles/client/views/admin/form-article.client.view.html',
templateUrl: '/modules/articles/client/views/admin/form-article.client.view.html',
controller: 'ArticlesAdminController',
controllerAs: 'vm',
data: {
Expand Down
4 changes: 2 additions & 2 deletions modules/articles/client/config/articles.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
})
.state('articles.list', {
url: '',
templateUrl: 'modules/articles/client/views/list-articles.client.view.html',
templateUrl: '/modules/articles/client/views/list-articles.client.view.html',
controller: 'ArticlesListController',
controllerAs: 'vm',
data: {
Expand All @@ -25,7 +25,7 @@
})
.state('articles.view', {
url: '/:articleId',
templateUrl: 'modules/articles/client/views/view-article.client.view.html',
templateUrl: '/modules/articles/client/views/view-article.client.view.html',
controller: 'ArticlesController',
controllerAs: 'vm',
resolve: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
.module('articles.admin')
.controller('ArticlesAdminController', ArticlesAdminController);

ArticlesAdminController.$inject = ['$scope', '$state', '$window', 'articleResolve', 'Authentication'];
ArticlesAdminController.$inject = ['$scope', '$state', '$window', 'articleResolve', 'Authentication', 'Notification'];

function ArticlesAdminController($scope, $state, $window, article, Authentication) {
function ArticlesAdminController($scope, $state, $window, article, Authentication, Notification) {
var vm = this;

vm.article = article;
vm.authentication = Authentication;
vm.error = null;
vm.form = {};
vm.remove = remove;
vm.save = save;
Expand All @@ -22,6 +21,7 @@
if ($window.confirm('Are you sure you want to delete?')) {
vm.article.$remove(function() {
$state.go('admin.articles.list');
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Article deleted successfully!' });
});
}
}
Expand All @@ -40,10 +40,11 @@

function successCallback(res) {
$state.go('admin.articles.list'); // should we send the User to the list or the updated Article's view?
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Article saved successfully!' });
}

function errorCallback(res) {
vm.error = res.data.message;
Notification.error({ message: res.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Article save error!' });
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

vm.article = article;
vm.authentication = Authentication;
vm.error = null;

}
}());
8 changes: 4 additions & 4 deletions modules/articles/client/services/articles.client.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
.module('articles.services')
.factory('ArticlesService', ArticlesService);

ArticlesService.$inject = ['$resource'];
ArticlesService.$inject = ['$resource', '$log'];

function ArticlesService($resource) {
var Article = $resource('api/articles/:articleId', {
function ArticlesService($resource, $log) {
var Article = $resource('/api/articles/:articleId', {
articleId: '@_id'
}, {
update: {
Expand Down Expand Up @@ -47,7 +47,7 @@

function handleError(error) {
// Log error
console.log(error);
$log.error(error);
}
}
}());
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ <h1>{{vm.article._id ? 'Edit Article' : 'New Article'}}</h1>
<div class="form-group">
<button type="submit" class="btn btn-default">{{vm.article._id ? 'Update' : 'Create'}}</button>
</div>
<div ng-show="vm.error" class="text-danger">
<strong ng-bind="vm.error"></strong>
</div>
</fieldset>
</form>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exports.create = function (req, res) {

article.save(function (err) {
if (err) {
return res.status(400).send({
return res.status(422).send({
message: errorHandler.getErrorMessage(err)
});
} else {
Expand Down Expand Up @@ -51,7 +51,7 @@ exports.update = function (req, res) {

article.save(function (err) {
if (err) {
return res.status(400).send({
return res.status(422).send({
message: errorHandler.getErrorMessage(err)
});
} else {
Expand All @@ -68,7 +68,7 @@ exports.delete = function (req, res) {

article.remove(function (err) {
if (err) {
return res.status(400).send({
return res.status(422).send({
message: errorHandler.getErrorMessage(err)
});
} else {
Expand All @@ -83,7 +83,7 @@ exports.delete = function (req, res) {
exports.list = function (req, res) {
Article.find().sort('-created').populate('user', 'displayName').exec(function (err, articles) {
if (err) {
return res.status(400).send({
return res.status(422).send({
message: errorHandler.getErrorMessage(err)
});
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
$state,
Authentication,
ArticlesService,
mockArticle;
mockArticle,
Notification;

// The $resource service augments the response object with methods for updating and deleting the resource.
// If we were to use the standard toEqual matcher, our tests would fail because the test values would not match
Expand All @@ -36,7 +37,7 @@
// The injector ignores leading and trailing underscores here (i.e. _$httpBackend_).
// This allows us to inject a service but then attach it to a variable
// with the same name as the service.
beforeEach(inject(function ($controller, $rootScope, _$state_, _$httpBackend_, _Authentication_, _ArticlesService_) {
beforeEach(inject(function ($controller, $rootScope, _$state_, _$httpBackend_, _Authentication_, _ArticlesService_, _Notification_) {
// Set a new global scope
$scope = $rootScope.$new();

Expand All @@ -45,6 +46,10 @@
$state = _$state_;
Authentication = _Authentication_;
ArticlesService = _ArticlesService_;
Notification = _Notification_;

// Ignore parent template get on state transitions
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200, '');

// create mock article
mockArticle = new ArticlesService({
Expand All @@ -66,6 +71,8 @@

// Spy on state go
spyOn($state, 'go');
spyOn(Notification, 'error');
spyOn(Notification, 'success');
}));

describe('vm.save() as create', function () {
Expand All @@ -83,26 +90,28 @@

it('should send a POST request with the form input values and then locate to new object URL', inject(function (ArticlesService) {
// Set POST response
$httpBackend.expectPOST('api/articles', sampleArticlePostData).respond(mockArticle);
$httpBackend.expectPOST('/api/articles', sampleArticlePostData).respond(mockArticle);

// Run controller functionality
$scope.vm.save(true);
$httpBackend.flush();

// Test Notification success was called
expect(Notification.success).toHaveBeenCalledWith({ message: '<i class="glyphicon glyphicon-ok"></i> Article saved successfully!' });
// Test URL redirection after the article was created
expect($state.go).toHaveBeenCalledWith('admin.articles.list');
}));

it('should set $scope.vm.error if error', function () {
it('should call Notification.error if error', function () {
var errorMessage = 'this is an error message';
$httpBackend.expectPOST('api/articles', sampleArticlePostData).respond(400, {
$httpBackend.expectPOST('/api/articles', sampleArticlePostData).respond(400, {
message: errorMessage
});

$scope.vm.save(true);
$httpBackend.flush();

expect($scope.vm.error).toBe(errorMessage);
expect(Notification.error).toHaveBeenCalledWith({ message: errorMessage, title: '<i class="glyphicon glyphicon-remove"></i> Article save error!' });
});
});

Expand All @@ -120,11 +129,13 @@
$scope.vm.save(true);
$httpBackend.flush();

// Test Notification success was called
expect(Notification.success).toHaveBeenCalledWith({ message: '<i class="glyphicon glyphicon-ok"></i> Article saved successfully!' });
// Test URL location to new object
expect($state.go).toHaveBeenCalledWith('admin.articles.list');
}));

it('should set $scope.vm.error if error', inject(function (ArticlesService) {
it('should call Notification.error if error', inject(function (ArticlesService) {
var errorMessage = 'error';
$httpBackend.expectPUT(/api\/articles\/([0-9a-fA-F]{24})$/).respond(400, {
message: errorMessage
Expand All @@ -133,7 +144,7 @@
$scope.vm.save(true);
$httpBackend.flush();

expect($scope.vm.error).toBe(errorMessage);
expect(Notification.error).toHaveBeenCalledWith({ message: errorMessage, title: '<i class="glyphicon glyphicon-remove"></i> Article save error!' });
}));
});

Expand All @@ -152,6 +163,7 @@
$scope.vm.remove();
$httpBackend.flush();

expect(Notification.success).toHaveBeenCalledWith({ message: '<i class="glyphicon glyphicon-ok"></i> Article deleted successfully!' });
expect($state.go).toHaveBeenCalledWith('admin.articles.list');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
});

it('Should have templateUrl', function () {
expect(liststate.templateUrl).toBe('modules/articles/client/views/admin/list-articles.client.view.html');
expect(liststate.templateUrl).toBe('/modules/articles/client/views/admin/list-articles.client.view.html');
});
});

Expand All @@ -64,7 +64,7 @@

beforeEach(inject(function ($controller, $state, $templateCache) {
createstate = $state.get('admin.articles.create');
$templateCache.put('modules/articles/client/views/admin/form-article.client.view.html', '');
$templateCache.put('/modules/articles/client/views/admin/form-article.client.view.html', '');

// Create mock article
mockArticle = new ArticlesService();
Expand Down Expand Up @@ -99,7 +99,7 @@
});

it('Should have templateUrl', function () {
expect(createstate.templateUrl).toBe('modules/articles/client/views/admin/form-article.client.view.html');
expect(createstate.templateUrl).toBe('/modules/articles/client/views/admin/form-article.client.view.html');
});
});

Expand All @@ -110,7 +110,7 @@

beforeEach(inject(function ($controller, $state, $templateCache) {
editstate = $state.get('admin.articles.edit');
$templateCache.put('modules/articles/client/views/admin/form-article.client.view.html', '');
$templateCache.put('/modules/articles/client/views/admin/form-article.client.view.html', '');

// Create mock article
mockArticle = new ArticlesService({
Expand Down Expand Up @@ -150,7 +150,7 @@
});

it('Should have templateUrl', function () {
expect(editstate.templateUrl).toBe('modules/articles/client/views/admin/form-article.client.view.html');
expect(editstate.templateUrl).toBe('/modules/articles/client/views/admin/form-article.client.view.html');
});

xit('Should go to unauthorized route', function () {
Expand Down
Loading

0 comments on commit 83ffc98

Please sign in to comment.