# HG changeset patch # User bsw # Date 1643886971 -3600 # Node ID caa6c71dd22a5d7223058f87fae2d49e19ab2fbb # Parent a5e1de39e19af7bbbe48a135adf295bea0176956 Show units as tree in member administration diff -r a5e1de39e19a -r caa6c71dd22a app/main/admin/member_edit.lua --- a/app/main/admin/member_edit.lua Thu Feb 03 12:05:42 2022 +0100 +++ b/app/main/admin/member_edit.lua Thu Feb 03 12:16:11 2022 +0100 @@ -12,8 +12,8 @@ end end -local function field_boolean(id, name, checked, label) - ui.container{ content = function() +local function field_boolean(id, name, checked, label, depth) + ui.container{ attr = { style = "margin-left: " .. (depth -1) * 20 .. "px;" }, content = function() ui.tag{ tag = "label", attr = { class = "mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect", ["for"] = id @@ -45,18 +45,7 @@ ui.titleAdmin(_"Member") -local units_selector = Unit:new_selector() - :add_where("active") - - -if member then - units_selector - :left_join("privilege", nil, { "privilege.member_id = ? AND privilege.unit_id = unit.id", member.id }) - :add_field("privilege.voting_right", "voting_right") - :add_order_by("unit.name") -end - -local units = units_selector:exec() +local units = Unit:get_flattened_tree{ include_inactive = inactive, include_hidden = true, member_id = member.id } ui.grid{ content = function() @@ -106,7 +95,7 @@ end for i, unit in ipairs(units) do - field_boolean("checkbox_unit_" .. unit.id, "unit_" .. unit.id, unit.voting_right, unit.name) + field_boolean("checkbox_unit_" .. unit.id, "unit_" .. unit.id, unit.voting_right, unit.name, unit.depth) end slot.put("
") diff -r a5e1de39e19a -r caa6c71dd22a model/unit.lua --- a/model/unit.lua Thu Feb 03 12:05:42 2022 +0100 +++ b/model/unit.lua Thu Feb 03 12:16:11 2022 +0100 @@ -104,6 +104,11 @@ if not args or not args.include_hidden then units_selector:add_where("attr->'hidden' ISNULL OR NOT (attr->'hidden' = 'true')") end + if args.member_id then + units_selector + :left_join("privilege", nil, { "privilege.member_id = ? AND privilege.unit_id = unit.id", args.member_id }) + :add_field("privilege.voting_right", "voting_right") + end local units = units_selector:exec() local unit_tree = {} for i, unit in ipairs(units) do