summaryrefslogtreecommitdiff
path: root/horizon/static
diff options
context:
space:
mode:
authorTravis Tripp <travis.tripp@hpe.com>2016-07-08 17:04:31 -0600
committerTravis Tripp <travis.tripp@hpe.com>2016-08-18 05:34:39 +0000
commit2166e5a0c5aa45262dd9ccc08486ccd82d148e34 (patch)
tree6d00a746d1d8fb97c065002c73a6b65ea4ef3627 /horizon/static
parenta0f18e34446c14c7cab77c21afc60d4a21b2b5ac (diff)
downloadhorizon-2166e5a0c5aa45262dd9ccc08486ccd82d148e34.tar.gz
Support project column in admin view of NG images
This adds the project name column to ng images, which is required in order to support an admin view for images. In addition the hz-property directive could not handle promises, which is required for doing things like looking up the project name from the project id. This adds limited support for that. Change-Id: I0bb3782a23cf6ddff249459089b96a532aa8a0d8 Partially-Implements: blueprint angularize-images-table
Diffstat (limited to 'horizon/static')
-rw-r--r--horizon/static/framework/widgets/property/hz-field.directive.js70
1 files changed, 50 insertions, 20 deletions
diff --git a/horizon/static/framework/widgets/property/hz-field.directive.js b/horizon/static/framework/widgets/property/hz-field.directive.js
index 22d1d47db..d4e0a657e 100644
--- a/horizon/static/framework/widgets/property/hz-field.directive.js
+++ b/horizon/static/framework/widgets/property/hz-field.directive.js
@@ -13,14 +13,16 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
-(function() {
+(function () {
'use strict';
angular
.module('horizon.framework.widgets.property')
.directive('hzField', hzField);
- hzField.$inject = ['$filter'];
+ hzField.$inject = [
+ '$filter'
+ ];
/**
* @ngdoc directive
@@ -39,8 +41,16 @@
* The field configuration may transform the data in the item's property
* using either a set of single-argument filters or functions, specified by
* the 'filters' property, or using the 'values' object in which the item
- * property is mapped via the keys to the values in the given object. Note
- * that a combination of 'filters' and 'values' may be used; in this case
+ * property is mapped via the keys to the values in the given object.
+ *
+ * The 'filters' property may contain an array of filters. Each filter may be
+ * a function or a name of a filter that will be looked up using $filter.
+ * If it is a function, the function must take one argument (the input to
+ * to be filtered) and return the result of the filtering process. This
+ * function may be a promise, but only if it is the only filter or the last
+ * filter in the array of filters.
+ *
+ * Note that a combination of 'filters' and 'values' may be used; in this case
* the filters are evaluated first. This allows for translations that will
* map to keys first (e.g. upper-casing a string with a filter so it matches
* upper-case keys), and allows the values provided in the 'values' mapping
@@ -100,32 +110,52 @@
var config = scope.config;
var item = scope.item;
var propValue = item[config.id];
+ var output = applyFilters(config, propValue);
+
+ if (output.then) {
+ //Last filter was a promise, resolve it and then finish output.
+ output.then(postFilterFormatting);
+ } else {
+ postFilterFormatting(output);
+ }
+
+ function postFilterFormatting(output) {
+ if (config && config.values) {
+ // apply mapping values to the data if applicable
+ output = config.values[output];
+ }
+
+ var url;
+ if (config && config.urlFunction) {
+ url = config.urlFunction(item);
+ }
+
+ if (url) {
+ element.append(angular.element('<a>').attr('href', url).append(output));
+ } else {
+ element.append(output);
+ }
+ }
+ }
+
+ function applyFilters(config, propValue) {
var output = propValue;
+
if (config && config.filters) {
for (var i = 0; i < config.filters.length; i++) {
var filter = config.filters[i];
// call horizon framework filter function if provided
if (angular.isFunction(filter)) {
- output = filter(propValue);
- // call angular filters
+ output = filter(output);
+ // call angular filters
} else {
- output = $filter(filter)(propValue);
+ output = $filter(filter)(output);
}
}
}
- if (config && config.values) {
- // apply mapping values to the data if applicable
- output = config.values[output];
- }
- var url;
- if (config && config.urlFunction) {
- url = config.urlFunction(item);
- }
- if (url) {
- element.append(angular.element('<a>').attr('href', url).append(output));
- } else {
- element.append(output);
- }
+
+ return output;
}
+
}
})();