# HG changeset patch
# User bsw
# Date 1330464439 -3600
# Node ID 7d6a3c411f99e7047332a3704b5feffe02777bfc
# Parent 6be42327b67f83bede7b28443a3bfb376f738c16
Code cleanup (removed code not needed any more)
diff -r 6be42327b67f -r 7d6a3c411f99 app/main/initiative/_list.lua
--- a/app/main/initiative/_list.lua Tue Feb 28 22:14:13 2012 +0100
+++ b/app/main/initiative/_list.lua Tue Feb 28 22:27:19 2012 +0100
@@ -28,204 +28,123 @@
local limit = param.get("limit", atom.number)
local no_sort = param.get("no_sort", atom.boolean)
-local show_for_issue = param.get("show_for_issue", atom.boolean)
-
-local show_for_initiative
-
-local show_for_initiative_id = param.get("for_initiative_id", atom.number)
-
-if show_for_initiative_id then
- show_for_initiative = Initiative:by_id(show_for_initiative_id)
-
-elseif not show_for_initiative_id and show_for_issue and issue and issue.ranks_available then
- winning_initiative = Initiative:new_selector()
- :add_where{ "issue_id = ?", issue.id }
- :add_where("rank = 1")
- :optional_object_mode()
- :exec()
- if winning_initiative then
- show_for_initiative = winning_initiative
- ui.container{
- attr = { class = "admitted_info" },
- content = _"This issue has been finished with the following winning initiative:"
- }
- else
- ui.container{
- attr = { class = "not_admitted_info" },
- content = _"This issue has been finished without any winning initiative."
- }
+local more_initiatives_count
+if limit then
+ if initiatives_count > limit then
+ more_initiatives_count = initiatives_count - limit
end
+ initiatives_selector:limit(limit)
end
+local issue = param.get("issue", "table")
-if show_for_initiative then
- initiatives_selector:add_where{ "initiative.id != ?", show_for_initiative.id }
+local name = "initiative_list"
+if issue then
+ name = "issue_" .. tostring(issue.id) .. "_initiative_list"
+end
+
+ui.add_partial_param_names{ name }
- execute.view{
- module = "initiative",
- view = "_list_element",
- params = {
- initiative = show_for_initiative,
- }
- }
- if show_for_issue then
- slot.put("
")
- ui.container{
- attr = { style = "font-weight: bold;" },
- content = function()
- slot.put(_"Alternative initiatives")
- end
- }
- end
-elseif show_for_issue then
- ui.container{
- attr = { style = "font-weight: bold;" },
- content = function()
- slot.put(_"Alternative initiatives")
- end
+local order_filter = {
+ name = name,
+ label = _"Order by"
+}
+
+if issue and issue.ranks_available then
+ order_filter[#order_filter+1] = {
+ name = "rank",
+ label = _"Rank",
+ 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
}
end
-if not show_for_initiative or initiatives_count > 1 then
-
+order_filter[#order_filter+1] = {
+ name = "potential_support",
+ label = _"Potential support",
+ 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
+}
- local more_initiatives_count
- if limit then
- limit = limit - (show_for_initiative and 1 or 0)
- if initiatives_count > limit then
- more_initiatives_count = initiatives_count - limit
- end
- initiatives_selector:limit(limit)
- end
-
- local issue = param.get("issue", "table")
-
- local name = "initiative_list"
- if issue then
- name = "issue_" .. tostring(issue.id) .. "_initiative_list"
- end
-
- ui.add_partial_param_names{ name }
+order_filter[#order_filter+1] = {
+ name = "support",
+ label = _"Support",
+ selector_modifier = function(selector) selector:add_order_by("initiative.satisfied_supporter_count::float / issue.population::float DESC, initiative.id") end
+}
- local order_filter = {
- name = name,
- label = _"Order by"
- }
+order_filter[#order_filter+1] = {
+ name = "newest",
+ label = _"Newest",
+ selector_modifier = function(selector) selector:add_order_by("initiative.created DESC, initiative.id") end
+}
- if issue and issue.ranks_available then
- order_filter[#order_filter+1] = {
- name = "rank",
- label = _"Rank",
- 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
- }
- end
+order_filter[#order_filter+1] = {
+ name = "oldest",
+ label = _"Oldest",
+ selector_modifier = function(selector) selector:add_order_by("initiative.created, initiative.id") end
+}
- order_filter[#order_filter+1] = {
- name = "potential_support",
- label = _"Potential support",
- 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
- }
-
- order_filter[#order_filter+1] = {
- name = "support",
- label = _"Support",
- selector_modifier = function(selector) selector:add_order_by("initiative.satisfied_supporter_count::float / issue.population::float DESC, initiative.id") end
- }
+ui_filters = ui.filters
- order_filter[#order_filter+1] = {
- name = "newest",
- label = _"Newest",
- selector_modifier = function(selector) selector:add_order_by("initiative.created DESC, initiative.id") end
- }
-
- order_filter[#order_filter+1] = {
- name = "oldest",
- label = _"Oldest",
- selector_modifier = function(selector) selector:add_order_by("initiative.created, initiative.id") end
- }
-
- ui_filters = ui.filters
-
- if no_sort then
- ui_filters = function(args) args.content() end
- if issue.ranks_available then
- initiatives_selector:add_order_by("initiative.rank, initiative.admitted DESC, vote_ratio(initiative.positive_votes, initiative.negative_votes) DESC, initiative.id")
- else
- 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")
- end
+if no_sort then
+ ui_filters = function(args) args.content() end
+ if issue.ranks_available then
+ initiatives_selector:add_order_by("initiative.rank, initiative.admitted DESC, vote_ratio(initiative.positive_votes, initiative.negative_votes) DESC, initiative.id")
+ else
+ 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")
end
+end
- ui_filters{
- label = _"Change order",
- order_filter,
- selector = initiatives_selector,
- content = function()
- ui.paginate{
- name = issue and "issue_" .. tostring(issue.id) .. "_page" or nil,
- selector = initiatives_selector,
- per_page = param.get("per_page", atom.number) or limit,
- content = function()
- local initiatives = initiatives_selector:exec()
- if highlight_initiative then
- local highlight_initiative_found
- for i, initiative in ipairs(initiatives) do
- if initiative.id == highlight_initiative.id then
- highhighlight_initiative_found = true
- end
- end
- if not highhighlight_initiative_found then
- initiatives[#initiatives+1] = highlight_initiative
- if more_initiatives_count then
- more_initiatives_count = more_initiatives_count - 1
- end
+ui_filters{
+ label = _"Change order",
+ order_filter,
+ selector = initiatives_selector,
+ content = function()
+ ui.paginate{
+ name = issue and "issue_" .. tostring(issue.id) .. "_page" or nil,
+ selector = initiatives_selector,
+ per_page = param.get("per_page", atom.number) or limit,
+ content = function()
+ local initiatives = initiatives_selector:exec()
+ if highlight_initiative then
+ local highlight_initiative_found
+ for i, initiative in ipairs(initiatives) do
+ if initiative.id == highlight_initiative.id then
+ highhighlight_initiative_found = true
end
end
- for i, initiative in ipairs(initiatives) do
- execute.view{
- module = "initiative",
- view = "_list_element",
- params = {
- initiative = initiative,
- selected = highlight_initiative and highlight_initiative.id == initiative.id or nil,
- }
- }
+ if not highhighlight_initiative_found then
+ initiatives[#initiatives+1] = highlight_initiative
+ if more_initiatives_count then
+ more_initiatives_count = more_initiatives_count - 1
+ end
end
end
- }
- end
- }
-
- if more_initiatives_count and more_initiatives_count > 0 then
- local text
- if more_initiatives_count == 1 then
- text = _("and one more initiative")
- else
- text = _("and #{count} more initiatives", { count = more_initiatives_count })
- end
- ui.link{
- attr = { class = "more_initiatives_link" },
- content = text,
- module = "issue",
- view = "show",
- id = issue.id,
- }
- end
-
-end
-
-if show_for_issue then
- slot.put("
")
-
- if issue and initiatives_count == 1 then
- ui.container{
- content = function()
- if issue.fully_frozen or issue.closed then
- slot.put(_"There were no more alternative initiatives.")
- else
- slot.put(_"There are no more alternative initiatives currently.")
+ for i, initiative in ipairs(initiatives) do
+ execute.view{
+ module = "initiative",
+ view = "_list_element",
+ params = {
+ initiative = initiative,
+ selected = highlight_initiative and highlight_initiative.id == initiative.id or nil,
+ }
+ }
end
end
}
end
+}
+if more_initiatives_count and more_initiatives_count > 0 then
+ local text
+ if more_initiatives_count == 1 then
+ text = _("and one more initiative")
+ else
+ text = _("and #{count} more initiatives", { count = more_initiatives_count })
+ end
+ ui.link{
+ attr = { class = "more_initiatives_link" },
+ content = text,
+ module = "issue",
+ view = "show",
+ id = issue.id,
+ }
end
diff -r 6be42327b67f -r 7d6a3c411f99 app/main/initiative/_list_element.lua
--- a/app/main/initiative/_list_element.lua Tue Feb 28 22:14:13 2012 +0100
+++ b/app/main/initiative/_list_element.lua Tue Feb 28 22:27:19 2012 +0100
@@ -1,181 +1,133 @@
local initiative = param.get("initiative", "table")
local selected = param.get("selected", atom.boolean)
-local head_name = "initiative_head_" .. tostring(initiative.id)
-local link_name = "initiative_link_" .. tostring(initiative.id)
-local name = "initiative_content_" .. tostring(initiative.id)
-local icon_name = "initiative_icon_" .. tostring(initiative.id)
-
-ui.container{
- attr = { class = "ui_tabs" .. (initiative.id == for_initiative_id and " active" or "") },
- content = function()
- local module = "initiative"
- local view = "show"
- local id = initiative.id
- local params = {}
- ui.container{
- attr = {
- name = name,
- class = "ui_tabs_accordeon_head",
- id = head_name,
- },
+ui.list{
+ attr = { class = "nohover" },
+ records = { { a = 1} },
+ columns = {
+ {
+ field_attr = { style = "width: 3em; text-align: center;"},
content = function()
-
- ui.list{
- attr = { class = "nohover" },
- records = { { a = 1} },
- columns = {
- {
- field_attr = { style = "width: 3em; text-align: center;"},
- content = function()
- if
- initiative.issue.accepted and initiative.issue.closed
- and initiative.issue.ranks_available or initiative.admitted == false
- then
- ui.field.rank{ image_attr = { id = icon_name }, attr = { class = "rank" }, value = initiative.rank, eligible = initiative.eligible }
- else
- slot.put(" ")
- end
- end
- },
+ if
+ initiative.issue.accepted and initiative.issue.closed
+ and initiative.issue.ranks_available or initiative.admitted == false
+ then
+ ui.field.rank{ attr = { class = "rank" }, value = initiative.rank, eligible = initiative.eligible }
+ else
+ slot.put(" ")
+ end
+ end
+ },
- {
- field_attr = { style = "width: 100px;"},
- content = function()
- if initiative.issue.fully_frozen and initiative.issue.closed then
- if initiative.issue.ranks_available then
- if initiative.negative_votes and initiative.positive_votes then
- local max_value = initiative.issue.voter_count
- ui.bargraph{
- max_value = max_value,
- width = 100,
- bars = {
- { color = "#0a0", value = initiative.positive_votes },
- { color = "#aaa", value = max_value - initiative.negative_votes - initiative.positive_votes },
- { color = "#a00", value = initiative.negative_votes },
- }
- }
- else
- slot.put(" ")
- end
- else
- slot.put(_"Counting of votes")
- end
- else
- local max_value = initiative.issue.population or 0
- ui.bargraph{
- max_value = max_value,
- width = 100,
- quorum = max_value * (initiative.issue.policy.initiative_quorum_num / initiative.issue.policy.initiative_quorum_den),
- quorum_color = "#00F",
- bars = {
- { color = "#0a0", value = (initiative.satisfied_supporter_count or 0) },
- { color = "#bbb", value = (initiative.supporter_count or 0) - (initiative.satisfied_supporter_count or 0) },
- { color = "#f7f7f7", value = max_value - (initiative.supporter_count or 0) },
- }
- }
- end
- end
- },
- {
- field_attr = { style = "width: 24px;" },
- content = function()
- if initiative.is_initiator then
- slot.put(" ")
- local label = _"You are initiator of this initiative"
- ui.image{
- attr = { alt = label, title = label },
- static = "icons/16/user_edit.png"
- }
- elseif initiative.is_supporter then
- slot.put(" ")
- local label = _"You are supporter of this initiative"
- ui.image{
- attr = { alt = label, title = label },
- static = "icons/16/thumb_up_green.png"
- }
- elseif initiative.is_potential_supporter then
- slot.put(" ")
- local label = _"You are potentially supporter of this initiative"
- ui.image{
- attr = { alt = label, title = label },
- static = "icons/16/thumb_up.png"
- }
- elseif initiative.is_supporter_via_delegation then
- slot.put(" ")
- local label = _"You are supporter of this initiative via delegation"
- ui.image{
- attr = { alt = label, title = label },
- static = "icons/16/thumb_up_green.png"
- }
- end
-
- end
- },
- {
- content = function()
- local link_class = "initiative_link"
- if initiative.revoked then
- link_class = "revoked"
- end
- if selected then
- link_class = link_class .. " selected"
- end
- if initiative.is_supporter then
- link_class = link_class .. " supported"
- end
- if initiative.is_potential_supporter then
- link_class = link_class .. " potentially_supported"
- end
- if initiative.is_supporter_via_delegation then
- link_class = link_class .. " supported"
- end
- ui.link{
- attr = { id = link_name, class = link_class },
- content = function()
- local name
- if initiative.name_highlighted then
- name = encode.highlight(initiative.name_highlighted)
- else
- name = encode.html(initiative.shortened_name)
- end
- ui.tag{ content = "i" .. initiative.id .. ": " }
- slot.put(name)
- end,
- module = module,
- view = view,
- id = id,
- params = params,
+ {
+ field_attr = { style = "width: 100px;"},
+ content = function()
+ if initiative.issue.fully_frozen and initiative.issue.closed then
+ if initiative.issue.ranks_available then
+ if initiative.negative_votes and initiative.positive_votes then
+ local max_value = initiative.issue.voter_count
+ ui.bargraph{
+ max_value = max_value,
+ width = 100,
+ bars = {
+ { color = "#0a0", value = initiative.positive_votes },
+ { color = "#aaa", value = max_value - initiative.negative_votes - initiative.positive_votes },
+ { color = "#a00", value = initiative.negative_votes },
}
-
- end
- }
- }
- }
- end
- }
- end
-}
-
-if ui.is_partial_loading_enabled() then
- ui.container{
- attr = {
- id = name,
- class = "ui_tabs_accordeon_content",
- },
- content = function()
- ui.container{
- attr = { id = name .. "_content", style = "clear: left;" },
- content = function()
- execute.view{
- module = "initiative",
- view = "show_partial",
- params = {
- initiative = initiative,
+ }
+ else
+ slot.put(" ")
+ end
+ else
+ slot.put(_"Counting of votes")
+ end
+ else
+ local max_value = initiative.issue.population or 0
+ ui.bargraph{
+ max_value = max_value,
+ width = 100,
+ quorum = max_value * (initiative.issue.policy.initiative_quorum_num / initiative.issue.policy.initiative_quorum_den),
+ quorum_color = "#00F",
+ bars = {
+ { color = "#0a0", value = (initiative.satisfied_supporter_count or 0) },
+ { color = "#bbb", value = (initiative.supporter_count or 0) - (initiative.satisfied_supporter_count or 0) },
+ { color = "#f7f7f7", value = max_value - (initiative.supporter_count or 0) },
}
}
end
- }
- end
+ end
+ },
+ {
+ field_attr = { style = "width: 24px;" },
+ content = function()
+ if initiative.is_initiator then
+ slot.put(" ")
+ local label = _"You are initiator of this initiative"
+ ui.image{
+ attr = { alt = label, title = label },
+ static = "icons/16/user_edit.png"
+ }
+ elseif initiative.is_supporter then
+ slot.put(" ")
+ local label = _"You are supporter of this initiative"
+ ui.image{
+ attr = { alt = label, title = label },
+ static = "icons/16/thumb_up_green.png"
+ }
+ elseif initiative.is_potential_supporter then
+ slot.put(" ")
+ local label = _"You are potentially supporter of this initiative"
+ ui.image{
+ attr = { alt = label, title = label },
+ static = "icons/16/thumb_up.png"
+ }
+ elseif initiative.is_supporter_via_delegation then
+ slot.put(" ")
+ local label = _"You are supporter of this initiative via delegation"
+ ui.image{
+ attr = { alt = label, title = label },
+ static = "icons/16/thumb_up_green.png"
+ }
+ end
+
+ end
+ },
+ {
+ content = function()
+ local link_class = "initiative_link"
+ if initiative.revoked then
+ link_class = "revoked"
+ end
+ if selected then
+ link_class = link_class .. " selected"
+ end
+ if initiative.is_supporter then
+ link_class = link_class .. " supported"
+ end
+ if initiative.is_potential_supporter then
+ link_class = link_class .. " potentially_supported"
+ end
+ if initiative.is_supporter_via_delegation then
+ link_class = link_class .. " supported"
+ end
+ ui.link{
+ attr = { class = link_class },
+ content = function()
+ local name
+ if initiative.name_highlighted then
+ name = encode.highlight(initiative.name_highlighted)
+ else
+ name = encode.html(initiative.shortened_name)
+ end
+ ui.tag{ content = "i" .. initiative.id .. ": " }
+ slot.put(name)
+ end,
+ module = "initiative",
+ view = "show",
+ id = initiative.id
+ }
+
+ end
+ }
}
-end
\ No newline at end of file
+}
diff -r 6be42327b67f -r 7d6a3c411f99 app/main/issue/_list.lua
--- a/app/main/issue/_list.lua Tue Feb 28 22:14:13 2012 +0100
+++ b/app/main/issue/_list.lua Tue Feb 28 22:27:19 2012 +0100
@@ -185,30 +185,3 @@
else
ui.filters(filters)
end
-
---[[
-if param.get("legend", atom.boolean) ~= false then
- local filter = param.get_all_cgi().filter
- if not filter or filter == "any" or filter ~= "finished" then
- ui.bargraph_legend{
- width = 25,
- bars = {
- { color = "#0a0", label = _"Supporter" },
- { color = "#777", label = _"Potential supporter" },
- { color = "#ddd", label = _"No support at all" },
- }
- }
- end
- if not filter or filter == "any" or filter == "finished" then
- ui.bargraph_legend{
- width = 25,
- bars = {
- { color = "#0a0", label = _"Yes" },
- { color = "#aaa", label = _"Abstention" },
- { color = "#a00", label = _"No" },
- }
- }
- end
-end
-
---]]
\ No newline at end of file
diff -r 6be42327b67f -r 7d6a3c411f99 app/main/issue/_list_initiatives.lua
--- a/app/main/issue/_list_initiatives.lua Tue Feb 28 22:14:13 2012 +0100
+++ b/app/main/issue/_list_initiatives.lua Tue Feb 28 22:27:19 2012 +0100
@@ -9,9 +9,6 @@
params = {
initiatives_selector = issue:get_reference_selector("initiatives"),
issue = issue,
- expandable = true,
- for_initiative_id = param.get("for_initiative_id", atom.number),
- xshow_for_issue = true,
no_sort = true
}
}
diff -r 6be42327b67f -r 7d6a3c411f99 env/ui/bargraph_legend.lua
--- a/env/ui/bargraph_legend.lua Tue Feb 28 22:14:13 2012 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-function ui.bargraph_legend(attr)
- local width = assert(attr.width)
- local bars = assert(attr.bars)
-
- ui.container{
- attr = { class = "bargraph_legend" },
- content = function()
- ui.container{
- attr = { class = "bargraph_legend_label" },
- content = _"Legend:"
- }
- for i, bar in ipairs(bars) do
- ui.bargraph{
- max_value = 1,
- width = width,
- bars = {
- {
- color = bar.color,
- value = 1,
- }
- }
- }
- ui.container{
- attr = { class = "bargraph_legend_label" },
- content = bar.label
- }
- end
- end
- }
-
- slot.put('
')
-end
\ No newline at end of file
diff -r 6be42327b67f -r 7d6a3c411f99 static/style.css
--- a/static/style.css Tue Feb 28 22:14:13 2012 +0100
+++ b/static/style.css Tue Feb 28 22:27:19 2012 +0100
@@ -661,25 +661,6 @@
height: 1.3ex;
}
-.bargraph_legend {
- margin-top: 2ex;
-}
-
-.bargraph_legend .bargraph {
- width: 26px;
-}
-
-.bargraph_legend div,
-.bargraph_legend div div,
-.bargraph_legend div div div {
- float: left;
-}
-
-.bargraph_legend_label {
- margin-left: 0.5em;
- margin-right: 1em;
-}
-
/*************************************************************************
* vertical ui.form
*/