From d5f816e4ec32315e0a2f74bc3c271d7773a2cf7e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Laurent?= <francois.laurent@posteo.net>
Date: Tue, 17 Sep 2024 10:15:39 +0200
Subject: [PATCH] feat: footer with version number

---
 .gitignore              |  1 +
 front/Containerfile     |  4 ++--
 routes.jl               |  8 ++++++--
 src/GenieExtras.jl      | 21 ++++++++++++++++++++-
 src/apps/catalog/app.jl |  4 ++--
 src/apps/muscles/app.jl |  4 ++--
 src/nyxui.css           |  5 +++++
 7 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/.gitignore b/.gitignore
index a18c523..fadcdf3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@ build/
 public/
 log/
 storage/
+version.txt
diff --git a/front/Containerfile b/front/Containerfile
index 3c501fb..4889e4e 100644
--- a/front/Containerfile
+++ b/front/Containerfile
@@ -20,8 +20,8 @@ RUN export HOME="$JULIA_PROJECT" \
 ENV PATH "$PATH:$JULIA_PROJECT/.juliaup/bin"
 
 RUN cd "$JULIA_PROJECT" \
- && rm -rf public \
- && rm -rf storage \
+ && git rev-parse --short HEAD > src/version.txt \
+ && rm -rf .git public storage \
  && cp front/Manifest.toml . \
  && julia -e 'using Pkg; Pkg.instantiate()' \
  && mkdir -p public \
diff --git a/routes.jl b/routes.jl
index 92aee8d..3e6bc03 100755
--- a/routes.jl
+++ b/routes.jl
@@ -30,19 +30,23 @@ if Genie.Configuration.isprod()
     @error "GENIE_ENV=prod is not implemented"
 end
 
+function modelview(model, view)
+    page(model, NyxUI.add_footer(view); title=nyxui_title)
+end
+
 Stipple.Layout.add_css(nyxui_css)
 
 include("src/apps/catalog/app.jl")
 
 route("/") do
-    AppCatalog.handler(nyxui_title)
+    AppCatalog.handler(modelview)
 end
 
 include("src/apps/muscles/app.jl")
 MuscleApp.bonito_app.name = "muscles"
 
 route("/muscles") do
-    MuscleApp.handler(nyxui_title)
+    MuscleApp.handler(modelview)
 end
 
 run_as_script = isinteractive()
diff --git a/src/GenieExtras.jl b/src/GenieExtras.jl
index 8441d9c..a46484b 100644
--- a/src/GenieExtras.jl
+++ b/src/GenieExtras.jl
@@ -1,6 +1,8 @@
 module GenieExtras
 
-export publish_css
+import Genie.Renderer.Html
+
+export publish_css, add_footer
 
 const project_root = dirname(Base.current_project())
 
@@ -28,4 +30,21 @@ function publish_css(; clear=true)
     return css_dir
 end
 
+function footer()
+    version = string(pkgversion(@__MODULE__))
+    if endswith(version, ".0")
+        version = version[1:end-2]
+    end
+    versionfile = joinpath(@__DIR__, "version.txt")
+    version = if isfile(versionfile)
+        join((version, readchomp(versionfile)), "-")
+    end
+    tagurl = "https://gitlab.com/dbc-nyx/NyxUI.jl/-/tags"
+    Html.footer("NyxUI.jl <a href=\"$tagurl\">v$version</a>")
+end
+
+add_footer(ui::AbstractString) = "$ui$(footer())"
+
+add_footer(ui::Function) = () -> add_footer(ui())
+
 end
diff --git a/src/apps/catalog/app.jl b/src/apps/catalog/app.jl
index 50eabd2..240cf82 100644
--- a/src/apps/catalog/app.jl
+++ b/src/apps/catalog/app.jl
@@ -46,11 +46,11 @@ end
 
 const ui = app_catalog_view
 
-function handler(title)
+function handler(modelview)
     Stipple.Layout.add_css("/css/appcatalog.css")
     publish_images()
     empty_model = @init
-    page(empty_model, app_catalog_view; title=title)
+    modelview(empty_model, app_catalog_view)
 end
 
 function publish_images()
diff --git a/src/apps/muscles/app.jl b/src/apps/muscles/app.jl
index 57347c6..4a70c66 100644
--- a/src/apps/muscles/app.jl
+++ b/src/apps/muscles/app.jl
@@ -298,13 +298,13 @@ end
 
 const ui = muscle_view
 
-function handler(title)
+function handler(modelview)
     muscle_model = @init
     url = ""
     #muscle_model, url = init_model()
     Stipple.Layout.add_css("/css/muscleapp.css")
     channel = muscle_model.channel__
-    page(muscle_model, muscle_view(url; channel=channel); title=title)
+    modelview(muscle_model, muscle_view(url; channel=channel))
 end
 
 function init_model(muscle_model=nothing)
diff --git a/src/nyxui.css b/src/nyxui.css
index 2eefde5..12eb979 100644
--- a/src/nyxui.css
+++ b/src/nyxui.css
@@ -49,3 +49,8 @@ div.no-file-listing .q-icon {
 .disabled {
   pointer-events: none;
 }
+
+footer {
+  text-align: right;
+  padding-right: 1rem;
+}
-- 
GitLab