| rev | 
   line source | 
| 
bsw@558
 | 
     1 local member = param.get("member", "table")
 | 
| 
bsw@558
 | 
     2 local for_member = param.get("for_member", atom.boolean)
 | 
| 
bsw@598
 | 
     3 local filter_unit = param.get_all_cgi()["filter_unit"] or "my_areas"
 | 
| 
bsw@558
 | 
     4 
 | 
| 
bsw@594
 | 
     5 if not for_member then
 | 
| 
bsw@619
 | 
     6 
 | 
| 
bsw@598
 | 
     7   ui.container{ attr = { class = "ui_filter" }, content = function()
 | 
| 
bsw@598
 | 
     8     ui.container{ attr = { class = "ui_filter_head" }, content = function()
 | 
| 
bsw@598
 | 
     9 
 | 
| 
bsw@598
 | 
    10       ui.link{
 | 
| 
bsw@598
 | 
    11         attr = { class = filter_unit == "my_areas" and "ui_tabs_link active" or nil },
 | 
| 
bsw@598
 | 
    12         text = _"My areas",
 | 
| 
bsw@598
 | 
    13         module = "index", view = "index", params = { filter_unit = "my_areas" }
 | 
| 
bsw@598
 | 
    14       }
 | 
| 
bsw@598
 | 
    15       
 | 
| 
bsw@598
 | 
    16       slot.put(" ")
 | 
| 
bsw@594
 | 
    17 
 | 
| 
bsw@598
 | 
    18       ui.link{
 | 
| 
bsw@598
 | 
    19         attr = { class = filter_unit == "my_units" and "ui_tabs_link active" or nil },
 | 
| 
bsw@598
 | 
    20         text = _"All areas in my units",
 | 
| 
bsw@598
 | 
    21         module = "index", view = "index", params = { filter_unit = "my_units" }
 | 
| 
bsw@598
 | 
    22       }
 | 
| 
bsw@598
 | 
    23       
 | 
| 
bsw@598
 | 
    24       slot.put(" ")
 | 
| 
bsw@558
 | 
    25 
 | 
| 
bsw@598
 | 
    26       ui.link{
 | 
| 
bsw@598
 | 
    27         attr = { class = filter_unit == "global" and "active" or nil },
 | 
| 
bsw@598
 | 
    28         text = _"All units",
 | 
| 
bsw@598
 | 
    29         module = "index", view = "index", params = { filter_unit = "global" }
 | 
| 
bsw@598
 | 
    30       }
 | 
| 
bsw@598
 | 
    31     end }
 | 
| 
bsw@594
 | 
    32   end }
 | 
| 
bsw@594
 | 
    33 end
 | 
| 
bsw@558
 | 
    34 
 | 
| 
bsw@594
 | 
    35 if not for_member then
 | 
| 
bsw@594
 | 
    36   if filter_unit == "global" then
 | 
| 
bsw@594
 | 
    37     execute.view{ module = "unit", view = "_list" }
 | 
| 
bsw@594
 | 
    38     return
 | 
| 
bsw@594
 | 
    39   end
 | 
| 
bsw@594
 | 
    40 
 | 
| 
bsw@558
 | 
    41 end
 | 
| 
bsw@558
 | 
    42 
 | 
| 
bsw@598
 | 
    43 local units = Unit:new_selector():add_order_by("name"):exec()
 | 
| 
bsw@598
 | 
    44 
 | 
| 
bsw@598
 | 
    45 if member then
 | 
| 
bsw@598
 | 
    46   units:load_delegation_info_once_for_member_id(member.id)
 | 
| 
bsw@598
 | 
    47 end
 | 
| 
bsw@558
 | 
    48 
 | 
| 
bsw@558
 | 
    49 for i, unit in ipairs(units) do
 | 
| 
bsw@571
 | 
    50   if member:has_voting_right_for_unit_id(unit.id) then
 | 
| 
bsw@598
 | 
    51    
 | 
| 
bsw@571
 | 
    52     local areas_selector = Area:new_selector()
 | 
| 
bsw@598
 | 
    53       :reset_fields()
 | 
| 
bsw@598
 | 
    54       :add_field("area.id", nil, { "grouped" })
 | 
| 
bsw@707
 | 
    55       :add_field("area.unit_id", nil, { "grouped" })
 | 
