forked from angular-app/angular-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(admin): refactored and fixed admin tests
- Loading branch information
1 parent
2b59a63
commit 5a94c88
Showing
11 changed files
with
441 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
angular.module('admin-users-list', [ | ||
'servics.crud', | ||
'services.i18nNotifications' | ||
]) | ||
|
||
.controller('UsersListCtrl', ['$scope', 'crudListMethods', 'users', 'i18nNotifications', function ($scope, crudListMethods, users, i18nNotifications) { | ||
$scope.users = users; | ||
|
||
angular.extend($scope, crudListMethods('/admin/users')); | ||
|
||
$scope.remove = function(user, $index, $event) { | ||
// Don't let the click bubble up to the ng-click on the enclosing div, which will try to trigger | ||
// an edit of this item. | ||
$event.stopPropagation(); | ||
|
||
// Remove this user | ||
user.$remove(function() { | ||
// It is gone from the DB so we can remove it from the local list too | ||
$scope.users.splice($index,1); | ||
i18nNotifications.pushForCurrentRoute('crud.user.remove.success', 'success', {id : user.$id()}); | ||
}, function() { | ||
i18nNotifications.pushForCurrentRoute('crud.user.remove.error', 'error', {id : user.$id()}); | ||
}); | ||
}; | ||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
angular.module('admin-users-edit-uniqueEmail', ['resources.users']) | ||
|
||
/** | ||
* A validation directive to ensure that the model contains a unique email address | ||
* @param Users service to provide access to the server's user database | ||
*/ | ||
.directive('uniqueEmail', ["Users", function (Users) { | ||
return { | ||
require:'ngModel', | ||
restrict:'A', | ||
link:function (scope, el, attrs, ctrl) { | ||
|
||
//TODO: We need to check that the value is different to the original | ||
|
||
//using push() here to run it as the last parser, after we are sure that other validators were run | ||
ctrl.$parsers.push(function (viewValue) { | ||
|
||
if (viewValue) { | ||
Users.query({email:viewValue}, function (users) { | ||
if (users.length === 0) { | ||
ctrl.$setValidity('uniqueEmail', true); | ||
} else { | ||
ctrl.$setValidity('uniqueEmail', false); | ||
} | ||
}); | ||
return viewValue; | ||
} | ||
}); | ||
} | ||
}; | ||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
angular.module('admin-users-edit-validateEquals', []) | ||
|
||
/** | ||
* A validation directive to ensure that this model has the same value as some other | ||
*/ | ||
.directive('validateEquals', function() { | ||
return { | ||
restrict: 'A', | ||
require: 'ngModel', | ||
link: function(scope, elm, attrs, ctrl) { | ||
|
||
function validateEqual(myValue, otherValue) { | ||
if (myValue === otherValue) { | ||
ctrl.$setValidity('equal', true); | ||
return myValue; | ||
} else { | ||
ctrl.$setValidity('equal', false); | ||
return undefined; | ||
} | ||
} | ||
|
||
scope.$watch(attrs.validateEquals, function(otherModelValue) { | ||
ctrl.$setValidity('equal', ctrl.$viewValue === otherModelValue); | ||
}); | ||
|
||
ctrl.$parsers.push(function(viewValue) { | ||
return validateEqual(viewValue, scope.$eval(attrs.validateEquals)); | ||
}); | ||
|
||
ctrl.$formatters.push(function(modelValue) { | ||
return validateEqual(modelValue, scope.$eval(attrs.validateEquals)); | ||
}); | ||
} | ||
}; | ||
}); |
Oops, something went wrong.