Merge "ngReorg - Relocate filters and a validator"

This commit is contained in:
Jenkins
2015-05-26 18:09:31 +00:00
committed by Gerrit Code Review
8 changed files with 94 additions and 95 deletions

View File

@@ -18,12 +18,12 @@
/**
* @ngdoc overview
* @name hz.filters
* @name horizon.framework.util.filters
* @description
* hz.filters provides common filters to be used within Horizon.
* horizon.framework.util.filters provides common filters to be used within Horizon.
*
*/
angular.module('hz.filters', ['horizon.framework.util.i18n'])
angular.module('horizon.framework.util.filters', ['horizon.framework.util.i18n'])
/**
* @ngdoc filter

View File

@@ -1,8 +1,8 @@
describe('hz.filters', function () {
describe('horizon.framework.util.filters', function () {
'use strict';
beforeEach(module('horizon.framework.util.i18n'));
beforeEach(module('hz.filters'));
beforeEach(module('horizon.framework.util.filters'));
describe('yesno', function() {

View File

@@ -3,6 +3,7 @@
angular.module('horizon.framework.util', [
'horizon.framework.util.bind-scope',
'horizon.framework.util.filters',
'horizon.framework.util.form',
'horizon.framework.util.i18n',
'horizon.framework.util.workflow',

View File

@@ -1,4 +1,4 @@
(function() {
(function () {
'use strict';
/**
@@ -19,43 +19,43 @@
*/
angular.module('horizon.framework.util.validators', [])
/**
* @ngdoc directive
* @name horizon.framework.util.validators.directive:validateNumberMax
* @element ng-model
* @description
* The `validateNumberMax` directive provides max validation
* for the form input elements. This is an alternative to
* `max` which doesn't re-evaluate expression passed in on
* change. This allows the max value to be dynamically
* specified.
*
* The model and view value is not set to undefined if
* input does not pass validation. This is so that
* components that are watching this value can determine
* what to do with it. For example, quota charts can
* still render and display over-utilized slices in red.
*
* Validator returns true if model/view value <= max value.
*
* @restrict A
*
* @example
* ```
* <input type="text" ng-model="value"
* validate-number-max="{$ maxNumber $}">
* ```
*/
.directive('validateNumberMax', [ function() {
/**
* @ngdoc directive
* @name horizon.framework.util.validators.directive:validateNumberMax
* @element ng-model
* @description
* The `validateNumberMax` directive provides max validation
* for the form input elements. This is an alternative to
* `max` which doesn't re-evaluate expression passed in on
* change. This allows the max value to be dynamically
* specified.
*
* The model and view value is not set to undefined if
* input does not pass validation. This is so that
* components that are watching this value can determine
* what to do with it. For example, quota charts can
* still render and display over-utilized slices in red.
*
* Validator returns true if model/view value <= max value.
*
* @restrict A
*
* @example
* ```
* <input type="text" ng-model="value"
* validate-number-max="{$ maxNumber $}">
* ```
*/
.directive('validateNumberMax', [function () {
return {
require: 'ngModel',
require: 'ngModel',
restrict: 'A',
link: function (scope, element, attrs, ctrl) {
link: function (scope, element, attrs, ctrl) {
if (!ctrl) {
return;
}
var maxValidator = function(value) {
var maxValidator = function (value) {
var max = scope.$eval(attrs.validateNumberMax);
if (angular.isDefined(max) && !ctrl.$isEmpty(value) && value > max) {
ctrl.$setValidity('validateNumberMax', false);
@@ -72,50 +72,50 @@
ctrl.$parsers.push(maxValidator);
ctrl.$formatters.push(maxValidator);
attrs.$observe('validateNumberMax', function() {
attrs.$observe('validateNumberMax', function () {
maxValidator(ctrl.$modelValue);
});
}
};
}])
/**
* @ngdoc directive
* @name horizon.framework.util.validators.directive:validateNumberMin
* @element ng-model
* @description
* The `validateNumberMin` directive provides min validation
* for form input elements. This is an alternative to `min`
* which doesn't re-evaluate the expression passed in on
* change. This allows the min value to be dynamically
* specified.
*
* The model and view value is not set to undefined if
* input does not pass validation. This is so that
* components that are watching this value can determine
* what to do with it. For example, quota charts can
* still render and display over-utilized slices in red.
*
* Validator returns true is model/view value >= min value.
*
* @restrict A
*
* @example
* ```
* <input type="text" ng-model="value"
* validate-number-min="{$ minNumber $}">
* ```
*/
.directive('validateNumberMin', [ function() {
/**
* @ngdoc directive
* @name horizon.framework.util.validators.directive:validateNumberMin
* @element ng-model
* @description
* The `validateNumberMin` directive provides min validation
* for form input elements. This is an alternative to `min`
* which doesn't re-evaluate the expression passed in on
* change. This allows the min value to be dynamically
* specified.
*
* The model and view value is not set to undefined if
* input does not pass validation. This is so that
* components that are watching this value can determine
* what to do with it. For example, quota charts can
* still render and display over-utilized slices in red.
*
* Validator returns true is model/view value >= min value.
*
* @restrict A
*
* @example
* ```
* <input type="text" ng-model="value"
* validate-number-min="{$ minNumber $}">
* ```
*/
.directive('validateNumberMin', [function () {
return {
require: 'ngModel',
require: 'ngModel',
restrict: 'A',
link: function (scope, element, attrs, ctrl) {
link: function (scope, element, attrs, ctrl) {
if (!ctrl) {
return;
}
var minValidator = function(value) {
var minValidator = function (value) {
var min = scope.$eval(attrs.validateNumberMin);
if (angular.isDefined(min) && !ctrl.$isEmpty(value) && value < min) {
ctrl.$setValidity('validateNumberMin', false);
@@ -132,11 +132,29 @@
ctrl.$parsers.push(minValidator);
ctrl.$formatters.push(minValidator);
attrs.$observe('validateNumberMin', function() {
attrs.$observe('validateNumberMin', function () {
minValidator(ctrl.$modelValue);
});
}
};
}]);
}])
.directive('notBlank', function () {
return {
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {
ctrl.$parsers.unshift(function (viewValue) {
if (viewValue.length) {
// it is valid
ctrl.$setValidity('notBlank', true);
return viewValue;
}
// it is invalid, return undefined (no model update)
ctrl.$setValidity('notBlank', false);
return undefined;
});
}
};
});
}());

View File

@@ -1,21 +0,0 @@
(function () {
'use strict';
angular.module('hz')
.directive('notBlank', function () {
return {
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {
ctrl.$parsers.unshift(function (viewValue) {
if (viewValue.length) {
// it is valid
ctrl.$setValidity('notBlank', true);
return viewValue;
}
// it is invalid, return undefined (no model update)
ctrl.$setValidity('notBlank', false);
return undefined;
});
}
};
});
}());

View File

@@ -2,7 +2,7 @@
(function () {
'use strict';
var horizon_dependencies = ['hz.conf', 'hz.utils', 'hz.api', 'ngCookies', 'horizon.framework', 'hz.filters'];
var horizon_dependencies = ['hz.conf', 'hz.utils', 'hz.api', 'ngCookies', 'horizon.framework'];
var dependencies = horizon_dependencies.concat(angularModuleExtension);
angular.module('hz', dependencies)
.config(['$interpolateProvider', '$httpProvider',

View File

@@ -17,7 +17,6 @@
<script src='{{ STATIC_URL }}horizon/js/angular/controllers/namespace-controller.js'></script>
<script src='{{ STATIC_URL }}horizon/js/angular/controllers/dummy.js'></script>
<script src='{{ STATIC_URL }}horizon/js/angular/controllers/modal-form-update-metadata-ctrl.js'></script>
<script src='{{ STATIC_URL }}horizon/js/angular/directives/forms.js'></script>
<script src='{{ STATIC_URL }}horizon/js/angular/horizon.conf.js'></script>
<script src='{{ STATIC_URL }}horizon/js/angular/services/horizon.utils.js'></script>
@@ -30,7 +29,6 @@
<script src='{{ STATIC_URL }}horizon/js/angular/services/hz.api.neutron.js'></script>
<script src='{{ STATIC_URL }}horizon/js/angular/services/hz.api.nova.js'></script>
<script src='{{ STATIC_URL }}horizon/js/angular/services/hz.api.policy.js'></script>
<script src='{{ STATIC_URL }}horizon/js/angular/filters/filters.js'></script>
<script src='{{ STATIC_URL }}horizon/js/angular/services/hz.api.security-group.js'></script>
<script src="{{ STATIC_URL }}horizon/lib/d3.js"></script>
@@ -39,6 +37,7 @@
<script src='{{ STATIC_URL }}framework/util/util.module.js'></script>
<script src='{{ STATIC_URL }}framework/util/bind-scope/bind-scope.js'></script>
<script src='{{ STATIC_URL }}framework/util/filters/filters.js'></script>
<script src='{{ STATIC_URL }}framework/util/form/form.js'></script>
<script src='{{ STATIC_URL }}framework/util/i18n/i18n.js'></script>
<script src='{{ STATIC_URL }}framework/util/validators/validators.js'></script>

View File

@@ -28,6 +28,7 @@ class ServicesTests(test.JasmineTests):
'framework/util/util.module.js',
'framework/util/bind-scope/bind-scope.js',
'framework/util/filters/filters.js',
'framework/util/form/form.js',
'framework/util/i18n/i18n.js',
'framework/util/validators/validators.js',
@@ -59,6 +60,7 @@ class ServicesTests(test.JasmineTests):
'horizon/tests/jasmine/utils.spec.js',
'framework/util/bind-scope/bind-scope.spec.js',
'framework/util/filters/filters.spec.js',
'framework/util/form/form.spec.js',
'framework/util/i18n/i18n.spec.js',
'framework/util/validators/validators.spec.js',