mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
WebUI: allow to show rows with same pkey in tables
Allows to show rows which have the same primary key. Used in Vault. https://fedorahosted.org/freeipa/ticket/5426 Reviewed-By: Martin Basti <mbasti@redhat.com> Reviewed-By: Petr Vobornik <pvoborni@redhat.com>
This commit is contained in:
parent
de4d4a51b5
commit
587b7324fb
@ -1042,6 +1042,7 @@ exp.association_facet = IPA.association_facet = function (spec, no_init) {
|
||||
that.facet_group = spec.facet_group;
|
||||
|
||||
that.read_only = spec.read_only;
|
||||
that.show_values_with_dup_key = spec.show_values_with_dup_key || false;
|
||||
|
||||
that.associator = spec.associator || IPA.bulk_associator;
|
||||
that.add_method = spec.add_method || 'add_member';
|
||||
@ -1318,6 +1319,7 @@ exp.association_facet = IPA.association_facet = function (spec, no_init) {
|
||||
that.get_records_map = function(data) {
|
||||
|
||||
var records_map = $.ordered_map();
|
||||
var pkeys_map = $.ordered_map();
|
||||
var association_name = that.get_attribute_name();
|
||||
var pkey_name = that.managed_entity.metadata.primary_key;
|
||||
|
||||
@ -1326,10 +1328,18 @@ exp.association_facet = IPA.association_facet = function (spec, no_init) {
|
||||
var pkey = pkeys[i];
|
||||
var record = {};
|
||||
record[pkey_name] = pkey;
|
||||
records_map.put(pkey, record);
|
||||
var compound_pkey = pkey;
|
||||
if (that.show_values_with_dup_key) {
|
||||
compound_pkey = pkey + i;
|
||||
}
|
||||
records_map.put(compound_pkey, record);
|
||||
pkeys_map.put(compound_pkey, pkey);
|
||||
}
|
||||
|
||||
return records_map;
|
||||
return {
|
||||
records_map: records_map,
|
||||
pkeys_map: pkeys_map
|
||||
};
|
||||
};
|
||||
|
||||
that.refresh = function() {
|
||||
@ -1488,16 +1498,22 @@ exp.attribute_facet = IPA.attribute_facet = function(spec, no_init) {
|
||||
that.get_records_map = function(data) {
|
||||
|
||||
var records_map = $.ordered_map();
|
||||
var pkeys_map = $.ordered_map();
|
||||
var pkeys = data.result.result[that.attribute];
|
||||
|
||||
for (var i=0; pkeys && i<pkeys.length; i++) {
|
||||
var pkey = pkeys[i];
|
||||
var record = {};
|
||||
record[that.attribute] = pkey;
|
||||
records_map.put(pkey, record);
|
||||
var compound_pkey = pkey + i;
|
||||
records_map.put(compound_pkey, record);
|
||||
pkeys_map.put(compound_pkey, pkey);
|
||||
}
|
||||
|
||||
return records_map;
|
||||
return {
|
||||
records_map: records_map,
|
||||
pkeys_map: pkeys_map
|
||||
};
|
||||
};
|
||||
|
||||
that.refresh = function() {
|
||||
|
@ -167,9 +167,10 @@ IPA.automember.rule_search_facet = function(spec) {
|
||||
return name;
|
||||
};
|
||||
|
||||
that.create_get_records_command = function(pkeys, on_success, on_error) {
|
||||
that.create_get_records_command = function(records, pkeys, on_success, on_error) {
|
||||
|
||||
var batch = that.table_facet_create_get_records_command(pkeys, on_success, on_error);
|
||||
var batch = that.table_facet_create_get_records_command(records, pkeys,
|
||||
on_success, on_error);
|
||||
|
||||
for (var i=0; i<batch.commands.length; i++) {
|
||||
var command = batch.commands[i];
|
||||
|
@ -875,7 +875,9 @@ IPA.dns.record_search_facet = function(spec) {
|
||||
|
||||
var that = IPA.nested_search_facet(spec);
|
||||
|
||||
that.get_records = function(pkeys, on_success, on_error) {
|
||||
that.get_records = function(records, pkeys_list, on_success, on_error) {
|
||||
|
||||
var pkeys = pkeys_list.keys;
|
||||
|
||||
var batch = rpc.batch_command({
|
||||
name: that.get_records_command_name(),
|
||||
@ -887,6 +889,7 @@ IPA.dns.record_search_facet = function(spec) {
|
||||
|
||||
for (var i=0; i<pkeys.length; i++) {
|
||||
var pkey = pkeys[i];
|
||||
var call_pkey = pkeys_list.get(pkey);
|
||||
|
||||
var command = rpc.command({
|
||||
entity: that.table.entity.name,
|
||||
|
@ -1834,6 +1834,14 @@ exp.table_facet = IPA.table_facet = function(spec, no_init) {
|
||||
|
||||
var that = IPA.facet(spec, no_init);
|
||||
|
||||
/**
|
||||
* Sets whether table on the facet will or will not show items with the
|
||||
* same key.
|
||||
*
|
||||
* @property {boolean}
|
||||
*/
|
||||
that.show_values_with_dup_key = spec.show_values_with_dup_key || false;
|
||||
|
||||
/**
|
||||
* Names of additional row attributes which will be send to another facet
|
||||
* during navigation as URL parameters.
|
||||
@ -2074,11 +2082,13 @@ exp.table_facet = IPA.table_facet = function(spec, no_init) {
|
||||
*
|
||||
* @protected
|
||||
* @param {Object} data RPC command data
|
||||
* @return {ordered_map} record map
|
||||
* @return {Object} ordered_maps with records and with pkeys. keys
|
||||
* are composed from pkey and index.
|
||||
*/
|
||||
that.get_records_map = function(data) {
|
||||
|
||||
var records_map = $.ordered_map();
|
||||
var pkeys_map = $.ordered_map();
|
||||
|
||||
var result = data.result.result;
|
||||
var pkey_name = that.managed_entity.metadata.primary_key ||
|
||||
@ -2089,11 +2099,21 @@ exp.table_facet = IPA.table_facet = function(spec, no_init) {
|
||||
var record = result[i];
|
||||
var pkey = adapter.load(record, pkey_name)[0];
|
||||
if (that.filter_records(records_map, pkey, record)) {
|
||||
records_map.put(pkey, record);
|
||||
// This solution allows to show tables where are the same
|
||||
// primary keys. (i.e. {User|Service} Vaults)
|
||||
var compound_pkey = pkey;
|
||||
if (that.show_values_with_dup_key) {
|
||||
compound_pkey = pkey + i;
|
||||
}
|
||||
records_map.put(compound_pkey, record);
|
||||
pkeys_map.put(compound_pkey, pkey);
|
||||
}
|
||||
}
|
||||
|
||||
return records_map;
|
||||
return {
|
||||
records_map: records_map,
|
||||
pkeys_map: pkeys_map
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
@ -2110,7 +2130,9 @@ exp.table_facet = IPA.table_facet = function(spec, no_init) {
|
||||
that.load_page = function(data) {
|
||||
|
||||
// get primary keys (and the complete records if search_all_entries is true)
|
||||
var records_map = that.get_records_map(data);
|
||||
var records = that.get_records_map(data);
|
||||
var records_map = records.records_map;
|
||||
var pkeys_map = records.pkeys_map;
|
||||
|
||||
var total = records_map.length;
|
||||
that.table.total_pages = total ? Math.ceil(total / that.table.page_length) : 1;
|
||||
@ -2146,11 +2168,11 @@ exp.table_facet = IPA.table_facet = function(spec, no_init) {
|
||||
|
||||
// sort map based on primary keys
|
||||
if (that.sort_enabled) {
|
||||
records_map = records_map.sort();
|
||||
pkeys_map = pkeys_map.sort();
|
||||
}
|
||||
|
||||
// trim map leaving the entries visible in the current page only
|
||||
records_map = records_map.slice(start-1, end);
|
||||
pkeys_map = pkeys_map.slice(start-1, end);
|
||||
|
||||
var columns = that.table.columns.values;
|
||||
if (columns.length == 1) { // show primary keys only
|
||||
@ -2167,16 +2189,19 @@ exp.table_facet = IPA.table_facet = function(spec, no_init) {
|
||||
// get the complete records
|
||||
that.get_records(
|
||||
records_map,
|
||||
pkeys_map,
|
||||
function(data, text_status, xhr) {
|
||||
var results = data.result.results;
|
||||
for (var i=0; i<records_map.length; i++) {
|
||||
var pkey = records_map.keys[i];
|
||||
var show_records_map = $.ordered_map();
|
||||
for (var i=0; i<pkeys_map.length; i++) {
|
||||
var pkey = pkeys_map.keys[i];
|
||||
var record = records_map.get(pkey);
|
||||
// merge the record obtained from the refresh()
|
||||
// with the record obtained from get_records()
|
||||
$.extend(record, results[i].result);
|
||||
show_records_map.put(pkey, record);
|
||||
}
|
||||
that.load_records(records_map.values);
|
||||
that.load_records(show_records_map.values);
|
||||
},
|
||||
function(xhr, text_status, error_thrown) {
|
||||
that.load_records([]);
|
||||
@ -2249,9 +2274,9 @@ exp.table_facet = IPA.table_facet = function(spec, no_init) {
|
||||
* @param {Function} on_success command success handler
|
||||
* @param {Function} on_failure command error handler
|
||||
*/
|
||||
that.create_get_records_command = function(records, on_success, on_error) {
|
||||
that.create_get_records_command = function(records, pkeys_list, on_success, on_error) {
|
||||
|
||||
var pkeys = records.keys;
|
||||
var pkeys = pkeys_list.keys;
|
||||
|
||||
var batch = rpc.batch_command({
|
||||
name: that.get_records_command_name(),
|
||||
@ -2261,11 +2286,12 @@ exp.table_facet = IPA.table_facet = function(spec, no_init) {
|
||||
|
||||
for (var i=0; i<pkeys.length; i++) {
|
||||
var pkey = pkeys[i];
|
||||
var call_pkey = pkeys_list.get(pkey);
|
||||
|
||||
var command = rpc.command({
|
||||
entity: that.table.entity.name,
|
||||
method: 'show',
|
||||
args: [pkey]
|
||||
args: [call_pkey]
|
||||
});
|
||||
|
||||
if (that.show_command_additional_attr) {
|
||||
@ -2304,13 +2330,13 @@ exp.table_facet = IPA.table_facet = function(spec, no_init) {
|
||||
* Execute command for obtaining complete records
|
||||
*
|
||||
* @protected
|
||||
* @param {Array.<string>} pkeys primary keys
|
||||
* @param records_map of all records
|
||||
* @param {Function} on_success command success handler
|
||||
* @param {Function} on_failure command error handler
|
||||
*/
|
||||
that.get_records = function(pkeys, on_success, on_error) {
|
||||
that.get_records = function(records, pkeys, on_success, on_error) {
|
||||
|
||||
var batch = that.create_get_records_command(pkeys, on_success, on_error);
|
||||
var batch = that.create_get_records_command(records, pkeys, on_success, on_error);
|
||||
|
||||
batch.execute();
|
||||
};
|
||||
|
@ -706,12 +706,15 @@ IPA.hbac.test_run_facet = function(spec) {
|
||||
that.get_records_map = function(data) {
|
||||
|
||||
var records_map = $.ordered_map();
|
||||
var pkeys_map = $.ordered_map();
|
||||
|
||||
var matched = data.result.matched;
|
||||
if (that.show_matched && matched) {
|
||||
for (var i=0; i<matched.length; i++) {
|
||||
var pkey = matched[i];
|
||||
records_map.put(pkey, { matched: true });
|
||||
var compound_pkey = pkey + i;
|
||||
records_map.put(compound_pkey, { matched: true });
|
||||
pkeys_map.put(compound_pkey, pkey);
|
||||
}
|
||||
}
|
||||
|
||||
@ -719,11 +722,16 @@ IPA.hbac.test_run_facet = function(spec) {
|
||||
if (that.show_unmatched && notmatched) {
|
||||
for (i=0; i<notmatched.length; i++) {
|
||||
pkey = notmatched[i];
|
||||
records_map.put(pkey, { matched: false });
|
||||
compound_pkey = pkey + i;
|
||||
records_map.put(compound_pkey, { matched: false });
|
||||
pkeys_map.put(compound_pkey, pkey);
|
||||
}
|
||||
}
|
||||
|
||||
return records_map;
|
||||
return {
|
||||
records_map: records_map,
|
||||
pkeys_map: pkeys_map
|
||||
};
|
||||
};
|
||||
|
||||
that.get_records_command_name = function() {
|
||||
@ -811,4 +819,4 @@ exp.register = function() {
|
||||
phases.on('registration', exp.register);
|
||||
|
||||
return exp;
|
||||
});
|
||||
});
|
||||
|
@ -430,6 +430,7 @@ IPA.service.search_facet = function(spec) {
|
||||
that.get_records_map = function(data) {
|
||||
|
||||
var records_map = $.ordered_map();
|
||||
var pkeys_map = $.ordered_map();
|
||||
|
||||
var result = data.result.result;
|
||||
var pkey_name = that.managed_entity.metadata.primary_key ||
|
||||
@ -443,11 +444,16 @@ IPA.service.search_facet = function(spec) {
|
||||
pkey = adapter.load(record, that.alternative_pkey)[0];
|
||||
}
|
||||
if (that.filter_records(records_map, pkey, record)) {
|
||||
records_map.put(pkey, record);
|
||||
var compound_pkey = pkey + i;
|
||||
records_map.put(compound_pkey, record);
|
||||
pkeys_map.put(compound_pkey, pkey);
|
||||
}
|
||||
}
|
||||
|
||||
return records_map;
|
||||
return {
|
||||
records_map: records_map,
|
||||
pkeys_map: pkeys_map
|
||||
};
|
||||
};
|
||||
|
||||
return that;
|
||||
|
@ -490,7 +490,7 @@ topology.servers_search_facet = function(spec, no_init) {
|
||||
|
||||
var that = IPA.search_facet(spec);
|
||||
|
||||
that.create_get_records_command = function(pkeys, on_success, on_error) {
|
||||
that.create_get_records_command = function(records, pkeys, on_success, on_error) {
|
||||
|
||||
var on_success_extended = function(data, text_status, xhr) {
|
||||
// Call original on_success handler
|
||||
@ -560,7 +560,7 @@ topology.servers_search_facet = function(spec, no_init) {
|
||||
dialog.open();
|
||||
};
|
||||
|
||||
var batch = that.table_facet_create_get_records_command(pkeys,
|
||||
var batch = that.table_facet_create_get_records_command(records, pkeys,
|
||||
on_success_extended, on_error);
|
||||
|
||||
return batch;
|
||||
|
Loading…
Reference in New Issue
Block a user