bsw/jbe@19: local initiative = param.get("initiative", "table") bsw/jbe@19: bsw/jbe@19: bsw/jbe@19: local battled_initiatives = Initiative:new_selector() bsw/jbe@19: :add_field("winning_battle.count", "winning_count") bsw/jbe@19: :add_field("losing_battle.count", "losing_count") bsw/jbe@19: :join("battle", "winning_battle", { "winning_battle.winning_initiative_id = ? AND winning_battle.losing_initiative_id = initiative.id", initiative.id }) bsw/jbe@19: :join("battle", "losing_battle", { "losing_battle.losing_initiative_id = ? AND losing_battle.winning_initiative_id = initiative.id", initiative.id }) bsw/jbe@19: :add_order_by("rank") bsw/jbe@19: :exec() bsw/jbe@19: bsw/jbe@19: local number_of_initiatives = Initiative:new_selector() bsw/jbe@19: :add_where{ "issue_id = ?", initiative.issue_id } bsw/jbe@19: :add_where("admitted") bsw/jbe@19: :count() bsw/jbe@19: bsw/jbe@19: if initiative.revoked then bsw/jbe@19: slot.put(_"Not voted (revoked from initiator)") bsw/jbe@19: elseif initiative.admitted == false then bsw/jbe@19: slot.put(_"Not voted (not admitted)") bsw/jbe@19: else bsw/jbe@19: if number_of_initiatives > 1 then bsw/jbe@19: ui.container{ bsw/jbe@19: attr = { class = "heading first" }, bsw/jbe@19: content = _"This initiative compared to alternative initiatives" bsw/jbe@19: } bsw/jbe@19: bsw/jbe@19: ui.list{ bsw/jbe@19: records = battled_initiatives, bsw/jbe@19: columns = { bsw/jbe@19: { bsw/jbe@19: content = function() bsw/jbe@19: slot.put(_"This initiative") bsw/jbe@19: end bsw/jbe@19: }, bsw/jbe@19: { bsw/jbe@19: content = function(record) bsw/jbe@19: local population = initiative.issue.voter_count bsw/jbe@19: local value = record.winning_count bsw/jbe@19: ui.bargraph{ bsw/jbe@19: class = "bargraph bargraph50", bsw/jbe@19: max_value = population, bsw/jbe@19: width = 50, bsw/jbe@19: bars = { bsw/jbe@19: { color = "#aaa", value = population - value }, bsw/jbe@19: { color = "#444", value = value }, bsw/jbe@19: } bsw/jbe@19: } bsw/jbe@19: end bsw/jbe@19: }, bsw/jbe@19: { bsw/jbe@19: content = function(record) bsw/jbe@19: slot.put(record.winning_count) bsw/jbe@19: end bsw/jbe@19: }, bsw/jbe@19: { bsw/jbe@19: content = function(record) bsw/jbe@19: if record.winning_count == record.losing_count then bsw/jbe@19: ui.image{ static = "icons/16/bullet_blue.png" } bsw/jbe@19: elseif record.winning_count > record.losing_count then bsw/jbe@19: ui.image{ static = "icons/16/resultset_previous.png" } bsw/jbe@19: else bsw/jbe@19: ui.image{ static = "icons/16/resultset_next.png" } bsw/jbe@19: end bsw/jbe@19: end bsw/jbe@19: }, bsw/jbe@19: { bsw/jbe@19: field_attr = { style = "text-align: right;" }, bsw/jbe@19: content = function(record) bsw/jbe@19: slot.put(record.losing_count) bsw/jbe@19: end bsw/jbe@19: }, bsw/jbe@19: { bsw/jbe@19: content = function(record) bsw/jbe@19: local population = initiative.issue.voter_count bsw/jbe@19: local value = record.losing_count bsw/jbe@19: ui.bargraph{ bsw/jbe@19: class = "bargraph bargraph50", bsw/jbe@19: max_value = population, bsw/jbe@19: width = 50, bsw/jbe@19: bars = { bsw/jbe@19: { color = "#444", value = value }, bsw/jbe@19: { color = "#aaa", value = population - value }, bsw/jbe@19: } bsw/jbe@19: } bsw/jbe@19: end bsw/jbe@19: }, bsw/jbe@19: { bsw/jbe@19: name = "name" bsw/jbe@19: } bsw/jbe@19: } bsw/jbe@19: } bsw/jbe@19: end bsw/jbe@19: bsw/jbe@19: ui.container{ bsw/jbe@19: attr = { class = "heading" }, bsw/jbe@19: content = _"Member voting" bsw/jbe@19: } bsw/jbe@19: bsw/jbe@19: execute.view{ bsw/jbe@19: module = "member", bsw/jbe@19: view = "_list", bsw/jbe@19: params = { bsw/jbe@19: initiative = initiative, bsw/jbe@19: members_selector = initiative.issue:get_reference_selector("direct_voters") bsw/jbe@19: :left_join("vote", nil, { "vote.initiative_id = ? AND vote.member_id = member.id", initiative.id }) bsw/jbe@19: :add_field("direct_voter.weight as voter_weight") bsw/jbe@19: :add_field("coalesce(vote.grade, 0) as grade") bsw/jbe@19: } bsw/jbe@19: } bsw/jbe@19: bsw/jbe@19: end