| rev | 
   line source | 
| 
bsw@718
 | 
     1 
 | 
| 
bsw@718
 | 
     2 local initiative = param.get("initiative", "table")
 | 
| 
bsw@718
 | 
     3 local suggestions_selector = param.get("suggestions_selector", "table")
 | 
| 
bsw@718
 | 
     4 
 | 
| 
bsw@718
 | 
     5 suggestions_selector:add_order_by("plus2_unfulfilled_count + plus1_unfulfilled_count DESC, id")
 | 
| 
bsw@718
 | 
     6 
 | 
| 
bsw@718
 | 
     7 local tab_id = param.get("tab_id")
 | 
| 
bsw@718
 | 
     8 local show_name = param.get("show_name", atom.boolean)
 | 
| 
bsw@718
 | 
     9 if show_name == nil then
 | 
| 
bsw@718
 | 
    10   show_name = true
 | 
| 
bsw@718
 | 
    11 end
 | 
| 
bsw@718
 | 
    12 local show_filter = param.get("show_filter", atom.boolean)
 | 
| 
bsw@718
 | 
    13 if show_filter == nil then
 | 
| 
bsw@718
 | 
    14   show_filter = true
 | 
| 
bsw@718
 | 
    15 end
 | 
| 
bsw@718
 | 
    16 
 | 
| 
bsw@718
 | 
    17 local partial = {
 | 
| 
bsw@718
 | 
    18   routing = {
 | 
| 
bsw@718
 | 
    19     default = {
 | 
| 
bsw@718
 | 
    20       mode = "redirect",
 | 
| 
bsw@718
 | 
    21       module = "initiative",
 | 
| 
bsw@718
 | 
    22       view = "show_tab",
 | 
| 
bsw@718
 | 
    23       params = {
 | 
| 
bsw@718
 | 
    24         initiative_id = initiative.id,
 | 
| 
bsw@718
 | 
    25         tab = "suggestions",
 | 
| 
bsw@718
 | 
    26         tab_id = tab_id
 | 
| 
bsw@718
 | 
    27       },
 | 
| 
bsw@718
 | 
    28     }
 | 
| 
bsw@718
 | 
    29   }
 | 
| 
bsw@718
 | 
    30 }
 | 
| 
bsw@718
 | 
    31 
 | 
| 
bsw@718
 | 
    32 local ui_filters = ui.filters
 | 
| 
bsw@718
 | 
    33 if true or not show_filter then
 | 
| 
bsw@718
 | 
    34   ui_filters = function(args) args.content() end
 | 
| 
bsw@718
 | 
    35 end
 | 
| 
bsw@718
 | 
    36 
 | 
