liquid_feedback_frontend
diff model/unit.lua @ 525:63d6549cc00b
Delegation chain preview improved, better visualisation of current context, code cleanup
author | bsw |
---|---|
date | Fri May 18 19:07:07 2012 +0200 (2012-05-18) |
parents | c587d8762e62 |
children | 5ca9de94cb13 |
line diff
1.1 --- a/model/unit.lua Tue Apr 17 00:07:04 2012 +0200 1.2 +++ b/model/unit.lua Fri May 18 19:07:07 2012 +0200 1.3 @@ -21,6 +21,61 @@ 1.4 ref = 'members' 1.5 } 1.6 1.7 +Unit:add_reference{ 1.8 + mode = "11", 1.9 + to = mondelefant.class_prototype, 1.10 + this_key = "id", 1.11 + that_key = "unit_id", 1.12 + ref = "delegation_info", 1.13 + back_ref = "unit", 1.14 + selector_generator = function(list, options) 1.15 + assert(options.member_id, "member_id mandatory for delegation_info") 1.16 + local ids = { sep = ", " } 1.17 + for i, object in ipairs(list) do 1.18 + local id = object.id 1.19 + if id ~= nil then 1.20 + ids[#ids+1] = {"?", id} 1.21 + end 1.22 + end 1.23 + local sub_selector = Unit:get_db_conn():new_selector() 1.24 + if #ids == 0 then 1.25 + return sub_selector:empty_list_mode() 1.26 + end 1.27 + sub_selector:from("unit") 1.28 + sub_selector:add_field("unit.id", "unit_id") 1.29 + sub_selector:add_field{ '(delegation_info(?, unit.id, null, null)).*', options.member_id } 1.30 + sub_selector:add_where{ 'unit.id IN ($)', ids } 1.31 + 1.32 + local selector = Unit:get_db_conn():new_selector() 1.33 + selector:add_from(sub_selector, "delegation_info") 1.34 + selector:left_join("member", "first_trustee", "first_trustee.id = delegation_info.first_trustee_id") 1.35 + selector:left_join("member", "other_trustee", "other_trustee.id = delegation_info.other_trustee_id") 1.36 + selector:add_field("delegation_info.*") 1.37 + selector:add_field("first_trustee.name", "first_trustee_name") 1.38 + selector:add_field("other_trustee.name", "other_trustee_name") 1.39 + return selector 1.40 + end 1.41 +} 1.42 + 1.43 +function Unit.list:load_delegation_info_once_for_member_id(member_id) 1.44 + if self._delegation_info_loaded_for_member_id ~= member_id then 1.45 + self:load("delegation_info", { member_id = member_id }) 1.46 + for i, unit in ipairs(self) do 1.47 + unit._delegation_info_loaded_for_member_id = member_id 1.48 + end 1.49 + self._delegation_info_loaded_for_member_id = member_id 1.50 + end 1.51 +end 1.52 + 1.53 +function Unit.object:load_delegation_info_once_for_member_id(member_id) 1.54 + if self._delegation_info_loaded_for_member_id ~= member_id then 1.55 + self:load("delegation_info", { member_id = member_id }) 1.56 + self._delegation_info_loaded_for_member_id = member_id 1.57 + end 1.58 +end 1.59 + 1.60 + 1.61 + 1.62 function recursive_add_child_units(units, parent_unit) 1.63 parent_unit.childs = {} 1.64 for i, unit in ipairs(units) do