bsw@558: local member = param.get("member", "table") bsw@558: local for_member = param.get("for_member", atom.boolean) bsw@598: local filter_unit = param.get_all_cgi()["filter_unit"] or "my_areas" bsw@558: bsw@594: if not for_member then bsw@594: execute.view{ bsw@594: module = "index", view = "_notifications" bsw@558: } bsw@594: 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: slot.put("
") 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@598: local units = Unit:new_selector():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@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@598: :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: :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@598: end bsw@571: bsw@571: local area_count = areas_selector:count() bsw@571: bsw@598: ui.container{ attr = { class = "area_list" }, content = function() bsw@571: ui.container{ attr = { class = "unit_head" }, content = function() bsw@571: ui.link{ bsw@571: text = unit.name, bsw@571: module = "unit", view = "show", id = unit.id bsw@571: } bsw@558: bsw@598: execute.view{ module = "delegation", view = "_info", params = { unit = unit } } bsw@598: end } bsw@598: bsw@598: if area_count > 0 then bsw@598: local areas = areas_selector:exec() bsw@598: for i, area in ipairs(areas) do bsw@571: execute.view{ bsw@598: module = "area", view = "_list_entry", params = { bsw@598: area = area bsw@571: } bsw@571: } bsw@571: end bsw@571: elseif member:has_voting_right_for_unit_id(unit.id) then bsw@598: ui.container{ attr = { class = "area" }, content = function() bsw@598: ui.container{ attr = { class = "content" }, content = function() bsw@598: slot.put("
") bsw@598: if for_member then bsw@598: ui.tag{ content = _"This member has voting privileges for this unit, but you ist not member of any of its areas." } bsw@598: else bsw@598: ui.tag{ content = _"You have voting privileges for this unit, but you are not member of any of its areas." } bsw@598: end bsw@598: end } bsw@598: end } bsw@571: end bsw@571: local max_area_count = Area:new_selector() bsw@571: :add_where{ "area.unit_id = ?", unit.id } bsw@571: :add_where{ "area.active" } bsw@571: :count() bsw@571: local more_area_count = max_area_count - area_count bsw@571: local delegated_count = Area:new_selector() bsw@571: :add_where{ "area.unit_id = ?", unit.id } bsw@571: :add_where{ "area.active" } bsw@571: :left_join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id } ) bsw@571: :add_where{ "membership.member_id ISNULL" } bsw@571: :join("delegation", nil, { "delegation.area_id = area.id AND delegation.truster_id = ?", member.id } ) bsw@598: :add_where{ "delegation.trustee_id NOTNULL" } bsw@571: :count() bsw@571: if more_area_count > 0 then bsw@598: ui.container{ attr = { class = "area" }, content = function() bsw@598: ui.container{ attr = { class = "content" }, content = function() bsw@598: slot.put("
") bsw@601: local text bsw@601: if more_area_count == 1 then bsw@601: text = _("One more area in this unit") bsw@601: else bsw@601: text = _("#{count} more areas in this unit", { count = more_area_count }) bsw@601: end bsw@601: ui.link{ module = "unit", view = "show", id = unit.id, text = text } bsw@601: if delegated_count > 0 then bsw@601: slot.put(" · ") bsw@601: local text bsw@601: if delegated_count == 1 then bsw@601: text = _("One of them have an area delegation set", { count = delegated_count }) bsw@601: else bsw@601: text = _("#{count} of them have an area delegation set", { count = delegated_count }) bsw@601: end bsw@601: ui.tag{ content = text } bsw@601: end bsw@598: end } bsw@571: end } bsw@558: end bsw@598: slot.put("
") bsw@598: slot.put("
") bsw@558: end } bsw@571: end bsw@558: end bsw@558: bsw@558: