# HG changeset patch # User bsw # Date 1325211190 -3600 # Node ID e3613831cd1e8b530f922e3bed560d1fe7101e02 # Parent 8e284d4319be044ae8749cedb02991694ed73f20 Migrate global delegation to unit level diff -r 8e284d4319be -r e3613831cd1e app/main/area/list.lua --- a/app/main/area/list.lua Fri Dec 30 03:11:57 2011 +0100 +++ b/app/main/area/list.lua Fri Dec 30 03:13:10 2011 +0100 @@ -24,6 +24,12 @@ util.help("area.list", _"Area list") +execute.view{ + module = "delegation", + view = "_show_box", + params = { unit_id = unit_id } +} + execute.view{ module = "area", diff -r 8e284d4319be -r e3613831cd1e app/main/delegation/_action/update.lua --- a/app/main/delegation/_action/update.lua Fri Dec 30 03:11:57 2011 +0100 +++ b/app/main/delegation/_action/update.lua Fri Dec 30 03:13:10 2011 +0100 @@ -2,6 +2,8 @@ local trustee_id = param.get("trustee_id", atom.integer) +local unit_id = param.get("unit_id", atom.integer) + local area_id = param.get("area_id", atom.integer) local issue_id = param.get("issue_id", atom.integer) @@ -10,7 +12,7 @@ area_id = nil end -local delegation = Delegation:by_pk(truster_id, area_id, issue_id) +local delegation = Delegation:by_pk(truster_id, unit_id, area_id, issue_id) if param.get("delete") or trustee_id == -1 then @@ -23,7 +25,7 @@ elseif area_id then slot.put_into("notice", _"Your delegation for this area has been deleted.") else - slot.put_into("notice", _"Your global delegation has been deleted.") + slot.put_into("notice", _"Your delegation for this unit has been deleted.") end end @@ -33,14 +35,15 @@ if not delegation then delegation = Delegation:new() delegation.truster_id = truster_id + delegation.unit_id = unit_id delegation.area_id = area_id delegation.issue_id = issue_id if issue_id then delegation.scope = "issue" elseif area_id then delegation.scope = "area" - else - delegation.scope = "global" + elseif unit_id then + delegation.scope = "unit" end end if trustee_id == 0 then @@ -56,7 +59,7 @@ elseif area_id then slot.put_into("notice", _"Your delegation for this area has been updated.") else - slot.put_into("notice", _"Your global delegation has been updated.") + slot.put_into("notice", _"Your delegation for this unit has been updated.") end end diff -r 8e284d4319be -r e3613831cd1e app/main/delegation/_list.lua --- a/app/main/delegation/_list.lua Fri Dec 30 03:11:57 2011 +0100 +++ b/app/main/delegation/_list.lua Fri Dec 30 03:13:10 2011 +0100 @@ -13,7 +13,7 @@ area = delegation.area end if not area then - ui.field.text{ value = _"Global delegation" } + ui.field.text{ value = _"Unit delegation" } end if area then ui.link{ diff -r 8e284d4319be -r e3613831cd1e app/main/delegation/_show_box.lua --- a/app/main/delegation/_show_box.lua Fri Dec 30 03:11:57 2011 +0100 +++ b/app/main/delegation/_show_box.lua Fri Dec 30 03:13:10 2011 +0100 @@ -1,12 +1,12 @@ -function change_delegation(scope, area_id, issue, delegation, initiative_id) +function change_delegation(scope, unit_id, area_id, issue, delegation, initiative_id) local image local text - if scope == "global" and delegation then + if scope == "unit" and delegation and delegation.unit_id then image = { static = "icons/16/table_go.png" } - text = _"Change global delegation" - elseif scope == "global" and not delegation then + text = _"Change unit delegation" + elseif scope == "unit" and not (delegation and delegation.unit_id) then image = { static = "icons/16/table_go.png" } - text = _"Set global delegation" + text = _"Set unit delegation" elseif scope == "area" and delegation and delegation.area_id then image = { static = "icons/16/table_go.png" } text = _"Change area delegation" @@ -35,7 +35,8 @@ params = { issue_id = issue and issue.id or nil, initiative_id = initiative_id or nil, - area_id = area_id + area_id = area_id, + unit_id = unit_id }, } if delegation then @@ -44,7 +45,7 @@ text = _"Revoke", module = "delegation", action = "update", - params = { issue_id = delegation.issue_id, area_id = delegation.area_id, delete = true }, + params = { issue_id = delegation.issue_id, area_id = delegation.area_id, unit_id = delegation.unit_id, delete = true }, routing = { default = { mode = "redirect", @@ -61,11 +62,14 @@ end local delegation +local unit_id local area_id local issue_id local initiative_id -local scope = "global" +local scope = "unit" + +unit_id = param.get("unit_id", atom.integer) if param.get("initiative_id", atom.integer) then initiative_id = param.get("initiative_id", atom.integer) @@ -90,16 +94,16 @@ if issue_id then issue = Issue:by_id(issue_id) - delegation = Delegation:by_pk(app.session.member.id, nil, issue_id) + delegation = Delegation:by_pk(app.session.member.id, nil, nil, issue_id) if not delegation then - delegation = Delegation:by_pk(app.session.member.id, issue.area_id) + delegation = Delegation:by_pk(app.session.member.id, nil, issue.area_id) end elseif area_id then - delegation = Delegation:by_pk(app.session.member.id, area_id) + delegation = Delegation:by_pk(app.session.member.id, nil, area_id) end if not delegation then - delegation = Delegation:by_pk(app.session.member.id) + delegation = Delegation:by_pk(app.session.member.id, unit_id) end @@ -126,7 +130,7 @@ elseif delegation.area_id then slot.put(_"Area delegation active") else - slot.put(_"Global delegation active") + slot.put(_"Unit delegation active") end else ui.image{ @@ -164,7 +168,7 @@ :exec() if not issue or (issue.state ~= "finished" and issue.state ~= "cancelled") then - change_delegation(scope, area_id, issue, delegation, initiative_id) + change_delegation(scope, unit_id, area_id, issue, delegation, initiative_id) end for i, record in ipairs(delegation_chain) do @@ -188,8 +192,8 @@ ui.container{ attr = { class = "delegation_scope" .. (overridden and " delegation_scope_overridden" or "") }, content = function() - if record.scope_in == "global" then - slot.put(_"Global delegation") + if record.scope_in == "unit" then + slot.put(_"Unit delegation") elseif record.scope_in == "area" then slot.put(_"Area delegation") elseif record.scope_in == "issue" then @@ -225,6 +229,6 @@ end } else - change_delegation(scope, area_id, issue, nil, initiative_id) + change_delegation(scope, unit_id, area_id, issue, nil, initiative_id) end end) diff -r 8e284d4319be -r e3613831cd1e app/main/delegation/new.lua --- a/app/main/delegation/new.lua Fri Dec 30 03:11:57 2011 +0100 +++ b/app/main/delegation/new.lua Fri Dec 30 03:13:10 2011 +0100 @@ -1,3 +1,9 @@ +local unit = Unit:by_id(param.get("unit_id", atom.integer)) +if unit then + slot.put_into("title", encode.html(_"Set unit delegation")) + util.help("delegation.new.unit") +end + local area = Area:by_id(param.get("area_id", atom.integer)) if area then slot.put_into("title", encode.html(_"Set delegation for Area '#{name}'":gsub("#{name}", area.name))) @@ -12,11 +18,6 @@ local initiative = Initiative:by_id(param.get("initiative_id", atom.integer)) -if not area and not issue then - slot.put_into("title", encode.html(_"Set global delegation")) - util.help("delegation.new.global") -end - slot.select("actions", function() if issue then ui.link{ @@ -61,6 +62,7 @@ module = "delegation", action = "update", params = { + unit_id = unit and unit.id or nil, area_id = area and area.id or nil, issue_id = issue and issue.id or nil, }, @@ -78,44 +80,44 @@ if issue then local delegate_name = "" local scope = "no delegation set" - local area_delegation = Delegation:by_pk(app.session.member_id, issue.area_id) + local area_delegation = Delegation:by_pk(app.session.member_id, nil, issue.area_id) if area_delegation then delegate_name = area_delegation.trustee and area_delegation.trustee.name or _"abandoned" scope = _"area" else - local global_delegation = Delegation:by_pk(app.session.member_id) - if global_delegation then - delegate_name = global_delegation.trustee.name - scope = _"global" + local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id) + if unit_delegation then + delegate_name = unit_delegation.trustee.name + scope = _"unit" + end end - end records = { { id = -1, - name = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) + name = _("Apply unit or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) }, { id = 0, - name = _"Abandon global and area delegations for this issue" + name = _"Abandon unit and area delegations for this issue" }, } elseif area then local delegate_name = "" local scope = "no delegation set" - local global_delegation = Delegation:by_pk(app.session.member_id) - if global_delegation then - delegate_name = global_delegation.trustee.name - scope = _"global" + local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id) + if unit_delegation then + delegate_name = unit_delegation.trustee.name + scope = _"unit" end records = { { id = -1, - name = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) + name = _("Apply unit delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope }) }, { id = 0, - name = _"Abandon global delegation for this area" + name = _"Abandon unit delegation for this area" } } diff -r 8e284d4319be -r e3613831cd1e app/main/index/index.lua --- a/app/main/index/index.lua Fri Dec 30 03:11:57 2011 +0100 +++ b/app/main/index/index.lua Fri Dec 30 03:13:10 2011 +0100 @@ -68,10 +68,6 @@ module = "member", view = "edit_images" } - execute.view{ - module = "delegation", - view = "_show_box" - } ui.link{ content = function() ui.image{ static = "icons/16/wrench.png" } diff -r 8e284d4319be -r e3613831cd1e model/delegation.lua --- a/model/delegation.lua Fri Dec 30 03:11:57 2011 +0100 +++ b/model/delegation.lua Fri Dec 30 03:13:10 2011 +0100 @@ -33,9 +33,14 @@ ref = 'issue', } -function Delegation:by_pk(truster_id, area_id, issue_id) +function Delegation:by_pk(truster_id, unit_id, area_id, issue_id) local selector = self:new_selector():optional_object_mode() selector:add_where{ "truster_id = ?", truster_id } + if unit_id then + selector:add_where{ "unit_id = ?", unit_id } + else + selector:add_where("unit_id ISNULL") + end if area_id then selector:add_where{ "area_id = ?", area_id } else @@ -47,4 +52,4 @@ selector:add_where("issue_id ISNULL ") end return selector:exec() -end \ No newline at end of file +end