diff options
author | Pavel Vomacka <pvomacka@redhat.com> | 2017-03-07 21:30:45 +0100 |
---|---|---|
committer | David Kupka <dkupka@redhat.com> | 2017-03-08 16:22:01 +0100 |
commit | 358caa7da44c997b505f54ec70cb6be58d188751 (patch) | |
tree | 2aa4b8bd2e5fb6012378333ffae71e4ee2be757c | |
parent | 1d6cc35c03669ea67d9e9ee9ca0ff62401d1b157 (diff) | |
download | freeipa-358caa7da44c997b505f54ec70cb6be58d188751.tar.gz freeipa-358caa7da44c997b505f54ec70cb6be58d188751.tar.xz freeipa-358caa7da44c997b505f54ec70cb6be58d188751.zip |
WebUI: Add Adapter for certmap_match result table
Result of certmap_match command is in the following format:
[{domain: 'domain1', uid:[uid11,uid12,uid13]}, {domain: 'domain2',
uid:[uid21, uid22, uid23},...]
For correct displaying in table we need to reformat it to the following:
[{domain: 'domain1', uid: 'uid11'}, {domain: 'domain1', uid: 'uid12'},...
This can be done using this Adapter.
Part of: https://pagure.io/freeipa/issue/6601
Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
-rw-r--r-- | install/ui/src/freeipa/field.js | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/install/ui/src/freeipa/field.js b/install/ui/src/freeipa/field.js index ea548c033..5df2f6c9a 100644 --- a/install/ui/src/freeipa/field.js +++ b/install/ui/src/freeipa/field.js @@ -1495,6 +1495,84 @@ field.AlternateAttrFieldAdapter = declare([field.Adapter], { /** + * Custom adapter specifically implemented for certmap_match where it + * transform items in format {domain: "xxx", uid: [arrayof_uids]} to + * {[{domain: "xxx", uid: "uid1"}, {domain: "xxx", uid: 'uid2'}, ...]}. + * This is necessary for possibility to correctly display table. + * + * @class + * @extends field.Adapter + */ +field.CertMatchTransformAdapter = declare([field.Adapter], { + + /** + * @param {Array} record + */ + transform_one_record: function(record) { + var domain = record.domain; + var uids = record.uid; + var results = []; + + for (var i=0, l=uids.length; i<l; i++) { + results.push({ + domain: domain, + uid: uids[i] + }); + } + + return results; + }, + + /** + * Transform record to array of arrays with objects in the following format: + * {domain: 'xxx', uid: 'uid1'} + * + * @param {Array|Object} record + */ + transform_record: function(record) { + if (lang.isArray(record)) { + for (var i=0, l=record.length; i<l; i++) { + record[i] = this.transform_one_record(record[i]); + } + } else { + record = this.transform_one_record(record); + } + }, + + /** + * Merge array of arrays of object into array of objects. + * + * @param {Array} records + */ + merge_object_into_array: function(records) { + if (!lang.isArray(records)) return records; + + var merged = []; + for (var i=0, l=records.length; i<l; i++) { + merged = merged.concat(records[i]); + } + + return merged; + }, + + /** + * + * @param {Object} data Object which contains the record or the record + * @returns {Array} attribute values + */ + load: function(data) { + var record = this.get_record(data); + + this.transform_record(record); + + var values = this.merge_object_into_array(record); + + return values; + } +}); + + +/** * Field for enabling/disabling entity * * - expects radio widget @@ -1769,6 +1847,7 @@ field.register = function() { l.register('adapter', field.Adapter); l.register('object_adapter', field.ObjectAdapter); l.register('alternate_attr_field_adapter', field.AlternateAttrFieldAdapter); + l.register('certmatch_transform', field.CertMatchTransformAdapter); }; phases.on('registration', field.register); |