Some more frontend

This commit is contained in:
2024-07-02 17:39:18 -03:00
parent a4f722a1e0
commit 227c770b61
4 changed files with 45 additions and 10 deletions

View File

@ -4,14 +4,31 @@ require "../funko.cr"
module Funkos
get "/funkos/" do |env|
funkos : Array(Funko) = Funko.from_docker
funkos = Funko.from_docker
funkos.sort! { |a, b| a.name <=> b.name }
result = [] of Hash(String, String)
funkos.each do |funko|
state = ""
case funko
when .running?
state = "running"
when .paused?
state = "paused"
else
state = "stopped"
end
result << {
"name" => funko.name,
"state" => state,
}
end
if env.params.query.fetch("format", "json") == "html"
render "src/views/funkos.ecr"
else
funkos.to_json
result.to_json
end
end
end