bsw/jbe@19: local initiative = param.get("initiative", "table") bsw/jbe@19: local initiator = param.get("initiator", "table") bsw/jbe@19: bsw/jbe@19: if not initiative then bsw/jbe@19: initiative = Initiative:by_id(param.get("initiative_id", atom.number)) bsw/jbe@19: end bsw/jbe@19: bsw@51: if not initiator and app.session.member_id then bsw/jbe@19: initiator = Initiator:by_pk(initiative.id, app.session.member.id) bsw/jbe@19: end bsw/jbe@19: bsw/jbe@19: local current_draft_name = _"Current draft" bsw/jbe@19: if initiative.issue.half_frozen then bsw/jbe@19: current_draft_name = _"Voting proposal" bsw/jbe@19: end bsw/jbe@19: bsw/jbe@19: if initiative.issue.state == "finished" then bsw/jbe@19: current_draft_name = _"Voted proposal" bsw/jbe@19: end bsw/jbe@19: bsw/jbe@19: local tabs = { bsw/jbe@19: { bsw/jbe@19: name = "current_draft", bsw/jbe@19: label = current_draft_name, bsw/jbe@19: icon = { static = "icons/16/script.png" }, bsw/jbe@19: module = "initiative", bsw/jbe@19: view = "_current_draft", bsw/jbe@19: params = { bsw/jbe@19: initiative = initiative, bsw/jbe@19: initiator = initiator bsw/jbe@19: } bsw/jbe@19: } bsw/jbe@19: } bsw/jbe@19: bsw@51: if app.session.member_id then bsw@51: if initiative.issue.ranks_available then bsw@51: tabs[#tabs+1] = { bsw@51: name = "voting", bsw@51: label = _"Voting details", bsw@51: icon = { static = "icons/16/email_open.png" }, bsw@51: module = "initiative", bsw@51: view = "_show_voting", bsw@51: params = { bsw@51: initiative = initiative bsw@51: } bsw/jbe@19: } bsw@51: end bsw/jbe@19: end bsw/jbe@19: bsw/jbe@19: local suggestion_count = initiative:get_reference_selector("suggestions"):count() bsw/jbe@19: bsw/jbe@19: tabs[#tabs+1] = { bsw/jbe@19: name = "suggestions", bsw/jbe@19: label = _"Suggestions" .. " (" .. tostring(suggestion_count) .. ")", bsw/jbe@19: icon = { static = "icons/16/comments.png" }, bsw/jbe@19: module = "initiative", bsw/jbe@19: view = "_suggestions", bsw/jbe@19: params = { bsw/jbe@19: initiative = initiative bsw/jbe@19: } bsw/jbe@19: } bsw/jbe@19: bsw@51: if app.session.member_id then bsw@51: local members_selector = initiative:get_reference_selector("supporting_members_snapshot") bsw@51: :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id") bsw@51: :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id") bsw@51: :add_field("direct_interest_snapshot.weight") bsw@51: :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event") bsw@51: :add_where("direct_supporter_snapshot.satisfied") bsw@51: :add_field("direct_supporter_snapshot.informed", "is_informed") bsw@51: bsw@51: local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object") bsw@51: local direct_satisfied_supporter_count = tmp.count bsw@51: local indirect_satisfied_supporter_count = (tmp.weight or 0) - tmp.count bsw@51: bsw@51: local count_string bsw@51: if indirect_satisfied_supporter_count > 0 then bsw@51: count_string = "(" .. tostring(direct_satisfied_supporter_count) .. "+" .. tostring(indirect_satisfied_supporter_count) .. ")" bsw@51: else bsw@51: count_string = "(" .. tostring(direct_satisfied_supporter_count) .. ")" bsw@51: end bsw@51: bsw@51: tabs[#tabs+1] = { bsw@51: name = "satisfied_supporter", bsw@51: label = _"Supporter" .. " " .. count_string, bsw@51: icon = { static = "icons/16/thumb_up_green.png" }, bsw@51: module = "member", bsw@51: view = "_list", bsw@51: params = { bsw@51: initiative = initiative, bsw@51: members_selector = members_selector bsw@51: } bsw/jbe@19: } bsw@51: bsw@51: local members_selector = initiative:get_reference_selector("supporting_members_snapshot") bsw@51: :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id") bsw@51: :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id") bsw@51: :add_field("direct_interest_snapshot.weight") bsw@51: :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event") bsw@51: :add_where("NOT direct_supporter_snapshot.satisfied") bsw@51: :add_field("direct_supporter_snapshot.informed", "is_informed") bsw@51: bsw@51: local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object") bsw@51: local direct_potential_supporter_count = tmp.count bsw@51: local indirect_potential_supporter_count = (tmp.weight or 0) - tmp.count bsw@51: bsw@51: local count_string bsw@51: if indirect_potential_supporter_count > 0 then bsw@51: count_string = "(" .. tostring(direct_potential_supporter_count) .. "+" .. tostring(indirect_potential_supporter_count) .. ")" bsw@51: else bsw@51: count_string = "(" .. tostring(direct_potential_supporter_count) .. ")" bsw@51: end bsw@51: bsw@51: tabs[#tabs+1] = { bsw@51: name = "supporter", bsw@51: label = _"Potential supporter" .. " " .. count_string, bsw@51: icon = { static = "icons/16/thumb_up.png" }, bsw@51: module = "member", bsw@51: view = "_list", bsw@51: params = { bsw@51: initiative = initiative, bsw@51: members_selector = members_selector bsw@51: } bsw@51: } bsw@51: bsw@51: local initiators_members_selector = initiative:get_reference_selector("initiating_members") bsw@51: :add_field("initiator.accepted", "accepted") bsw@51: bsw@51: if not (initiator and initiator.accepted) then bsw@51: initiators_members_selector:add_where("initiator.accepted") bsw@51: end bsw@51: bsw@51: local initiator_count = initiators_members_selector:count() bsw@51: bsw@51: tabs[#tabs+1] = { bsw@51: name = "initiators", bsw@51: label = _"Initiators" .. " (" .. tostring(initiator_count) .. ")", bsw@51: icon = { static = "icons/16/user_edit.png" }, bsw@51: module = "initiative", bsw@51: view = "_initiators", bsw@51: params = { bsw@51: initiative = initiative, bsw@51: initiator = initiator, bsw@51: initiators_members_selector = initiators_members_selector bsw@51: } bsw@51: } bsw/jbe@19: end bsw/jbe@19: bsw/jbe@19: local drafts_count = initiative:get_reference_selector("drafts"):count() bsw/jbe@19: bsw/jbe@19: tabs[#tabs+1] = { bsw/jbe@19: name = "drafts", bsw/jbe@19: label = _"Draft history" .. " (" .. tostring(drafts_count) .. ")", bsw/jbe@19: icon = { static = "icons/16/script.png" }, bsw/jbe@19: module = "draft", bsw/jbe@19: view = "_list", bsw/jbe@19: params = { drafts = initiative.drafts } bsw/jbe@19: } bsw/jbe@19: bsw/jbe@19: tabs[#tabs+1] = { bsw/jbe@19: name = "details", bsw/jbe@19: label = _"Details", bsw/jbe@19: icon = { static = "icons/16/magnifier.png" }, bsw/jbe@19: module = "initiative", bsw/jbe@19: view = "_details", bsw/jbe@19: params = { bsw/jbe@19: initiative = initiative, bsw/jbe@19: members_selector = members_selector bsw/jbe@19: } bsw/jbe@19: } bsw/jbe@19: bsw/jbe@19: tabs.module = "initiative" bsw/jbe@19: tabs.view = "show_tab" bsw/jbe@19: tabs.static_params = { bsw/jbe@19: initiative_id = initiative.id bsw/jbe@19: } bsw/jbe@19: bsw/jbe@19: ui.tabs(tabs) bsw/jbe@19: