mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-02-28 01:00:59 +01:00
feat(core): add notification feedback with angular-ui-notification (#1532)
Added visual notification for user/article updates angular-ui-notification config added to core client config Notification idea from #369
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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: [
|
||||
@@ -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
|
||||
|
||||
@@ -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: [
|
||||
@@ -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',
|
||||
|
||||
@@ -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;
|
||||
@@ -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!' });
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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!' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
|
||||
vm.article = article;
|
||||
vm.authentication = Authentication;
|
||||
vm.error = null;
|
||||
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -24,9 +24,6 @@
|
||||
<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>
|
||||
|
||||
@@ -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
|
||||
@@ -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();
|
||||
|
||||
@@ -45,6 +46,7 @@
|
||||
$state = _$state_;
|
||||
Authentication = _Authentication_;
|
||||
ArticlesService = _ArticlesService_;
|
||||
Notification = _Notification_;
|
||||
|
||||
// create mock article
|
||||
mockArticle = new ArticlesService({
|
||||
@@ -66,6 +68,8 @@
|
||||
|
||||
// Spy on state go
|
||||
spyOn($state, 'go');
|
||||
spyOn(Notification, 'error');
|
||||
spyOn(Notification, 'success');
|
||||
}));
|
||||
|
||||
describe('vm.save() as create', function () {
|
||||
@@ -89,11 +93,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 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, {
|
||||
message: errorMessage
|
||||
@@ -102,7 +108,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!' });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -120,11 +126,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
|
||||
@@ -133,7 +141,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!' });
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -152,6 +160,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');
|
||||
});
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
var service = {
|
||||
applicationEnvironment: window.env,
|
||||
applicationModuleName: applicationModuleName,
|
||||
applicationModuleVendorDependencies: ['ngResource', 'ngAnimate', 'ngMessages', 'ui.router', 'ui.bootstrap', 'ngFileUpload', 'ngImgCrop'],
|
||||
applicationModuleVendorDependencies: ['ngResource', 'ngAnimate', 'ngMessages', 'ui.router', 'ui.bootstrap', 'ngFileUpload', 'ngImgCrop', 'ui-notification'],
|
||||
registerModule: registerModule
|
||||
};
|
||||
|
||||
@@ -20,4 +20,17 @@
|
||||
// Add the module to the AngularJS configuration file
|
||||
angular.module(applicationModuleName).requires.push(moduleName);
|
||||
}
|
||||
|
||||
// Angular-ui-notification configuration
|
||||
angular.module('ui-notification').config(function(NotificationProvider) {
|
||||
NotificationProvider.setOptions({
|
||||
delay: 2000,
|
||||
startTop: 20,
|
||||
startRight: 10,
|
||||
verticalSpacing: 20,
|
||||
horizontalSpacing: 20,
|
||||
positionX: 'right',
|
||||
positionY: 'bottom'
|
||||
});
|
||||
});
|
||||
}(window));
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
.module('users.admin')
|
||||
.controller('UserController', UserController);
|
||||
|
||||
UserController.$inject = ['$scope', '$state', '$window', 'Authentication', 'userResolve'];
|
||||
UserController.$inject = ['$scope', '$state', '$window', 'Authentication', 'userResolve', 'Notification'];
|
||||
|
||||
function UserController($scope, $state, $window, Authentication, user) {
|
||||
function UserController($scope, $state, $window, Authentication, user, Notification) {
|
||||
var vm = this;
|
||||
|
||||
vm.authentication = Authentication;
|
||||
@@ -22,9 +22,11 @@
|
||||
user.$remove();
|
||||
|
||||
vm.users.splice(vm.users.indexOf(user), 1);
|
||||
Notification.success('User deleted successfully!');
|
||||
} else {
|
||||
vm.user.$remove(function () {
|
||||
$state.go('admin.users');
|
||||
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> User deleted successfully!' });
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -43,8 +45,9 @@
|
||||
$state.go('admin.user', {
|
||||
userId: user._id
|
||||
});
|
||||
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> User saved successfully!' });
|
||||
}, function (errorResponse) {
|
||||
vm.error = errorResponse.data.message;
|
||||
Notification.error({ message: errorResponse.data.message, title: '<i class="glyphicon glyphicon-remove"></i> User update error!' });
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
.module('users')
|
||||
.controller('AuthenticationController', AuthenticationController);
|
||||
|
||||
AuthenticationController.$inject = ['$scope', '$state', 'UsersService', '$location', '$window', 'Authentication', 'PasswordValidator'];
|
||||
AuthenticationController.$inject = ['$scope', '$state', 'UsersService', '$location', '$window', 'Authentication', 'PasswordValidator', 'Notification'];
|
||||
|
||||
function AuthenticationController($scope, $state, UsersService, $location, $window, Authentication, PasswordValidator) {
|
||||
function AuthenticationController($scope, $state, UsersService, $location, $window, Authentication, PasswordValidator, Notification) {
|
||||
var vm = this;
|
||||
|
||||
vm.authentication = Authentication;
|
||||
@@ -17,7 +17,9 @@
|
||||
vm.callOauthProvider = callOauthProvider;
|
||||
|
||||
// Get an eventual error defined in the URL query string:
|
||||
vm.error = $location.search().err;
|
||||
if ($location.search().err) {
|
||||
Notification.error({ message: $location.search().err });
|
||||
}
|
||||
|
||||
// If user is signed in then redirect back home
|
||||
if (vm.authentication.user) {
|
||||
@@ -25,7 +27,6 @@
|
||||
}
|
||||
|
||||
function signup(isValid) {
|
||||
vm.error = null;
|
||||
|
||||
if (!isValid) {
|
||||
$scope.$broadcast('show-errors-check-validity', 'vm.userForm');
|
||||
@@ -39,7 +40,6 @@
|
||||
}
|
||||
|
||||
function signin(isValid) {
|
||||
vm.error = null;
|
||||
|
||||
if (!isValid) {
|
||||
$scope.$broadcast('show-errors-check-validity', 'vm.userForm');
|
||||
@@ -67,25 +67,25 @@
|
||||
function onUserSignupSuccess(response) {
|
||||
// If successful we assign the response to the global user model
|
||||
vm.authentication.user = response;
|
||||
|
||||
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Signup successful!' });
|
||||
// And redirect to the previous or home page
|
||||
$state.go($state.previous.state.name || 'home', $state.previous.params);
|
||||
}
|
||||
|
||||
function onUserSignupError(response) {
|
||||
vm.error = response.data.message;
|
||||
Notification.error({ message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Signup Error!', delay: 6000 });
|
||||
}
|
||||
|
||||
function onUserSigninSuccess(response) {
|
||||
// If successful we assign the response to the global user model
|
||||
vm.authentication.user = response;
|
||||
|
||||
Notification.info({ message: 'Welcome ' + response.firstName });
|
||||
// And redirect to the previous or home page
|
||||
$state.go($state.previous.state.name || 'home', $state.previous.params);
|
||||
}
|
||||
|
||||
function onUserSigninError(response) {
|
||||
vm.error = response.data.message;
|
||||
Notification.error({ message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Signin Error!', delay: 6000 });
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
.module('users')
|
||||
.controller('PasswordController', PasswordController);
|
||||
|
||||
PasswordController.$inject = ['$scope', '$stateParams', 'UsersService', '$location', 'Authentication', 'PasswordValidator'];
|
||||
PasswordController.$inject = ['$scope', '$stateParams', 'UsersService', '$location', 'Authentication', 'PasswordValidator', 'Notification'];
|
||||
|
||||
function PasswordController($scope, $stateParams, UsersService, $location, Authentication, PasswordValidator) {
|
||||
function PasswordController($scope, $stateParams, UsersService, $location, Authentication, PasswordValidator, Notification) {
|
||||
var vm = this;
|
||||
|
||||
vm.resetUserPassword = resetUserPassword;
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
// Submit forgotten password account id
|
||||
function askForPasswordReset(isValid) {
|
||||
vm.success = vm.error = null;
|
||||
|
||||
if (!isValid) {
|
||||
$scope.$broadcast('show-errors-check-validity', 'vm.forgotPasswordForm');
|
||||
@@ -37,7 +36,6 @@
|
||||
|
||||
// Change user password
|
||||
function resetUserPassword(isValid) {
|
||||
vm.success = vm.error = null;
|
||||
|
||||
if (!isValid) {
|
||||
$scope.$broadcast('show-errors-check-validity', 'vm.resetPasswordForm');
|
||||
@@ -55,13 +53,13 @@
|
||||
function onRequestPasswordResetSuccess(response) {
|
||||
// Show user success message and clear form
|
||||
vm.credentials = null;
|
||||
vm.success = response.message;
|
||||
Notification.success({ message: response.message, title: '<i class="glyphicon glyphicon-ok"></i> Password reset email sent successfully!' });
|
||||
}
|
||||
|
||||
function onRequestPasswordResetError(response) {
|
||||
// Show user error message and clear form
|
||||
vm.credentials = null;
|
||||
vm.error = response.data.message;
|
||||
Notification.error({ message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Failed to send password reset email!', delay: 4000 });
|
||||
}
|
||||
|
||||
function onResetPasswordSuccess(response) {
|
||||
@@ -70,12 +68,13 @@
|
||||
|
||||
// Attach user profile
|
||||
Authentication.user = response;
|
||||
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Password reset successful!' });
|
||||
// And redirect to the index page
|
||||
$location.path('/password/reset/success');
|
||||
}
|
||||
|
||||
function onResetPasswordError(response) {
|
||||
vm.error = response.data.message;
|
||||
Notification.error({ message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Password reset failed!', delay: 4000 });
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
.module('users')
|
||||
.controller('ChangePasswordController', ChangePasswordController);
|
||||
|
||||
ChangePasswordController.$inject = ['$scope', '$http', 'Authentication', 'UsersService', 'PasswordValidator'];
|
||||
ChangePasswordController.$inject = ['$scope', '$http', 'Authentication', 'UsersService', 'PasswordValidator', 'Notification'];
|
||||
|
||||
function ChangePasswordController($scope, $http, Authentication, UsersService, PasswordValidator) {
|
||||
function ChangePasswordController($scope, $http, Authentication, UsersService, PasswordValidator, Notification) {
|
||||
var vm = this;
|
||||
|
||||
vm.user = Authentication.user;
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
// Change user password
|
||||
function changeUserPassword(isValid) {
|
||||
vm.success = vm.error = null;
|
||||
|
||||
if (!isValid) {
|
||||
$scope.$broadcast('show-errors-check-validity', 'vm.passwordForm');
|
||||
@@ -31,13 +30,12 @@
|
||||
|
||||
function onChangePasswordSuccess(response) {
|
||||
// If successful show success message and clear form
|
||||
$scope.$broadcast('show-errors-reset', 'vm.passwordForm');
|
||||
vm.success = true;
|
||||
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Password Changed Successfully' });
|
||||
vm.passwordDetails = null;
|
||||
}
|
||||
|
||||
function onChangePasswordError(response) {
|
||||
vm.error = response.data.message;
|
||||
Notification.error({ message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Password change failed!' });
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -5,16 +5,15 @@
|
||||
.module('users')
|
||||
.controller('ChangeProfilePictureController', ChangeProfilePictureController);
|
||||
|
||||
ChangeProfilePictureController.$inject = ['$timeout', 'Authentication', 'Upload'];
|
||||
ChangeProfilePictureController.$inject = ['$timeout', 'Authentication', 'Upload', 'Notification'];
|
||||
|
||||
function ChangeProfilePictureController($timeout, Authentication, Upload) {
|
||||
function ChangeProfilePictureController($timeout, Authentication, Upload, Notification) {
|
||||
var vm = this;
|
||||
|
||||
vm.user = Authentication.user;
|
||||
vm.fileSelected = false;
|
||||
|
||||
vm.upload = function (dataUrl, name) {
|
||||
vm.success = vm.error = null;
|
||||
|
||||
Upload.upload({
|
||||
url: 'api/users/picture',
|
||||
@@ -35,7 +34,7 @@
|
||||
// Called after the user has successfully uploaded a new picture
|
||||
function onSuccessItem(response) {
|
||||
// Show success message
|
||||
vm.success = true;
|
||||
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Change profile picture successful!' });
|
||||
|
||||
// Populate user object
|
||||
vm.user = Authentication.user = response;
|
||||
@@ -50,7 +49,7 @@
|
||||
vm.fileSelected = false;
|
||||
|
||||
// Show error message
|
||||
vm.error = response.message;
|
||||
Notification.error({ message: response.message, title: '<i class="glyphicon glyphicon-remove"></i> Change profile picture failed!' });
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
.module('users')
|
||||
.controller('EditProfileController', EditProfileController);
|
||||
|
||||
EditProfileController.$inject = ['$scope', '$http', '$location', 'UsersService', 'Authentication'];
|
||||
EditProfileController.$inject = ['$scope', '$http', '$location', 'UsersService', 'Authentication', 'Notification'];
|
||||
|
||||
function EditProfileController($scope, $http, $location, UsersService, Authentication) {
|
||||
function EditProfileController($scope, $http, $location, UsersService, Authentication, Notification) {
|
||||
var vm = this;
|
||||
|
||||
vm.user = Authentication.user;
|
||||
@@ -15,7 +15,6 @@
|
||||
|
||||
// Update a user profile
|
||||
function updateUserProfile(isValid) {
|
||||
vm.success = vm.error = null;
|
||||
|
||||
if (!isValid) {
|
||||
$scope.$broadcast('show-errors-check-validity', 'vm.userForm');
|
||||
@@ -28,10 +27,10 @@
|
||||
user.$update(function (response) {
|
||||
$scope.$broadcast('show-errors-reset', 'vm.userForm');
|
||||
|
||||
vm.success = true;
|
||||
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Edit profile successful!' });
|
||||
Authentication.user = response;
|
||||
}, function (response) {
|
||||
vm.error = response.data.message;
|
||||
Notification.error({ message: response.data.message, title: '<i class="glyphicon glyphicon-remove"></i> Edit profile failed!' });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
.module('users')
|
||||
.controller('SocialAccountsController', SocialAccountsController);
|
||||
|
||||
SocialAccountsController.$inject = ['$scope', 'UsersService', 'Authentication'];
|
||||
SocialAccountsController.$inject = ['$scope', 'UsersService', 'Authentication', 'Notification'];
|
||||
|
||||
function SocialAccountsController($scope, UsersService, Authentication) {
|
||||
function SocialAccountsController($scope, UsersService, Authentication, Notification) {
|
||||
var vm = this;
|
||||
|
||||
vm.user = Authentication.user;
|
||||
@@ -27,7 +27,6 @@
|
||||
|
||||
// Remove a user social account
|
||||
function removeUserSocialAccount(provider) {
|
||||
vm.success = vm.error = null;
|
||||
|
||||
UsersService.removeSocialAccount(provider)
|
||||
.then(onRemoveSocialAccountSuccess)
|
||||
@@ -36,12 +35,12 @@
|
||||
|
||||
function onRemoveSocialAccountSuccess(response) {
|
||||
// If successful show success message and clear form
|
||||
vm.success = true;
|
||||
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> Removed successfully!' });
|
||||
vm.user = Authentication.user = response;
|
||||
}
|
||||
|
||||
function onRemoveSocialAccountError(response) {
|
||||
vm.error = response.message;
|
||||
Notification.error({ message: response.message, title: '<i class="glyphicon glyphicon-remove"></i> Remove failed!' });
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
@@ -31,9 +31,6 @@
|
||||
<div class="form-group">
|
||||
<input type="submit" value="Update" class="btn btn-default">
|
||||
</div>
|
||||
<div ng-show="vm.error" class="text-danger">
|
||||
<strong ng-bind="vm.error"></strong>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -51,9 +51,6 @@
|
||||
or
|
||||
<a ui-sref="authentication.signin" class="show-signup">Sign in</a>
|
||||
</div>
|
||||
<div ng-show="vm.error" class="text-center text-danger">
|
||||
<strong ng-bind="vm.error"></strong>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -13,12 +13,6 @@
|
||||
<div class="text-center form-group">
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</div>
|
||||
<div ng-show="vm.error" class="text-center text-danger">
|
||||
<strong ng-bind="vm.error"></strong>
|
||||
</div>
|
||||
<div ng-show="vm.success" class="text-center text-success">
|
||||
<strong ng-bind="vm.success"></strong>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -28,12 +28,6 @@
|
||||
<div class="text-center form-group">
|
||||
<button type="submit" class="btn btn-primary">Update Password</button>
|
||||
</div>
|
||||
<div ng-show="error" class="text-center text-danger">
|
||||
<strong ng-bind="vm.error"></strong>
|
||||
</div>
|
||||
<div ng-show="success" class="text-center text-success">
|
||||
<strong ng-bind="vm.success"></strong>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -34,12 +34,6 @@
|
||||
<div class="text-center form-group">
|
||||
<button type="submit" class="btn btn-primary">Save Password</button>
|
||||
</div>
|
||||
<div ng-show="vm.success" class="text-center text-success">
|
||||
<strong>Password Changed Successfully</strong>
|
||||
</div>
|
||||
<div ng-show="vm.error" class="text-center text-danger">
|
||||
<strong ng-bind="vm.error"></strong>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<img ng-src="{{vm.fileSelected ? croppedDataUrl : vm.user.profileImageURL}}" alt="{{vm.user.displayName}}" class="img-thumbnail user-profile-picture" ngf-drop>
|
||||
</div>
|
||||
<div ng-show="!vm.fileSelected" class="text-center form-group">
|
||||
<button class="btn btn-default btn-file" ngf-select="vm.fileSelected = true; vm.success = null" ng-model="picFile" accept="image/*">Select Picture</button>
|
||||
<button class="btn btn-default btn-file" ngf-select="vm.fileSelected = true" ng-model="picFile" accept="image/*">Select Picture</button>
|
||||
</div>
|
||||
<div ng-show="vm.fileSelected" class="text-center form-group">
|
||||
<button class="btn btn-primary" ng-click="vm.upload(croppedDataUrl, picFile.name)">Upload</button>
|
||||
@@ -23,12 +23,6 @@
|
||||
<span class="sr-only">{{vm.progress}}% Complete</span>
|
||||
</div>
|
||||
</div>
|
||||
<div ng-show="vm.success" class="text-center text-success">
|
||||
<strong>Profile Picture Changed Successfully</strong>
|
||||
</div>
|
||||
<div ng-show="vm.error" class="text-center text-danger">
|
||||
<strong ng-bind="vm.error"></strong>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -34,12 +34,6 @@
|
||||
<div class="text-center form-group">
|
||||
<button type="submit" class="btn btn-primary">Save Profile</button>
|
||||
</div>
|
||||
<div ng-show="vm.success" class="text-center text-success">
|
||||
<strong>Profile Saved Successfully</strong>
|
||||
</div>
|
||||
<div ng-show="vm.error" class="text-center text-danger">
|
||||
<strong ng-bind="vm.error"></strong>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
$httpBackend,
|
||||
$stateParams,
|
||||
$state,
|
||||
$location;
|
||||
$location,
|
||||
Notification;
|
||||
|
||||
beforeEach(function () {
|
||||
jasmine.addMatchers({
|
||||
@@ -32,7 +33,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, _$location_, _$stateParams_, _$httpBackend_) {
|
||||
beforeEach(inject(function ($controller, $rootScope, _$location_, _$stateParams_, _$httpBackend_, _Notification_) {
|
||||
// Set a new global scope
|
||||
scope = $rootScope.$new();
|
||||
|
||||
@@ -40,6 +41,11 @@
|
||||
$stateParams = _$stateParams_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$location = _$location_;
|
||||
Notification = _Notification_;
|
||||
|
||||
// Spy on Notification
|
||||
spyOn(Notification, 'error');
|
||||
spyOn(Notification, 'success');
|
||||
|
||||
// Initialize the Authentication controller
|
||||
AuthenticationController = $controller('AuthenticationController as vm', {
|
||||
@@ -107,8 +113,8 @@
|
||||
scope.vm.signin(true);
|
||||
$httpBackend.flush();
|
||||
|
||||
// Test scope value
|
||||
expect(scope.vm.error).toEqual('Missing credentials');
|
||||
// Test Notification.error is called
|
||||
expect(Notification.error).toHaveBeenCalledWith({ message: 'Missing credentials', title: '<i class="glyphicon glyphicon-remove"></i> Signin Error!', delay: 6000 });
|
||||
});
|
||||
|
||||
it('should fail to log in with wrong credentials', function () {
|
||||
@@ -124,8 +130,8 @@
|
||||
scope.vm.signin(true);
|
||||
$httpBackend.flush();
|
||||
|
||||
// Test scope value
|
||||
expect(scope.vm.error).toEqual('Unknown user');
|
||||
// Test Notification.error is called
|
||||
expect(Notification.error).toHaveBeenCalledWith({ message: 'Unknown user', title: '<i class="glyphicon glyphicon-remove"></i> Signin Error!', delay: 6000 });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -140,7 +146,7 @@
|
||||
|
||||
// test scope value
|
||||
expect(scope.vm.authentication.user.username).toBe('Fred');
|
||||
expect(scope.vm.error).toEqual(null);
|
||||
expect(Notification.success).toHaveBeenCalledWith({ message: '<i class="glyphicon glyphicon-ok"></i> Signup successful!' });
|
||||
expect($location.url()).toBe('/');
|
||||
});
|
||||
|
||||
@@ -153,8 +159,8 @@
|
||||
scope.vm.signup(true);
|
||||
$httpBackend.flush();
|
||||
|
||||
// Test scope value
|
||||
expect(scope.vm.error).toBe('Username already exists');
|
||||
// Test Notification.error is called
|
||||
expect(Notification.error).toHaveBeenCalledWith({ message: 'Username already exists', title: '<i class="glyphicon glyphicon-remove"></i> Signup Error!', delay: 6000 });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
$httpBackend,
|
||||
$location,
|
||||
Authentication,
|
||||
UsersService;
|
||||
UsersService,
|
||||
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
|
||||
@@ -35,7 +36,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, _$location_, _$httpBackend_, _Authentication_, _UsersService_) {
|
||||
beforeEach(inject(function ($controller, $rootScope, _$location_, _$httpBackend_, _Authentication_, _UsersService_, _Notification_) {
|
||||
// Set a new global scope
|
||||
$scope = $rootScope.$new();
|
||||
|
||||
@@ -44,6 +45,11 @@
|
||||
$location = _$location_;
|
||||
Authentication = _Authentication_;
|
||||
UsersService = _UsersService_;
|
||||
Notification = _Notification_;
|
||||
|
||||
// Spy on Notification
|
||||
spyOn(Notification, 'error');
|
||||
spyOn(Notification, 'success');
|
||||
|
||||
// Mock logged in user
|
||||
Authentication.user = {
|
||||
@@ -72,10 +78,10 @@
|
||||
$scope.vm.updateUserProfile(true);
|
||||
$httpBackend.flush();
|
||||
|
||||
expect($scope.vm.success).toBe(true);
|
||||
expect(Notification.success).toHaveBeenCalledWith({ message: '<i class="glyphicon glyphicon-ok"></i> Edit profile successful!' });
|
||||
}));
|
||||
|
||||
it('should set vm.error if error', inject(function (UsersService) {
|
||||
it('should call Notification.error if error', inject(function (UsersService) {
|
||||
var errorMessage = 'error';
|
||||
$httpBackend.expectPUT(/api\/users/).respond(400, {
|
||||
message: errorMessage
|
||||
@@ -84,7 +90,7 @@
|
||||
$scope.vm.updateUserProfile(true);
|
||||
$httpBackend.flush();
|
||||
|
||||
expect($scope.vm.error).toBe(errorMessage);
|
||||
expect(Notification.error).toHaveBeenCalledWith({ message: errorMessage, title: '<i class="glyphicon glyphicon-remove"></i> Edit profile failed!' });
|
||||
}));
|
||||
});
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
$httpBackend,
|
||||
$stateParams,
|
||||
$location,
|
||||
$window;
|
||||
$window,
|
||||
Notification;
|
||||
|
||||
beforeEach(function() {
|
||||
jasmine.addMatchers({
|
||||
@@ -57,7 +58,7 @@
|
||||
});
|
||||
|
||||
describe('Logged out user', function() {
|
||||
beforeEach(inject(function($controller, $rootScope, _$window_, _$stateParams_, _$httpBackend_, _$location_) {
|
||||
beforeEach(inject(function($controller, $rootScope, _$window_, _$stateParams_, _$httpBackend_, _$location_, _Notification_) {
|
||||
// Set a new global scope
|
||||
scope = $rootScope.$new();
|
||||
|
||||
@@ -68,6 +69,10 @@
|
||||
$location.path = jasmine.createSpy().and.returnValue(true);
|
||||
$window = _$window_;
|
||||
$window.user = null;
|
||||
Notification = _Notification_;
|
||||
|
||||
spyOn(Notification, 'error');
|
||||
spyOn(Notification, 'success');
|
||||
|
||||
// Initialize the Authentication controller
|
||||
PasswordController = $controller('PasswordController as vm', {
|
||||
@@ -88,15 +93,6 @@
|
||||
scope.vm.credentials = credentials;
|
||||
});
|
||||
|
||||
it('should clear scope.success and scope.error', function() {
|
||||
scope.vm.success = 'test';
|
||||
scope.vm.error = 'test';
|
||||
scope.vm.askForPasswordReset(true);
|
||||
|
||||
expect(scope.vm.success).toBeNull();
|
||||
expect(scope.vm.error).toBeNull();
|
||||
});
|
||||
|
||||
describe('POST error', function() {
|
||||
var errorMessage = 'No account with that username has been found';
|
||||
beforeEach(function() {
|
||||
@@ -112,8 +108,8 @@
|
||||
expect(scope.vm.credentials).toBe(null);
|
||||
});
|
||||
|
||||
it('should set error to response message', function() {
|
||||
expect(scope.vm.error).toBe(errorMessage);
|
||||
it('should call Notification.error with response message', function() {
|
||||
expect(Notification.error).toHaveBeenCalledWith({ message: errorMessage, title: '<i class="glyphicon glyphicon-remove"></i> Failed to send password reset email!', delay: 4000 });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -132,8 +128,8 @@
|
||||
expect(scope.vm.credentials).toBe(null);
|
||||
});
|
||||
|
||||
it('should set success to response message', function() {
|
||||
expect(scope.vm.success).toBe(successMessage);
|
||||
it('should call Notification.success with response message', function() {
|
||||
expect(Notification.success).toHaveBeenCalledWith({ message: successMessage, title: '<i class="glyphicon glyphicon-ok"></i> Password reset email sent successfully!' });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -148,16 +144,7 @@
|
||||
scope.vm.passwordDetails = passwordDetails;
|
||||
});
|
||||
|
||||
it('should clear scope.success and scope.vm.error', function() {
|
||||
scope.vm.success = 'test';
|
||||
scope.vm.error = 'test';
|
||||
scope.vm.resetUserPassword(true);
|
||||
|
||||
expect(scope.vm.success).toBeNull();
|
||||
expect(scope.vm.error).toBeNull();
|
||||
});
|
||||
|
||||
it('POST error should set scope.error to response message', function() {
|
||||
it('POST error should call Notification.error with response message', function() {
|
||||
var errorMessage = 'Passwords do not match';
|
||||
$httpBackend.when('POST', 'api/auth/reset/' + token, passwordDetails).respond(400, {
|
||||
'message': errorMessage
|
||||
@@ -166,7 +153,7 @@
|
||||
scope.vm.resetUserPassword(true);
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(scope.vm.error).toBe(errorMessage);
|
||||
expect(Notification.error).toHaveBeenCalledWith({ message: errorMessage, title: '<i class="glyphicon glyphicon-remove"></i> Password reset failed!', delay: 4000 });
|
||||
});
|
||||
|
||||
describe('POST success', function() {
|
||||
@@ -188,7 +175,8 @@
|
||||
expect(scope.vm.authentication.user.username).toEqual(user.username);
|
||||
});
|
||||
|
||||
it('should redirect to password reset success view', function() {
|
||||
it('should redirect to password reset success view with Notification.success', function() {
|
||||
expect(Notification.success).toHaveBeenCalledWith({ message: '<i class="glyphicon glyphicon-ok"></i> Password reset successful!' });
|
||||
expect($location.path).toHaveBeenCalledWith('/password/reset/success');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -272,7 +272,7 @@ describe('Users E2E Tests:', function () {
|
||||
// Click Submit button
|
||||
element(by.css('button[type=submit]')).click();
|
||||
// Password Error
|
||||
expect(element.all(by.css('strong')).get(0).getText()).toBe('Email already exists');
|
||||
expect(element.all(by.css('.message')).get(0).getText()).toBe('Email already exists');
|
||||
});
|
||||
|
||||
it('Should report Username already exists', function () {
|
||||
@@ -291,7 +291,7 @@ describe('Users E2E Tests:', function () {
|
||||
// Click Submit button
|
||||
element(by.css('button[type=submit]')).click();
|
||||
// Password Error
|
||||
expect(element.all(by.css('strong')).get(0).getText()).toBe('Username already exists');
|
||||
expect(element.all(by.css('.message')).get(0).getText()).toBe('Username already exists');
|
||||
});
|
||||
|
||||
});
|
||||
@@ -436,7 +436,7 @@ describe('Users E2E Tests:', function () {
|
||||
// Click Submit button
|
||||
element(by.css('button[type=submit]')).click();
|
||||
// Password Changed
|
||||
expect(element.all(by.css('.text-success')).get(0).getText()).toBe('Password Changed Successfully');
|
||||
expect(element.all(by.css('.ui-notification')).get(0).getText()).toBe('Password Changed Successfully');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user