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@5: order_by = "initiative.rank, initiative.admitted DESC, vote_ratio(initiative.positive_votes, initiative.negative_votes) DESC, initiative.id" bsw/jbe@0: } bsw/jbe@0: end bsw/jbe@0: bsw/jbe@0: order_options[#order_options+1] = { bsw/jbe@5: name = "potential_support", bsw/jbe@5: label = _"Potential support", bsw/jbe@5: order_by = "initiative.supporter_count::float / issue.population::float DESC, initiative.id" bsw/jbe@5: } bsw/jbe@5: bsw/jbe@5: order_options[#order_options+1] = { bsw/jbe@0: name = "support", bsw/jbe@0: label = _"Support", bsw/jbe@5: order_by = "initiative.satisfied_supporter_count::float / issue.population::float DESC, initiative.id" 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@5: order_by = "initiative.created DESC, initiative.id" 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@5: order_by = "initiative.created, initiative.id" 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@2: columns[#columns+1] = { bsw@2: content = function(record) bsw@2: if record.issue.accepted and record.issue.closed and record.issue.ranks_available then bsw@3: ui.field.rank{ attr = { class = "rank" }, value = record.rank } bsw@3: end bsw@3: end bsw@3: } bsw@3: columns[#columns+1] = { bsw@3: content = function(record) bsw/jbe@5: if record.issue.accepted and record.issue.closed then bsw/jbe@5: if record.issue.ranks_available then bsw/jbe@5: if record.negative_votes and record.positive_votes then bsw/jbe@5: local max_value = record.issue.voter_count bsw/jbe@5: ui.bargraph{ bsw/jbe@5: max_value = max_value, bsw/jbe@5: width = 100, bsw/jbe@5: bars = { bsw/jbe@5: { color = "#0a0", value = record.positive_votes }, bsw/jbe@5: { color = "#aaa", value = max_value - record.negative_votes - record.positive_votes }, bsw/jbe@5: { color = "#a00", value = record.negative_votes }, bsw/jbe@5: } bsw/jbe@0: } bsw/jbe@5: end bsw/jbe@5: else bsw/jbe@5: slot.put(_"Counting of votes") bsw/jbe@0: end bsw@2: else 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@4: width = 100, bsw/jbe@0: bars = { bsw@2: { color = "#0a0", value = (record.satisfied_supporter_count or 0) }, bsw/jbe@5: { color = "#777", value = (record.supporter_count or 0) - (record.satisfied_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@2: end bsw@2: } bsw/jbe@0: columns[#columns+1] = { bsw/jbe@0: content = function(record) bsw/jbe@0: ui.link{ bsw/jbe@0: content = function() bsw@2: local name bsw@2: if record.name_highlighted then bsw@2: name = encode.highlight(record.name_highlighted) bsw@2: else bsw@2: name = encode.html(record.name) bsw@2: end bsw@2: slot.put(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@2: if record.issue.state == "new" then bsw@2: ui.image{ bsw@2: static = "icons/16/new.png" bsw@2: } bsw@2: end 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: }