liquid_feedback_frontend
view app/main/index/index.lua @ 1852:e593570a23c5
More efficient algorithm
| author | bsw | 
|---|---|
| date | Tue Mar 22 10:35:44 2022 +0100 (2022-03-22) | 
| parents | ed156969a447 | 
| children | 
 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     request.redirect{ 
    31       external = encode.url{
    32         module = "index", view = "index", params = {
    33           unit = unit_id
    34         }
    35       }
    36     }
    37     return
    38   end
    39   area:load_delegation_info_once_for_member_id(app.session.member_id)
    40 end
    42 if area then
    43   execute.view{ module = "area", view = "_head", params = { area = area } }
    44 elseif unit then
    45   execute.view{ module = "unit", view = "_head", params = { unit = unit } }
    46 end
    49 ui.grid{ content = function()
    50   ui.cell_main{ content = function()
    52     execute.view{ module = "index", view = "_sidebar_motd_public" }
    53     if not unit_id and not area_id then
    54       execute.view{ module = "index", view = "_sidebar_motd_intern_top" }
    55     end
    57     execute.view{ module = "issue", view = "_list" }
    58   end }
    60   ui.cell_sidebar{ content = function()
    61     if not unit and not area and config.logo_startpage then
    62       config.logo_startpage()
    63     end
    64     execute.view{ module = "index", view = "_head" }
    66     execute.view{ module = "index", view = "_sidebar_motd" }
    67     if app.session.member then
    68       execute.view{ module = "index", view = "_sidebar_notifications" }
    69     end
    70     if config.firstlife then
    71       ui.container{ attr = { class = "map mdl-special-card mdl-shadow--2dp pos-before-main" }, content = function()
    72         ui.tag{ tag = "iframe", attr = { src = config.firstlife.areaviewer_url .. "?" .. config.firstlife.coordinates .. "&domain=" .. request.get_absolute_baseurl(), class = "map" }, content = "" }
    73       end }
    74     end
    75     if config.map then
    76       local initiatives = Initiative:new_selector():exec()
    77       local geo_objects = {}
    78       for i, initiative in ipairs(initiatives) do
    79         if initiative.location and initiative.location.coordinates then
    80           local geo_object = {
    81             lon = initiative.location.coordinates[1],
    82             lat = initiative.location.coordinates[2],
    83             label = "i" .. initiative.id,
    84             description = slot.use_temporary(function()
    85               ui.link{ module = "initiative", view = "show", id = initiative.id, text = initiative.display_name }
    86             end),
    87             type = "initiative"
    88           }
    89           table.insert(geo_objects, geo_object)
    90         end
    91       end
    92       if ontomap_get_instances then
    93         local instances = ontomap_get_instances()
    94         for i, instance in ipairs(instances) do
    95           table.insert(geo_objects, instance)
    96         end
    97       end
    98       ui.container{ attr = { class = "map mdl-special-card mdl-shadow--2dp pos-before-main" }, content = function()
    99         ui.map(geo_objects)  
   100       end }
   101     end
   102     if config.logo then
   103       config.logo()
   104     end
   105     if area then
   106       execute.view{ module = "area", view = "_sidebar_whatcanido", params = { area = area } }
   107     elseif unit then
   108       execute.view{ module = "unit", view = "_sidebar_whatcanido", params = { unit = unit } }
   109     else
   110       execute.view{ module = "index", view = "_sidebar_whatcanido" }
   111     end
   113     execute.view { module = "index", view = "_sidebar_members" }
   115   end }
   116 end }
