bsw/jbe@0: local initiatives_selector = param.get("initiatives_selector", "table") bsw/jbe@0: initiatives_selector:join("issue", nil, "issue.id = initiative.issue_id") bsw/jbe@0: bsw/jbe@0: local issue = param.get("issue", "table") bsw/jbe@0: bsw/jbe@0: local order_options = {} bsw/jbe@0: bsw/jbe@0: if issue and issue.ranks_available then bsw/jbe@0: order_options[#order_options+1] = { bsw/jbe@0: name = "rank", bsw/jbe@0: label = _"Rank", bsw/jbe@0: order_by = "initiative.rank" bsw/jbe@0: } bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: order_options[#order_options+1] = { bsw/jbe@0: name = "support", bsw/jbe@0: label = _"Support", bsw/jbe@0: order_by = "initiative.supporter_count::float / issue.population::float DESC" bsw/jbe@0: } bsw/jbe@0: bsw/jbe@0: order_options[#order_options+1] = { bsw/jbe@0: name = "support_si", bsw/jbe@0: label = _"Support S+I", bsw/jbe@0: order_by = "initiative.satisfied_informed_supporter_count::float / issue.population::float DESC" bsw/jbe@0: } bsw/jbe@0: bsw/jbe@0: order_options[#order_options+1] = { bsw/jbe@0: name = "newest", bsw/jbe@0: label = _"Newest", bsw/jbe@0: order_by = "initiative.created DESC" bsw/jbe@0: } bsw/jbe@0: bsw/jbe@0: order_options[#order_options+1] = { bsw/jbe@0: name = "oldest", bsw/jbe@0: label = _"Oldest", bsw/jbe@0: order_by = "initiative.created" bsw/jbe@0: } bsw/jbe@0: bsw/jbe@0: local name = "initiative_list" bsw/jbe@0: if issue then bsw/jbe@0: name = "issue_" .. tostring(issue.id) .. "_initiative_list" bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: ui.order{ bsw/jbe@0: name = name, bsw/jbe@0: selector = initiatives_selector, bsw/jbe@0: options = order_options, bsw/jbe@0: content = function() bsw/jbe@0: ui.paginate{ bsw/jbe@0: selector = initiatives_selector, bsw/jbe@0: content = function() bsw/jbe@0: local initiatives = initiatives_selector:exec() bsw/jbe@0: local columns = {} bsw/jbe@0: local issue = initiatives[1] and initiatives[1].issue or {} bsw/jbe@0: if issue.accepted and issue.closed and issue.ranks_available then bsw/jbe@0: columns[#columns+1] = { bsw/jbe@0: content = function(record) bsw/jbe@0: ui.field.rank{ value = record.rank } bsw/jbe@0: end bsw/jbe@0: } bsw/jbe@0: columns[#columns+1] = { bsw/jbe@0: content = function(record) bsw/jbe@0: if record.negative_votes and record.positive_votes then bsw/jbe@0: local max_value = record.issue.voter_count bsw/jbe@0: trace.debug(record.issue.voter_count) bsw/jbe@0: ui.bargraph{ bsw/jbe@0: max_value = max_value, bsw/jbe@0: width = 100, bsw/jbe@0: bars = { bsw/jbe@0: { color = "#0a0", value = record.positive_votes }, bsw/jbe@0: { color = "#aaa", value = max_value - record.negative_votes - record.positive_votes }, bsw/jbe@0: { color = "#a00", value = record.negative_votes }, bsw/jbe@0: } bsw/jbe@0: } bsw/jbe@0: end bsw/jbe@0: end bsw/jbe@0: } bsw/jbe@0: else bsw/jbe@0: columns[#columns+1] = { bsw/jbe@0: content = function(record) bsw/jbe@0: local max_value = (record.issue.population or 0) bsw/jbe@0: ui.bargraph{ bsw/jbe@0: max_value = max_value, bsw/jbe@0: width = 100, bsw/jbe@0: bars = { bsw/jbe@0: { color = "#0a0", value = (record.satisfied_informed_supporter_count or 0) }, bsw/jbe@0: { color = "#8f8", value = (record.supporter_count or 0) - (record.satisfied_informed_supporter_count or 0) }, bsw/jbe@0: { color = "#ddd", value = max_value - (record.supporter_count or 0) }, bsw/jbe@0: } bsw/jbe@0: } bsw/jbe@0: end bsw/jbe@0: } bsw/jbe@0: end bsw/jbe@0: columns[#columns+1] = { bsw/jbe@0: content = function(record) bsw/jbe@0: ui.link{ bsw/jbe@0: content = function() bsw/jbe@0: util.put_highlighted_string(record.shortened_name) bsw/jbe@0: end, bsw/jbe@0: module = "initiative", bsw/jbe@0: view = "show", bsw/jbe@0: id = record.id bsw/jbe@0: } bsw/jbe@0: end bsw/jbe@0: } bsw/jbe@0: bsw/jbe@0: ui.list{ bsw/jbe@0: attr = { class = "initiatives" }, bsw/jbe@0: records = initiatives, bsw/jbe@0: columns = columns bsw/jbe@0: } bsw/jbe@0: end bsw/jbe@0: } bsw/jbe@0: end bsw/jbe@0: }