liquid_feedback_frontend

annotate app/main/initiative/show_tab.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 808269b7f41c
children 4cee33ad5e16
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@525 55 module = "suggestion",
bsw@525 56 view = "_list",
bsw/jbe@19 57 params = {
bsw@525 58 initiative = initiative,
bsw@525 59 suggestions_selector = initiative:get_reference_selector("suggestions"),
bsw@525 60 tab_id = param.get("tab_id")
bsw/jbe@19 61 }
bsw/jbe@19 62 }
bsw/jbe@19 63
bsw@51 64 if app.session.member_id then
bsw@51 65 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
bsw@51 66 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
bsw@51 67 :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 68 :add_field("direct_interest_snapshot.weight")
bsw@51 69 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
bsw@51 70 :add_where("direct_supporter_snapshot.satisfied")
bsw@51 71 :add_field("direct_supporter_snapshot.informed", "is_informed")
bsw@51 72
bsw@51 73 local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object")
bsw@51 74 local direct_satisfied_supporter_count = tmp.count
bsw@51 75 local indirect_satisfied_supporter_count = (tmp.weight or 0) - tmp.count
bsw@51 76
bsw@51 77 local count_string
bsw@51 78 if indirect_satisfied_supporter_count > 0 then
bsw@51 79 count_string = "(" .. tostring(direct_satisfied_supporter_count) .. "+" .. tostring(indirect_satisfied_supporter_count) .. ")"
bsw@51 80 else
bsw@51 81 count_string = "(" .. tostring(direct_satisfied_supporter_count) .. ")"
bsw@51 82 end
bsw@51 83
bsw@51 84 tabs[#tabs+1] = {
bsw@51 85 name = "satisfied_supporter",
bsw@51 86 label = _"Supporter" .. " " .. count_string,
bsw@51 87 icon = { static = "icons/16/thumb_up_green.png" },
bsw@51 88 module = "member",
bsw@51 89 view = "_list",
bsw@51 90 params = {
bsw@51 91 initiative = initiative,
bsw@51 92 members_selector = members_selector
bsw@51 93 }
bsw/jbe@19 94 }
bsw@51 95
bsw@51 96 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
bsw@51 97 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
bsw@51 98 :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 99 :add_field("direct_interest_snapshot.weight")
bsw@51 100 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
bsw@51 101 :add_where("NOT direct_supporter_snapshot.satisfied")
bsw@51 102 :add_field("direct_supporter_snapshot.informed", "is_informed")
bsw@51 103
bsw@51 104 local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object")
bsw@51 105 local direct_potential_supporter_count = tmp.count
bsw@51 106 local indirect_potential_supporter_count = (tmp.weight or 0) - tmp.count
bsw@51 107
bsw@51 108 local count_string
bsw@51 109 if indirect_potential_supporter_count > 0 then
bsw@51 110 count_string = "(" .. tostring(direct_potential_supporter_count) .. "+" .. tostring(indirect_potential_supporter_count) .. ")"
bsw@51 111 else
bsw@51 112 count_string = "(" .. tostring(direct_potential_supporter_count) .. ")"
bsw@51 113 end
bsw@51 114
bsw@51 115 tabs[#tabs+1] = {
bsw@51 116 name = "supporter",
bsw@51 117 label = _"Potential supporter" .. " " .. count_string,
bsw@51 118 icon = { static = "icons/16/thumb_up.png" },
bsw@51 119 module = "member",
bsw@51 120 view = "_list",
bsw@51 121 params = {
bsw@51 122 initiative = initiative,
bsw@51 123 members_selector = members_selector
bsw@51 124 }
bsw@51 125 }
bsw@51 126
bsw/jbe@19 127 end
bsw/jbe@19 128
bsw/jbe@19 129 local drafts_count = initiative:get_reference_selector("drafts"):count()
bsw/jbe@19 130
bsw/jbe@19 131 tabs[#tabs+1] = {
bsw/jbe@19 132 name = "drafts",
bsw/jbe@19 133 label = _"Draft history" .. " (" .. tostring(drafts_count) .. ")",
bsw/jbe@19 134 icon = { static = "icons/16/script.png" },
bsw/jbe@19 135 module = "draft",
bsw/jbe@19 136 view = "_list",
bsw/jbe@19 137 params = { drafts = initiative.drafts }
bsw/jbe@19 138 }
bsw/jbe@19 139
bsw/jbe@19 140 tabs[#tabs+1] = {
bsw/jbe@19 141 name = "details",
bsw/jbe@19 142 label = _"Details",
bsw/jbe@19 143 icon = { static = "icons/16/magnifier.png" },
bsw/jbe@19 144 module = "initiative",
bsw/jbe@19 145 view = "_details",
bsw/jbe@19 146 params = {
bsw/jbe@19 147 initiative = initiative,
bsw/jbe@19 148 members_selector = members_selector
bsw/jbe@19 149 }
bsw/jbe@19 150 }
bsw/jbe@19 151
bsw/jbe@19 152 tabs.module = "initiative"
bsw/jbe@19 153 tabs.view = "show_tab"
bsw/jbe@19 154 tabs.static_params = {
bsw/jbe@19 155 initiative_id = initiative.id
bsw/jbe@19 156 }
bsw/jbe@19 157
bsw/jbe@19 158 ui.tabs(tabs)
bsw/jbe@19 159

Impressum / About Us