liquid_feedback_frontend

annotate app/main/initiative/_list.lua @ 279:23c98752e697

Added wiki support for suggestions and member statements
author bsw
date Thu Feb 16 14:08:43 2012 +0100 (2012-02-16)
parents fecd4c13054a
children 6c88b4bfb56c
rev   line source
bsw/jbe@0 1 local issue = param.get("issue", "table")
bsw/jbe@0 2
bsw/jbe@19 3 local initiatives_selector = param.get("initiatives_selector", "table")
bsw@51 4
bsw@274 5 local highlight_initiative = param.get("highlight_initiative", "table")
bsw@274 6
bsw@11 7 initiatives_selector
bsw/jbe@19 8 :join("issue", nil, "issue.id = initiative.issue_id")
bsw@11 9
bsw@51 10 if app.session.member_id then
bsw@51 11 initiatives_selector
bsw@57 12 :left_join("initiator", "_initiator", { "_initiator.initiative_id = initiative.id AND _initiator.member_id = ? AND _initiator.accepted", app.session.member.id} )
bsw@51 13 :left_join("supporter", "_supporter", { "_supporter.initiative_id = initiative.id AND _supporter.member_id = ?", app.session.member.id} )
bsw@51 14
bsw@51 15 :add_field("(_initiator.member_id NOTNULL)", "is_initiator")
bsw@51 16 :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)))", app.session.member.id }, "is_supporter")
bsw@51 17 :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)))", app.session.member.id }, "is_potential_supporter")
bsw@51 18 end
bsw@11 19
bsw/jbe@19 20 local initiatives_count = initiatives_selector:count()
bsw@11 21
bsw/jbe@19 22 local limit = param.get("limit", atom.number)
bsw/jbe@19 23 local no_sort = param.get("no_sort", atom.boolean)
bsw/jbe@19 24
bsw/jbe@19 25 local show_for_issue = param.get("show_for_issue", atom.boolean)
bsw/jbe@19 26
bsw/jbe@19 27 local show_for_initiative
bsw/jbe@19 28
bsw/jbe@19 29 local show_for_initiative_id = param.get("for_initiative_id", atom.number)
bsw/jbe@19 30
bsw/jbe@19 31 if show_for_initiative_id then
bsw/jbe@19 32 show_for_initiative = Initiative:by_id(show_for_initiative_id)
bsw/jbe@19 33
bsw/jbe@19 34 elseif not show_for_initiative_id and show_for_issue and issue and issue.ranks_available then
bsw/jbe@19 35 winning_initiative = Initiative:new_selector()
bsw/jbe@19 36 :add_where{ "issue_id = ?", issue.id }
bsw/jbe@19 37 :add_where("rank = 1")
bsw@24 38 :optional_object_mode()
bsw/jbe@19 39 :exec()
bsw/jbe@19 40 if winning_initiative then
bsw/jbe@19 41 show_for_initiative = winning_initiative
bsw/jbe@19 42 ui.container{
bsw/jbe@19 43 attr = { class = "admitted_info" },
bsw/jbe@19 44 content = _"This issue has been finished with the following winning initiative:"
bsw/jbe@19 45 }
bsw/jbe@19 46 else
bsw/jbe@19 47 ui.container{
bsw/jbe@19 48 attr = { class = "not_admitted_info" },
bsw/jbe@19 49 content = _"This issue has been finished without any winning initiative."
bsw/jbe@19 50 }
bsw/jbe@19 51 end
bsw/jbe@19 52 end
bsw/jbe@19 53
bsw/jbe@19 54
bsw/jbe@19 55 if show_for_initiative then
bsw/jbe@19 56 initiatives_selector:add_where{ "initiative.id != ?", show_for_initiative.id }
bsw/jbe@19 57
bsw/jbe@19 58 execute.view{
bsw/jbe@19 59 module = "initiative",
bsw/jbe@19 60 view = "_list_element",
bsw/jbe@19 61 params = {
bsw/jbe@19 62 initiative = show_for_initiative,
bsw/jbe@19 63 }
bsw/jbe@19 64 }
bsw/jbe@19 65 if show_for_issue then
bsw/jbe@19 66 slot.put("<br />")
bsw/jbe@19 67 ui.container{
bsw/jbe@19 68 attr = { style = "font-weight: bold;" },
bsw/jbe@0 69 content = function()
bsw/jbe@19 70 slot.put(_"Alternative initiatives")
bsw/jbe@0 71 end
bsw/jbe@0 72 }
bsw/jbe@0 73 end
bsw/jbe@19 74 elseif show_for_issue then
bsw/jbe@19 75 ui.container{
bsw/jbe@19 76 attr = { style = "font-weight: bold;" },
bsw/jbe@19 77 content = function()
bsw/jbe@19 78 slot.put(_"Alternative initiatives")
bsw/jbe@19 79 end
bsw@11 80 }
bsw@11 81 end
bsw/jbe@19 82
bsw/jbe@19 83 if not show_for_initiative or initiatives_count > 1 then
bsw/jbe@19 84
bsw/jbe@19 85
bsw/jbe@19 86 local more_initiatives_count
bsw/jbe@19 87 if limit then
bsw/jbe@19 88 limit = limit - (show_for_initiative and 1 or 0)
bsw/jbe@19 89 if initiatives_count > limit then
bsw/jbe@19 90 more_initiatives_count = initiatives_count - limit
bsw/jbe@19 91 end
bsw/jbe@19 92 initiatives_selector:limit(limit)
bsw/jbe@19 93 end
bsw/jbe@19 94
bsw/jbe@19 95 local issue = param.get("issue", "table")
bsw/jbe@19 96
bsw/jbe@19 97 local name = "initiative_list"
bsw/jbe@19 98 if issue then
bsw/jbe@19 99 name = "issue_" .. tostring(issue.id) .. "_initiative_list"
bsw/jbe@19 100 end
bsw/jbe@19 101
bsw/jbe@19 102 ui.add_partial_param_names{ name }
bsw/jbe@19 103
bsw/jbe@19 104 local order_filter = {
bsw/jbe@19 105 name = name,
bsw/jbe@19 106 label = _"Order by"
bsw/jbe@19 107 }
bsw/jbe@19 108
bsw/jbe@19 109 if issue and issue.ranks_available then
bsw/jbe@19 110 order_filter[#order_filter+1] = {
bsw/jbe@19 111 name = "rank",
bsw/jbe@19 112 label = _"Rank",
bsw/jbe@19 113 selector_modifier = function(selector) selector:add_order_by("initiative.rank, initiative.admitted DESC, vote_ratio(initiative.positive_votes, initiative.negative_votes) DESC, initiative.id") end
bsw/jbe@19 114 }
bsw/jbe@19 115 end
bsw/jbe@19 116
bsw/jbe@19 117 order_filter[#order_filter+1] = {
bsw/jbe@19 118 name = "potential_support",
bsw/jbe@19 119 label = _"Potential support",
bsw@270 120 selector_modifier = function(selector) selector:add_order_by("CASE WHEN issue.population = 0 THEN 0 ELSE initiative.supporter_count::float / issue.population::float END DESC, initiative.id") end
bsw/jbe@19 121 }
bsw/jbe@19 122
bsw/jbe@19 123 order_filter[#order_filter+1] = {
bsw/jbe@19 124 name = "support",
bsw/jbe@19 125 label = _"Support",
bsw/jbe@19 126 selector_modifier = function(selector) selector:add_order_by("initiative.satisfied_supporter_count::float / issue.population::float DESC, initiative.id") end
bsw/jbe@19 127 }
bsw/jbe@19 128
bsw/jbe@19 129 order_filter[#order_filter+1] = {
bsw/jbe@19 130 name = "newest",
bsw/jbe@19 131 label = _"Newest",
bsw/jbe@19 132 selector_modifier = function(selector) selector:add_order_by("initiative.created DESC, initiative.id") end
bsw/jbe@19 133 }
bsw/jbe@19 134
bsw/jbe@19 135 order_filter[#order_filter+1] = {
bsw/jbe@19 136 name = "oldest",
bsw/jbe@19 137 label = _"Oldest",
bsw/jbe@19 138 selector_modifier = function(selector) selector:add_order_by("initiative.created, initiative.id") end
bsw/jbe@19 139 }
bsw/jbe@19 140
bsw/jbe@19 141 ui_filters = ui.filters
bsw/jbe@19 142
bsw/jbe@19 143 if no_sort then
bsw/jbe@19 144 ui_filters = function(args) args.content() end
bsw/jbe@19 145 if issue.ranks_available then
bsw/jbe@19 146 initiatives_selector:add_order_by("initiative.rank, initiative.admitted DESC, vote_ratio(initiative.positive_votes, initiative.negative_votes) DESC, initiative.id")
bsw/jbe@19 147 else
bsw@274 148 initiatives_selector:add_order_by("CASE WHEN issue.population = 0 OR initiative.supporter_count = 0 OR initiative.supporter_count ISNULL THEN 0 ELSE initiative.supporter_count::float / issue.population::float END DESC, initiative.id")
bsw/jbe@19 149 end
bsw/jbe@19 150 end
bsw/jbe@19 151
bsw/jbe@19 152 ui_filters{
bsw/jbe@19 153 label = _"Change order",
bsw/jbe@19 154 order_filter,
bsw/jbe@19 155 selector = initiatives_selector,
bsw/jbe@19 156 content = function()
bsw/jbe@19 157 ui.paginate{
bsw/jbe@19 158 name = issue and "issue_" .. tostring(issue.id) .. "_page" or nil,
bsw/jbe@19 159 selector = initiatives_selector,
bsw@274 160 per_page = param.get("per_page", atom.number) or limit,
bsw/jbe@19 161 content = function()
bsw/jbe@19 162 local initiatives = initiatives_selector:exec()
bsw@274 163 if highlight_initiative then
bsw@274 164 local highlight_initiative_found
bsw@274 165 for i, initiative in ipairs(initiatives) do
bsw@274 166 if initiative.id == highlight_initiative.id then
bsw@274 167 highhighlight_initiative_found = true
bsw@274 168 end
bsw@274 169 end
bsw@274 170 if not highhighlight_initiative_found then
bsw@274 171 initiatives[#initiatives+1] = highlight_initiative
bsw@274 172 if more_initiatives_count then
bsw@274 173 more_initiatives_count = more_initiatives_count - 1
bsw@274 174 end
bsw@274 175 end
bsw@274 176 end
bsw/jbe@19 177 for i, initiative in ipairs(initiatives) do
bsw/jbe@19 178 execute.view{
bsw/jbe@19 179 module = "initiative",
bsw/jbe@19 180 view = "_list_element",
bsw/jbe@19 181 params = {
bsw/jbe@19 182 initiative = initiative,
bsw@274 183 selected = highlight_initiative and highlight_initiative.id == initiative.id or nil,
bsw/jbe@19 184 }
bsw/jbe@19 185 }
bsw/jbe@19 186 end
bsw/jbe@19 187 end
bsw/jbe@19 188 }
bsw/jbe@19 189 end
bsw/jbe@19 190 }
bsw/jbe@19 191
bsw/jbe@19 192 if more_initiatives_count then
bsw@274 193 local text
bsw@274 194 if more_initiatives_count == 1 then
bsw@274 195 text = _("and one more initiative")
bsw@274 196 else
bsw@274 197 text = _("and #{count} more initiatives", { count = more_initiatives_count })
bsw@274 198 end
bsw/jbe@19 199 ui.link{
bsw@274 200 attr = { class = "more_initiatives_link" },
bsw@274 201 content = text,
bsw/jbe@19 202 module = "issue",
bsw/jbe@19 203 view = "show",
bsw/jbe@19 204 id = issue.id,
bsw/jbe@19 205 }
bsw/jbe@19 206 end
bsw/jbe@19 207
bsw/jbe@19 208 end
bsw/jbe@19 209
bsw/jbe@19 210 if show_for_issue then
bsw/jbe@19 211 slot.put("<br />")
bsw/jbe@19 212
bsw/jbe@19 213 if issue and initiatives_count == 1 then
bsw/jbe@19 214 ui.container{
bsw/jbe@19 215 content = function()
bsw/jbe@19 216 if issue.fully_frozen or issue.closed then
bsw/jbe@19 217 slot.put(_"There were no more alternative initiatives.")
bsw/jbe@19 218 else
bsw/jbe@19 219 slot.put(_"There are no more alternative initiatives currently.")
bsw/jbe@19 220 end
bsw/jbe@19 221 end
bsw/jbe@19 222 }
bsw/jbe@19 223 end
bsw/jbe@19 224
bsw/jbe@19 225 end

Impressum / About Us