From 1f3d9cf88d90fc9dbaf5ff6ea4ec1845a118f57c Mon Sep 17 00:00:00 2001 From: Sylvain Date: Tue, 14 Jan 2020 17:12:36 +0100 Subject: [PATCH] display upgrade infos directly on the interface --- .../controllers/application.js.erb | 25 +++++++++++++++++-- .../admin/versions/upgradeModal.html | 19 ++++++++++++++ app/controllers/api/version_controller.rb | 5 +++- app/views/application/index.html.erb | 6 +++-- config/locales/app.public.en.yml | 6 +++++ config/locales/app.public.es.yml | 6 +++++ config/locales/app.public.fr.yml | 6 +++++ config/locales/app.public.pt.yml | 6 +++++ lib/version.rb | 2 +- 9 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 app/assets/templates/admin/versions/upgradeModal.html diff --git a/app/assets/javascripts/controllers/application.js.erb b/app/assets/javascripts/controllers/application.js.erb index 249efb8fc..e7580f1a6 100644 --- a/app/assets/javascripts/controllers/application.js.erb +++ b/app/assets/javascripts/controllers/application.js.erb @@ -23,7 +23,7 @@ Application.Controllers.controller('ApplicationController', ['$rootScope', '$sco // Fab-manager's version $scope.version = - { version: '' }; + { current: '' }; // currency symbol for the current locale (cf. angular-i18n) $rootScope.currencySymbol = $locale.NUMBER_FORMATS.CURRENCY_SYM; @@ -41,7 +41,7 @@ Application.Controllers.controller('ApplicationController', ['$rootScope', '$sco if (user.role === 'admin') { return $scope.version = Version.get(); } else { - return $scope.version = { version: '' }; + return $scope.version = { current: '' }; } } }; @@ -267,6 +267,16 @@ Application.Controllers.controller('ApplicationController', ['$rootScope', '$sco toggler.toggleClass('active'); }; + $scope.versionModal = function() { + $uibModal.open({ + templateUrl: '<%= asset_path "admin/versions/upgradeModal.html" %>', + controller: 'VersionModalController', + resolve: { + version() { return $scope.version; } + } + }); + } + /* PRIVATE SCOPE */ /** * Kind of constructor: these actions will be realized first when the controller is loaded @@ -513,3 +523,14 @@ Application.Controllers.controller('ApplicationController', ['$rootScope', '$sco return initialize(); } ]); + + +Application.Controllers.controller('VersionModalController', ['$scope', '$uibModalInstance', 'version', function ($scope, $uibModalInstance, version) { + // version infos (current version + upgrade infos from hub) + $scope.version = version; + + // callback to close the modal + $scope.close = function () { + $uibModalInstance.dismiss(); + } +}]); diff --git a/app/assets/templates/admin/versions/upgradeModal.html b/app/assets/templates/admin/versions/upgradeModal.html new file mode 100644 index 000000000..7bb6cd973 --- /dev/null +++ b/app/assets/templates/admin/versions/upgradeModal.html @@ -0,0 +1,19 @@ + + + diff --git a/app/controllers/api/version_controller.rb b/app/controllers/api/version_controller.rb index b466c27a9..bc3ff255b 100644 --- a/app/controllers/api/version_controller.rb +++ b/app/controllers/api/version_controller.rb @@ -7,7 +7,10 @@ class API::VersionController < API::ApiController def show authorize :version + update_status = Setting.find_by(name: 'hub_last_version')&.value || '{}' - render json: { version: Version.current }, status: :ok + json = JSON.parse(update_status) + json['current'] = Version.current + render json: json, status: :ok end end diff --git a/app/views/application/index.html.erb b/app/views/application/index.html.erb index 3799c881b..ce2bfee2f 100644 --- a/app/views/application/index.html.erb +++ b/app/views/application/index.html.erb @@ -116,8 +116,10 @@
- - + + + + Powered by Fab Manager
diff --git a/config/locales/app.public.en.yml b/config/locales/app.public.en.yml index 60a396ccb..a349028db 100644 --- a/config/locales/app.public.en.yml +++ b/config/locales/app.public.en.yml @@ -123,6 +123,12 @@ en: # Fab-manager's version version: "Version:" + upgrade_fabmanager: "Upgrade Fab-Manager" + current_version: "You are currently using version {VERSION} of Fab-Manager." + upgrade_to: "A new release is available. You can upgrade up to version {VERSION}." + read_more: "View the details of this release" + security_version_html: "Your current version is vulnerable!
A later version, currently available, includes security fixes. Upgrade as soon as possible!" + how_to: "How to upgrade? # Notifications and_NUMBER_other_notifications: "and {NUMBER, plural, =0{no other notifications} =1{one other notification} other{{NUMBER} other notifications}}..." diff --git a/config/locales/app.public.es.yml b/config/locales/app.public.es.yml index 23f75de38..6f3d87c61 100644 --- a/config/locales/app.public.es.yml +++ b/config/locales/app.public.es.yml @@ -123,6 +123,12 @@ es: # Fab-manager's version version: "Version:" + upgrade_fabmanager: "Upgrade Fab-Manager" + current_version: "You are currently using version {VERSION} of Fab-Manager." + upgrade_to: "A new release is available. You can upgrade up to version {VERSION}." + read_more: "View the details of this release" + security_version_html: "Your current version is vulnerable!
A later version, currently available, includes security fixes. Upgrade as soon as possible!" + how_to: "How to upgrade? # Notifications and_NUMBER_other_notifications: "y {NUMBER, plural, =0{no other notifications} =1{one other notification} otras{{NUMBER} other notifications}}..." diff --git a/config/locales/app.public.fr.yml b/config/locales/app.public.fr.yml index f2d708612..6a969ff36 100644 --- a/config/locales/app.public.fr.yml +++ b/config/locales/app.public.fr.yml @@ -123,6 +123,12 @@ fr: # Fab-manager's version version: "Version :" + upgrade_fabmanager: "Mettez à jour Fab-Manager" + current_version: "Vous utilisez actuellement la version {VERSION} de Fab-Manager." + upgrade_to: "Une nouvelle version est disponible. Vous pouvez mettre à jour vers la version {VERSION}." + read_more: "Voir les détails de cette version" + security_version_html: "Votre version actuelle est vulnérable !
Une version ultérieure, actuellement disponible, inclut des correctifs de sécurité. Mettez à jour dès que possible !" + how_to: "Comment mettre à jour ?" # Notifications and_NUMBER_other_notifications: "et {NUMBER, plural, =0{aucune autre notification} =1{une autre notification} other{{NUMBER} autres notifications}}..." diff --git a/config/locales/app.public.pt.yml b/config/locales/app.public.pt.yml index 9eeb153b8..36efc4181 100755 --- a/config/locales/app.public.pt.yml +++ b/config/locales/app.public.pt.yml @@ -123,6 +123,12 @@ pt: # Fab-manager's version version: "Versão:" + upgrade_fabmanager: "Upgrade Fab-Manager" + current_version: "You are currently using version {VERSION} of Fab-Manager." + upgrade_to: "A new release is available. You can upgrade up to version {VERSION}." + read_more: "View the details of this release" + security_version_html: "Your current version is vulnerable!
A later version, currently available, includes security fixes. Upgrade as soon as possible!" + how_to: "How to upgrade? # Notifications and_NUMBER_other_notifications: "and {NUMBER, plural, =0{no other notifications} =1{one other notification} other{{NUMBER} other notifications}}..." diff --git a/lib/version.rb b/lib/version.rb index 0f6f9c1a1..34aa27d69 100644 --- a/lib/version.rb +++ b/lib/version.rb @@ -12,7 +12,7 @@ class Version return unless hub_version json = JSON.parse(hub_version) - json['status'] + json['up_to_date'] end def self.check_and_schedule