| 
bsw@598
 | 
    56       :add_field("area.name", nil, { "grouped" })
 | 
| 
bsw@598
 | 
    57       :add_field("member_weight", nil, { "grouped" })
 | 
| 
bsw@598
 | 
    58       :add_field("direct_member_count", nil, { "grouped" })
 | 
| 
bsw@598
 | 
    59       :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.accepted ISNULL AND issue.closed ISNULL)", "issues_new_count")
 | 
| 
bsw@598
 | 
    60       :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")
 | 
| 
bsw@598
 | 
    61       :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")
 | 
| 
bsw@598
 | 
    62       :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.fully_frozen NOTNULL AND issue.closed ISNULL)", "issues_voting_count")
 | 
| 
bsw@598
 | 
    63       :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.fully_frozen NOTNULL AND issue.closed NOTNULL)", "issues_finished_count")
 | 
| 
bsw@598
 | 
    64       :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.fully_frozen ISNULL AND issue.closed NOTNULL)", "issues_cancelled_count")
 | 
| 
bsw@571
 | 
    65       :add_where{ "area.unit_id = ?", unit.id }
 | 
| 
bsw@571
 | 
    66       :add_where{ "area.active" }
 | 
| 
bsw@598
 | 
    67       :add_order_by("area.name")
 | 
| 
bsw@598
 | 
    68 
 | 
| 
bsw@598
 | 
    69     if filter_unit == "my_areas" then
 | 
| 
bsw@598
 | 
    70       areas_selector:join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id })
 | 
| 
bsw@706
 | 
    71     else
 | 
| 
bsw@706
 | 
    72       areas_selector:join("privilege", nil, { "privilege.unit_id = area.unit_id AND privilege.member_id = ? AND privilege.voting_right", member.id })
 | 
| 
bsw@598
 | 
    73     end
 | 
| 
bsw@571
 | 
    74     
 | 
| 
bsw@571
 | 
    75     local area_count = areas_selector:count()
 | 
| 
bsw@571
 | 
    76     
 | 
| 
bsw@619
 | 
    77     local max_area_count = Area:new_selector()
 | 
| 
bsw@619
 | 
    78       :add_where{ "area.unit_id = ?", unit.id }
 | 
| 
bsw@619
 | 
    79       :add_where{ "area.active" }
 | 
| 
bsw@619
 | 
    80       :count()
 | 
| 
bsw@619
 | 
    81     local more_area_count = max_area_count - area_count
 | 
| 
bsw@619
 | 
    82     local delegated_count = Area:new_selector()
 | 
| 
bsw@619
 | 
    83       :add_where{ "area.unit_id = ?", unit.id }
 | 
| 
bsw@619
 | 
    84       :add_where{ "area.active" }
 | 
| 
bsw@619
 | 
    85       :left_join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id } )
 | 
| 
bsw@619
 | 
    86       :add_where{ "membership.member_id ISNULL" }
 | 
| 
bsw@619
 | 
    87       :join("delegation", nil, { "delegation.area_id = area.id AND delegation.truster_id = ?", member.id } )
 | 
| 
bsw@619
 | 
    88       :add_where{ "delegation.trustee_id NOTNULL" }
 | 
| 
bsw@619
 | 
    89       :count()
 | 
| 
bsw@558
 | 
    90 
 | 
| 
bsw@619
 | 
    91     local more_area_text
 | 
| 
bsw@619
 | 
    92     if area_count == 0 and more_area_count == 1 then
 | 
| 
bsw@778
 | 
    93       if app.session.member_id == member.id then
 | 
| 
bsw@778
 | 
    94         more_area_text = _("You are not participating in the only area of the unit")
 | 
| 
bsw@778
 | 
    95       else
 | 
| 
bsw@778
 | 
    96         more_area_text = _("Member is not participating in the only area of the unit")
 | 
| 
bsw@778
 | 
    97       end
 | 
| 
bsw@619
 | 
    98     elseif area_count == 0 and more_area_count > 0 then
 | 
| 
bsw@778
 | 
    99       if app.session.member_id == member.id then
 | 
| 
bsw@778
 | 
   100         more_area_text = _("You are not participating in any of the #{count} areas in this unit", { count = more_area_count })
 | 
