liquid_feedback_frontend
view app/main/area/_list.lua @ 212:3e4ad069847a
Some more work at 2nd generation frontend code
| author | bsw | 
|---|---|
| date | Thu Mar 03 18:39:00 2011 +0100 (2011-03-03) | 
| parents | 0849be391140 | 
| children | 910bbf6bc6b1 | 
 line source
     1 local areas_selector = param.get("areas_selector", "table")
     3 areas_selector
     4   :reset_fields()
     5   :add_field("area.id", nil, { "grouped" })
     6   :add_field("area.name", nil, { "grouped" })
     7   :add_field("member_weight", nil, { "grouped" })
     8   :add_field("direct_member_count", nil, { "grouped" })
     9   :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.accepted ISNULL AND issue.closed ISNULL)", "issues_new_count")
    10   :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.accepted NOTNULL AND issue.half_frozen ISNULL AND issue.closed ISNULL)", "issues_discussion_count")
    11   :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.half_frozen NOTNULL AND issue.fully_frozen ISNULL AND issue.closed ISNULL)", "issues_frozen_count")
    12   :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.fully_frozen NOTNULL AND issue.closed ISNULL)", "issues_voting_count")
    13   :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.fully_frozen NOTNULL AND issue.closed NOTNULL)", "issues_finished_count")
    14   :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.fully_frozen ISNULL AND issue.closed NOTNULL)", "issues_cancelled_count")
    16 if app.session.member_id then
    17   areas_selector
    18     :add_field({ "(SELECT COUNT(*) FROM issue LEFT JOIN direct_voter ON direct_voter.issue_id = issue.id AND direct_voter.member_id = ? WHERE issue.area_id = area.id AND issue.fully_frozen NOTNULL AND issue.closed ISNULL AND direct_voter.member_id ISNULL)", app.session.member.id }, "issues_to_vote_count")
    19     :left_join("membership", "_membership", { "_membership.area_id = area.id AND _membership.member_id = ?", app.session.member.id })
    20     :add_field("_membership.member_id NOTNULL", "is_member", { "grouped" })
    21 else
    22   areas_selector:add_field("0", "issues_to_vote_count")
    23 end
    25 local label_attr = { style = "text-align: right; width: 4em;" }
    26 local field_attr = { style = "text-align: right; width: 4em;" }
    28 ui.filters{
    29   label = _"Change order",
    30   selector = areas_selector,
    31   {
    32     label = _"Order by",
    33     {
    34       name = "member_weight",
    35       label = _"Population",
    36       selector_modifier = function(selector) selector:add_order_by("area.member_weight DESC") end
    37     },
    38     {
    39       name = "direct_member_count",
    40       label = _"Direct member count",
    41       selector_modifier = function(selector) selector:add_order_by("area.direct_member_count DESC") end
    42     },
    43     {
    44       name = "az",
    45       label = _"A-Z",
    46       selector_modifier = function(selector) selector:add_order_by("area.name") end
    47     },
    48     {
    49       name = "za",
    50       label = _"Z-A",
    51       selector_modifier = function(selector) selector:add_order_by("area.name DESC") end
    52     }
    53   },
    54   content = function()
    55     ui.list{
    56       attr = { class = "area_list" },
    57       records = areas_selector:exec(),
    58       columns = {
    59         {
    60           content = function(record)
    61             if record.is_member then
    62               local text = _"Member of area"
    63               ui.image{
    64                 attr = { title = text, alt = text, style = "vertical-align: middle;" },
    65                 static = "icons/16/user_gray.png",
    66               }
    67             end
    68           end
    69         },
    70         {
    71           content = function(record)
    72             if record.member_weight and record.direct_member_count then
    73               local max_value = MemberCount:get()
    74               ui.bargraph{
    75                 max_value = max_value,
    76                 width = 100,
    77                 bars = {
    78                   { color = "#444", value = record.direct_member_count },
    79                   { color = "#777", value = record.member_weight - record.direct_member_count },
    80                   { color = "#ddd", value = max_value - record.member_weight },
    81                 }
    82               }
    83             end
    84           end
    85         },
    86         {
    87           content = function(record)
    88             ui.link{
    89               text = record.name,
    90               module = "area",
    91               view = "show",
    92               id = record.id
    93             }
    94           end
    95         },
    96         {
    97           label = function()
    98             local title = _"New"
    99             ui.image{
   100               attr = { title = title, alt = title },
   101               static = "icons/16/new.png"
   102             }
   103           end,
   104           field_attr = field_attr,
   105           label_attr = label_attr,
   106           content = function(record)
   107             ui.link{
   108               text = tostring(record.issues_new_count),
   109               module = "area",
   110               view = "show",
   111               id = record.id,
   112               params = { filter = "new", tab = "issues" }
   113             }
   114           end
   115         },
   116         {
   117           label = function()
   118             local title = _"Discussion"
   119             ui.image{
   120               attr = { title = title, alt = title },
   121               static = "icons/16/comments.png"
   122             }
   123           end,
   124           field_attr = field_attr,
   125           label_attr = label_attr,
   126           content = function(record)
   127             ui.link{
   128               text = tostring(record.issues_discussion_count),
   129               module = "area",
   130               view = "show",
   131               id = record.id,
   132               params = { filter = "accepted", tab = "issues" }
   133             }
   134           end
   135         },
   136         {
   137           label = function()
   138             local title = _"Frozen"
   139             ui.image{
   140               attr = { title = title, alt = title },
   141               static = "icons/16/lock.png"
   142             }
   143           end,
   144           field_attr = field_attr,
   145           label_attr = label_attr,
   146           content = function(record)
   147             ui.link{
   148               text = tostring(record.issues_frozen_count),
   149               module = "area",
   150               view = "show",
   151               id = record.id,
   152               params = { filter = "half_frozen", tab = "issues" }
   153             }
   154           end
   155         },
   156         {
   157           label = function()
   158             local title = _"Voting"
   159             ui.image{
   160               attr = { title = title, alt = title },
   161               static = "icons/16/email_open.png"
   162             }
   163           end,
   164           field_attr = field_attr,
   165           label_attr = label_attr,
   166           content = function(record)
   167             ui.link{
   168               text = tostring(record.issues_voting_count),
   169               module = "area",
   170               view = "show",
   171               id = record.id,
   172               params = { filter = "frozen", tab = "issues" }
   173             }
   174           end
   175         },
   176         {
   177           label = function()
   178             local title = _"Finished"
   179             ui.image{
   180               attr = { title = title, alt = title },
   181               static = "icons/16/tick.png"
   182             }
   183           end,
   184           field_attr = field_attr,
   185           label_attr = label_attr,
   186           content = function(record)
   187             ui.link{
   188               text = tostring(record.issues_finished_count),
   189               module = "area",
   190               view = "show",
   191               id = record.id,
   192               params = { filter = "finished", issue_list = "newest", tab = "issues" }
   193             }
   194           end
   195         },
   196         {
   197           label = function()
   198             local title = _"Cancelled"
   199             ui.image{
   200               attr = { title = title, alt = title },
   201               static = "icons/16/cross.png"
   202             }
   203           end,
   204           field_attr = field_attr,
   205           label_attr = label_attr,
   206           content = function(record)
   207             ui.link{
   208               text = tostring(record.issues_cancelled_count),
   209               module = "area",
   210               view = "show",
   211               id = record.id,
   212               params = { filter = "cancelled", issue_list = "newest", tab = "issues" }
   213             }
   214           end
   215         },
   216         {
   217           content = function(record)
   218             if record.issues_to_vote_count > 0 then
   219               ui.link{
   220                 attr = { class = "not_voted" },
   221                 text = _"Not yet voted" .. ": " .. tostring(record.issues_to_vote_count),
   222                 module = "area",
   223                 view = "show",
   224                 id = record.id,
   225                 params = {
   226                   filter = "frozen",
   227                   filter_voting = "not_voted",
   228                   tab = "issues"
   229                 }
   230               }
   231             end
   232           end
   233         },
   234       }
   235     }
   236   end
   237 }
   239 ui.bargraph_legend{
   240   width = 25,
   241   bars = {
   242     { color = "#444", label = _"Direct membership" },
   243     { color = "#777", label = _"Membership by delegation" },
   244     { color = "#ddd", label = _"No membership at all" },
   245   }
   246 }
   248 slot.put("<br />   ")
   251 if app.session.member_id then
   252   ui.image{
   253     attr = { title = title, alt = title },
   254     static = "icons/16/user_gray.png"
   255   }
   256   slot.put(" ")
   257   slot.put(_"Member of area")
   258   slot.put("   ")
   259 end
   261 ui.image{
   262   attr = { title = title, alt = title },
   263   static = "icons/16/new.png"
   264 }
   265 slot.put(" ")
   266 slot.put(_"New")
   267 slot.put("   ")
   269 ui.image{
   270   attr = { title = title, alt = title },
   271   static = "icons/16/comments.png"
   272 }
   273 slot.put(" ")
   274 slot.put(_"Discussion")
   275 slot.put("   ")
   277 ui.image{
   278   attr = { title = title, alt = title },
   279   static = "icons/16/lock.png"
   280 }
   281 slot.put(" ")
   282 slot.put(_"Frozen")
   283 slot.put("   ")
   285 ui.image{
   286   attr = { title = title, alt = title },
   287   static = "icons/16/email_open.png"
   288 }
   289 slot.put(" ")
   290 slot.put(_"Voting")
   291 slot.put("   ")
   293 ui.image{
   294   attr = { title = title, alt = title },
   295   static = "icons/16/tick.png"
   296 }
   297 slot.put(" ")
   298 slot.put(_"Finished")
   299 slot.put("   ")
   301 ui.image{
   302   attr = { title = title, alt = title },
   303   static = "icons/16/cross.png"
   304 }
   305 slot.put(" ")
   306 slot.put(_"Cancelled")
