| rev | 
   line source | 
| 
bsw/jbe@4
 | 
     1 
 | 
| 
bsw/jbe@4
 | 
     2 local initiative = param.get("initiative", "table")
 | 
| 
bsw/jbe@0
 | 
     3 local suggestions_selector = param.get("suggestions_selector", "table")
 | 
| 
bsw@454
 | 
     4 
 | 
| 
bsw@981
 | 
     5 suggestions_selector:add_order_by("proportional_order NULLS LAST, plus2_unfulfilled_count + plus1_unfulfilled_count DESC, id")
 | 
| 
bsw@454
 | 
     6 
 | 
| 
bsw/jbe@19
 | 
     7 local ui_filters = ui.filters
 | 
| 
bsw@454
 | 
     8 if true or not show_filter then
 | 
| 
bsw/jbe@19
 | 
     9   ui_filters = function(args) args.content() end
 | 
| 
bsw/jbe@19
 | 
    10 end
 | 
| 
bsw/jbe@19
 | 
    11 
 | 
| 
bsw@718
 | 
    12 ui.container{ attr = { class = "initiative_head" },
 | 
| 
bsw/jbe@0
 | 
    13   content = function()
 | 
| 
bsw@979
 | 
    14     ui.tag{ tag = "a", attr = { class = "title", name = "suggestions" }, content = _"Suggestions" }
 | 
| 
bsw@718
 | 
    15     ui.container{ attr = { class = "content" }, content = function()
 | 
| 
bsw@718
 | 
    16       ui.paginate{
 | 
| 
bsw@718
 | 
    17         selector = suggestions_selector,
 | 
| 
bsw@978
 | 
    18         anchor = "suggestions",
 | 
| 
bsw@718
 | 
    19         content = function()
 | 
| 
bsw@718
 | 
    20           local suggestions = suggestions_selector:exec()
 | 
| 
bsw@718
 | 
    21           if #suggestions < 1 then
 | 
| 
bsw@718
 | 
    22             if not initiative.issue.fully_frozen and not initiative.issue.closed then
 | 
| 
bsw@718
 | 
    23               ui.tag{ content = _"No suggestions yet" }
 | 
| 
bsw@718
 | 
    24             else
 | 
| 
bsw@718
 | 
    25               ui.tag{ content = _"No suggestions" }
 | 
| 
bsw@718
 | 
    26             end
 | 
| 
bsw@718
 | 
    27           else
 | 
| 
bsw@718
 | 
    28             ui.list{
 | 
| 
bsw@718
 | 
    29               attr = { style = "table-layout: fixed;" },
 | 
| 
bsw@718
 | 
    30               records = suggestions,
 | 
| 
bsw@718
 | 
    31               columns = {
 | 
| 
bsw@718
 | 
    32                 {
 | 
| 
bsw@718
 | 
    33                   label_attr = { style = "width: 101px;" },
 | 
| 
bsw@718
 | 
    34                   content = function(record)
 | 
| 
bsw@718
 | 
    35                     if record.minus2_unfulfilled_count then
 | 
| 
bsw@718
 | 
    36                       local max_value = record.initiative.supporter_count
 | 
| 
bsw@718
 | 
    37                       ui.bargraph{
 | 
| 
bsw@718
 | 
    38                         max_value = max_value,
 | 
| 
bsw@718
 | 
    39                         width = 100,
 | 
| 
bsw@718
 | 
    40                         bars = {
 | 
| 
bsw@718
 | 
    41                           { color = "#0a0", value = record.plus2_unfulfilled_count + record.plus2_fulfilled_count },
 | 
| 
bsw@718
 | 
    42                           { color = "#8f8", value = record.plus1_unfulfilled_count + record.plus1_fulfilled_count },
 | 
| 
bsw@718
 | 
    43                           { 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
 | 
    44                           { color = "#f88", value = record.minus1_unfulfilled_count + record.minus1_fulfilled_count },
 | 
| 
bsw@718
 | 
    45                           { color = "#a00", value = record.minus2_unfulfilled_count + record.minus2_fulfilled_count },
 | 
| 
bsw@51
 | 
    46                         }
 | 
| 
bsw@718
 | 
    47                       }
 | 
| 
bsw/jbe@19
 | 
    48                     end
 | 
| 
bsw/jbe@5
 | 
    49                   end
 | 
| 
bsw@718
 | 
    50                 },
 | 
| 
bsw@718
 | 
    51                 {
 | 
| 
bsw@718
 | 
    52                   content = function(record)
 | 
| 
bsw@718
 | 
    53                     ui.link{
 | 
| 
bsw@718
 | 
    54                       text = record.name,
 | 
| 
bsw@718
 | 
    55                       module = "suggestion",
 | 
| 
bsw@718
 | 
    56                       view = "show",
 | 
| 
bsw@718
 | 
    57                       id = record.id
 | 
| 
bsw/jbe@4
 | 
    58                     }
 | 
| 
bsw@718
 | 
    59                     local degree
 | 
| 
bsw@718
 | 
    60                     local opinion
 | 
| 
bsw@718
 | 
    61                     if app.session.member_id then
 | 
| 
bsw@718
 | 
    62                       opinion = Opinion:by_pk(app.session.member.id, record.id)
 | 
| 
bsw@718
 | 
    63                     end
 | 
| 
bsw@718
 | 
    64                     if opinion then
 | 
| 
bsw@718
 | 
    65                       local degrees = {
 | 
| 
bsw@718
 | 
    66                         ["-2"] = _"must not",
 | 
| 
bsw@718
 | 
    67                         ["-1"] = _"should not",
 | 
| 
bsw@718
 | 
    68                         ["0"] = _"neutral",
 | 
| 
bsw@718
 | 
    69                         ["1"] = _"should",
 | 
| 
bsw@718
 | 
    70                         ["2"] = _"must"
 | 
| 
bsw@718
 | 
    71                       }
 | 
| 
bsw@718
 | 
    72                       slot.put(" · ")
 | 
| 
bsw@718
 | 
    73                       ui.tag{ content = degrees[tostring(opinion.degree)] }
 | 
| 
bsw@718
 | 
    74                       slot.put(" · ")
 | 
| 
bsw@718
 | 
    75                       if opinion.fulfilled then
 | 
| 
bsw@718
 | 
    76                         ui.tag{ content = _"implemented" }
 | 
| 
bsw@718
 | 
    77                       else
 | 
| 
bsw@718
 | 
    78                         ui.tag{ content = _"not implemented" }
 | 
| 
bsw@718
 | 
    79                       end
 | 
| 
bsw@718
 | 
    80                     end
 | 
| 
bsw/jbe@4
 | 
    81                   end
 | 
| 
bsw@718
 | 
    82                 },
 | 
| 
bsw@718
 | 
    83               }
 | 
| 
bsw@718
 | 
    84             }
 | 
| 
bsw@718
 | 
    85           end
 | 
| 
bsw@718
 | 
    86         end
 | 
| 
bsw@718
 | 
    87       }
 | 
| 
bsw@718
 | 
    88     end }
 | 
| 
bsw@720
 | 
    89     if app.session.member_id
 | 
| 
bsw@720
 | 
    90       and not initiative.issue.half_frozen
 | 
| 
bsw@720
 | 
    91       and not initiative.issue.closed
 | 
| 
bsw@720
 | 
    92       and not initiative.revoked
 | 
| 
bsw@720
 | 
    93       and app.session.member:has_voting_right_for_unit_id(initiative.issue.area.unit_id)
 | 
| 
bsw@720
 | 
    94     then
 | 
| 
bsw@718
 | 
    95       ui.container{ attr = { class = "content" }, content = function()
 | 
| 
bsw@718
 | 
    96         ui.link{
 | 
| 
bsw@718
 | 
    97           module = "suggestion", view = "new", params = { initiative_id = initiative.id },
 | 
| 
bsw@718
 | 
    98           text = _"New suggestion"
 | 
| 
bsw/jbe@4
 | 
    99         }
 | 
| 
bsw@718
 | 
   100       end }
 | 
| 
bsw@718
 | 
   101     end
 | 
| 
bsw/jbe@0
 | 
   102   end
 | 
| 
bsw/jbe@0
 | 
   103 }
 |