mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Enabled paging on automount keys.
The automount keys search facet has been modified to support paging. Since the automountkey-find command doesn't support --pkey-only option, the facet is configured such that during a refresh operation it will retrieve all entries (including the key and info attributes) and then display only the ones that are supposed to be visible in the current page. Ticket #2093
This commit is contained in:
committed by
Petr Voborník
parent
ae2e49a222
commit
7c0c39581c
@@ -998,8 +998,21 @@ IPA.association_facet = function (spec) {
|
|||||||
dialog.open(that.container);
|
dialog.open(that.container);
|
||||||
};
|
};
|
||||||
|
|
||||||
that.get_pkeys = function(data) {
|
that.get_records_map = function(data) {
|
||||||
return data.result.result[that.get_attribute_name()] || [];
|
|
||||||
|
var records_map = $.ordered_map();
|
||||||
|
var association_name = that.get_attribute_name();
|
||||||
|
var pkey_name = that.managed_entity.metadata.primary_key;
|
||||||
|
|
||||||
|
var pkeys = data.result.result[association_name];
|
||||||
|
for (var i=0; pkeys && i<pkeys.length; i++) {
|
||||||
|
var pkey = pkeys[i];
|
||||||
|
var record = {};
|
||||||
|
record[pkey_name] = pkey;
|
||||||
|
records_map.put(pkey, record);
|
||||||
|
}
|
||||||
|
|
||||||
|
return records_map;
|
||||||
};
|
};
|
||||||
|
|
||||||
that.refresh = function() {
|
that.refresh = function() {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ IPA.automount.map_entity = function(spec) {
|
|||||||
factory: IPA.automount.key_search_facet,
|
factory: IPA.automount.key_search_facet,
|
||||||
facet_group: 'automountkey',
|
facet_group: 'automountkey',
|
||||||
nested_entity: 'automountkey',
|
nested_entity: 'automountkey',
|
||||||
pagination: false,
|
search_all_entries: true,
|
||||||
label: IPA.metadata.objects.automountkey.label,
|
label: IPA.metadata.objects.automountkey.label,
|
||||||
name: 'keys',
|
name: 'keys',
|
||||||
columns: [
|
columns: [
|
||||||
@@ -237,9 +237,13 @@ IPA.automount_key_column = function(spec) {
|
|||||||
var that = IPA.column(spec);
|
var that = IPA.column(spec);
|
||||||
|
|
||||||
that.setup = function(container, record) {
|
that.setup = function(container, record) {
|
||||||
|
|
||||||
container.empty();
|
container.empty();
|
||||||
|
|
||||||
var key = record.automountkey;
|
var key = record.automountkey;
|
||||||
|
if (key instanceof Array) key = key[0];
|
||||||
var info = record.automountinformation;
|
var info = record.automountinformation;
|
||||||
|
if (info instanceof Array) info = info[0];
|
||||||
|
|
||||||
$('<a/>', {
|
$('<a/>', {
|
||||||
href: '#'+key,
|
href: '#'+key,
|
||||||
|
|||||||
@@ -409,7 +409,8 @@ IPA.table_facet = function(spec) {
|
|||||||
that.managed_entity = spec.managed_entity ? IPA.get_entity(spec.managed_entity) : that.entity;
|
that.managed_entity = spec.managed_entity ? IPA.get_entity(spec.managed_entity) : that.entity;
|
||||||
|
|
||||||
that.pagination = spec.pagination === undefined ? true : spec.pagination;
|
that.pagination = spec.pagination === undefined ? true : spec.pagination;
|
||||||
that.search_all = spec.search_all;
|
that.search_all_entries = spec.search_all_entries;
|
||||||
|
that.search_all_attributes = spec.search_all_attributes;
|
||||||
that.selectable = spec.selectable === undefined ? true : spec.selectable;
|
that.selectable = spec.selectable === undefined ? true : spec.selectable;
|
||||||
|
|
||||||
that.columns = $.ordered_map();
|
that.columns = $.ordered_map();
|
||||||
@@ -504,20 +505,30 @@ IPA.table_facet = function(spec) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
that.get_pkeys = function(data) {
|
that.get_records_map = function(data) {
|
||||||
return [];
|
|
||||||
|
var records_map = $.ordered_map();
|
||||||
|
|
||||||
|
var result = data.result.result;
|
||||||
|
var pkey_name = that.managed_entity.metadata.primary_key;
|
||||||
|
|
||||||
|
for (var i=0; i<result.length; i++) {
|
||||||
|
var record = result[i];
|
||||||
|
var pkey = record[pkey_name];
|
||||||
|
if (pkey instanceof Array) pkey = pkey[0];
|
||||||
|
records_map.put(pkey, record);
|
||||||
|
}
|
||||||
|
|
||||||
|
return records_map;
|
||||||
};
|
};
|
||||||
|
|
||||||
that.load_page = function(data) {
|
that.load_page = function(data) {
|
||||||
|
|
||||||
that.pkeys = that.get_pkeys(data);
|
// get primary keys (and the complete records if search_all_entries is true)
|
||||||
|
var records_map = that.get_records_map(data);
|
||||||
|
|
||||||
if (that.pkeys.length) {
|
var total = records_map.length;
|
||||||
that.table.total_pages =
|
that.table.total_pages = total ? Math.ceil(total / that.table.page_length) : 1;
|
||||||
Math.ceil(that.pkeys.length / that.table.page_length);
|
|
||||||
} else {
|
|
||||||
that.table.total_pages = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete that.table.current_page;
|
delete that.table.current_page;
|
||||||
|
|
||||||
@@ -534,15 +545,13 @@ IPA.table_facet = function(spec) {
|
|||||||
}
|
}
|
||||||
that.table.current_page = page;
|
that.table.current_page = page;
|
||||||
|
|
||||||
if (!that.pkeys || !that.pkeys.length) {
|
if (!total) {
|
||||||
that.load_records([]);
|
|
||||||
that.table.summary.text(IPA.messages.association.no_entries);
|
that.table.summary.text(IPA.messages.association.no_entries);
|
||||||
|
that.load_records([]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
that.pkeys.sort();
|
// calculate the start and end of the current page
|
||||||
var total = that.pkeys.length;
|
|
||||||
|
|
||||||
var start = (that.table.current_page - 1) * that.table.page_length + 1;
|
var start = (that.table.current_page - 1) * that.table.page_length + 1;
|
||||||
var end = that.table.current_page * that.table.page_length;
|
var end = that.table.current_page * that.table.page_length;
|
||||||
end = end > total ? total : end;
|
end = end > total ? total : end;
|
||||||
@@ -553,31 +562,37 @@ IPA.table_facet = function(spec) {
|
|||||||
summary = summary.replace('${total}', total);
|
summary = summary.replace('${total}', total);
|
||||||
that.table.summary.text(summary);
|
that.table.summary.text(summary);
|
||||||
|
|
||||||
that.values = that.pkeys.slice(start-1, end);
|
// sort map based on primary keys
|
||||||
|
records_map = records_map.sort();
|
||||||
|
|
||||||
|
// trim map leaving the entries visible in the current page only
|
||||||
|
records_map = records_map.slice(start-1, end);
|
||||||
|
|
||||||
var columns = that.table.columns.values;
|
var columns = that.table.columns.values;
|
||||||
if (columns.length == 1) { // show pkey only
|
if (columns.length == 1) { // show primary keys only
|
||||||
var name = columns[0].name;
|
that.load_records(records_map.values);
|
||||||
var records = [];
|
|
||||||
for (var i=0; i<that.values.length; i++) {
|
|
||||||
var record = {};
|
|
||||||
record[name] = that.values[i];
|
|
||||||
records.push(record);
|
|
||||||
}
|
|
||||||
that.load_records(records);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get and show additional fields
|
if (that.search_all_entries) {
|
||||||
|
// map contains the primary keys and the complete records
|
||||||
|
that.load_records(records_map.values);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the complete records
|
||||||
that.get_records(
|
that.get_records(
|
||||||
|
records_map.keys,
|
||||||
function(data, text_status, xhr) {
|
function(data, text_status, xhr) {
|
||||||
var results = data.result.results;
|
var results = data.result.results;
|
||||||
var records = [];
|
for (var i=0; i<records_map.length; i++) {
|
||||||
for (var i=0; i<results.length; i++) {
|
var pkey = records_map.keys[i];
|
||||||
var record = results[i].result;
|
var record = records_map.get(pkey);
|
||||||
records.push(record);
|
// merge the record obtained from the refresh()
|
||||||
|
// with the record obtained from get_records()
|
||||||
|
$.extend(record, results[i].result);
|
||||||
}
|
}
|
||||||
that.load_records(records);
|
that.load_records(records_map.values);
|
||||||
},
|
},
|
||||||
function(xhr, text_status, error_thrown) {
|
function(xhr, text_status, error_thrown) {
|
||||||
that.load_records([]);
|
that.load_records([]);
|
||||||
@@ -599,10 +614,7 @@ IPA.table_facet = function(spec) {
|
|||||||
return that.managed_entity.name+'_get_records';
|
return that.managed_entity.name+'_get_records';
|
||||||
};
|
};
|
||||||
|
|
||||||
that.get_records = function(on_success, on_error) {
|
that.get_records = function(pkeys, on_success, on_error) {
|
||||||
|
|
||||||
var length = that.values.length;
|
|
||||||
if (!length) return;
|
|
||||||
|
|
||||||
var batch = IPA.batch_command({
|
var batch = IPA.batch_command({
|
||||||
name: that.get_records_command_name(),
|
name: that.get_records_command_name(),
|
||||||
@@ -610,13 +622,13 @@ IPA.table_facet = function(spec) {
|
|||||||
on_error: on_error
|
on_error: on_error
|
||||||
});
|
});
|
||||||
|
|
||||||
for (var i=0; i<length; i++) {
|
for (var i=0; i<pkeys.length; i++) {
|
||||||
var pkey = that.values[i];
|
var pkey = pkeys[i];
|
||||||
|
|
||||||
var command = IPA.command({
|
var command = IPA.command({
|
||||||
entity: that.table.entity.name,
|
entity: that.table.entity.name,
|
||||||
method: 'show',
|
method: 'show',
|
||||||
args: [pkey],
|
args: [ pkey ],
|
||||||
options: { all: true }
|
options: { all: true }
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -651,7 +663,7 @@ IPA.table_facet = function(spec) {
|
|||||||
label: entity.metadata.label,
|
label: entity.metadata.label,
|
||||||
entity: entity,
|
entity: entity,
|
||||||
pagination: true,
|
pagination: true,
|
||||||
search_all: that.search_all,
|
search_all_attributes: that.search_all_attributes,
|
||||||
scrollable: true,
|
scrollable: true,
|
||||||
selectable: that.selectable && !that.read_only
|
selectable: that.selectable && !that.read_only
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ IPA.hbac.rule_entity = function(spec) {
|
|||||||
that.entity_init();
|
that.entity_init();
|
||||||
|
|
||||||
that.builder.search_facet({
|
that.builder.search_facet({
|
||||||
search_all: true,
|
search_all_attributes: true,
|
||||||
columns: [
|
columns: [
|
||||||
'cn',
|
'cn',
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -230,18 +230,6 @@ IPA.hbac.test_facet = function(spec) {
|
|||||||
IPA.nav.push_state(state);
|
IPA.nav.push_state(state);
|
||||||
};
|
};
|
||||||
|
|
||||||
that.get_pkeys = function(data) {
|
|
||||||
var result = data.result.result;
|
|
||||||
var pkey_name = that.managed_entity.metadata.primary_key;
|
|
||||||
var pkeys = [];
|
|
||||||
for (var i=0; i<result.length; i++) {
|
|
||||||
var record = result[i];
|
|
||||||
var values = record[pkey_name];
|
|
||||||
pkeys.push(values[0]);
|
|
||||||
}
|
|
||||||
return pkeys;
|
|
||||||
};
|
|
||||||
|
|
||||||
that.get_search_command_name = function() {
|
that.get_search_command_name = function() {
|
||||||
return that.managed_entity.name + '_find' + (that.pagination ? '_pkeys' : '');
|
return that.managed_entity.name + '_find' + (that.pagination ? '_pkeys' : '');
|
||||||
};
|
};
|
||||||
@@ -730,16 +718,15 @@ IPA.hbac.test_run_facet = function(spec) {
|
|||||||
command.execute();
|
command.execute();
|
||||||
};
|
};
|
||||||
|
|
||||||
that.get_pkeys = function(data) {
|
that.get_records_map = function(data) {
|
||||||
var pkeys = [];
|
|
||||||
that.matched = {};
|
var records_map = $.ordered_map();
|
||||||
|
|
||||||
var matched = data.result.matched;
|
var matched = data.result.matched;
|
||||||
if (that.show_matched && matched) {
|
if (that.show_matched && matched) {
|
||||||
for (var i=0; i<matched.length; i++) {
|
for (var i=0; i<matched.length; i++) {
|
||||||
var pkey = matched[i];
|
var pkey = matched[i];
|
||||||
pkeys.push(pkey);
|
records_map.put(pkey, { matched: true });
|
||||||
that.matched[pkey] = 'TRUE';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -747,12 +734,11 @@ IPA.hbac.test_run_facet = function(spec) {
|
|||||||
if (that.show_unmatched && notmatched) {
|
if (that.show_unmatched && notmatched) {
|
||||||
for (i=0; i<notmatched.length; i++) {
|
for (i=0; i<notmatched.length; i++) {
|
||||||
pkey = notmatched[i];
|
pkey = notmatched[i];
|
||||||
pkeys.push(pkey);
|
records_map.put(pkey, { matched: false });
|
||||||
that.matched[pkey] = 'FALSE';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pkeys;
|
return records_map;
|
||||||
};
|
};
|
||||||
|
|
||||||
that.get_records_command_name = function() {
|
that.get_records_command_name = function() {
|
||||||
@@ -765,18 +751,6 @@ IPA.hbac.test_run_facet = function(spec) {
|
|||||||
return that.managed_entity.name+'_get_records';
|
return that.managed_entity.name+'_get_records';
|
||||||
};
|
};
|
||||||
|
|
||||||
that.load_records = function(records) {
|
|
||||||
var pkey_name = that.table.entity.metadata.primary_key;
|
|
||||||
that.table.empty();
|
|
||||||
for (var i=0; i<records.length; i++) {
|
|
||||||
var record = records[i];
|
|
||||||
var pkey = record[pkey_name][0];
|
|
||||||
record.matched = that.matched[pkey];
|
|
||||||
that.table.add_record(record);
|
|
||||||
}
|
|
||||||
that.table.set_values(that.selected_values);
|
|
||||||
};
|
|
||||||
|
|
||||||
init();
|
init();
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
|
|||||||
@@ -351,6 +351,10 @@ IPA.command = function(spec) {
|
|||||||
return that.options[name];
|
return that.options[name];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
that.remove_option = function(name) {
|
||||||
|
delete that.options[name];
|
||||||
|
};
|
||||||
|
|
||||||
that.execute = function() {
|
that.execute = function() {
|
||||||
|
|
||||||
function dialog_open(xhr, text_status, error_thrown) {
|
function dialog_open(xhr, text_status, error_thrown) {
|
||||||
|
|||||||
@@ -75,5 +75,28 @@ jQuery.ordered_map = jQuery.fn.ordered_map = function() {
|
|||||||
return that.values[index];
|
return that.values[index];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
that.sort = function() {
|
||||||
|
var keys = that.keys.slice(0);
|
||||||
|
keys.sort();
|
||||||
|
return that.trim(keys);
|
||||||
|
};
|
||||||
|
|
||||||
|
that.slice = function(start, end) {
|
||||||
|
var keys = that.keys.slice(start, end);
|
||||||
|
return that.trim(keys);
|
||||||
|
};
|
||||||
|
|
||||||
|
that.trim = function(keys) {
|
||||||
|
var new_map = $.ordered_map();
|
||||||
|
|
||||||
|
for (var i=0; i<keys.length; i++) {
|
||||||
|
var key = keys[i];
|
||||||
|
var value = that.get(key);
|
||||||
|
new_map.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new_map;
|
||||||
|
};
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -156,26 +156,15 @@ IPA.search_facet = function(spec) {
|
|||||||
IPA.nav.push_state(state);
|
IPA.nav.push_state(state);
|
||||||
};
|
};
|
||||||
|
|
||||||
that.get_pkeys = function(data) {
|
|
||||||
var result = data.result.result;
|
|
||||||
var pkey_name = that.managed_entity.metadata.primary_key;
|
|
||||||
var pkeys = [];
|
|
||||||
for (var i=0; i<result.length; i++) {
|
|
||||||
var record = result[i];
|
|
||||||
var value = record[pkey_name];
|
|
||||||
if (value instanceof Array) {
|
|
||||||
value = value[0];
|
|
||||||
}
|
|
||||||
pkeys.push(value);
|
|
||||||
}
|
|
||||||
return pkeys;
|
|
||||||
};
|
|
||||||
|
|
||||||
that.get_search_command_name = function() {
|
that.get_search_command_name = function() {
|
||||||
return that.managed_entity.name + '_find' + (that.pagination ? '_pkeys' : '');
|
var name = that.managed_entity.name + '_find';
|
||||||
|
if (that.pagination && !that.search_all_entries) {
|
||||||
|
name += '_pkeys';
|
||||||
|
}
|
||||||
|
return name;
|
||||||
};
|
};
|
||||||
|
|
||||||
that.refresh = function() {
|
that.create_refresh_command = function() {
|
||||||
|
|
||||||
var filter = [];
|
var filter = [];
|
||||||
var entity = that.managed_entity;
|
var entity = that.managed_entity;
|
||||||
@@ -194,15 +183,22 @@ IPA.search_facet = function(spec) {
|
|||||||
method: 'find',
|
method: 'find',
|
||||||
args: filter,
|
args: filter,
|
||||||
options: {
|
options: {
|
||||||
all: that.search_all
|
all: that.search_all_attributes
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (that.pagination) {
|
if (that.pagination) {
|
||||||
command.set_option('pkey_only', true);
|
if (!that.search_all_entries) command.set_option('pkey_only', true);
|
||||||
command.set_option('sizelimit', 0);
|
command.set_option('sizelimit', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return command;
|
||||||
|
};
|
||||||
|
|
||||||
|
that.refresh = function() {
|
||||||
|
|
||||||
|
var command = that.create_refresh_command();
|
||||||
|
|
||||||
command.on_success = function(data, text_status, xhr) {
|
command.on_success = function(data, text_status, xhr) {
|
||||||
that.filter.focus();
|
that.filter.focus();
|
||||||
that.load(data);
|
that.load(data);
|
||||||
@@ -230,6 +226,7 @@ IPA.search_facet = function(spec) {
|
|||||||
|
|
||||||
// methods that should be invoked by subclasses
|
// methods that should be invoked by subclasses
|
||||||
that.search_facet_refresh = that.refresh;
|
that.search_facet_refresh = that.refresh;
|
||||||
|
that.search_facet_create_refresh_command = that.create_refresh_command;
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ IPA.selinux.selinuxusermap_entity = function(spec) {
|
|||||||
that.entity_init();
|
that.entity_init();
|
||||||
|
|
||||||
that.builder.search_facet({
|
that.builder.search_facet({
|
||||||
search_all: true,
|
search_all_attributes: true,
|
||||||
columns: [
|
columns: [
|
||||||
'cn',
|
'cn',
|
||||||
'ipaselinuxuser',
|
'ipaselinuxuser',
|
||||||
|
|||||||
Reference in New Issue
Block a user