| 
bsw@718
 | 
    37 ui.container{ attr = { class = "box" },
 | 
| 
bsw@718
 | 
    38   content = function()
 | 
| 
bsw@718
 | 
    39     ui.paginate{
 | 
| 
bsw@718
 | 
    40       selector = suggestions_selector,
 | 
| 
bsw@718
 | 
    41       content = function()
 | 
| 
bsw@718
 | 
    42         ui.list{
 | 
| 
bsw@718
 | 
    43           attr = { style = "table-layout: fixed;" },
 | 
| 
bsw@718
 | 
    44           records = suggestions_selector:exec(),
 | 
| 
bsw@718
 | 
    45           columns = {
 | 
| 
bsw@718
 | 
    46             {
 | 
| 
bsw@718
 | 
    47               label = show_name and _"Suggestion" or nil,
 | 
| 
bsw@718
 | 
    48               content = function(record)
 | 
| 
bsw@718
 | 
    49                 if show_name then
 | 
| 
bsw@718
 | 
    50                   ui.link{
 | 
| 
bsw@718
 | 
    51                     text = record.name,
 | 
| 
bsw@718
 | 
    52                     module = "suggestion",
 | 
| 
bsw@718
 | 
    53                     view = "show",
 | 
| 
bsw@718
 | 
    54                     id = record.id
 | 
| 
bsw@718
 | 
    55                   }
 | 
| 
bsw@718
 | 
    56                 end
 | 
| 
bsw@718
 | 
    57               end
 | 
| 
bsw@718
 | 
    58             },
 | 
| 
bsw@718
 | 
    59             {
 | 
| 
bsw@718
 | 
    60               label = _"Collective opinion of supporters",
 | 
| 
bsw@718
 | 
    61               label_attr = { style = "width: 101px;" },
 | 
| 
bsw@718
 | 
    62               content = function(record)
 | 
| 
bsw@718
 | 
    63                 if record.minus2_unfulfilled_count then
 | 
| 
bsw@718
 | 
    64                   local max_value = record.initiative.supporter_count
 | 
| 
bsw@718
 | 
    65                   ui.bargraph{
 | 
| 
bsw@718
 | 
    66                     max_value = max_value,
 | 
| 
bsw@718
 | 
    67                     width = 100,
 | 
| 
bsw@718
 | 
    68                     bars = {
 | 
| 
bsw@718
 | 
    69                       { color = "#0a0", value = record.plus2_unfulfilled_count + record.plus2_fulfilled_count },
 | 
| 
bsw@718
 | 
    70                       { color = "#8f8", value = record.plus1_unfulfilled_count + record.plus1_fulfilled_count },
 | 
| 
bsw@718
 | 
    71                       { 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
 | 
    72                       { color = "#f88", value = record.minus1_unfulfilled_count + record.minus1_fulfilled_count },
 | 
| 
bsw@718
 | 
    73                       { color = "#a00", value = record.minus2_unfulfilled_count + record.minus2_fulfilled_count },
 | 
| 
bsw@718
 | 
    74                     }
 | 
| 
bsw@718
 | 
    75                   }
 | 
| 
bsw@718
 | 
    76                 end
 | 
| 
bsw@718
 | 
    77               end
 | 
| 
bsw@718
 | 
    78             },
 | 
| 
bsw@718
 | 
    79             {
 | 
| 
bsw@718
 | 
    80               label = _"Suggestion currently not implemented",
 | 
| 
bsw@718
 | 
    81               label_attr = { style = "width: 101px;" },
 | 
| 
bsw@718
 | 
    82               content = function(record)
 | 
| 
bsw@718
 | 
    83                 if record.minus2_unfulfilled_count then
 | 
| 
bsw@718
 | 
    84                   local max_value = record.initiative.supporter_count
 | 
| 
bsw@718
 | 
    85                   ui.bargraph{
 | 
| 
bsw@718
 | 
    86                     max_value = max_value,
 | 
| 
bsw@718
 | 
    87                     width = 100,
 | 
| 
bsw@718
 | 
    88                     bars = {
 | 
| 
bsw@718
 | 
    89                       { color = "#0a0", value = record.plus2_unfulfilled_count },
 | 
| 
bsw@718
 | 
    90                       { color = "#8f8", value = record.plus1_unfulfilled_count },
 | 
| 
bsw@718
 | 
    91                       { color = "#eee", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count },
 | 
| 
bsw@718
 | 
    92                       { color = "#f88", value = record.minus1_unfulfilled_count },
 | 
| 
bsw@718
 | 
    93                       { color = "#a00", value = record.minus2_unfulfilled_count },
 | 
| 
bsw@718
 | 
    94                     }
 | 
| 
bsw@718
 | 
    95                   }
 | 
| 
bsw@718
 | 
    96                 end
 | 
| 
bsw@718
 | 
    97               end
 | 
| 
bsw@718
 | 
    98             },
 | 
| 
bsw@718
 | 
    99             {
 | 
| 
bsw@718
 | 
   100               label = _"Suggestion currently implemented",
 | 
| 
bsw@718
 | 
   101               label_attr = { style = "width: 101px;" },
 | 
| 
bsw@718
 | 
   102               content = function(record)
 | 
| 
bsw@718
 | 
   103                 if record.minus2_fulfilled_count then
 | 
| 
bsw@718
 | 
   104                   local max_value = record.initiative.supporter_count
 | 
| 
bsw@718
 | 
   105                   ui.bargraph{
 | 
| 
bsw@718
 | 
   106                     max_value = max_value,
 | 
| 
bsw@718
 | 
   107                     width = 100,
 | 
| 
bsw@718
 | 
   108                     bars = {
 | 
| 
bsw@718
 | 
   109                       { color = "#0a0", value = record.plus2_fulfilled_count },
 | 
| 
bsw@718
 | 
   110                       { color = "#8f8", value = record.plus1_fulfilled_count },
 | 
| 
bsw@718
 | 
   111                       { color = "#eee", value = max_value - record.minus2_fulfilled_count - record.minus1_fulfilled_count - record.plus1_fulfilled_count - record.plus2_fulfilled_count},
 | 
| 
bsw@718
 | 
   112                       { color = "#f88", value = record.minus1_fulfilled_count },
 | 
| 
bsw@718
 | 
   113                       { color = "#a00", value = record.minus2_fulfilled_count },
 | 
| 
bsw@718
 | 
   114                     }
 | 
| 
bsw@718
 | 
   115                   }
 | 
| 
bsw@718
 | 
   116                 end
 | 
| 
bsw@718
 | 
   117               end
 | 
| 
bsw@718
 | 
   118             },
 | 
| 
bsw@718
 | 
   119           }
 | 
| 
bsw@718
 | 
   120         }
 | 
| 
bsw@718
 | 
   121       end
 | 
| 
bsw@718
 | 
   122     }
 | 
| 
bsw@718
 | 
   123   end
 | 
| 
bsw@718
 | 
   124 }
 |