| 
bsw@778
 | 
   101       else
 | 
| 
bsw@778
 | 
   102         more_area_text = _("Member is not participating in any of the #{count} areas in this unit", { count = more_area_count })
 | 
| 
bsw@778
 | 
   103       end
 | 
| 
bsw@619
 | 
   104     elseif area_count > 0 and more_area_count == 1 then
 | 
| 
bsw@619
 | 
   105       more_area_text = _("One more area in this unit")
 | 
| 
bsw@619
 | 
   106     elseif area_count > 0 and more_area_count > 0 then
 | 
| 
bsw@619
 | 
   107       more_area_text = _("#{count} more areas in this unit", { count = more_area_count })
 | 
| 
bsw@619
 | 
   108     end
 | 
| 
bsw@619
 | 
   109     local delegated_text
 | 
| 
bsw@619
 | 
   110     if delegated_count == 1 then
 | 
| 
bsw@619
 | 
   111       delegated_text = _("One of them have an area delegation set", { count = delegated_count })
 | 
| 
bsw@619
 | 
   112     elseif delegated_count > 0 then
 | 
| 
bsw@619
 | 
   113       delegated_text = _("#{count} of them have an area delegation set", { count = delegated_count })
 | 
| 
bsw@619
 | 
   114     end
 | 
| 
bsw@619
 | 
   115 
 | 
| 
bsw@622
 | 
   116     ui.container{ attr = { class = "area_list" }, content = function()
 | 
| 
bsw@774
 | 
   117       execute.view{ module = "unit", view = "_head", params = { unit = unit, show_content = true, member = member } }
 | 
| 
bsw@598
 | 
   118 
 | 
| 
bsw@598
 | 
   119       if area_count > 0 then
 | 
| 
bsw@598
 | 
   120         local areas = areas_selector:exec()
 | 
| 
bsw@707
 | 
   121         
 | 
| 
bsw@713
 | 
   122         areas:load_delegation_info_once_for_member_id(member.id)
 | 
| 
bsw@713
 | 
   123         
 | 
| 
bsw@598
 | 
   124         for i, area in ipairs(areas) do
 | 
| 
bsw@571
 | 
   125           execute.view{
 | 
| 
bsw@598
 | 
   126             module = "area", view = "_list_entry", params = {
 | 
| 
bsw@774
 | 
   127               area = area, member = member
 | 
| 
bsw@571
 | 
   128             }
 | 
| 
bsw@571
 | 
   129           }
 | 
| 
bsw@571
 | 
   130         end
 | 
| 
bsw@623
 | 
   131       end 
 | 
| 
bsw@623
 | 
   132 
 | 
| 
bsw@619
 | 
   133       if area_count == 0 and member:has_voting_right_for_unit_id(unit.id) or
 | 
| 
bsw@619
 | 
   134          more_area_count > 0 then
 | 
| 
bsw@619
 | 
   135         
 | 
| 
bsw@571
 | 
   136       end
 | 
| 
bsw@558
 | 
   137     end }
 | 
| 
bsw@623
 | 
   138     ui.container{ attr = { class = "area", style="margin-top: 1ex; margin-left: 10px;" }, content = function()
 | 
| 
bsw@623
 | 
   139       ui.container{ attr = { class = "title" }, content = function()
 | 
| 
bsw@623
 | 
   140         if more_area_text then
 | 
| 
bsw@623
 | 
   141           ui.link{ module = "unit", view = "show", id = unit.id, text = more_area_text }
 | 
| 
bsw@623
 | 
   142         end
 | 
| 
bsw@623
 | 
   143         if delegated_text then
 | 
| 
bsw@623
 | 
   144           slot.put(" · ")
 | 
| 
bsw@623
 | 
   145           ui.tag{ content = delegated_text }
 | 
| 
bsw@623
 | 
   146         end
 | 
| 
bsw@623
 | 
   147       end }
 | 
| 
bsw@623
 | 
   148     end }
 | 
| 
bsw@623
 | 
   149     slot.put("<br />")
 | 
| 
bsw@571
 | 
   150   end
 | 
| 
bsw@558
 | 
   151 end
 | 
| 
bsw@558
 | 
   152 
 | 
| 
bsw@558
 | 
   153 
 |