liquid_feedback_frontend
view app/main/issue/_list.lua @ 15:a3ac899559de
Esperanto support activated in frontend
| author | bsw | 
|---|---|
| date | Sun Jan 31 22:34:45 2010 +0100 (2010-01-31) | 
| parents | 77d58efe99fd | 
| children | 00d1004545f1 | 
 line source
     1 local issues_selector = param.get("issues_selector", "table")
     3 issues_selector
     4   :left_join("interest", "_interest", { "_interest.issue_id = issue.id AND _interest.member_id = ?", app.session.member.id} )
     5   :add_field("(_interest.member_id NOTNULL)", "is_interested")
     7 local ui_filter = ui.filter
     8 if param.get("filter", atom.boolean) == false then
     9   ui_filter = function(args) args.content() end
    10 end
    12 if param.get("no_filter", atom.boolean) then
    13   ui_filter = function(args) args.content() end
    14 end
    16 local filter_voting = false
    17 ui_filter{
    18   selector = issues_selector,
    19   filters = {
    20     {
    21       type = "boolean",
    22       name = "open",
    23       label = _"Open",
    24       selector_modifier = function(selector, value)
    25         if value then
    26           selector:add_where("issue.closed ISNULL")
    27         end
    28       end
    29     },
    30     {
    31       type = "boolean",
    32       name = "new",
    33       label = _"New",
    34       selector_modifier = function(selector, value)
    35         if value then
    36           selector:add_where("issue.accepted ISNULL AND issue.closed ISNULL")
    37         end
    38       end
    39     },
    40     {
    41       type = "boolean",
    42       name = "accepted",
    43       label = _"In discussion",
    44       selector_modifier = function(selector, value)
    45         if value then
    46           selector:add_where("issue.accepted NOTNULL AND issue.half_frozen ISNULL AND issue.closed ISNULL")
    47         end
    48       end
    49     },
    50     {
    51       type = "boolean",
    52       name = "half_frozen",
    53       label = _"Frozen",
    54       selector_modifier = function(selector, value)
    55         if value then
    56           selector:add_where("issue.half_frozen NOTNULL AND issue.fully_frozen ISNULL")
    57         end
    58       end
    59     },
    60     {
    61       type = "boolean",
    62       name = "frozen",
    63       label = _"Voting",
    64       selector_modifier = function(selector, value)
    65         if value then
    66           selector:add_where("issue.fully_frozen NOTNULL AND issue.closed ISNULL")
    67           filter_voting = true
    68         end
    69       end
    70     },
    71     {
    72       type = "boolean",
    73       name = "finished",
    74       label = _"Finished",
    75       selector_modifier = function(selector, value)
    76         if value then
    77           selector:add_where("issue.closed NOTNULL AND issue.fully_frozen NOTNULL")
    78         end
    79       end
    80     },
    81     {
    82       type = "boolean",
    83       name = "cancelled",
    84       label = _"Cancelled",
    85       selector_modifier = function(selector, value)
    86         if value then
    87           selector:add_where("issue.closed NOTNULL AND issue.accepted ISNULL")
    88         end
    89       end
    90     },
    91   },
    92   content = function()
    93     local ui_filter = ui.filter
    94     if not filter_voting then
    95       ui_filter = function(args) args.content() end
    96     end
    97     if param.get("no_filter", atom.boolean) then
    98       ui_filter = function(args) args.content() end
    99     end
   100     ui_filter{
   101       selector = issues_selector,
   102       name = "filter_voting",
   103       filters = {
   104         {
   105           type = "boolean",
   106           name = "any",
   107           label = _"Any",
   108           selector_modifier = function()  end
   109         },
   110         {
   111           type = "boolean",
   112           name = "not_voted",
   113           label = _"Not voted",
   114           selector_modifier = function(selector, value)
   115             if value then
   116               selector:left_join("direct_voter", nil, { "direct_voter.issue_id = issue.id AND direct_voter.member_id = ?", app.session.member.id })
   117               selector:add_where("direct_voter.member_id ISNULL")
   118             end
   119           end
   120         },
   121         {
   122           type = "boolean",
   123           name = "voted",
   124           label = _"Voted",
   125           selector_modifier = function(selector, value)
   126             if value then
   127               selector:join("direct_voter", nil, { "direct_voter.issue_id = issue.id AND direct_voter.member_id = ?", app.session.member.id })
   128             end
   129           end
   130         },
   131       },
   132       content = function()
   133         local ui_filter = ui.filter
   134         if param.get("filter", atom.boolean) == false then
   135           ui_filter = function(args) args.content() end
   136         end
   137         ui_filter{
   138           selector = issues_selector,
   139           name = "filter_interest",
   140           filters = {
   141             {
   142               type = "boolean",
   143               name = "any",
   144               label = _"Any",
   145               selector_modifier = function()  end
   146             },
   147             {
   148               type = "boolean",
   149               name = "my",
   150               label = _"Interested",
   151               selector_modifier = function(selector, value)
   152                 if value then
   153                   selector:join("interest", "filter_interest", { "filter_interest.issue_id = issue.id AND filter_interest.member_id = ? ", app.session.member.id })
   154                 end
   155               end
   156             },
   157             {
   158               type = "boolean",
   159               name = "supported",
   160               label = _"Supported",
   161               selector_modifier = function(selector, value)
   162                 if value then
   163                   selector:add_where({ "EXISTS (SELECT 1 FROM initiative JOIN supporter ON supporter.initiative_id = initiative.id AND supporter.member_id = ? LEFT JOIN opinion ON opinion.initiative_id = initiative.id AND opinion.member_id = ? AND ((opinion.degree = 2 AND NOT fulfilled) OR (opinion.degree = -2 AND fulfilled)) WHERE initiative.issue_id = issue.id AND opinion.member_id ISNULL LIMIT 1)", app.session.member.id, app.session.member.id })
   164                 end
   165               end
   166             },
   167             {
   168               type = "boolean",
   169               name = "potentially_supported",
   170               label = _"Potential supported",
   171               selector_modifier = function(selector, value)
   172                 if value then
   173                   selector:add_where({ "EXISTS (SELECT 1 FROM initiative JOIN supporter ON supporter.initiative_id = initiative.id AND supporter.member_id = ? JOIN opinion ON opinion.initiative_id = initiative.id AND opinion.member_id = ? AND ((opinion.degree = 2 AND NOT fulfilled) OR (opinion.degree = -2 AND fulfilled)) WHERE initiative.issue_id = issue.id LIMIT 1)", app.session.member.id, app.session.member.id })
   174                 end
   175               end
   176             },
   177             {
   178               type = "boolean",
   179               name = "initiated",
   180               label = _"Initiated",
   181               selector_modifier = function(selector, value)
   182                 if value then
   183                   selector:add_where({ "EXISTS (SELECT 1 FROM initiative JOIN initiator ON initiator.initiative_id = initiative.id AND initiator.member_id = ? WHERE initiative.issue_id = issue.id)", app.session.member.id })
   184                 end
   185               end
   186             },
   187           },
   188           content = function()
   189             local ui_order = ui.order
   190             if param.get("no_sort", atom.boolean) then
   191               ui_order = function(args) args.content() end
   192             end
   193             ui_order{
   194               name = "issue_list",
   195               selector = issues_selector,
   196               options = {
   197                 {
   198                   name = "max_potential_support",
   199                   label = _"Max potential support",
   200                   selector_modifier = function(selector)
   201                     selector:add_order_by("(SELECT max(supporter_count) FROM initiative WHERE initiative.issue_id = issue.id) DESC")
   202                   end
   203                 },
   204                 {
   205                   name = "max_support",
   206                   label = _"Max support",
   207                   selector_modifier = function(selector)
   208                     selector:add_order_by("(SELECT max(satisfied_supporter_count) FROM initiative WHERE initiative.issue_id = issue.id) DESC")
   209                   end
   210                 },
   211                 {
   212                   name = "population",
   213                   label = _"Population",
   214                   order_by = "issue.population DESC"
   215                 },
   216                 {
   217                   name = "newest",
   218                   label = _"Newest",
   219                   order_by = "issue.created DESC"
   220                 },
   221                 {
   222                   name = "oldest",
   223                   label = _"Oldest",
   224                   order_by = "issue.created"
   225                 }
   226               },
   227               content = function()
   228                 local ui_paginate = ui.paginate
   229                 if param.get("per_page") == "all" then
   230                   ui_paginate = function(args) args.content() end
   231                 end
   232                 ui_paginate{
   233                   per_page = tonumber(param.get("per_page")),
   234                   selector = issues_selector,
   235                   content = function()
   236                     local highlight_string = param.get("highlight_string", "string")
   237                     local issues = issues or issues_selector:exec()
   238         --            issues:load(initiatives)
   239                     ui.list{
   240                       attr = { class = "issues" },
   241                       records = issues,
   242                       columns = {
   243                         {
   244                           label = _"Issue",
   245                           content = function(record)
   246                             if not param.get("for_area_list", atom.boolean) then
   247                               ui.field.text{
   248                                 value = record.area.name
   249                               }
   250                               slot.put("<br />")
   251                             end
   252                             if record.is_interested then
   253                               local label = _"You are interested in this issue",
   254                               ui.image{
   255                                 attr = { alt = label, title = label },
   256                                 static = "icons/16/eye.png"
   257                               }
   258                               slot.put(" ")
   259                             end
   260                             ui.link{
   261                               text = _("Issue ##{id}", { id = tostring(record.id) }),
   262                               module = "issue",
   263                               view = "show",
   264                               id = record.id
   265                             }
   266                             if record.state == "new" then
   267                               ui.image{
   268                                 static = "icons/16/new.png"
   269                               }
   270                             end
   271                             slot.put("<br />")
   272                             slot.put("<br />")
   273                             if record.old_state then
   274                               ui.field.text{ value = format.time(record.sort) }
   275                               ui.field.text{ value = Issue:get_state_name_for_state(record.old_state) .. " > " .. Issue:get_state_name_for_state(record.new_state) }
   276                             else
   277                             end
   278                           end
   279                         },
   280                         {
   281                           label = _"State",
   282                           content = function(record)
   283                             if record.state == "voting" then
   284                               ui.link{
   285                                 content = _"Voting",
   286                                 module = "vote",
   287                                 view = "list",
   288                                 params = { issue_id = record.id }
   289                               }
   290                             else
   291                               ui.field.issue_state{ value = record.state }
   292                             end
   293                           end
   294                         },
   295                         {
   296                           label = _"Initiatives",
   297                           content = function(record)
   298                             local initiatives_selector = record:get_reference_selector("initiatives")
   299                             local highlight_string = param.get("highlight_string")
   300                             if highlight_string then
   301                               initiatives_selector:add_field( {'"highlight"("initiative"."name", ?)', highlight_string }, "name_highlighted")
   302                             end
   303                             execute.view{
   304                               module = "initiative",
   305                               view = "_list",
   306                               params = {
   307                                 issue = record,
   308                                 initiatives_selector = initiatives_selector,
   309                                 highlight_string = highlight_string,
   310                                 per_page = param.get("initiatives_per_page", atom.number),
   311                                 no_sort = param.get("initiatives_no_sort", atom.boolean)
   312                               }
   313                             }
   314                           end
   315                         },
   316                       }
   317                     }
   318                   end
   319                 }
   320               end
   321             }
   322           end
   323         }
   324       end
   325     }
   326     if param.get("legend", atom.boolean) ~= false then
   327       local filter = param.get_all_cgi().filter
   328       if not filter or filter == "any" or filter ~= "finished" then
   329         ui.bargraph_legend{
   330           width = 25,
   331           bars = {
   332             { color = "#0a0", label = _"Supporter" },
   333             { color = "#777", label = _"Potential supporter" },
   334             { color = "#ddd", label = _"No support at all" },
   335           }
   336         }
   337       end
   338       if not filter or filter == "any" or filter == "finished" then
   339         ui.bargraph_legend{
   340           width = 25,
   341           bars = {
   342             { color = "#0a0", label = _"Yes" },
   343             { color = "#aaa", label = _"Abstention" },
   344             { color = "#a00", label = _"No" },
   345           }
   346         }
   347       end
   348     end
   349   end
   350 }
