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@598
|
55 :add_field("area.name", nil, { "grouped" })
|
bsw@598
|
56 :add_field("member_weight", nil, { "grouped" })
|
bsw@598
|
57 :add_field("direct_member_count", nil, { "grouped" })
|
bsw@598
|
58 :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
|
59 :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
|
60 :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
|
61 :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
|
62 :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
|
63 :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
|
64 :add_where{ "area.unit_id = ?", unit.id }
|
bsw@571
|
65 :add_where{ "area.active" }
|
bsw@598
|
66 :add_order_by("area.name")
|
bsw@598
|
67
|
bsw@598
|
68 if filter_unit == "my_areas" then
|
bsw@598
|
69 areas_selector:join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id })
|
bsw@598
|
70 end
|
bsw@571
|
71
|
bsw@571
|
72 local area_count = areas_selector:count()
|
bsw@571
|
73
|
bsw@619
|
74 local max_area_count = Area:new_selector()
|
bsw@619
|
75 :add_where{ "area.unit_id = ?", unit.id }
|
bsw@619
|
76 :add_where{ "area.active" }
|
bsw@619
|
77 :count()
|
bsw@619
|
78 local more_area_count = max_area_count - area_count
|
bsw@619
|
79 local delegated_count = Area:new_selector()
|
bsw@619
|
80 :add_where{ "area.unit_id = ?", unit.id }
|
bsw@619
|
81 :add_where{ "area.active" }
|
bsw@619
|
82 :left_join("membership", nil, { "membership.area_id = area.id AND membership.member_id = ?", member.id } )
|
bsw@619
|
83 :add_where{ "membership.member_id ISNULL" }
|
bsw@619
|
84 :join("delegation", nil, { "delegation.area_id = area.id AND delegation.truster_id = ?", member.id } )
|
bsw@619
|
85 :add_where{ "delegation.trustee_id NOTNULL" }
|
bsw@619
|
86 :count()
|
bsw@558
|
87
|
bsw@619
|
88 local more_area_text
|
bsw@619
|
89 if area_count == 0 and more_area_count == 1 then
|
bsw@619
|
90 more_area_text = _("You are not participating in the only area of the unit")
|
bsw@619
|
91 elseif area_count == 0 and more_area_count > 0 then
|
bsw@619
|
92 more_area_text = _("You are not participating in any of the #{count} areas in this unit", { count = more_area_count })
|
bsw@619
|
93 elseif area_count > 0 and more_area_count == 1 then
|
bsw@619
|
94 more_area_text = _("One more area in this unit")
|
bsw@619
|
95 elseif area_count > 0 and more_area_count > 0 then
|
bsw@619
|
96 more_area_text = _("#{count} more areas in this unit", { count = more_area_count })
|
bsw@619
|
97 end
|
bsw@619
|
98 local delegated_text
|
bsw@619
|
99 if delegated_count == 1 then
|
bsw@619
|
100 delegated_text = _("One of them have an area delegation set", { count = delegated_count })
|
bsw@619
|
101 elseif delegated_count > 0 then
|
bsw@619
|
102 delegated_text = _("#{count} of them have an area delegation set", { count = delegated_count })
|
bsw@619
|
103 end
|
bsw@619
|
104
|
bsw@622
|
105 ui.container{ attr = { class = "area_list" }, content = function()
|
bsw@619
|
106
|
bsw@622
|
107 execute.view{ module = "unit", view = "_head", params = { unit = unit, show_content = true } }
|
bsw@598
|
108
|
bsw@598
|
109 if area_count > 0 then
|
bsw@598
|
110 local areas = areas_selector:exec()
|
bsw@598
|
111 for i, area in ipairs(areas) do
|
bsw@571
|
112 execute.view{
|
bsw@598
|
113 module = "area", view = "_list_entry", params = {
|
bsw@598
|
114 area = area
|
bsw@571
|
115 }
|
bsw@571
|
116 }
|
bsw@571
|
117 end
|
bsw@623
|
118 end
|
bsw@623
|
119
|
bsw@619
|
120 if area_count == 0 and member:has_voting_right_for_unit_id(unit.id) or
|
bsw@619
|
121 more_area_count > 0 then
|
bsw@619
|
122
|
bsw@571
|
123 end
|
bsw@558
|
124 end }
|
bsw@623
|
125 ui.container{ attr = { class = "area", style="margin-top: 1ex; margin-left: 10px;" }, content = function()
|
bsw@623
|
126 ui.container{ attr = { class = "title" }, content = function()
|
bsw@623
|
127 if more_area_text then
|
bsw@623
|
128 ui.link{ module = "unit", view = "show", id = unit.id, text = more_area_text }
|
bsw@623
|
129 end
|
bsw@623
|
130 if delegated_text then
|
bsw@623
|
131 slot.put(" · ")
|
bsw@623
|
132 ui.tag{ content = delegated_text }
|
bsw@623
|
133 end
|
bsw@623
|
134 end }
|
bsw@623
|
135 end }
|
bsw@623
|
136 slot.put("<br />")
|
bsw@571
|
137 end
|
bsw@558
|
138 end
|
bsw@558
|
139
|
bsw@558
|
140
|