liquid_feedback_frontend
changeset 551:c1dc3b14a4f3
Initiative and initiative member_info preloading
author | bsw |
---|---|
date | Fri Jun 15 19:00:43 2012 +0200 (2012-06-15) |
parents | 65ddf5998458 |
children | 3344717939f0 |
files | app/main/delegation/_info.lua app/main/delegation/show.lua app/main/initiative/_list.lua app/main/initiative/_list_element.lua app/main/interest/_show_box.lua app/main/issue/_list.lua app/main/issue/_show.lua model/initiative.lua model/issue.lua model/member.lua static/icons/16/thumb_up_arrow.png static/icons/16/thumb_up_green_arrow.png |
line diff
1.1 --- a/app/main/delegation/_info.lua Tue May 29 20:52:49 2012 +0200 1.2 +++ b/app/main/delegation/_info.lua Fri Jun 15 19:00:43 2012 +0200 1.3 @@ -25,7 +25,9 @@ 1.4 end 1.5 1.6 if issue then 1.7 - info = issue.member_info 1.8 + if app.session.member_id then 1.9 + info = issue.member_info 1.10 + end 1.11 delegation_text = _"Delegate issue" 1.12 end 1.13 1.14 @@ -185,4 +187,4 @@ 1.15 1.16 } 1.17 1.18 -end 1.19 \ No newline at end of file 1.20 +end
2.1 --- a/app/main/delegation/show.lua Tue May 29 20:52:49 2012 +0200 2.2 +++ b/app/main/delegation/show.lua Fri Jun 15 19:00:43 2012 +0200 2.3 @@ -24,7 +24,7 @@ 2.4 2.5 local issue = Issue:by_id(param.get("issue_id", atom.integer)) 2.6 if issue then 2.7 - issue:load_delegation_info_once_for_member_id(app.session.member_id) 2.8 + issue:load("member_info", { member_id = app.session.member_id }) 2.9 voting_right_unit_id = issue.area.unit_id 2.10 slot.put_into("title", encode.html(_"Set delegation for Issue ##{number} in Area '#{area_name}'":gsub("#{number}", issue.id):gsub("#{area_name}", issue.area.name))) 2.11 util.help("delegation.new.issue")
3.1 --- a/app/main/initiative/_list.lua Tue May 29 20:52:49 2012 +0200 3.2 +++ b/app/main/initiative/_list.lua Fri Jun 15 19:00:43 2012 +0200 3.3 @@ -1,40 +1,24 @@ 3.4 local issue = param.get("issue", "table") 3.5 3.6 -local initiatives_selector = param.get("initiatives_selector", "table") 3.7 +local initiatives = issue.initiatives 3.8 3.9 local highlight_initiative = param.get("highlight_initiative", "table") 3.10 3.11 local for_member = param.get("for_member", "table") or app.session.member 3.12 3.13 -initiatives_selector 3.14 - :join("issue", nil, "issue.id = initiative.issue_id") 3.15 - 3.16 -if app.session.member_id then 3.17 - initiatives_selector 3.18 - :left_join("initiator", "_initiator", { "_initiator.initiative_id = initiative.id AND _initiator.member_id = ? AND _initiator.accepted", for_member.id } ) 3.19 - :left_join("supporter", "_supporter", { "_supporter.initiative_id = initiative.id AND _supporter.member_id = ?", for_member.id} ) 3.20 - :left_join("delegating_interest_snapshot", "_delegating_interest_snapshot", { "_delegating_interest_snapshot.issue_id = initiative.issue_id AND _delegating_interest_snapshot.member_id = ? AND _delegating_interest_snapshot.event = issue.latest_snapshot_event", for_member.id} ) 3.21 - :left_join("direct_supporter_snapshot", "_direct_supporter_snapshot", "_direct_supporter_snapshot.initiative_id = initiative.id AND _direct_supporter_snapshot.member_id = _delegating_interest_snapshot.delegate_member_ids[array_upper(_delegating_interest_snapshot.delegate_member_ids, 1)] AND _direct_supporter_snapshot.event = issue.latest_snapshot_event") 3.22 - 3.23 - :add_field("(_initiator.member_id NOTNULL)", "is_initiator") 3.24 - :add_field({"(_supporter.member_id NOTNULL) AND NOT EXISTS(SELECT 1 FROM opinion WHERE opinion.initiative_id = initiative.id AND opinion.member_id = ? AND ((opinion.degree = 2 AND NOT fulfilled) OR (opinion.degree = -2 AND fulfilled)))", for_member.id }, "is_supporter") 3.25 - :add_field({"EXISTS(SELECT 1 FROM opinion WHERE opinion.initiative_id = initiative.id AND opinion.member_id = ? AND ((opinion.degree = 2 AND NOT fulfilled) OR (opinion.degree = -2 AND fulfilled)))", for_member.id }, "is_potential_supporter") 3.26 - 3.27 - :add_field("_direct_supporter_snapshot.member_id NOTNULL", "is_supporter_via_delegation") 3.28 -end 3.29 - 3.30 -initiatives_selector:add_order_by("initiative.rank, initiative.supporter_count DESC, initiative.id") 3.31 - 3.32 -local initiatives_count = initiatives_selector:count() 3.33 - 3.34 local limit = param.get("limit", atom.number) 3.35 3.36 local more_initiatives_count 3.37 if limit then 3.38 - if initiatives_count > limit then 3.39 - more_initiatives_count = initiatives_count - limit 3.40 + if #initiatives > limit then 3.41 + more_initiatives_count = #initiatives - limit 3.42 end 3.43 - initiatives_selector:limit(limit) 3.44 + initiatives = {} 3.45 + for i, initiative in ipairs(issue.initiatives) do 3.46 + if i <= limit then 3.47 + initiatives[#initiatives+1] = initiative 3.48 + end 3.49 + end 3.50 end 3.51 3.52 local issue = param.get("issue", "table") 3.53 @@ -46,38 +30,30 @@ 3.54 3.55 ui.add_partial_param_names{ name } 3.56 3.57 -ui.paginate{ 3.58 - name = issue and "issue_" .. tostring(issue.id) .. "_page" or nil, 3.59 - selector = initiatives_selector, 3.60 - per_page = param.get("per_page", atom.number) or limit or 25, 3.61 - content = function() 3.62 - local initiatives = initiatives_selector:exec() 3.63 - if highlight_initiative then 3.64 - local highlight_initiative_found 3.65 - for i, initiative in ipairs(initiatives) do 3.66 - if initiative.id == highlight_initiative.id then 3.67 - highhighlight_initiative_found = true 3.68 - end 3.69 - end 3.70 - if not highhighlight_initiative_found then 3.71 - initiatives[#initiatives+1] = highlight_initiative 3.72 - if more_initiatives_count then 3.73 - more_initiatives_count = more_initiatives_count - 1 3.74 - end 3.75 - end 3.76 - end 3.77 - for i, initiative in ipairs(initiatives) do 3.78 - execute.view{ 3.79 - module = "initiative", 3.80 - view = "_list_element", 3.81 - params = { 3.82 - initiative = initiative, 3.83 - selected = highlight_initiative and highlight_initiative.id == initiative.id or nil, 3.84 - } 3.85 - } 3.86 +if highlight_initiative then 3.87 + local highlight_initiative_found 3.88 + for i, initiative in ipairs(initiatives) do 3.89 + if initiative.id == highlight_initiative.id then 3.90 + highhighlight_initiative_found = true 3.91 end 3.92 end 3.93 -} 3.94 + if not highhighlight_initiative_found then 3.95 + initiatives[#initiatives+1] = highlight_initiative 3.96 + if more_initiatives_count then 3.97 + more_initiatives_count = more_initiatives_count - 1 3.98 + end 3.99 + end 3.100 +end 3.101 +for i, initiative in ipairs(initiatives) do 3.102 + execute.view{ 3.103 + module = "initiative", 3.104 + view = "_list_element", 3.105 + params = { 3.106 + initiative = initiative, 3.107 + selected = highlight_initiative and highlight_initiative.id == initiative.id or nil, 3.108 + } 3.109 + } 3.110 +end 3.111 3.112 if more_initiatives_count and more_initiatives_count > 0 then 3.113 local text
4.1 --- a/app/main/initiative/_list_element.lua Tue May 29 20:52:49 2012 +0200 4.2 +++ b/app/main/initiative/_list_element.lua Fri Jun 15 19:00:43 2012 +0200 4.3 @@ -59,30 +59,40 @@ 4.4 end } 4.5 4.6 ui.container{ attr = { class = "interest" }, content = function() 4.7 - if initiative.is_initiator then 4.8 + if initiative.member_info.initiated then 4.9 local label = _"You are initiator of this initiative" 4.10 ui.image{ 4.11 attr = { alt = label, title = label }, 4.12 static = "icons/16/user_edit.png" 4.13 } 4.14 - elseif initiative.is_supporter then 4.15 - local label = _"You are supporter of this initiative" 4.16 - ui.image{ 4.17 - attr = { alt = label, title = label }, 4.18 - static = "icons/16/thumb_up_green.png" 4.19 - } 4.20 - elseif initiative.is_potential_supporter then 4.21 - local label = _"You are potentially supporter of this initiative" 4.22 - ui.image{ 4.23 - attr = { alt = label, title = label }, 4.24 - static = "icons/16/thumb_up.png" 4.25 - } 4.26 - elseif initiative.is_supporter_via_delegation then 4.27 - local label = _"You are supporter of this initiative via delegation" 4.28 - ui.image{ 4.29 - attr = { alt = label, title = label }, 4.30 - static = "icons/16/thumb_up_green.png" 4.31 - } 4.32 + elseif initiative.member_info.directly_supported then 4.33 + if initiative.member_info.satisfied then 4.34 + local label = _"You are supporter of this initiative" 4.35 + ui.image{ 4.36 + attr = { alt = label, title = label }, 4.37 + static = "icons/16/thumb_up_green.png" 4.38 + } 4.39 + else 4.40 + local label = _"You are potential supporter of this initiative" 4.41 + ui.image{ 4.42 + attr = { alt = label, title = label }, 4.43 + static = "icons/16/thumb_up.png" 4.44 + } 4.45 + end 4.46 + elseif initiative.member_info.supported then 4.47 + if initiative.member_info.satisfied then 4.48 + local label = _"You are supporter of this initiative via delegation" 4.49 + ui.image{ 4.50 + attr = { alt = label, title = label }, 4.51 + static = "icons/16/thumb_up_green_arrow.png" 4.52 + } 4.53 + else 4.54 + local label = _"You are potential supporter of this initiative via delegation" 4.55 + ui.image{ 4.56 + attr = { alt = label, title = label }, 4.57 + static = "icons/16/thumb_up_arrow.png" 4.58 + } 4.59 + end 4.60 end 4.61 end } 4.62
5.1 --- a/app/main/interest/_show_box.lua Tue May 29 20:52:49 2012 +0200 5.2 +++ b/app/main/interest/_show_box.lua Fri Jun 15 19:00:43 2012 +0200 5.3 @@ -2,10 +2,7 @@ 5.4 local issue = param.get("issue", "table") 5.5 local initiative = param.get("initiative", "table") 5.6 5.7 -local interest = Interest:by_pk(issue.id, app.session.member.id) 5.8 -local membership = Membership:by_pk(issue.area_id, app.session.member_id) 5.9 - 5.10 -if interest then 5.11 +if issue.member_info.own_participation then 5.12 5.13 if issue.closed then 5.14 ui.tag{ content = _"You were interested" }
6.1 --- a/app/main/issue/_list.lua Tue May 29 20:52:49 2012 +0200 6.2 +++ b/app/main/issue/_list.lua Fri Jun 15 19:00:43 2012 +0200 6.3 @@ -31,7 +31,7 @@ 6.4 content = function() 6.5 local highlight_string = param.get("highlight_string", "string") 6.6 local issues = issues_selector:exec() 6.7 - issues:load_everything_for_member_id(member.id) 6.8 + issues:load_everything_for_member_id(member and member.id or nil) 6.9 6.10 ui.container{ attr = { class = "issues" }, content = function() 6.11
7.1 --- a/app/main/issue/_show.lua Tue May 29 20:52:49 2012 +0200 7.2 +++ b/app/main/issue/_show.lua Fri Jun 15 19:00:43 2012 +0200 7.3 @@ -94,7 +94,7 @@ 7.4 slot.put(" · ") 7.5 end 7.6 7.7 - if not issue.closed then 7.8 + if not issue.closed and app.session.member_id then 7.9 if issue.member_info.own_delegation_scope ~= "issue" then 7.10 ui.link{ text = _"Delegate issue", module = "delegation", view = "show", params = { issue_id = issue.id } } 7.11 else 7.12 @@ -181,9 +181,8 @@ 7.13 issue = issue, 7.14 initiatives_selector = initiatives_selector, 7.15 highlight_string = highlight_string, 7.16 - per_page = initiative_limit, 7.17 no_sort = true, 7.18 - limit = initiative_limit, 7.19 + limit = 5, 7.20 for_member = for_member 7.21 } 7.22 }
8.1 --- a/model/initiative.lua Tue May 29 20:52:49 2012 +0200 8.2 +++ b/model/initiative.lua Fri Jun 15 19:00:43 2012 +0200 8.3 @@ -108,6 +108,75 @@ 8.4 ref = 'supporting_members_snapshot' 8.5 } 8.6 8.7 +Initiative:add_reference{ 8.8 + mode = "11", 8.9 + to = mondelefant.class_prototype, 8.10 + this_key = "id", 8.11 + that_key = "initiative_id", 8.12 + ref = "member_info", 8.13 + back_ref = "initiative", 8.14 + selector_generator = function(list, options) 8.15 + assert(options.member_id, "member_id mandatory for member_info") 8.16 + local ids = { sep = ", " } 8.17 + local issue_ids = { sep = ", " } 8.18 + for i, object in ipairs(list) do 8.19 + local id = object.id 8.20 + if id ~= nil then 8.21 + ids[#ids+1] = {"?", id} 8.22 + issue_ids[#issue_ids+1] = { "?", object.issue_id } 8.23 + end 8.24 + end 8.25 + 8.26 + local sub_selector = Issue:get_db_conn():new_selector() 8.27 + if #ids == 0 then 8.28 + return sub_selector:empty_list_mode() 8.29 + end 8.30 + sub_selector:from("issue") 8.31 + sub_selector:add_field("issue.id", "issue_id") 8.32 + sub_selector:add_field{ '(delegation_info(?, null, null, issue.id, ?)).*', options.member_id, options.trustee_id } 8.33 + sub_selector:add_where{ 'issue.id IN ($)', issue_ids } 8.34 + 8.35 + local selector = Initiative:get_db_conn():new_selector() 8.36 + selector:add_from("initiative") 8.37 + selector:add_field("initiative.id", "initiative_id") 8.38 + selector:join("issue", nil, "issue.id = initiative.issue_id") 8.39 + selector:join(sub_selector, "delegation_info", "delegation_info.issue_id = issue.id") 8.40 + selector:add_field("delegation_info.*") 8.41 + 8.42 + selector:left_join("supporter", nil, "supporter.initiative_id = initiative.id AND supporter.member_id = delegation_info.participating_member_id") 8.43 + 8.44 + selector:left_join("delegating_interest_snapshot", "delegating_interest_s", { "delegating_interest_s.event = issue.latest_snapshot_event AND delegating_interest_s.issue_id = issue.id AND delegating_interest_s.member_id = ?", options.member_id }) 8.45 + 8.46 + selector:left_join("direct_supporter_snapshot", "supporter_s", { "supporter_s.event = issue.latest_snapshot_event AND supporter_s.initiative_id = initiative.id AND (supporter_s.member_id = ? OR supporter_s.member_id = delegating_interest_s.delegate_member_ids[array_upper(delegating_interest_s.delegate_member_ids, 1)])", options.member_id }) 8.47 + 8.48 + selector:add_field("CASE WHEN issue.fully_frozen ISNULL AND issue.closed ISNULL THEN supporter.member_id NOTNULL ELSE supporter_s.member_id NOTNULL END", "supported") 8.49 + selector:add_field({ "CASE WHEN issue.fully_frozen ISNULL AND issue.closed ISNULL THEN delegation_info.own_participation AND supporter.member_id NOTNULL ELSE supporter_s.member_id = ? END", options.member_id }, "directly_supported") 8.50 + 8.51 + selector:add_field("CASE WHEN issue.fully_frozen ISNULL AND issue.closed ISNULL THEN supporter.member_id NOTNULL AND NOT EXISTS(SELECT 1 FROM critical_opinion WHERE critical_opinion.initiative_id = initiative.id AND critical_opinion.member_id = delegation_info.participating_member_id) ELSE supporter_s.satisfied NOTNULL END", "satisfied") 8.52 + 8.53 + 8.54 + --selector:add_field("", "informed") 8.55 + selector:left_join("initiator", nil, { "initiator.initiative_id = initiative.id AND initiator.member_id = ? AND initiator.accepted", options.member_id }) 8.56 + selector:add_field("initiator.member_id NOTNULL", "initiated") 8.57 + 8.58 + return selector 8.59 + end 8.60 +} 8.61 + 8.62 +function Initiative.list:load_everything_for_member_id(member_id) 8.63 + if member_id then 8.64 + self:load("member_info", { member_id = member_id }) 8.65 + end 8.66 +end 8.67 + 8.68 +function Initiative.object:load_everything_for_member_id(member_id) 8.69 + if member_id then 8.70 + self:load("member_info", { member_id = member_id }) 8.71 + end 8.72 +end 8.73 + 8.74 + 8.75 + 8.76 8.77 function Initiative:get_search_selector(search_string) 8.78 return self:new_selector()
9.1 --- a/model/issue.lua Tue May 29 20:52:49 2012 +0200 9.2 +++ b/model/issue.lua Fri Jun 15 19:00:43 2012 +0200 9.3 @@ -31,7 +31,8 @@ 9.4 this_key = 'id', 9.5 that_key = 'issue_id', 9.6 ref = 'initiatives', 9.7 - back_ref = 'issue' 9.8 + back_ref = 'issue', 9.9 + default_order = 'initiative.rank, initiative.supporter_count DESC, id' 9.10 } 9.11 9.12 Issue:add_reference{ 9.13 @@ -159,14 +160,22 @@ 9.14 local areas = self:load("area") 9.15 areas:load("unit") 9.16 self:load("policy") 9.17 - self:load("member_info", { member_id = member_id }) 9.18 + if member_id then 9.19 + self:load("member_info", { member_id = member_id }) 9.20 + end 9.21 + local initiatives = self:load("initiatives") 9.22 + initiatives:load_everything_for_member_id(member_id) 9.23 end 9.24 9.25 function Issue.object:load_everything_for_member_id(member_id) 9.26 local areas = self:load("area") 9.27 areas:load("unit") 9.28 self:load("policy") 9.29 - self:load("member_info", { member_id = member_id }) 9.30 + if member_id then 9.31 + self:load("member_info", { member_id = member_id }) 9.32 + end 9.33 + local initiatives = self:load("initiatives") 9.34 + initiatives:load_everything_for_member_id(member_id) 9.35 end 9.36 9.37 function Issue:get_state_name_for_state(value) 9.38 @@ -281,4 +290,4 @@ 9.39 9.40 function Issue.object_get:etherpad_url() 9.41 return config.etherpad.base_url .. "p/" .. config.etherpad.group_id .. "$Issue" .. self.id 9.42 -end 9.43 \ No newline at end of file 9.44 +end
10.1 --- a/model/member.lua Tue May 29 20:52:49 2012 +0200 10.2 +++ b/model/member.lua Fri Jun 15 19:00:43 2012 +0200 10.3 @@ -488,9 +488,9 @@ 10.4 :for_share() 10.5 :exec() 10.6 self.__units_with_voting_right_hash = {} 10.7 - for i, privilege in ipairs(privileges) do 10.8 - self.__units_with_voting_right_hash[privilege.unit_id] = true 10.9 - end 10.10 + for i, privilege in ipairs(privileges) do 10.11 + self.__units_with_voting_right_hash[privilege.unit_id] = true 10.12 + end 10.13 end 10.14 return self.__units_with_voting_right_hash[unit_id] and true or false 10.15 end
11.1 Binary file static/icons/16/thumb_up_arrow.png has changed
12.1 Binary file static/icons/16/thumb_up_green_arrow.png has changed