liquid_feedback_frontend

changeset 193:46351752814f

Admin module refactored
author bsw
date Mon Nov 08 15:04:44 2010 +0100 (2010-11-08)
parents 032346d7e21b
children c0292c3a70d8
files app/main/admin/_action/area_update.lua app/main/admin/_action/member_update.lua app/main/admin/_filter/90_admin.lua app/main/admin/area_list.lua app/main/admin/area_show.lua app/main/admin/member_edit.lua app/main/admin/member_list.lua model/area.lua model/member.lua model/policy.lua
line diff
     1.1 --- a/app/main/admin/_action/area_update.lua	Mon Nov 08 02:39:30 2010 +0100
     1.2 +++ b/app/main/admin/_action/area_update.lua	Mon Nov 08 15:04:44 2010 +0100
     1.3 @@ -1,16 +1,4 @@
     1.4 -if not app.session.member.admin then
     1.5 -  error()
     1.6 -end
     1.7 -
     1.8 -local id = param.get_id()
     1.9 -
    1.10 -local area
    1.11 -if id then
    1.12 -  area = Area:new_selector():add_where{ "id = ?", id }:single_object_mode():exec()
    1.13 -else
    1.14 -  area = Area:new()
    1.15 -end
    1.16 -
    1.17 +local area = Area:by_id(param.get_id()) or Area:new()
    1.18  
    1.19  param.update(area, "name", "description", "active")
    1.20  
     2.1 --- a/app/main/admin/_action/member_update.lua	Mon Nov 08 02:39:30 2010 +0100
     2.2 +++ b/app/main/admin/_action/member_update.lua	Mon Nov 08 15:04:44 2010 +0100
     2.3 @@ -1,16 +1,4 @@
     2.4 -if not app.session.member.admin then
     2.5 -  error('access denied')
     2.6 -end
     2.7 -
     2.8 -local id = param.get_id()
     2.9 -
    2.10 -local member
    2.11 -
    2.12 -if id then
    2.13 -  member = Member:new_selector():add_where{"id = ?", id}:single_object_mode():exec()
    2.14 -else
    2.15 -  member = Member:new()
    2.16 -end
    2.17 +local member = Member:by_id(param.get_id()) or Member:new()
    2.18  
    2.19  param.update(member, "login", "admin", "name", "active")
    2.20  
     3.1 --- a/app/main/admin/_filter/90_admin.lua	Mon Nov 08 02:39:30 2010 +0100
     3.2 +++ b/app/main/admin/_filter/90_admin.lua	Mon Nov 08 15:04:44 2010 +0100
     3.3 @@ -1,4 +1,4 @@
     3.4 -if request.get_module() == "admin" and not app.session.member.admin then
     3.5 +if not app.session.member.admin then
     3.6    error('access denied')
     3.7  end
     3.8  
     4.1 --- a/app/main/admin/area_list.lua	Mon Nov 08 02:39:30 2010 +0100
     4.2 +++ b/app/main/admin/area_list.lua	Mon Nov 08 15:04:44 2010 +0100
     4.3 @@ -1,52 +1,47 @@
     4.4 -local show_not_in_use = param.get("show_not_in_use", atom.boolean)
     4.5 +local show_not_in_use = param.get("show_not_in_use", atom.boolean) or false
     4.6  
     4.7 -local selector = Area:new_selector()
     4.8 -if show_not_in_use then
     4.9 -  selector:add_where("NOT active")
    4.10 -else
    4.11 -  selector:add_where("active")
    4.12 -end
    4.13 +local areas = Area:build_selector{ active = not show_not_in_use }:exec()
    4.14  
    4.15 -local areas = selector:exec()
    4.16  
    4.17  slot.put_into("title", _"Area list")
    4.18  
    4.19 -if app.session.member.admin then
    4.20 -  slot.select("actions", function()
    4.21 -    if show_not_in_use then
    4.22 -      ui.link{
    4.23 -        attr = { class = { "admin_only" } },
    4.24 -        text = _"Show areas in use",
    4.25 -        module = "admin",
    4.26 -        view = "area_list"
    4.27 -      }
    4.28 -    else
    4.29 -      ui.link{
    4.30 -        attr = { class = { "admin_only" } },
    4.31 -        text = _"Create new area",
    4.32 -        module = "admin",
    4.33 -        view = "area_show"
    4.34 -      }
    4.35 -      ui.link{
    4.36 -        attr = { class = { "admin_only" } },
    4.37 -        text = _"Show areas not in use",
    4.38 -        module = "admin",
    4.39 -        view = "area_list",
    4.40 -        params = { show_not_in_use = true }
    4.41 -      }
    4.42 -    end
    4.43 -  end)
    4.44 -end
    4.45 +
    4.46 +slot.select("actions", function()
    4.47 +
    4.48 +  if show_not_in_use then
    4.49 +    ui.link{
    4.50 +      attr = { class = { "admin_only" } },
    4.51 +      text = _"Show areas in use",
    4.52 +      module = "admin",
    4.53 +      view = "area_list"
    4.54 +    }
    4.55 +
    4.56 +  else
    4.57 +    ui.link{
    4.58 +      attr = { class = { "admin_only" } },
    4.59 +      text = _"Create new area",
    4.60 +      module = "admin",
    4.61 +      view = "area_show"
    4.62 +    }
    4.63 +    ui.link{
    4.64 +      attr = { class = { "admin_only" } },
    4.65 +      text = _"Show areas not in use",
    4.66 +      module = "admin",
    4.67 +      view = "area_list",
    4.68 +      params = { show_not_in_use = true }
    4.69 +    }
    4.70 +  end
    4.71 +
    4.72 +end)
    4.73 +
    4.74  
    4.75  ui.list{
    4.76    records = areas,
    4.77    columns = {
    4.78 -    {
    4.79 -      label = _"Area",
    4.80 -      name = "name"
    4.81 -    },
    4.82 -    {
    4.83 -      content = function(record)
    4.84 +
    4.85 +    { label = _"Area", name = "name" },
    4.86 +
    4.87 +    { content = function(record)
    4.88          if app.session.member.admin then
    4.89            ui.link{
    4.90              attr = { class = { "action admin_only" } },
    4.91 @@ -58,5 +53,6 @@
    4.92          end
    4.93        end
    4.94      }
    4.95 +
    4.96    }
    4.97  }
    4.98 \ No newline at end of file
     5.1 --- a/app/main/admin/area_show.lua	Mon Nov 08 02:39:30 2010 +0100
     5.2 +++ b/app/main/admin/area_show.lua	Mon Nov 08 15:04:44 2010 +0100
     5.3 @@ -1,11 +1,17 @@
     5.4  local id = param.get_id()
     5.5  
     5.6 -local area
     5.7 -if id then
     5.8 -  area = Area:new_selector():add_where{ "id = ?", id }:single_object_mode():exec()
     5.9 -end
    5.10 +local area = Area:by_id(id) or Area:new()
    5.11 +
    5.12 +slot.put_into("title", _"Create / edit area")
    5.13  
    5.14 -slot.put_into("title", _"Create new area")
    5.15 +slot.select("actions", function()
    5.16 +  ui.link{
    5.17 +    attr = { class = { "admin_only" } },
    5.18 +    text = _"Cancel",
    5.19 +    module = "admin",
    5.20 +    view = "area_list"
    5.21 +  }
    5.22 +end)
    5.23  
    5.24  ui.form{
    5.25    attr = { class = "vertical" },
    5.26 @@ -19,9 +25,9 @@
    5.27        view = "area_list"
    5.28      }
    5.29    },
    5.30 -  id = area and area.id or nil,
    5.31 +  id = id,
    5.32    content = function()
    5.33 -    policies = Policy:new_selector():add_where{ "active='t'"}:exec()
    5.34 +    policies = Policy:build_selector{ active = true }:exec()
    5.35      local def_policy = {
    5.36        {
    5.37          id = "-1",
    5.38 @@ -35,7 +41,7 @@
    5.39      ui.field.text{    label = _"Name",        name = "name" }
    5.40      ui.field.boolean{ label = _"Active?",     name = "active" }
    5.41      ui.field.text{    label = _"Description", name = "description", multiline = true }
    5.42 -    ui.field.select{   label = _"Default Policy",   name = "default_policy",
    5.43 +    ui.field.select{  label = _"Default Policy",   name = "default_policy",
    5.44                   value=area.default_policy and area.default_policy.id or "-1",
    5.45                   foreign_records = def_policy,
    5.46                   foreign_id      = "id",
    5.47 @@ -45,8 +51,9 @@
    5.48                        foreign_records = policies,
    5.49                        foreign_id      = "id",
    5.50                        foreign_name    = "name",
    5.51 -                      connecting_records = area.allowed_policies,
    5.52 -                      foreign_reference  = "id" }
    5.53 +                      connecting_records = area.allowed_policies or {},
    5.54 +                      foreign_reference  = "id",
    5.55 +    }
    5.56      ui.submit{ text = _"Save" }
    5.57    end
    5.58  }
     6.1 --- a/app/main/admin/member_edit.lua	Mon Nov 08 02:39:30 2010 +0100
     6.2 +++ b/app/main/admin/member_edit.lua	Mon Nov 08 15:04:44 2010 +0100
     6.3 @@ -1,8 +1,8 @@
     6.4  local id = param.get_id()
     6.5  
     6.6 -local member
     6.7 -if id then
     6.8 -  member = Member:new_selector():add_where{"id = ?", id}:optional_object_mode():exec()
     6.9 +local member = Member:by_id(id)
    6.10 +
    6.11 +if member then
    6.12    slot.put_into("title", encode.html(_("Member: '#{login}' (#{name})", { login = member.login, name = member.name })))
    6.13  else
    6.14    slot.put_into("title", encode.html(_"Register new member"))
     7.1 --- a/app/main/admin/member_list.lua	Mon Nov 08 02:39:30 2010 +0100
     7.2 +++ b/app/main/admin/member_list.lua	Mon Nov 08 15:04:44 2010 +0100
     7.3 @@ -1,5 +1,14 @@
     7.4 +local show_locked = param.get("show_locked", atom.boolean)
     7.5 +
     7.6 +local members_selector = Member:build_selector{ 
     7.7 +  active = not show_locked,
     7.8 +  order = "login"
     7.9 +}
    7.10 +
    7.11 +
    7.12  slot.put_into("title", _"Member list")
    7.13  
    7.14 +
    7.15  slot.select("actions", function()
    7.16    ui.link{
    7.17      attr = { class = { "admin_only" } },
    7.18 @@ -7,7 +16,7 @@
    7.19      module = "admin",
    7.20      view = "member_edit"
    7.21    }
    7.22 -  if param.get("show_locked") then
    7.23 +  if show_locked then
    7.24      ui.link{
    7.25        attr = { class = { "admin_only" } },
    7.26        text = _"Show active members",
    7.27 @@ -25,20 +34,10 @@
    7.28    end
    7.29  end)
    7.30  
    7.31 -local members_selector
    7.32 -
    7.33 -if param.get("show_locked", atom.boolean) then
    7.34 -  members_selector = Member:new_selector()
    7.35 -    :add_where("not active")
    7.36 -    :add_order_by("login")
    7.37 -else
    7.38 -  members_selector = Member:new_selector()
    7.39 -    :add_where("active")
    7.40 -    :add_order_by("login")
    7.41 -end
    7.42  
    7.43  ui.paginate{
    7.44    selector = members_selector,
    7.45 +  per_page = 30,
    7.46    content = function() 
    7.47      ui.list{
    7.48        records = members_selector:exec(),
    7.49 @@ -68,22 +67,20 @@
    7.50          },
    7.51          {
    7.52            content = function(record)
    7.53 -            if app.session.member.admin and not record.active then
    7.54 +            if not record.active then
    7.55                ui.field.text{ value = "locked" }
    7.56              end
    7.57            end
    7.58          },
    7.59          {
    7.60            content = function(record)
    7.61 -            if app.session.member.admin then
    7.62 -              ui.link{
    7.63 -                attr = { class = "action admin_only" },
    7.64 -                text = _"Edit",
    7.65 -                module = "admin",
    7.66 -                view = "member_edit",
    7.67 -                id = record.id
    7.68 -              }
    7.69 -            end
    7.70 +            ui.link{
    7.71 +              attr = { class = "action admin_only" },
    7.72 +              text = _"Edit",
    7.73 +              module = "admin",
    7.74 +              view = "member_edit",
    7.75 +              id = record.id
    7.76 +            }
    7.77            end
    7.78          }
    7.79        }
     8.1 --- a/model/area.lua	Mon Nov 08 02:39:30 2010 +0100
     8.2 +++ b/model/area.lua	Mon Nov 08 15:04:44 2010 +0100
     8.3 @@ -58,3 +58,10 @@
     8.4      :exec()
     8.5  end
     8.6  
     8.7 +function Area:build_selector(args)
     8.8 +  local selector = Area:new_selector()
     8.9 +  if args.active ~= nil then
    8.10 +    selector:add_where{ "active = ?", args.active }
    8.11 +  end
    8.12 +  return selector
    8.13 +end
     9.1 --- a/model/member.lua	Mon Nov 08 02:39:30 2010 +0100
     9.2 +++ b/model/member.lua	Mon Nov 08 15:04:44 2010 +0100
     9.3 @@ -223,6 +223,25 @@
     9.4    ref                   = 'supported_initiatives'
     9.5  }
     9.6  
     9.7 +function Member:build_selector(args)
     9.8 +  local selector = self:new_selector()
     9.9 +  if args.active ~= nil then
    9.10 +    selector:add_where{ "member.active = ?", args.active }
    9.11 +  end
    9.12 +  if args.order then
    9.13 +    if args.order == "id" then
    9.14 +      selector:add_order_by("id")
    9.15 +    elseif args.order == "login" then
    9.16 +      selector:add_order_by("login")
    9.17 +    elseif args.order == "name" then
    9.18 +      selector:add_order_by("name")
    9.19 +    else
    9.20 +      error("invalid order")
    9.21 +    end
    9.22 +  end
    9.23 +  return selector
    9.24 +end
    9.25 +
    9.26  function Member.object:set_password(password)
    9.27    local hash = os.crypt(
    9.28      password,
    10.1 --- a/model/policy.lua	Mon Nov 08 02:39:30 2010 +0100
    10.2 +++ b/model/policy.lua	Mon Nov 08 15:04:44 2010 +0100
    10.3 @@ -9,3 +9,12 @@
    10.4    ref           = 'issues',
    10.5    back_ref      = 'policy'
    10.6  }
    10.7 +
    10.8 +function Policy:build_selector(args)
    10.9 +  local selector = self:new_selector()
   10.10 +  if args.active ~= nil then
   10.11 +    selector:add_where{ "active = ?", args.active }
   10.12 +  end
   10.13 +  selector:add_order_by("index")
   10.14 +  return selector
   10.15 +end

Impressum / About Us