| 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 util.help("unit.show", _"Unit") | 
| bsw@301 | 20 | 
| bsw@301 | 21 local areas_selector = Area:build_selector{ active = true, unit_id = unit_id } | 
| bsw@301 | 22 areas_selector:add_order_by("member_weight DESC") | 
| bsw@301 | 23 | 
| bsw@301 | 24 local members_selector = Member:build_selector{ | 
| bsw@301 | 25   active = true, | 
| bsw@301 | 26   voting_right_for_unit_id = unit.id | 
| bsw@301 | 27 } | 
| bsw@301 | 28 | 
| bsw@301 | 29 local delegations_selector = Delegation:new_selector() | 
| bsw@301 | 30   :join("member", "truster", "truster.id = delegation.truster_id AND truster.active") | 
| bsw@302 | 31   :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 | 32   :join("member", "trustee", "trustee.id = delegation.trustee_id AND truster.active") | 
| bsw@302 | 33   :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 | 34   :add_where{ "delegation.unit_id = ?", unit.id } | 
| bsw@301 | 35 | 
| bsw@414 | 36 local open_issues_selector = Issue:new_selector() | 
| bsw@301 | 37   :join("area", nil, "area.id = issue.area_id") | 
| bsw@301 | 38   :add_where{ "area.unit_id = ?", unit.id } | 
| bsw@414 | 39   :add_where("issue.closed ISNULL") | 
| bsw@414 | 40   :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 | 41 | 
| bsw@414 | 42 local closed_issues_selector = Issue:new_selector() | 
| bsw@414 | 43   :join("area", nil, "area.id = issue.area_id") | 
| bsw@414 | 44   :add_where{ "area.unit_id = ?", unit.id } | 
| bsw@414 | 45   :add_where("issue.closed NOTNULL") | 
| bsw@414 | 46   :add_order_by("issue.closed DESC") | 
| bsw@301 | 47 | 
| bsw@301 | 48 local tabs = { | 
| bsw@301 | 49   module = "unit", | 
| bsw@301 | 50   view = "show", | 
| bsw@301 | 51   id = unit.id | 
| bsw@301 | 52 } | 
| bsw@301 | 53 | 
| bsw@301 | 54 tabs[#tabs+1] = { | 
| bsw@301 | 55   name = "areas", | 
| bsw@301 | 56   label = _"Areas", | 
| bsw@301 | 57   module = "area", | 
| bsw@301 | 58   view = "_list", | 
| bsw@301 | 59   params = { areas_selector = areas_selector } | 
| bsw@301 | 60 } | 
| bsw@301 | 61 | 
| bsw@301 | 62 tabs[#tabs+1] = { | 
| bsw@414 | 63   name = "timeline", | 
| bsw@528 | 64   label = _"Latest events", | 
| bsw@414 | 65   module = "event", | 
| bsw@414 | 66   view = "_list", | 
| bsw@414 | 67   params = { for_unit = unit } | 
| bsw@414 | 68 } | 
| bsw@414 | 69 | 
| bsw@414 | 70 tabs[#tabs+1] = { | 
| bsw@414 | 71   name = "open", | 
| bsw@414 | 72   label = _"Open issues", | 
| bsw@301 | 73   module = "issue", | 
| bsw@301 | 74   view = "_list", | 
| bsw@414 | 75   params = { | 
| bsw@414 | 76     for_state = "open", | 
| bsw@414 | 77     issues_selector = open_issues_selector, for_unit = true | 
| bsw@414 | 78   } | 
| bsw@414 | 79 } | 
| bsw@414 | 80 tabs[#tabs+1] = { | 
| bsw@414 | 81   name = "closed", | 
| bsw@414 | 82   label = _"Closed issues", | 
| bsw@414 | 83   module = "issue", | 
| bsw@414 | 84   view = "_list", | 
| bsw@414 | 85   params = { | 
| bsw@414 | 86     for_state = "closed", | 
| bsw@414 | 87     issues_selector = closed_issues_selector, for_unit = true | 
| bsw@414 | 88   } | 
| bsw@301 | 89 } | 
| bsw@301 | 90 | 
| bsw@301 | 91 if app.session.member_id then | 
| bsw@301 | 92   tabs[#tabs+1] = { | 
| bsw@525 | 93     name = "eligible_voters", | 
| bsw@525 | 94     label = _"Eligible voters", | 
| bsw@301 | 95     module = "member", | 
| bsw@301 | 96     view = "_list", | 
| bsw@301 | 97     params = { members_selector = members_selector } | 
| bsw@301 | 98   } | 
| bsw@301 | 99 | 
| bsw@301 | 100   tabs[#tabs+1] = { | 
| bsw@301 | 101     name = "delegations", | 
| bsw@301 | 102     label = _"Delegations", | 
| bsw@301 | 103     module = "delegation", | 
| bsw@301 | 104     view = "_list", | 
| bsw@301 | 105     params = { delegations_selector = delegations_selector } | 
| bsw@301 | 106   } | 
| bsw@301 | 107 end | 
| bsw@301 | 108 | 
| bsw@301 | 109 ui.tabs(tabs) |