From 9d51444479cec02d0b250ae65a91d36beb5f6b1b Mon Sep 17 00:00:00 2001 From: hellekin Date: Fri, 22 Jan 2021 14:45:15 +0100 Subject: Link to current source code version (per AGPL-3.0) --- app/assets/stylesheets/application/_footer.scss | 20 ++++++++++++++++++++ app/helpers/application_helper.rb | 11 +++++++++++ app/lib/incommon.rb | 10 ++++++++++ app/views/welcome/index.html.erb | 4 ++++ 4 files changed, 45 insertions(+) create mode 100644 app/assets/stylesheets/application/_footer.scss diff --git a/app/assets/stylesheets/application/_footer.scss b/app/assets/stylesheets/application/_footer.scss new file mode 100644 index 0000000..4ab34a2 --- /dev/null +++ b/app/assets/stylesheets/application/_footer.scss @@ -0,0 +1,20 @@ +body>footer { + position: absolute; + z-index: 1004; + margin: 0 auto; + background-color: rgba(0,0,0,0.5); + color: white; + text-align: center; + bottom: 0; + left: 0; + right: 0; + width: 10rem; + border-top-left-radius: 1rem; + border-top-right-radius: 1rem; +} + +.app-version a:link, +.app-version a:visited { + color: whitesmoke; +} + diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e39da5f..89b3b6d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -23,6 +23,17 @@ module ApplicationHelper ).to_html.html_safe, class: 'markdown') end + # Display current application version + def version_string + version = begin + IO.read('.app-version')&.strip + rescue + 'HEAD' + end + + tag.div(link_to(version, INCOMMON.repo_url(version), title: 'Read source code'), class: 'app-version') + end + private # CommonMarker extensions diff --git a/app/lib/incommon.rb b/app/lib/incommon.rb index 091f022..c2f30b5 100644 --- a/app/lib/incommon.rb +++ b/app/lib/incommon.rb @@ -3,4 +3,14 @@ # SPDX-License-Identifier: AGPL-3.0-or-later module INCOMMON + module_function + def repo_url(version) + case version + when /^(HEAD|v\d)/ + query="h=#{version}" + else + query="h=HEAD&id=#{version}" + end + URI.parse("https://code.cepheide.org/incommon-map.git/tree/?#{query}").to_s + end end diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index d9fd0f6..a7bf9b8 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -16,3 +16,7 @@ <% if current_user.present? %> <% end %><%# ensure it does not break when we don't have a record... %> <% end %> + +<% content_for :footer do %> + <%= version_string %> +<% end %> -- cgit v1.2.3