# Fonctions Lua pour générer la page “Hub” des Univers


```space-lua

-- priority: 100
hub = hub or {}

local line = template.new[==[* [[${name}]] ${title}
]==]
local projectLine = template.new[==[* [[${name}]] ${title} (${domain})
]==]
local taskLine = template.new[==[* ${name} ([[${page}]])
]==]

function hub.code()
  return string.match(editor.getCurrentPage(), "[^/]+$")
end

function hub.norm(v)
  if type(v) ~= "string" then return nil end
  local inner = string.match(v, "%[%[([^%]|]+)") or v
  return string.match(inner, "[^/]+$")
end

-- Hubs d'univers
function hub.domains(u)
  return template.each(query[[
    from p = index.pages()
    where p.type and p.type == "domain" and p.univers and p.univers == u
    order by p.name
  ]], line) or "Aucune ligne à afficher"
end

function hub.projects(u)
  return template.each(query[[
    from p = index.pages()
    where p.type == "project" and p.status == "active" and p.univers == u
    order by p.domain
  ]], projectLine) or "Aucune ligne à afficher"
end

function hub.procedures(u)
  return template.each(query[[
    from p = index.pages()
    where p.type == "note" and p.nature == "process" and (string.find(p.name, "PROC-", 1, true) or table.includes(p.tags, "procedure")) and p.univers == u
    order by p.last_exec
    limit 5
  ]], line) or "Aucune ligne à afficher"
end

function hub.overdue()
  return template.each(query[[
    from t = index.tasks()
    where not t.done and t.date and t.date <= os.date("%Y-%m-%d")
    order by t.date
    limit 15
  ]], taskLine) or "Aucune ligne à afficher"
end

-- Pages domaine et projet
function hub.projectsOfDomain()
  return template.each(query[[
    from p = index.pages()
    where p.type == "project" and p.status == "active"
      and hub.norm(p.domain) == hub.code()
    order by p.name
  ]], line) or "Aucune ligne à afficher"
end

function hub.proceduresOfDomain()
  return template.each(query[[
    from p = index.pages()
    where p.type == "note" and p.nature == "process" and (string.find(p.name, "PROC-", 1, true) or table.includes(p.tags, "procedure")) and hub.norm(p.domain) == hub.code()
    order by p.name
  ]], line) or "Aucune ligne à afficher"
end

function hub.tasksOfProject()
  return template.each(query[[
    from t = index.tasks()
    where not t.done and hub.norm(t.project) == hub.code()
    order by t.name
  ]], taskLine) or "Aucune ligne à afficher"
end
```

