liquid_feedback_frontend

changeset 1696:446d2798f424

Automatically switch to single unit mode for users having only one unit
author bsw
date Thu Sep 23 17:47:58 2021 +0200 (2021-09-23)
parents 97ff2a26c84e
children 7cbc5a4638b8
files app/main/_filter/20_session.lua app/main/_filter/21_auth.lua app/main/delegation/show.lua app/main/index/_head.lua app/main/issue/_filters.lua app/main/issue/_head.lua app/main/issue/_list.lua model/member.lua
line diff
     1.1 --- a/app/main/_filter/20_session.lua	Thu Sep 23 14:30:18 2021 +0200
     1.2 +++ b/app/main/_filter/20_session.lua	Thu Sep 23 17:47:58 2021 +0200
     1.3 @@ -66,4 +66,13 @@
     1.4    }
     1.5  end
     1.6  
     1.7 +app.single_unit_id = config.single_unit_id
     1.8 +
     1.9 +if app.session.member then
    1.10 +  local member_single_unit_id = app.session.member:get_single_unit_id() or config.single_unit_id
    1.11 +  if member_single_unit_id then
    1.12 +    app.single_unit_id = member_single_unit_id
    1.13 +  end
    1.14 +end
    1.15 +
    1.16  execute.inner()
     2.1 --- a/app/main/_filter/21_auth.lua	Thu Sep 23 14:30:18 2021 +0200
     2.2 +++ b/app/main/_filter/21_auth.lua	Thu Sep 23 17:47:58 2021 +0200
     2.3 @@ -113,8 +113,8 @@
     2.4  end
     2.5  
     2.6  if app.session:has_access("anonymous") and not app.session.member_id and auth_needed and module == "index" and view == "index" then
     2.7 -  if config.single_unit_id then
     2.8 -    request.redirect{ module = "unit", view = "show", id = config.single_unit_id }
     2.9 +  if app.single_unit_id then
    2.10 +    request.redirect{ module = "unit", view = "show", id = app.single_unit_id }
    2.11    else
    2.12      request.redirect{ module = "unit", view = "list" }
    2.13    end
     3.1 --- a/app/main/delegation/show.lua	Thu Sep 23 14:30:18 2021 +0200
     3.2 +++ b/app/main/delegation/show.lua	Thu Sep 23 17:47:58 2021 +0200
     3.3 @@ -156,12 +156,12 @@
     3.4                  local unit_delegation = Delegation:by_pk(app.session.member_id, issue.area.unit_id)
     3.5                  if unit_delegation then
     3.6                    delegate_name = unit_delegation.trustee.name
     3.7 -                  scope = config.single_unit_id and _"global" or _"unit"
     3.8 +                  scope = app.single_unit_id and _"global" or _"unit"
     3.9                  end
    3.10                end
    3.11                local text_apply
    3.12                local text_abandon
    3.13 -              if config.single_unit_id then
    3.14 +              if app.single_unit_id then
    3.15                  text_apply = _("Apply global or area delegation for this issue (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
    3.16                  text_abandon = _"Abandon unit and area delegations for this issue"
    3.17                else
    3.18 @@ -179,11 +179,11 @@
    3.19                local unit_delegation = Delegation:by_pk(app.session.member_id, area.unit_id)
    3.20                if unit_delegation then
    3.21                  delegate_name = unit_delegation.trustee.name
    3.22 -                scope = config.single_unit_id and _"global" or _"unit"
    3.23 +                scope = app.single_unit_id and _"global" or _"unit"
    3.24                end
    3.25                local text_apply
    3.26                local text_abandon
    3.27 -              if config.single_unit_id then
    3.28 +              if app.single_unit_id then
    3.29                  text_apply = _("Apply global delegation for this area (Currently: #{delegate_name} [#{scope}])", { delegate_name = delegate_name, scope = scope })
    3.30                  text_abandon = _"Abandon global delegation for this area"
    3.31                else
     4.1 --- a/app/main/index/_head.lua	Thu Sep 23 14:30:18 2021 +0200
     4.2 +++ b/app/main/index/_head.lua	Thu Sep 23 17:47:58 2021 +0200
     4.3 @@ -1,4 +1,4 @@
     4.4 -local unit_id = config.single_unit_id or request.get_param{ name = "unit" }
     4.5 +local unit_id = app.single_unit_id or request.get_param{ name = "unit" }
     4.6  local area_id = config.single_area_id or request.get_param{ name = "area" }
     4.7  
     4.8  local initiative = param.get("initiative", "table")
     5.1 --- a/app/main/issue/_filters.lua	Thu Sep 23 14:30:18 2021 +0200
     5.2 +++ b/app/main/issue/_filters.lua	Thu Sep 23 17:47:58 2021 +0200
     5.3 @@ -5,7 +5,7 @@
     5.4  local member = param.get("member", "table")
     5.5  local phase = request.get_param{ name = "phase" }
     5.6  
     5.7 -local selected_unit_id = config.single_unit_id or request.get_param{ name = "unit" }
     5.8 +local selected_unit_id = app.single_unit_id or request.get_param{ name = "unit" }
     5.9  if selected_unit_id == "all" then
    5.10    selected_unit_id = nil 
    5.11  end
    5.12 @@ -38,7 +38,7 @@
    5.13  
    5.14    -- units
    5.15    
    5.16 -  if not config.single_unit_id then
    5.17 +  if not app.single_unit_id then
    5.18  
    5.19      local units_selector  
    5.20  
    5.21 @@ -177,7 +177,7 @@
    5.22        selector_modifier = function()  end
    5.23      }
    5.24  
    5.25 -    if member and not for_unit and not for_area and not config.single_unit_id then
    5.26 +    if member and not for_unit and not for_area and not app.single_unit_id then
    5.27        filter[#filter+1] = {
    5.28          name = "my_units",
    5.29          label = _"in my units",
     6.1 --- a/app/main/issue/_head.lua	Thu Sep 23 14:30:18 2021 +0200
     6.2 +++ b/app/main/issue/_head.lua	Thu Sep 23 17:47:58 2021 +0200
     6.3 @@ -5,7 +5,7 @@
     6.4  
     6.5  ui.title ( function ()
     6.6    
     6.7 -  if not config.single_unit_id then
     6.8 +  if not app.single_unit_id then
     6.9      ui.link {
    6.10        attr = { class = "unit" },
    6.11        content = function()
     7.1 --- a/app/main/issue/_list.lua	Thu Sep 23 14:30:18 2021 +0200
     7.2 +++ b/app/main/issue/_list.lua	Thu Sep 23 17:47:58 2021 +0200
     7.3 @@ -15,8 +15,8 @@
     7.4    mode = "timeline"
     7.5  end
     7.6  
     7.7 -if config.single_unit_id then
     7.8 -  for_unit = Unit:by_id(config.single_unit_id)
     7.9 +if app.single_unit_id then
    7.10 +  for_unit = Unit:by_id(app.single_unit_id)
    7.11  end
    7.12  
    7.13  local selector
    7.14 @@ -201,8 +201,8 @@
    7.15        if not for_issue and not for_initiative then
    7.16          ui.container{ attr = { class = "mdl-card__title mdl-card--has-fab mdl-card--border card-issue" }, content = function()
    7.17            ui.container{ attr = { class = "contextlinks" }, content = function()
    7.18 -            if not (config.single_unit_id and config.single_area_id) then
    7.19 -              if not config.single_unit_id then
    7.20 +            if not (app.single_unit_id and config.single_area_id) then
    7.21 +              if not app.single_unit_id then
    7.22                  ui.icon("group")
    7.23                  slot.put(" ")
    7.24                  ui.link{
    7.25 @@ -210,7 +210,7 @@
    7.26                    attr = { class = "unit" }, content = issue.area.unit.name                 }
    7.27                end
    7.28                if not config.single_area_id then
    7.29 -                if not config.single_unit_id then
    7.30 +                if not app.single_unit_id then
    7.31                    slot.put("     ")
    7.32                  end
    7.33                  ui.icon("category")
     8.1 --- a/model/member.lua	Thu Sep 23 14:30:18 2021 +0200
     8.2 +++ b/model/member.lua	Thu Sep 23 17:47:58 2021 +0200
     8.3 @@ -837,6 +837,19 @@
     8.4    return self.__units_with_polling_right_hash[unit_id] and true or false
     8.5  end
     8.6  
     8.7 +function Member.object:get_single_unit_id()
     8.8 +  populate_units_with_voting_right_hash(self)
     8.9 +  local single_unit_id
    8.10 +  local count = 0
    8.11 +  for unit_id in pairs(self.__units_with_voting_right_hash) do
    8.12 +    single_unit_id = unit_id
    8.13 +    count = count + 1
    8.14 +  end
    8.15 +  if count == 1 then
    8.16 +    return single_unit_id
    8.17 +  end
    8.18 +end
    8.19 +
    8.20  function Member.object:get_delegatee_member(unit_id, area_id, issue_id)
    8.21    local selector = Member:new_selector()
    8.22    if unit_id then

Impressum / About Us