| rev | line source | 
| bsw@301 | 1 local unit_id = config.single_unit_id or param.get_id() | 
| bsw@301 | 2 | 
| bsw@301 | 3 local unit = Unit:by_id(unit_id) | 
| bsw@301 | 4 | 
| bsw@526 | 5 slot.select("head", function() | 
| bsw@529 | 6   execute.view{ module = "unit", view = "_head", params = { unit = unit, show_content = true } } | 
| bsw@526 | 7 end) | 
| bsw@301 | 8 | 
| bsw@301 | 9 if config.single_unit_id and not app.session.member_id and config.motd_public then | 
| bsw@301 | 10   local help_text = config.motd_public | 
| bsw@301 | 11   ui.container{ | 
| bsw@301 | 12     attr = { class = "wiki motd" }, | 
| bsw@301 | 13     content = function() | 
| bsw@301 | 14       slot.put(format.wiki_text(help_text)) | 
| bsw@301 | 15     end | 
| bsw@301 | 16   } | 
| bsw@301 | 17 end | 
| bsw@301 | 18 | 
| bsw@301 | 19 local areas_selector = Area:build_selector{ active = true, unit_id = unit_id } | 
| bsw@301 | 20 areas_selector:add_order_by("member_weight DESC") | 
| bsw@301 | 21 | 
| bsw@301 | 22 local members_selector = Member:build_selector{ | 
| bsw@301 | 23   active = true, | 
| bsw@301 | 24   voting_right_for_unit_id = unit.id | 
| bsw@301 | 25 } | 
| bsw@301 | 26 | 
| bsw@301 | 27 local delegations_selector = Delegation:new_selector() | 
| bsw@301 | 28   :join("member", "truster", "truster.id = delegation.truster_id AND truster.active") | 
| bsw@302 | 29   :join("privilege", "truster_privilege", "truster_privilege.member_id = truster.id AND truster_privilege.unit_id = delegation.unit_id AND truster_privilege.voting_right") | 
| bsw@301 | 30   :join("member", "trustee", "trustee.id = delegation.trustee_id AND truster.active") | 
| bsw@302 | 31   :join("privilege", "trustee_privilege", "trustee_privilege.member_id = trustee.id AND trustee_privilege.unit_id = delegation.unit_id AND trustee_privilege.voting_right") | 
| bsw@301 | 32   :add_where{ "delegation.unit_id = ?", unit.id } | 
| bsw@301 | 33 | 
| bsw@414 | 34 local open_issues_selector = Issue:new_selector() | 
| bsw@301 | 35   :join("area", nil, "area.id = issue.area_id") | 
| bsw@301 | 36   :add_where{ "area.unit_id = ?", unit.id } | 
| bsw@414 | 37   :add_where("issue.closed ISNULL") | 
| bsw@414 | 38   :add_order_by("coalesce(issue.fully_frozen + issue.voting_time, issue.half_frozen + issue.verification_time, issue.accepted + issue.discussion_time, issue.created + issue.admission_time) - now()") | 
| bsw@414 | 39 | 
| bsw@414 | 40 local closed_issues_selector = Issue:new_selector() | 
| bsw@414 | 41   :join("area", nil, "area.id = issue.area_id") | 
| bsw@414 | 42   :add_where{ "area.unit_id = ?", unit.id } | 
| bsw@414 | 43   :add_where("issue.closed NOTNULL") | 
| bsw@414 | 44   :add_order_by("issue.closed DESC") | 
| bsw@301 | 45 | 
| bsw@301 | 46 local tabs = { | 
| bsw@301 | 47   module = "unit", | 
| bsw@301 | 48   view = "show", | 
| bsw@301 | 49   id = unit.id | 
| bsw@301 | 50 } | 
| bsw@301 | 51 | 
| bsw@301 | 52 tabs[#tabs+1] = { | 
| bsw@301 | 53   name = "areas", | 
| bsw@301 | 54   label = _"Areas", | 
| bsw@301 | 55   module = "area", | 
| bsw@301 | 56   view = "_list", | 
| bsw@301 | 57   params = { areas_selector = areas_selector } | 
| bsw@301 | 58 } | 
| bsw@301 | 59 | 
| bsw@301 | 60 tabs[#tabs+1] = { | 
| bsw@414 | 61   name = "timeline", | 
| bsw@528 | 62   label = _"Latest events", | 
| bsw@414 | 63   module = "event", | 
| bsw@414 | 64   view = "_list", | 
| bsw@414 | 65   params = { for_unit = unit } | 
| bsw@414 | 66 } | 
| bsw@414 | 67 | 
| bsw@414 | 68 tabs[#tabs+1] = { | 
| bsw@414 | 69   name = "open", | 
| bsw@414 | 70   label = _"Open issues", | 
| bsw@301 | 71   module = "issue", | 
| bsw@301 | 72   view = "_list", | 
| bsw@414 | 73   params = { | 
| bsw@414 | 74     for_state = "open", | 
| bsw@414 | 75     issues_selector = open_issues_selector, for_unit = true | 
| bsw@414 | 76   } | 
| bsw@414 | 77 } | 
| bsw@414 | 78 tabs[#tabs+1] = { | 
| bsw@414 | 79   name = "closed", | 
| bsw@414 | 80   label = _"Closed issues", | 
| bsw@414 | 81   module = "issue", | 
| bsw@414 | 82   view = "_list", | 
| bsw@414 | 83   params = { | 
| bsw@414 | 84     for_state = "closed", | 
| bsw@414 | 85     issues_selector = closed_issues_selector, for_unit = true | 
| bsw@414 | 86   } | 
| bsw@301 | 87 } | 
| bsw@301 | 88 | 
| bsw@301 | 89 if app.session.member_id then | 
| bsw@301 | 90   tabs[#tabs+1] = { | 
| bsw@525 | 91     name = "eligible_voters", | 
| bsw@525 | 92     label = _"Eligible voters", | 
| bsw@301 | 93     module = "member", | 
| bsw@301 | 94     view = "_list", | 
| bsw@301 | 95     params = { members_selector = members_selector } | 
| bsw@301 | 96   } | 
| bsw@301 | 97 | 
| bsw@301 | 98   tabs[#tabs+1] = { | 
| bsw@301 | 99     name = "delegations", | 
| bsw@301 | 100     label = _"Delegations", | 
| bsw@301 | 101     module = "delegation", | 
| bsw@301 | 102     view = "_list", | 
| bsw@301 | 103     params = { delegations_selector = delegations_selector } | 
| bsw@301 | 104   } | 
| bsw@301 | 105 end | 
| bsw@301 | 106 | 
| bsw@301 | 107 ui.tabs(tabs) |