bsw@558: local member = param.get("member", "table") bsw@558: local for_member = param.get("for_member", atom.boolean) bsw@1145: local filter_unit = request.get_param_strings()["filter_unit"] or "my_areas" bsw@558: bsw@594: if not for_member then bsw@619: bsw@598: ui.container{ attr = { class = "ui_filter" }, content = function() bsw@598: ui.container{ attr = { class = "ui_filter_head" }, content = function() bsw@598: bsw@598: ui.link{ bsw@598: attr = { class = filter_unit == "my_areas" and "ui_tabs_link active" or nil }, bsw@598: text = _"My areas", bsw@598: module = "index", view = "index", params = { filter_unit = "my_areas" } bsw@598: } bsw@598: bsw@598: slot.put(" ") bsw@594: bsw@598: ui.link{ bsw@598: attr = { class = filter_unit == "my_units" and "ui_tabs_link active" or nil }, bsw@598: text = _"All areas in my units", bsw@598: module = "index", view = "index", params = { filter_unit = "my_units" } bsw@598: } bsw@598: bsw@598: slot.put(" ") bsw@558: bsw@598: ui.link{ bsw@598: attr = { class = filter_unit == "global" and "active" or nil }, bsw@598: text = _"All units", bsw@598: module = "index", view = "index", params = { filter_unit = "global" } bsw@598: } bsw@598: end } bsw@594: end } bsw@594: end bsw@558: bsw@594: if not for_member then bsw@594: if filter_unit == "global" then bsw@594: execute.view{ module = "unit", view = "_list" } bsw@594: return bsw@594: end bsw@594: bsw@558: end bsw@558: bsw@830: local units = Unit:new_selector():add_where("active"):add_order_by("name"):exec() bsw@598: bsw@598: if member then bsw@598: units:load_delegation_info_once_for_member_id(member.id) bsw@598: end bsw@558: bsw@558: for i, unit in ipairs(units) do bsw@571: if member:has_voting_right_for_unit_id(unit.id) then bsw@598: bsw@571: local areas_selector = Area:new_selector() bsw@598: :reset_fields() bsw@598: :add_field("area.id", nil, { "grouped" }) bsw@707: :add_field("area.unit_id", nil, { "grouped" }) bsw@598: :add_field("area.name", nil, { "grouped" }) bsw@598: :add_field("member_weight", nil, { "grouped" }) bsw@598: :add_field("direct_member_count", nil, { "grouped" }) bsw@598: :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: :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: :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: :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: :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@973: :add_field("(SELECT COUNT(*) FROM issue WHERE issue.area_id = area.id AND issue.fully_frozen ISNULL AND issue.closed NOTNULL)", "issues_canceled_count") bsw@571: :add_where{ "area.unit_id = ?", unit.id } bsw@571: :add_where{ "area.active" } bsw@598: :add_order_by("area.name") bsw@598: bsw@598: if filter_unit == "my_areas" then bsw@598: areas_selector:join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id }) bsw@706: else bsw@706: areas_selector:join("privilege", nil, { "privilege.unit_id = area.unit_id AND privilege.member_id = ? AND privilege.voting_right", member.id }) bsw@598: end bsw@571: bsw@571: local area_count = areas_selector:count() bsw@571: bsw@619: local max_area_count = Area:new_selector() bsw@619: :add_where{ "area.unit_id = ?", unit.id } bsw@619: :add_where{ "area.active" } bsw@619: :count() bsw@619: local more_area_count = max_area_count - area_count bsw@619: local delegated_count = Area:new_selector() bsw@619: :add_where{ "area.unit_id = ?", unit.id } bsw@619: :add_where{ "area.active" } bsw@619: :left_join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id } ) bsw@619: :add_where{ "membership.member_id ISNULL" } bsw@619: :join("delegation", nil, { "delegation.area_id = area.id AND delegation.truster_id = ?", member.id } ) bsw@619: :add_where{ "delegation.trustee_id NOTNULL" } bsw@619: :count() bsw@558: bsw@619: local more_area_text bsw@619: if area_count == 0 and more_area_count == 1 then bsw@778: if app.session.member_id == member.id then bsw@778: more_area_text = _("You are not participating in the only area of the unit") bsw@778: else bsw@778: more_area_text = _("Member is not participating in the only area of the unit") bsw@778: end bsw@619: elseif area_count == 0 and more_area_count > 0 then bsw@778: if app.session.member_id == member.id then bsw@778: more_area_text = _("You are not participating in any of the #{count} areas in this unit", { count = more_area_count }) bsw@778: else bsw@778: more_area_text = _("Member is not participating in any of the #{count} areas in this unit", { count = more_area_count }) bsw@778: end bsw@619: elseif area_count > 0 and more_area_count == 1 then bsw@619: more_area_text = _("One more area in this unit") bsw@619: elseif area_count > 0 and more_area_count > 0 then bsw@619: more_area_text = _("#{count} more areas in this unit", { count = more_area_count }) bsw@619: end bsw@619: local delegated_text bsw@619: if delegated_count == 1 then bsw@619: delegated_text = _("One of them have an area delegation set", { count = delegated_count }) bsw@619: elseif delegated_count > 0 then bsw@619: delegated_text = _("#{count} of them have an area delegation set", { count = delegated_count }) bsw@619: end bsw@619: bsw@622: ui.container{ attr = { class = "area_list" }, content = function() bsw@774: execute.view{ module = "unit", view = "_head", params = { unit = unit, show_content = true, member = member } } bsw@598: bsw@598: if area_count > 0 then bsw@598: local areas = areas_selector:exec() bsw@707: bsw@713: areas:load_delegation_info_once_for_member_id(member.id) bsw@713: bsw@598: for i, area in ipairs(areas) do bsw@571: execute.view{ bsw@598: module = "area", view = "_list_entry", params = { bsw@774: area = area, member = member bsw@571: } bsw@571: } bsw@571: end bsw@623: end bsw@623: bsw@619: if area_count == 0 and member:has_voting_right_for_unit_id(unit.id) or bsw@619: more_area_count > 0 then bsw@619: bsw@571: end bsw@558: end } bsw@623: ui.container{ attr = { class = "area", style="margin-top: 1ex; margin-left: 10px;" }, content = function() bsw@623: ui.container{ attr = { class = "title" }, content = function() bsw@623: if more_area_text then bsw@623: ui.link{ module = "unit", view = "show", id = unit.id, text = more_area_text } bsw@623: end bsw@623: if delegated_text then bsw@623: slot.put(" · ") bsw@623: ui.tag{ content = delegated_text } bsw@623: end bsw@623: end } bsw@623: end } bsw@623: slot.put("
") bsw@571: end bsw@558: end bsw@558: bsw@558: