Hi, Please review the attached patch. Thanks!
ipa_entity_quick_links() has been added to generate quick links automatically from object's attribute_members, the same logic used for generating facet list. The search definition for each entity has been updated to use the new function. A unit test has been added for this function. -- Endi S. Dewata
>From 5e2c32a16b571257603eebfd30563714c6ca0190 Mon Sep 17 00:00:00 2001 From: Endi S. Dewata <edew...@redhat.com> Date: Fri, 1 Oct 2010 12:53:13 -0500 Subject: [PATCH] Autogenerating Quick Links. ipa_entity_quick_links() has been added to generate quick links automatically from object's attribute_members, the same logic used for generating facet list. The search definition for each entity has been updated to use the new function. A unit test has been added for this function. --- install/static/entity.js | 47 +++++++++++++ install/static/group.js | 46 +------------- install/static/host.js | 3 +- install/static/hostgroup.js | 3 +- install/static/netgroup.js | 3 +- install/static/rolegroup.js | 72 +-------------------- install/static/service.js | 33 +--------- install/static/test/entity_tests.html | 1 + install/static/test/entity_tests.js | 115 ++++++++++++++++++++++++++++++++- install/static/test/ipa_tests.js | 6 +- install/static/user.js | 59 +----------------- 11 files changed, 173 insertions(+), 215 deletions(-) diff --git a/install/static/entity.js b/install/static/entity.js index 39836fe..5be67a3 100644 --- a/install/static/entity.js +++ b/install/static/entity.js @@ -202,3 +202,50 @@ function ipa_entity_generate_views(obj_name, container, switch_view) container.append(ul); } + +function ipa_entity_quick_links(tr, attr, value, entry_attrs) { + + var obj_name = tr.closest('.search-container').attr('title'); + var pkey = ipa_objs[obj_name].primary_key; + var pkey_value = entry_attrs[pkey][0]; + + var td = $("<td/>"); + tr.append(td); + + $("<a/>", { + href: "#details", + click: function() { + var state = {}; + state[obj_name+'-facet'] = 'details'; + state[obj_name+'-pkey'] = pkey_value; + nav_push_state(state); + return false; + } + }).append($('<img/>', { + src: obj_name+'_details.png' + })).appendTo(td); + + var attribute_members = ipa_objs[obj_name].attribute_members; + for (attr_name in attribute_members) { + var objs = attribute_members[attr_name]; + for (var i = 0; i < objs.length; ++i) { + var m = objs[i]; + + $("<a/>", { + href: '#'+m, + click: function(m) { + return function() { + var state = {}; + state[obj_name+'-facet'] = 'associate'; + state[obj_name+'-enroll'] = m; + state[obj_name+'-pkey'] = pkey_value; + nav_push_state(state); + return false; + } + }(m) + }).append($('<img/>', { + src: m+'_member.png' + })).appendTo(td); + } + } +} diff --git a/install/static/group.js b/install/static/group.js index b1c0d89..4c2c5b0 100644 --- a/install/static/group.js +++ b/install/static/group.js @@ -24,7 +24,7 @@ ipa_entity_set_search_definition('group', [ ['cn', 'Name', null], ['gidnumber', 'GID', null], ['description', 'Description', null], - ['quick_links', 'Quick Links', group_render_quick_links] + ['quick_links', 'Quick Links', ipa_entity_quick_links] ]); ipa_entity_set_add_definition('group', [ @@ -64,47 +64,3 @@ function f_posix(dlg, mode) return (false); } } - -function group_render_quick_links(tr, attr, value, entry_attrs) { - - var td = $("<td/>"); - tr.append(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='group_details.png' />"), - click: function() { - var state = {}; - state['group-facet'] = 'details'; - state['group-pkey'] = entry_attrs['cn'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='user_enroll.png' />"), - click: function() { - var state = {}; - state['group-facet'] = 'associate'; - state['group-enroll'] = 'user'; - state['group-pkey'] = entry_attrs['cn'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='netgroup_member.png' />"), - click: function() { - var state = {}; - state['group-facet'] = 'associate'; - state['group-enroll'] = 'netgroup'; - state['group-pkey'] = entry_attrs['cn'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); -} diff --git a/install/static/host.js b/install/static/host.js index f59c1a3..432f2f7 100644 --- a/install/static/host.js +++ b/install/static/host.js @@ -24,7 +24,8 @@ ipa_entity_set_search_definition('host', [ ['fqdn', 'Name', null], ['description', 'Description', null], ['enrolled', 'Enrolled?', null], - ['manages', 'Manages?', null] + ['manages', 'Manages?', null], + ['quick_links', 'Quick Links', ipa_entity_quick_links] ]); ipa_entity_set_add_definition('host', [ diff --git a/install/static/hostgroup.js b/install/static/hostgroup.js index 512ebcf..e3863fe 100644 --- a/install/static/hostgroup.js +++ b/install/static/hostgroup.js @@ -22,7 +22,8 @@ ipa_entity_set_search_definition('hostgroup', [ ['cn', 'Name', null], - ['description', 'Description', null] + ['description', 'Description', null], + ['quick_links', 'Quick Links', ipa_entity_quick_links] ]); ipa_entity_set_add_definition('hostgroup', [ diff --git a/install/static/netgroup.js b/install/static/netgroup.js index 625ebfd..577590a 100644 --- a/install/static/netgroup.js +++ b/install/static/netgroup.js @@ -22,7 +22,8 @@ ipa_entity_set_search_definition('netgroup', [ ['cn', 'Name', null], - ['description', 'Description', null] + ['description', 'Description', null], + ['quick_links', 'Quick Links', ipa_entity_quick_links] ]); ipa_entity_set_add_definition('netgroup', [ diff --git a/install/static/rolegroup.js b/install/static/rolegroup.js index 2e52f10..0297554 100644 --- a/install/static/rolegroup.js +++ b/install/static/rolegroup.js @@ -23,7 +23,7 @@ ipa_entity_set_search_definition('rolegroup', [ ['cn', 'Role-group name', null], ['description', 'Description', null], - ['quick_links', 'Quick Links', rolegroup_render_quick_links] + ['quick_links', 'Quick Links', ipa_entity_quick_links] ]); ipa_entity_set_add_definition('rolegroup', [ @@ -39,73 +39,3 @@ ipa_entity_set_details_definition('rolegroup', [ ['description', 'Description', null], ]] ]); - -function rolegroup_render_quick_links(tr, attr, value, entry_attrs) { - - var td = $("<td/>"); - tr.append(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='rolegroup_details.png' />"), - click: function() { - var state = {}; - state['rolegroup-facet'] = 'details'; - state['rolegroup-pkey'] = entry_attrs['cn'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='user_member.png' />"), - click: function() { - var state = {}; - state['rolegroup-facet'] = 'associate'; - state['rolegroup-enroll'] = 'user'; - state['rolegroup-pkey'] = entry_attrs['cn'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='group_member.png' />"), - click: function() { - var state = {}; - state['rolegroup-facet'] = 'associate'; - state['rolegroup-enroll'] = 'group'; - state['rolegroup-pkey'] = entry_attrs['cn'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='host_member.png' />"), - click: function() { - var state = {}; - state['rolegroup-facet'] = 'associate'; - state['rolegroup-enroll'] = 'host'; - state['rolegroup-pkey'] = entry_attrs['cn'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='hostgroup_member.png' />"), - click: function() { - var state = {}; - state['rolegroup-facet'] = 'associate'; - state['rolegroup-enroll'] = 'hostgroup'; - state['rolegroup-pkey'] = entry_attrs['cn'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); -} diff --git a/install/static/service.js b/install/static/service.js index 8d8e103..c12e563 100644 --- a/install/static/service.js +++ b/install/static/service.js @@ -22,7 +22,7 @@ ipa_entity_set_search_definition('service', [ ['krbprincipalname', 'Principal', null], - ['quick_links', 'Quick Links', service_render_quick_links] + ['quick_links', 'Quick Links', ipa_entity_quick_links] ]); ipa_entity_set_add_definition('service', [ @@ -39,37 +39,6 @@ ipa_entity_set_details_definition('service', [ ]] ]); -function service_render_quick_links(tr, attr, value, entry_attrs) { - - var td = $("<td/>"); - tr.append(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='service_details.png' />"), - click: function() { - var state = {}; - state['service-facet'] = 'details'; - state['service-pkey'] = entry_attrs['krbprincipalname'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='host_enroll.png' />"), - click: function() { - var state = {}; - state['service-facet'] = 'associate'; - state['service-enroll'] = 'host'; - state['service-pkey'] = entry_attrs['krbprincipalname'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); -} - function service_add_krbprincipalname(add_dialog, flag) { if (flag == IPA_ADD_UPDATE) { var service = add_dialog.find('input[name=service]').val(); diff --git a/install/static/test/entity_tests.html b/install/static/test/entity_tests.html index 224bb23..a6d3f72 100644 --- a/install/static/test/entity_tests.html +++ b/install/static/test/entity_tests.html @@ -9,6 +9,7 @@ <script type="text/javascript" src="../details.js"></script> <script type="text/javascript" src="../search.js"></script> <script type="text/javascript" src="../add.js"></script> + <script type="text/javascript" src="../navigation.js"></script> <script type="text/javascript" src="../entity.js"></script> <script type="text/javascript" src="entity_tests.js"></script> </head> diff --git a/install/static/test/entity_tests.js b/install/static/test/entity_tests.js index 78fa2d4..09967c2 100644 --- a/install/static/test/entity_tests.js +++ b/install/static/test/entity_tests.js @@ -69,11 +69,11 @@ test("Testing ipa_entity_generate_views().", function() { ipa_init( "data", true, - function(data, status, xhr) { + function(data, text_status, xhr) { ok(true, "ipa_init() succeeded."); }, - function(xhr, options, thrownError) { - ok(false, "ipa_init() failed: "+thrownError); + function(xhr, text_status, error_thrown) { + ok(false, "ipa_init() failed: "+error_thrown); } ); @@ -135,3 +135,112 @@ test("Testing ipa_entity_generate_views().", function() { "Checking callback invocations" ); }); + +test("Testing ipa_entity_quick_links().", function() { + + var orig_push_state = nav_push_state; + var orig_get_state = nav_get_state; + var orig_remove_state = nav_remove_state; + + var state = {}; + + nav_push_state = function(params) { + $.extend(state, params); + }; + nav_get_state = function(key) { + return state[key]; + }; + nav_remove_state = function(key) { + delete state[key]; + }; + + ipa_ajax_options["async"] = false; + + ipa_init( + "data", + true, + function(data, text_status, xhr) { + ok(true, "ipa_init() succeeded."); + }, + function(xhr, text_status, error_thrown) { + ok(false, "ipa_init() failed: "+error_thrown); + } + ); + + var obj_name = "user"; + var pkey = ipa_objs[obj_name].primary_key; + var pkey_value = "test"; + + var entry_attrs = {}; + entry_attrs[pkey] = [pkey_value]; + + var container = $("<div/>", { + title: obj_name, + class: "search-container" + }); + + var search_table = $('<table/>', { + class: 'search-table' + }).appendTo(container); + + var tbody = $("<tbody/>").appendTo(search_table); + var tr = $("<tr/>").appendTo(tbody); + + ipa_entity_quick_links(tr, null, null, entry_attrs); + + var td = tr.children().first(); + var link = td.children().first(); + + equals( + link.attr("href"), "#details", + "Checking details link" + ); + + link.click(); + + equals( + state[obj_name+"-facet"], "details", + "Checking state[\""+obj_name+"-facet\"]" + ); + + equals( + state[obj_name+"-pkey"], pkey_value, + "Checking state[\""+obj_name+"-pkey\"]" + ); + + var attribute_members = ipa_objs[obj_name].attribute_members; + for (attr_name in attribute_members) { + var objs = attribute_members[attr_name]; + for (var i = 0; i < objs.length; ++i) { + var m = objs[i]; + + link = link.next(); + + equals( + link.attr("href"), "#"+m, + "Checking "+m+" link" + ); + + link.click(); + + equals( + state[obj_name+"-facet"], "associate", + "Checking state[\""+obj_name+"-facet\"]" + ); + + equals( + state[obj_name+"-enroll"], m, + "Checking state[\""+obj_name+"-enroll\"]" + ); + + equals( + state[obj_name+"-pkey"], pkey_value, + "Checking state[\""+obj_name+"-pkey\"]" + ); + } + } + + nav_push_state = orig_push_state; + nav_get_state = orig_get_state; + nav_remove_state = orig_remove_state; +}); diff --git a/install/static/test/ipa_tests.js b/install/static/test/ipa_tests.js index 8617a84..5831558 100644 --- a/install/static/test/ipa_tests.js +++ b/install/static/test/ipa_tests.js @@ -27,11 +27,11 @@ test("Testing ipa_init().", function() { ipa_init( "data", true, - function(data, status, xhr) { + function(data, text_status, xhr) { ok(true, "ipa_init() succeeded."); }, - function(xhr, options, thrownError) { - ok(false, "ipa_init() failed: "+thrownError); + function(xhr, text_status, error_thrown) { + ok(false, "ipa_init() failed: "+error_thrown); } ); }); diff --git a/install/static/user.js b/install/static/user.js index 5ac7f0a..2698c8b 100644 --- a/install/static/user.js +++ b/install/static/user.js @@ -27,7 +27,7 @@ ipa_entity_set_search_definition('user', [ ['mail', 'EMAIL', null], ['telephonenumber', 'Phone', null], ['title', 'Job Title', null], - ['quick_links', 'Quick Links', user_render_quick_links] + ['quick_links', 'Quick Links', ipa_entity_quick_links] ]); ipa_entity_set_add_definition('user', [ @@ -208,60 +208,3 @@ function a_numbers(jobj, result, mode) function a_manager(jobj, result, mode) { } - -function user_render_quick_links(tr, attr, value, entry_attrs) { - - var td = $("<td/>"); - tr.append(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='user_details.png' />"), - click: function() { - var state = {}; - state['user-facet'] = 'details'; - state['user-pkey'] = entry_attrs['uid'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='group_member.png' />"), - click: function() { - var state = {}; - state['user-facet'] = 'associate'; - state['user-enroll'] = 'group'; - state['user-pkey'] = entry_attrs['uid'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='netgroup_member.png' />"), - click: function() { - var state = {}; - state['user-facet'] = 'associate'; - state['user-enroll'] = 'netgroup'; - state['user-pkey'] = entry_attrs['uid'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); - - $("<a/>", { - href: "jslink", - html: $("<img src='rolegroup_member.png' />"), - click: function() { - var state = {}; - state['user-facet'] = 'associate'; - state['user-enroll'] = 'role'; - state['user-pkey'] = entry_attrs['uid'][0]; - $.bbq.pushState(state); - return false; - } - }).appendTo(td); -} -- 1.6.6.1
_______________________________________________ Freeipa-devel mailing list Freeipa-devel@redhat.com https://www.redhat.com/mailman/listinfo/freeipa-devel