summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2012-03-22 17:03:57 +0100
committerPetr Vobornik <pvoborni@redhat.com>2012-03-29 13:39:37 +0200
commitbbe672a2aea1651a4a0eeca20b8339f0799f3431 (patch)
tree6f14a8c94472b33f1c6373fd0e0f6ba51b790e96
parent5cfee2338d548035151926c5c235f3426fca0499 (diff)
downloadfreeipa-bbe672a2aea1651a4a0eeca20b8339f0799f3431.tar.gz
freeipa-bbe672a2aea1651a4a0eeca20b8339f0799f3431.tar.xz
freeipa-bbe672a2aea1651a4a0eeca20b8339f0799f3431.zip
Facet expiration flag
Problem: For performance reason a facet may cache the data in browser's memory. There should be a flag to indicate whether a facet has expired and should be refreshed. The expired flag could be set by these events: 1) any update operation 2) changing search filter in search facet 3) switching page in a multi-paged search/association facet 4) switching direct/indirect view in association facet 5) facet expiration time A facet should be able to use these methods to refresh itself: 6) on demand: an expired facet should be refreshed when a user opens it. 7) automatic: an open facet should automatically refresh itself when it expires. Solution: This patch solves cases: #2, #3, #5, #6. Case #4 works without any change. Case #1 will be solved later. Case #7 is deffered. Default expiration timeout was set to 10 minutes. In this patch are also updated facet.needs_update methods to reflect changes in containing facets. https://fedorahosted.org/freeipa/ticket/2075
-rw-r--r--install/ui/association.js4
-rw-r--r--install/ui/details.js10
-rw-r--r--install/ui/facet.js37
-rw-r--r--install/ui/ipa.js15
-rw-r--r--install/ui/search.js43
5 files changed, 92 insertions, 17 deletions
diff --git a/install/ui/association.js b/install/ui/association.js
index 238006f42..ab43518f6 100644
--- a/install/ui/association.js
+++ b/install/ui/association.js
@@ -1064,9 +1064,7 @@ IPA.association_facet = function (spec) {
var page = parseInt(IPA.nav.get_state(that.entity.name+'-page'), 10) || 1;
if (that.table.current_page !== page) return true;
- if (that.error_displayed()) return true;
-
- return false;
+ return that.facet_needs_update();
};
init();
diff --git a/install/ui/details.js b/install/ui/details.js
index 32ace398f..f7e95ebfe 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -413,14 +413,21 @@ IPA.details_facet = function(spec) {
that.facet_show();
that.pkey = IPA.nav.get_state(that.entity.name+'-pkey');
+ that.old_key_prefix = that.entity.get_primary_key_prefix();
that.header.set_pkey(that.pkey);
};
that.needs_update = function() {
if (that._needs_update !== undefined) return that._needs_update;
+
+ var needs_update = that.facet_needs_update();
+
var pkey = IPA.nav.get_state(that.entity.name+'-pkey');
- var needs_update = that.error_displayed();
+ var key_prefix = that.entity.get_primary_key_prefix();
+
needs_update = needs_update || pkey !== that.pkey;
+ needs_update = needs_update || IPA.array_diff(key_prefix, that.old_key_prefix);
+
return needs_update;
};
@@ -472,6 +479,7 @@ IPA.details_facet = function(spec) {
}
that.policies.post_load(data);
that.enable_update(false);
+ that.clear_expired_flag();
};
that.save = function(record) {
diff --git a/install/ui/facet.js b/install/ui/facet.js
index ab71f820f..a38bcddfa 100644
--- a/install/ui/facet.js
+++ b/install/ui/facet.js
@@ -45,6 +45,9 @@ IPA.facet = function(spec) {
that.header = spec.header || IPA.facet_header({ facet: that });
that._needs_update = spec.needs_update;
+ that.expired_flag = true;
+ that.last_updated = null;
+ that.expire_timeout = spec.expire_timeout || 600; //[seconds]
that.dialogs = $.ordered_map();
@@ -140,8 +143,34 @@ IPA.facet = function(spec) {
};
that.needs_update = function() {
+
if (that._needs_update !== undefined) return that._needs_update;
- return true;
+
+ var needs_update = false;
+
+ if (that.expire_timeout && that.expire_timeout > 0) {
+
+ if (!that.last_updated) {
+ needs_update = true;
+ } else {
+ var now = Date.now();
+ needs_update = (now - that.last_updated) > that.expire_timeout * 1000;
+ }
+ }
+
+ needs_update = needs_update || that.expired_flag;
+ needs_update = needs_update || that.error_displayed();
+
+ return needs_update;
+ };
+
+ that.set_expired_flag = function() {
+ that.expired_flag = true;
+ };
+
+ that.clear_expired_flag = function() {
+ that.expired_flag = false;
+ that.last_updated = Date.now();
};
that.is_dirty = function() {
@@ -263,6 +292,7 @@ IPA.facet = function(spec) {
that.facet_create = that.create;
that.facet_create_header = that.create_header;
that.facet_create_content = that.create_content;
+ that.facet_needs_update = that.needs_update;
that.facet_show = that.show;
that.facet_hide = that.hide;
that.facet_load = that.load;
@@ -583,6 +613,8 @@ IPA.table_facet = function(spec) {
that.table.total_pages_span.text(that.table.total_pages);
that.table.pagination_control.css('visibility', 'visible');
+
+ that.clear_expired_flag();
};
@@ -821,6 +853,7 @@ IPA.table_facet = function(spec) {
if (that.table.current_page > 1) {
var state = {};
state[that.entity.name+'-page'] = that.table.current_page - 1;
+ that.set_expired_flag();
IPA.nav.push_state(state);
}
};
@@ -829,6 +862,7 @@ IPA.table_facet = function(spec) {
if (that.table.current_page < that.table.total_pages) {
var state = {};
state[that.entity.name+'-page'] = that.table.current_page + 1;
+ that.set_expired_flag();
IPA.nav.push_state(state);
}
};
@@ -841,6 +875,7 @@ IPA.table_facet = function(spec) {
}
var state = {};
state[that.entity.name+'-page'] = page;
+ that.set_expired_flag();
IPA.nav.push_state(state);
};
};
diff --git a/install/ui/ipa.js b/install/ui/ipa.js
index 34174c81a..be8748101 100644
--- a/install/ui/ipa.js
+++ b/install/ui/ipa.js
@@ -1548,6 +1548,21 @@ IPA.is_empty = function(value) {
return empty;
};
+IPA.array_diff = function(a, b) {
+
+ if (a === b || (!a && !b)) return false;
+
+ if (!a || !b) return true;
+
+ if (a.length !== b.length) return true;
+
+ for (var i=0; i<a.length; i++) {
+ if (a[i] !== b[i]) return true;
+ }
+
+ return false;
+};
+
IPA.config = {
default_priority: 500
};
diff --git a/install/ui/search.js b/install/ui/search.js
index 6bde398be..b7c5034ab 100644
--- a/install/ui/search.js
+++ b/install/ui/search.js
@@ -4,6 +4,7 @@
* Pavel Zuna <pzuna@redhat.com>
* Adam Young <ayoung@redhat.com>
* Endi S. Dewata <edewata@redhat.com>
+ * Petr Vobornik <pvoborni@redhat.com>
*
* Copyright (C) 2010 Red Hat
* see file 'COPYING' for use and warranty information
@@ -128,12 +129,25 @@ IPA.search_facet = function(spec) {
var filter = IPA.nav.get_state(that.entity.name+'-filter');
that.old_filter = filter || '';
+ that.old_pkeys = that.managed_entity.get_primary_key_prefix();
if (that.filter) {
that.filter.val(filter);
}
};
+ that.needs_update = function() {
+ if (that._needs_update !== undefined) return that._needs_update;
+
+ var needs_update = that.facet_needs_update();
+
+ //check if state changed
+ var pkeys = that.managed_entity.get_primary_key_prefix();
+ needs_update = needs_update || IPA.array_diff(pkeys, that.old_pkeys);
+
+ return needs_update;
+ };
+
that.show_add_dialog = function() {
var dialog = that.managed_entity.get_dialog('add');
dialog.open(that.container);
@@ -171,8 +185,12 @@ IPA.search_facet = function(spec) {
that.find = function() {
var filter = that.filter.val();
+ var old_filter = IPA.nav.get_state(that.managed_entity.name+'-filter');
var state = {};
state[that.managed_entity.name + '-filter'] = filter;
+
+ if (filter !== old_filter) that.set_expired_flag();
+
IPA.nav.push_state(state);
};
@@ -186,16 +204,8 @@ IPA.search_facet = function(spec) {
that.create_refresh_command = function() {
- var filter = [];
- var entity = that.managed_entity;
-
- filter.unshift(IPA.nav.get_state(entity.name+'-filter'));
- entity = entity.get_containing_entity();
-
- while (entity !== null) {
- filter.unshift(IPA.nav.get_state(entity.name+'-pkey'));
- entity = entity.get_containing_entity();
- }
+ var filter = that.managed_entity.get_primary_key_prefix();
+ filter.push(IPA.nav.get_state(that.managed_entity.name+'-filter'));
var command = IPA.command({
name: that.get_search_command_name(),
@@ -239,8 +249,14 @@ IPA.search_facet = function(spec) {
};
that.needs_clear = function() {
+ var clear = false;
var filter = IPA.nav.get_state(that.entity.name+'-filter') || '';
- return that.old_filter !== '' || that.old_filter !== filter;
+ clear = that.old_filter !== '' || that.old_filter !== filter;
+
+ var pkeys = that.managed_entity.get_primary_key_prefix();
+ clear = clear || IPA.array_diff(pkeys, that.old_pkeys);
+
+ return clear;
};
init();
@@ -337,8 +353,11 @@ IPA.nested_search_facet = function(spec) {
that.header.set_pkey(
IPA.nav.get_state(IPA.current_entity.name+'-pkey'));
+ var filter = IPA.nav.get_state(that.managed_entity.name+'-filter');
+ that.old_filter = filter || '';
+ that.old_pkeys = that.managed_entity.get_primary_key_prefix();
+
if (that.filter) {
- var filter = IPA.nav.get_state(that.managed_entity.name+'-filter');
that.filter.val(filter);
}
};