liquid_feedback_frontend

annotate app/main/initiative/_list.lua @ 0:3bfb2fcf7ab9

Version alpha1
author bsw/jbe
date Wed Nov 18 12:00:00 2009 +0100 (2009-11-18)
parents
children 5c601807d397
rev   line source
bsw/jbe@0 1 local initiatives_selector = param.get("initiatives_selector", "table")
bsw/jbe@0 2 initiatives_selector:join("issue", nil, "issue.id = initiative.issue_id")
bsw/jbe@0 3
bsw/jbe@0 4 local issue = param.get("issue", "table")
bsw/jbe@0 5
bsw/jbe@0 6 local order_options = {}
bsw/jbe@0 7
bsw/jbe@0 8 if issue and issue.ranks_available then
bsw/jbe@0 9 order_options[#order_options+1] = {
bsw/jbe@0 10 name = "rank",
bsw/jbe@0 11 label = _"Rank",
bsw/jbe@0 12 order_by = "initiative.rank"
bsw/jbe@0 13 }
bsw/jbe@0 14 end
bsw/jbe@0 15
bsw/jbe@0 16 order_options[#order_options+1] = {
bsw/jbe@0 17 name = "support",
bsw/jbe@0 18 label = _"Support",
bsw/jbe@0 19 order_by = "initiative.supporter_count::float / issue.population::float DESC"
bsw/jbe@0 20 }
bsw/jbe@0 21
bsw/jbe@0 22 order_options[#order_options+1] = {
bsw/jbe@0 23 name = "support_si",
bsw/jbe@0 24 label = _"Support S+I",
bsw/jbe@0 25 order_by = "initiative.satisfied_informed_supporter_count::float / issue.population::float DESC"
bsw/jbe@0 26 }
bsw/jbe@0 27
bsw/jbe@0 28 order_options[#order_options+1] = {
bsw/jbe@0 29 name = "newest",
bsw/jbe@0 30 label = _"Newest",
bsw/jbe@0 31 order_by = "initiative.created DESC"
bsw/jbe@0 32 }
bsw/jbe@0 33
bsw/jbe@0 34 order_options[#order_options+1] = {
bsw/jbe@0 35 name = "oldest",
bsw/jbe@0 36 label = _"Oldest",
bsw/jbe@0 37 order_by = "initiative.created"
bsw/jbe@0 38 }
bsw/jbe@0 39
bsw/jbe@0 40 local name = "initiative_list"
bsw/jbe@0 41 if issue then
bsw/jbe@0 42 name = "issue_" .. tostring(issue.id) .. "_initiative_list"
bsw/jbe@0 43 end
bsw/jbe@0 44
bsw/jbe@0 45 ui.order{
bsw/jbe@0 46 name = name,
bsw/jbe@0 47 selector = initiatives_selector,
bsw/jbe@0 48 options = order_options,
bsw/jbe@0 49 content = function()
bsw/jbe@0 50 ui.paginate{
bsw/jbe@0 51 selector = initiatives_selector,
bsw/jbe@0 52 content = function()
bsw/jbe@0 53 local initiatives = initiatives_selector:exec()
bsw/jbe@0 54 local columns = {}
bsw/jbe@0 55 local issue = initiatives[1] and initiatives[1].issue or {}
bsw/jbe@0 56 if issue.accepted and issue.closed and issue.ranks_available then
bsw/jbe@0 57 columns[#columns+1] = {
bsw/jbe@0 58 content = function(record)
bsw/jbe@0 59 ui.field.rank{ value = record.rank }
bsw/jbe@0 60 end
bsw/jbe@0 61 }
bsw/jbe@0 62 columns[#columns+1] = {
bsw/jbe@0 63 content = function(record)
bsw/jbe@0 64 if record.negative_votes and record.positive_votes then
bsw/jbe@0 65 local max_value = record.issue.voter_count
bsw/jbe@0 66 trace.debug(record.issue.voter_count)
bsw/jbe@0 67 ui.bargraph{
bsw/jbe@0 68 max_value = max_value,
bsw/jbe@0 69 width = 100,
bsw/jbe@0 70 bars = {
bsw/jbe@0 71 { color = "#0a0", value = record.positive_votes },
bsw/jbe@0 72 { color = "#aaa", value = max_value - record.negative_votes - record.positive_votes },
bsw/jbe@0 73 { color = "#a00", value = record.negative_votes },
bsw/jbe@0 74 }
bsw/jbe@0 75 }
bsw/jbe@0 76 end
bsw/jbe@0 77 end
bsw/jbe@0 78 }
bsw/jbe@0 79 else
bsw/jbe@0 80 columns[#columns+1] = {
bsw/jbe@0 81 content = function(record)
bsw/jbe@0 82 local max_value = (record.issue.population or 0)
bsw/jbe@0 83 ui.bargraph{
bsw/jbe@0 84 max_value = max_value,
bsw/jbe@0 85 width = 100,
bsw/jbe@0 86 bars = {
bsw/jbe@0 87 { color = "#0a0", value = (record.satisfied_informed_supporter_count or 0) },
bsw/jbe@0 88 { color = "#8f8", value = (record.supporter_count or 0) - (record.satisfied_informed_supporter_count or 0) },
bsw/jbe@0 89 { color = "#ddd", value = max_value - (record.supporter_count or 0) },
bsw/jbe@0 90 }
bsw/jbe@0 91 }
bsw/jbe@0 92 end
bsw/jbe@0 93 }
bsw/jbe@0 94 end
bsw/jbe@0 95 columns[#columns+1] = {
bsw/jbe@0 96 content = function(record)
bsw/jbe@0 97 ui.link{
bsw/jbe@0 98 content = function()
bsw/jbe@0 99 util.put_highlighted_string(record.shortened_name)
bsw/jbe@0 100 end,
bsw/jbe@0 101 module = "initiative",
bsw/jbe@0 102 view = "show",
bsw/jbe@0 103 id = record.id
bsw/jbe@0 104 }
bsw/jbe@0 105 end
bsw/jbe@0 106 }
bsw/jbe@0 107
bsw/jbe@0 108 ui.list{
bsw/jbe@0 109 attr = { class = "initiatives" },
bsw/jbe@0 110 records = initiatives,
bsw/jbe@0 111 columns = columns
bsw/jbe@0 112 }
bsw/jbe@0 113 end
bsw/jbe@0 114 }
bsw/jbe@0 115 end
bsw/jbe@0 116 }

Impressum / About Us