liquid_feedback_frontend
view app/main/suggestion/_list.lua @ 256:d28594eb0d42
Mark issue quorum instead of initiative quorum at initiative bargraphs unless issue is accepted
| author | bsw | 
|---|---|
| date | Mon Jan 16 21:40:25 2012 +0100 (2012-01-16) | 
| parents | 44ba79952610 | 
| children | f460555c9896 | 
 line source
     2 local initiative = param.get("initiative", "table")
     3 local suggestions_selector = param.get("suggestions_selector", "table")
     4 local tab_id = param.get("tab_id")
     5 local show_name = param.get("show_name", atom.boolean)
     6 if show_name == nil then
     7   show_name = true
     8 end
     9 local show_filter = param.get("show_filter", atom.boolean)
    10 if show_filter == nil then
    11   show_filter = true
    12 end
    14 local partial = {
    15   routing = {
    16     default = {
    17       mode = "redirect",
    18       module = "initiative",
    19       view = "show_tab",
    20       params = {
    21         initiative_id = initiative.id,
    22         tab = "suggestions",
    23         tab_id = tab_id
    24       },
    25     }
    26   }
    27 }
    29 local ui_filters = ui.filters
    30 if not show_filter then
    31   ui_filters = function(args) args.content() end
    32 end
    34 ui_filters{
    35   label = _"Show filter",
    36   selector = suggestions_selector,
    37   {
    38     label = _"Order by",
    39     {
    40       name = "plus_unfulfilled",
    41       label = _"requested",
    42       selector_modifier = function(selector) selector:add_order_by("plus2_unfulfilled_count + plus1_unfulfilled_count DESC, id") end
    43     },
    44     {
    45       name = "plus2",
    46       label = _"must",
    47       selector_modifier = function(selector) selector:add_order_by("plus2_unfulfilled_count + plus2_fulfilled_count DESC, id") end
    48     },
    49     {
    50       name = "plus",
    51       label = _"must/should",
    52       selector_modifier = function(selector) selector:add_order_by("plus2_unfulfilled_count + plus1_unfulfilled_count + plus2_fulfilled_count + plus1_fulfilled_count DESC, id") end
    53     },
    54     {
    55       name = "minus",
    56       label = _"must/should not",
    57       selector_modifier = function(selector) selector:add_order_by("minus2_unfulfilled_count + minus1_unfulfilled_count + minus2_fulfilled_count + minus1_fulfilled_count DESC, id") end
    58     },
    59     {
    60       name = "minus2",
    61       label = _"must not",
    62       selector_modifier = function(selector) selector:add_order_by("minus2_unfulfilled_count + minus2_fulfilled_count DESC, id") end
    63     }
    64   },
    65   content = function()
    66     ui.paginate{
    67       selector = suggestions_selector,
    68       content = function()
    69         ui.list{
    70           attr = { style = "table-layout: fixed;" },
    71           records = suggestions_selector:exec(),
    72           columns = {
    73             {
    74               label = show_name and _"Suggestion" or nil,
    75               content = function(record)
    76                 if show_name then
    77                   ui.link{
    78                     text = record.name,
    79                     module = "suggestion",
    80                     view = "show",
    81                     id = record.id
    82                   }
    83                 end
    84               end
    85             },
    86             {
    87               label = _"Collective opinion of supporters",
    88               label_attr = { style = "width: 101px;" },
    89               content = function(record)
    90                 if record.minus2_unfulfilled_count then
    91                   local max_value = record.initiative.supporter_count
    92                   ui.bargraph{
    93                     max_value = max_value,
    94                     width = 100,
    95                     bars = {
    96                       { color = "#0a0", value = record.plus2_unfulfilled_count + record.plus2_fulfilled_count },
    97                       { color = "#8f8", value = record.plus1_unfulfilled_count + record.plus1_fulfilled_count },
    98                       { 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},
    99                       { color = "#f88", value = record.minus1_unfulfilled_count + record.minus1_fulfilled_count },
   100                       { color = "#a00", value = record.minus2_unfulfilled_count + record.minus2_fulfilled_count },
   101                     }
   102                   }
   103                 end
   104               end
   105             },
   106             {
   107               label = _"My opinion",
   108               label_attr = { style = "width: 130px; font-style: italic;" },
   109               content = function(record)
   110                 local degree
   111                 local opinion
   112                 if app.session.member_id then
   113                   opinion = Opinion:by_pk(app.session.member.id, record.id)
   114                 end
   115                 if opinion then
   116                   degree = opinion.degree
   117                 end
   118                 ui.container{
   119                   attr = { class = "suggestion_my_opinion" },
   120                   content = function()
   121                     if app.session.member_id then
   122                       if initiative.issue.state == "voting" or initiative.issue.state == "closed" then
   123                         if degree == -2 then
   124                           ui.tag{
   125                             tag = "span",
   126                             attr = {
   127                               class = "action" .. (degree == -2 and " active_red2" or "")
   128                             },
   129                             content = _"must not"
   130                           }
   131                         end
   132                         if degree == -1 then
   133                           ui.tag{
   134                             tag = "span",
   135                             attr = { class = "action" .. (degree == -1 and " active_red1" or "") },
   136                             content = _"should not"
   137                           }
   138                         end
   139                         if degree == nil then
   140                           ui.tag{
   141                             tag = "span",
   142                             attr = { class = "action" .. (degree == nil and " active" or "") },
   143                             content = _"neutral"
   144                           }
   145                         end
   146                         if degree == 1 then
   147                           ui.tag{
   148                             tag = "span",
   149                             attr = { class = "action" .. (degree == 1 and " active_green1" or "") },
   150                             content = _"should"
   151                           }
   152                         end
   153                         if degree == 2 then
   154                           ui.tag{
   155                             tag = "span",
   156                             attr = { class = "action" .. (degree == 2 and " active_green2" or "") },
   157                             content = _"must"
   158                           }
   159                         end
   160                       else
   161                         -- we need to put initiative_id into the parameters to have a redirect target in case the suggestion is gone after the action
   162                         params = param.get_all_cgi()
   163                         params['initiative_id'] = initiative.id
   165                         ui.link{
   166                           attr = { class = "action" .. (degree == 2 and " active_green2" or "") },
   167                           text = _"must",
   168                           module = "opinion",
   169                           action = "update",
   170                           routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
   171                           params = {
   172                             suggestion_id = record.id,
   173                             degree = 2
   174                           },
   175                           partial = partial
   176                         }
   177                         slot.put(" ")
   178                         ui.link{
   179                           attr = { class = "action" .. (degree == 1 and " active_green1" or "") },
   180                           text = _"should",
   181                           module = "opinion",
   182                           action = "update",
   183                           routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params} },
   184                           params = {
   185                             suggestion_id = record.id,
   186                             degree = 1
   187                           },
   188                           partial = partial
   189                         }
   190                         slot.put(" ")
   191                         ui.link{
   192                           attr = { class = "action" .. (degree == nil and " active" or "") },
   193                           text = _"neutral",
   194                           module = "opinion",
   195                           action = "update",
   196                           routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
   197                           params = {
   198                             suggestion_id = record.id,
   199                             delete = true
   200                           },
   201                           partial = partial
   202                         }
   203                         slot.put(" ")
   204                         ui.link{
   205                           attr = { class = "action" .. (degree == -1 and " active_red1" or "") },
   206                           text = _"should not",
   207                           module = "opinion",
   208                           action = "update",
   209                           routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
   210                           params = {
   211                             suggestion_id = record.id,
   212                             degree = -1
   213                           },
   214                           partial = partial
   215                         }
   216                         slot.put(" ")
   217                         ui.link{
   218                           attr = { class = "action" .. (degree == -2 and " active_red2" or "") },
   219                           text = _"must not",
   220                           module = "opinion",
   221                           action = "update",
   222                           routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
   223                           params = {
   224                             suggestion_id = record.id,
   225                             degree = -2
   226                           },
   227                           partial = partial
   228                         }
   229                       end
   230                     else
   231                       ui.field.text{ value = _"[Registered members only]" }
   232                     end
   233                   end
   234                 }
   235               end
   236             },
   237             {
   238               label = _"Suggestion currently not implemented",
   239               label_attr = { style = "width: 101px;" },
   240               content = function(record)
   241                 if record.minus2_unfulfilled_count then
   242                   local max_value = record.initiative.supporter_count
   243                   ui.bargraph{
   244                     max_value = max_value,
   245                     width = 100,
   246                     bars = {
   247                       { color = "#0a0", value = record.plus2_unfulfilled_count },
   248                       { color = "#8f8", value = record.plus1_unfulfilled_count },
   249                       { color = "#eee", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count },
   250                       { color = "#f88", value = record.minus1_unfulfilled_count },
   251                       { color = "#a00", value = record.minus2_unfulfilled_count },
   252                     }
   253                   }
   254                 end
   255               end
   256             },
   257             {
   258               label = _"Suggestion currently implemented",
   259               label_attr = { style = "width: 101px;" },
   260               content = function(record)
   261                 if record.minus2_fulfilled_count then
   262                   local max_value = record.initiative.supporter_count
   263                   ui.bargraph{
   264                     max_value = max_value,
   265                     width = 100,
   266                     bars = {
   267                       { color = "#0a0", value = record.plus2_fulfilled_count },
   268                       { color = "#8f8", value = record.plus1_fulfilled_count },
   269                       { color = "#eee", value = max_value - record.minus2_fulfilled_count - record.minus1_fulfilled_count - record.plus1_fulfilled_count - record.plus2_fulfilled_count},
   270                       { color = "#f88", value = record.minus1_fulfilled_count },
   271                       { color = "#a00", value = record.minus2_fulfilled_count },
   272                     }
   273                   }
   274                 end
   275               end
   276             },
   277             {
   278               label = app.session.member_id and _"I consider suggestion as" or nil,
   279               label_attr = { style = "width: 100px; font-style: italic;" },
   280               content = function(record)
   281                 local degree
   282                 local opinion
   283                 if app.session.member_id then
   284                   opinion = Opinion:by_pk(app.session.member.id, record.id)
   285                 end
   286                 if opinion then
   287                   degree = opinion.degree
   288                 end
   289                 if opinion then
   291                   ui.link{
   292                     attr = { class = opinion.fulfilled and "action active" or "action" },
   293                     text = _"implemented",
   294                     module = "opinion",
   295                     action = "update",
   296                     routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
   297                     params = {
   298                       suggestion_id = record.id,
   299                       fulfilled = true
   300                     },
   301                     partial = partial
   302                   }
   303                   slot.put("<br />")
   304                   ui.link{
   305                     attr = { class = not opinion.fulfilled and "action active" or "action" },
   306                     text = _"not implemented",
   307                     module = "opinion",
   308                     action = "update",
   309                     routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
   310                     params = {
   311                       suggestion_id = record.id,
   312                       fulfilled = false
   313                     },
   314                     partial = partial
   315                   }
   317                 end
   318               end
   319             },
   320             {
   321               label = app.session.member_id and _"So I'm" or nil,
   322               content = function(record)
   323                 local opinion
   324                 if app.session.member_id then
   325                   opinion = Opinion:by_pk(app.session.member.id, record.id)
   326                 end
   327                 if opinion then
   328                   if (opinion.fulfilled and opinion.degree > 0) or (not opinion.fulfilled and opinion.degree < 0) then
   329                     local title = _"satisfied"
   330                     ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_happy.png" }
   331                   elseif opinion.degree == 1 or opinion.degree == -1 then
   332                     local title = _"a bit unsatisfied"
   333                     ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_unhappy.png" }
   334                   else
   335                     local title = _"more unsatisfied"
   336                     ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_unhappy_red.png" }
   337                   end
   338                 end
   339               end
   340             },
   341           }
   342         }
   343       end
   344     }
   345   end
   346 }
