liquid_feedback_frontend
view app/main/index/index.lua @ 1695:97ff2a26c84e
Fixed area without unit in single_unit mode
| author | bsw | 
|---|---|
| date | Thu Sep 23 14:30:18 2021 +0200 (2021-09-23) | 
| parents | bca6a066d429 | 
| children | 4ddc5841e136 | 
 line source
     1 local unit_id = request.get_param{ name = "unit" }
     2 local area_id = request.get_param{ name = "area" }
     4 if unit_id == "all" then
     5   unit_id = nil
     6   area_id = nil
     7 end
     9 if area_id == "all" then
    10   area_id = nil
    11 end
    13 local unit
    14 local area
    16 if unit_id then
    17   unit = Unit:by_id(unit_id)
    18   if not unit or unit.attr.hidden then
    19     execute.view { module = "index", view = "404" }
    20     request.set_status("404 Not Found")
    21     return
    22   end
    23   unit:load_delegation_info_once_for_member_id(app.session.member_id)
    24 end
    27 if area_id then
    28   area = Area:by_id(area_id)
    29   if not area or (unit and area.unit_id ~= unit.id) then
    30     execute.view { module = "index", view = "404" }
    31     request.set_status("404 Not Found")
    32     return
    33   end
    34   area:load_delegation_info_once_for_member_id(app.session.member_id)
    35 end
    37 if area then
    38   execute.view{ module = "area", view = "_head", params = { area = area } }
    39 elseif unit then
    40   execute.view{ module = "unit", view = "_head", params = { unit = unit } }
    41 end
    44 ui.grid{ content = function()
    45   ui.cell_main{ content = function()
    47     execute.view{ module = "index", view = "_sidebar_motd_public" }
    49     execute.view{ module = "issue", view = "_list" }
    50   end }
    52   ui.cell_sidebar{ content = function()
    53     execute.view{ module = "index", view = "_head" }
    55     execute.view{ module = "index", view = "_sidebar_motd" }
    56     if app.session.member then
    57       execute.view{ module = "index", view = "_sidebar_notifications" }
    58     end
    59     if config.firstlife then
    60       ui.container{ attr = { class = "map mdl-special-card mdl-shadow--2dp pos-before-main" }, content = function()
    61         ui.tag{ tag = "iframe", attr = { src = config.firstlife.areaviewer_url .. "?" .. config.firstlife.coordinates .. "&domain=" .. request.get_absolute_baseurl(), class = "map" }, content = "" }
    62       end }
    63     end
    64     if config.map then
    65       local initiatives = Initiative:new_selector():exec()
    66       local geo_objects = {}
    67       for i, initiative in ipairs(initiatives) do
    68         if initiative.location and initiative.location.coordinates then
    69           local geo_object = {
    70             lon = initiative.location.coordinates[1],
    71             lat = initiative.location.coordinates[2],
    72             label = "i" .. initiative.id,
    73             description = slot.use_temporary(function()
    74               ui.link{ module = "initiative", view = "show", id = initiative.id, text = initiative.display_name }
    75             end),
    76             type = "initiative"
    77           }
    78           table.insert(geo_objects, geo_object)
    79         end
    80       end
    81       if ontomap_get_instances then
    82         local instances = ontomap_get_instances()
    83         for i, instance in ipairs(instances) do
    84           table.insert(geo_objects, instance)
    85         end
    86       end
    87       ui.container{ attr = { class = "map mdl-special-card mdl-shadow--2dp pos-before-main" }, content = function()
    88         ui.map(geo_objects)  
    89       end }
    90     end
    91     if config.logo then
    92       config.logo()
    93     end
    94     if area then
    95       execute.view{ module = "area", view = "_sidebar_whatcanido", params = { area = area } }
    96     elseif unit then
    97       execute.view{ module = "unit", view = "_sidebar_whatcanido", params = { unit = unit } }
    98     else
    99       execute.view{ module = "index", view = "_sidebar_whatcanido" }
   100     end
   102     execute.view { module = "index", view = "_sidebar_members" }
   104   end }
   105 end }
