liquid_feedback_frontend

annotate app/main/initiative/show_tab.lua @ 280:808269b7f41c

More repositioning and optical enhancements
author bsw
date Thu Feb 16 14:08:55 2012 +0100 (2012-02-16)
parents 65a1f7a01e7b
children 63d6549cc00b
rev   line source
bsw/jbe@19 1 local initiative = param.get("initiative", "table")
bsw/jbe@19 2 local initiator = param.get("initiator", "table")
bsw/jbe@19 3
bsw/jbe@19 4 if not initiative then
bsw/jbe@19 5 initiative = Initiative:by_id(param.get("initiative_id", atom.number))
bsw/jbe@19 6 end
bsw/jbe@19 7
bsw@51 8 if not initiator and app.session.member_id then
bsw/jbe@19 9 initiator = Initiator:by_pk(initiative.id, app.session.member.id)
bsw/jbe@19 10 end
bsw/jbe@19 11
bsw/jbe@19 12 local current_draft_name = _"Current draft"
bsw/jbe@19 13 if initiative.issue.half_frozen then
bsw/jbe@19 14 current_draft_name = _"Voting proposal"
bsw/jbe@19 15 end
bsw/jbe@19 16
bsw/jbe@19 17 if initiative.issue.state == "finished" then
bsw/jbe@19 18 current_draft_name = _"Voted proposal"
bsw/jbe@19 19 end
bsw/jbe@19 20
bsw/jbe@19 21 local tabs = {
bsw/jbe@19 22 {
bsw/jbe@19 23 name = "current_draft",
bsw/jbe@19 24 label = current_draft_name,
bsw/jbe@19 25 icon = { static = "icons/16/script.png" },
bsw@280 26 module = "draft",
bsw@280 27 view = "_show",
bsw/jbe@19 28 params = {
bsw@280 29 draft = initiative.current_draft
bsw/jbe@19 30 }
bsw/jbe@19 31 }
bsw/jbe@19 32 }
bsw/jbe@19 33
bsw@51 34 if app.session.member_id then
bsw@51 35 if initiative.issue.ranks_available then
bsw@51 36 tabs[#tabs+1] = {
bsw@51 37 name = "voting",
bsw@51 38 label = _"Voting details",
bsw@51 39 icon = { static = "icons/16/email_open.png" },
bsw@51 40 module = "initiative",
bsw@51 41 view = "_show_voting",
bsw@51 42 params = {
bsw@51 43 initiative = initiative
bsw@51 44 }
bsw/jbe@19 45 }
bsw@51 46 end
bsw/jbe@19 47 end
bsw/jbe@19 48
bsw/jbe@19 49 local suggestion_count = initiative:get_reference_selector("suggestions"):count()
bsw/jbe@19 50
bsw/jbe@19 51 tabs[#tabs+1] = {
bsw/jbe@19 52 name = "suggestions",
bsw/jbe@19 53 label = _"Suggestions" .. " (" .. tostring(suggestion_count) .. ")",
bsw/jbe@19 54 icon = { static = "icons/16/comments.png" },
bsw/jbe@19 55 module = "initiative",
bsw/jbe@19 56 view = "_suggestions",
bsw/jbe@19 57 params = {
bsw/jbe@19 58 initiative = initiative
bsw/jbe@19 59 }
bsw/jbe@19 60 }
bsw/jbe@19 61
bsw@51 62 if app.session.member_id then
bsw@51 63 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
bsw@51 64 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
bsw@51 65 :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 66 :add_field("direct_interest_snapshot.weight")
bsw@51 67 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
bsw@51 68 :add_where("direct_supporter_snapshot.satisfied")
bsw@51 69 :add_field("direct_supporter_snapshot.informed", "is_informed")
bsw@51 70
bsw@51 71 local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object")
bsw@51 72 local direct_satisfied_supporter_count = tmp.count
bsw@51 73 local indirect_satisfied_supporter_count = (tmp.weight or 0) - tmp.count
bsw@51 74
bsw@51 75 local count_string
bsw@51 76 if indirect_satisfied_supporter_count > 0 then
bsw@51 77 count_string = "(" .. tostring(direct_satisfied_supporter_count) .. "+" .. tostring(indirect_satisfied_supporter_count) .. ")"
bsw@51 78 else
bsw@51 79 count_string = "(" .. tostring(direct_satisfied_supporter_count) .. ")"
bsw@51 80 end
bsw@51 81
bsw@51 82 tabs[#tabs+1] = {
bsw@51 83 name = "satisfied_supporter",
bsw@51 84 label = _"Supporter" .. " " .. count_string,
bsw@51 85 icon = { static = "icons/16/thumb_up_green.png" },
bsw@51 86 module = "member",
bsw@51 87 view = "_list",
bsw@51 88 params = {
bsw@51 89 initiative = initiative,
bsw@51 90 members_selector = members_selector
bsw@51 91 }
bsw/jbe@19 92 }
bsw@51 93
bsw@51 94 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
bsw@51 95 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
bsw@51 96 :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 97 :add_field("direct_interest_snapshot.weight")
bsw@51 98 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
bsw@51 99 :add_where("NOT direct_supporter_snapshot.satisfied")
bsw@51 100 :add_field("direct_supporter_snapshot.informed", "is_informed")
bsw@51 101
bsw@51 102 local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object")
bsw@51 103 local direct_potential_supporter_count = tmp.count
bsw@51 104 local indirect_potential_supporter_count = (tmp.weight or 0) - tmp.count
bsw@51 105
bsw@51 106 local count_string
bsw@51 107 if indirect_potential_supporter_count > 0 then
bsw@51 108 count_string = "(" .. tostring(direct_potential_supporter_count) .. "+" .. tostring(indirect_potential_supporter_count) .. ")"
bsw@51 109 else
bsw@51 110 count_string = "(" .. tostring(direct_potential_supporter_count) .. ")"
bsw@51 111 end
bsw@51 112
bsw@51 113 tabs[#tabs+1] = {
bsw@51 114 name = "supporter",
bsw@51 115 label = _"Potential supporter" .. " " .. count_string,
bsw@51 116 icon = { static = "icons/16/thumb_up.png" },
bsw@51 117 module = "member",
bsw@51 118 view = "_list",
bsw@51 119 params = {
bsw@51 120 initiative = initiative,
bsw@51 121 members_selector = members_selector
bsw@51 122 }
bsw@51 123 }
bsw@51 124
bsw/jbe@19 125 end
bsw/jbe@19 126
bsw/jbe@19 127 local drafts_count = initiative:get_reference_selector("drafts"):count()
bsw/jbe@19 128
bsw/jbe@19 129 tabs[#tabs+1] = {
bsw/jbe@19 130 name = "drafts",
bsw/jbe@19 131 label = _"Draft history" .. " (" .. tostring(drafts_count) .. ")",
bsw/jbe@19 132 icon = { static = "icons/16/script.png" },
bsw/jbe@19 133 module = "draft",
bsw/jbe@19 134 view = "_list",
bsw/jbe@19 135 params = { drafts = initiative.drafts }
bsw/jbe@19 136 }
bsw/jbe@19 137
bsw/jbe@19 138 tabs[#tabs+1] = {
bsw/jbe@19 139 name = "details",
bsw/jbe@19 140 label = _"Details",
bsw/jbe@19 141 icon = { static = "icons/16/magnifier.png" },
bsw/jbe@19 142 module = "initiative",
bsw/jbe@19 143 view = "_details",
bsw/jbe@19 144 params = {
bsw/jbe@19 145 initiative = initiative,
bsw/jbe@19 146 members_selector = members_selector
bsw/jbe@19 147 }
bsw/jbe@19 148 }
bsw/jbe@19 149
bsw/jbe@19 150 tabs.module = "initiative"
bsw/jbe@19 151 tabs.view = "show_tab"
bsw/jbe@19 152 tabs.static_params = {
bsw/jbe@19 153 initiative_id = initiative.id
bsw/jbe@19 154 }
bsw/jbe@19 155
bsw/jbe@19 156 ui.tabs(tabs)
bsw/jbe@19 157

Impressum / About Us