bsw@718: bsw@718: local initiative = param.get("initiative", "table") bsw@718: local suggestions_selector = param.get("suggestions_selector", "table") bsw@718: bsw@718: suggestions_selector:add_order_by("plus2_unfulfilled_count + plus1_unfulfilled_count DESC, id") bsw@718: bsw@718: local tab_id = param.get("tab_id") bsw@718: local show_name = param.get("show_name", atom.boolean) bsw@718: if show_name == nil then bsw@718: show_name = true bsw@718: end bsw@718: local show_filter = param.get("show_filter", atom.boolean) bsw@718: if show_filter == nil then bsw@718: show_filter = true bsw@718: end bsw@718: bsw@718: local partial = { bsw@718: routing = { bsw@718: default = { bsw@718: mode = "redirect", bsw@718: module = "initiative", bsw@718: view = "show_tab", bsw@718: params = { bsw@718: initiative_id = initiative.id, bsw@718: tab = "suggestions", bsw@718: tab_id = tab_id bsw@718: }, bsw@718: } bsw@718: } bsw@718: } bsw@718: bsw@718: local ui_filters = ui.filters bsw@718: if true or not show_filter then bsw@718: ui_filters = function(args) args.content() end bsw@718: end bsw@718: bsw@718: ui.container{ attr = { class = "box" }, bsw@718: content = function() bsw@718: ui.paginate{ bsw@718: selector = suggestions_selector, bsw@718: content = function() bsw@718: ui.list{ bsw@718: attr = { style = "table-layout: fixed;" }, bsw@718: records = suggestions_selector:exec(), bsw@718: columns = { bsw@718: { bsw@718: label = show_name and _"Suggestion" or nil, bsw@718: content = function(record) bsw@718: if show_name then bsw@718: ui.link{ bsw@718: text = record.name, bsw@718: module = "suggestion", bsw@718: view = "show", bsw@718: id = record.id bsw@718: } bsw@718: end bsw@718: end bsw@718: }, bsw@718: { bsw@718: label = _"Collective opinion of supporters", bsw@718: label_attr = { style = "width: 101px;" }, bsw@718: content = function(record) bsw@718: if record.minus2_unfulfilled_count then bsw@718: local max_value = record.initiative.supporter_count bsw@718: ui.bargraph{ bsw@718: max_value = max_value, bsw@718: width = 100, bsw@718: bars = { bsw@718: { color = "#0a0", value = record.plus2_unfulfilled_count + record.plus2_fulfilled_count }, bsw@718: { color = "#8f8", value = record.plus1_unfulfilled_count + record.plus1_fulfilled_count }, bsw@718: { color = "#eee", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count - record.minus2_fulfilled_count - record.minus1_fulfilled_count - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count - record.plus1_fulfilled_count - record.plus2_fulfilled_count}, bsw@718: { color = "#f88", value = record.minus1_unfulfilled_count + record.minus1_fulfilled_count }, bsw@718: { color = "#a00", value = record.minus2_unfulfilled_count + record.minus2_fulfilled_count }, bsw@718: } bsw@718: } bsw@718: end bsw@718: end bsw@718: }, bsw@718: { bsw@718: label = _"Suggestion currently not implemented", bsw@718: label_attr = { style = "width: 101px;" }, bsw@718: content = function(record) bsw@718: if record.minus2_unfulfilled_count then bsw@718: local max_value = record.initiative.supporter_count bsw@718: ui.bargraph{ bsw@718: max_value = max_value, bsw@718: width = 100, bsw@718: bars = { bsw@718: { color = "#0a0", value = record.plus2_unfulfilled_count }, bsw@718: { color = "#8f8", value = record.plus1_unfulfilled_count }, bsw@718: { color = "#eee", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count }, bsw@718: { color = "#f88", value = record.minus1_unfulfilled_count }, bsw@718: { color = "#a00", value = record.minus2_unfulfilled_count }, bsw@718: } bsw@718: } bsw@718: end bsw@718: end bsw@718: }, bsw@718: { bsw@718: label = _"Suggestion currently implemented", bsw@718: label_attr = { style = "width: 101px;" }, bsw@718: content = function(record) bsw@718: if record.minus2_fulfilled_count then bsw@718: local max_value = record.initiative.supporter_count bsw@718: ui.bargraph{ bsw@718: max_value = max_value, bsw@718: width = 100, bsw@718: bars = { bsw@718: { color = "#0a0", value = record.plus2_fulfilled_count }, bsw@718: { color = "#8f8", value = record.plus1_fulfilled_count }, bsw@718: { color = "#eee", value = max_value - record.minus2_fulfilled_count - record.minus1_fulfilled_count - record.plus1_fulfilled_count - record.plus2_fulfilled_count}, bsw@718: { color = "#f88", value = record.minus1_fulfilled_count }, bsw@718: { color = "#a00", value = record.minus2_fulfilled_count }, bsw@718: } bsw@718: } bsw@718: end bsw@718: end bsw@718: }, bsw@718: } bsw@718: } bsw@718: end bsw@718: } bsw@718: end bsw@718: }