From 2b4949e3a40bde6b04c1b9db4390153fbc243ca9 Mon Sep 17 00:00:00 2001 From: Jorge Lobo Date: Tue, 2 Apr 2019 17:25:31 +0200 Subject: [PATCH] F #3167 add Sunstone Banner Signed-off-by: Jorge Lobo (cherry picked from commit ecea41a4fc8053fbdfc57bead5c27bcec5142063) --- src/sunstone/public/app/opennebula/action.js | 22 ++++++++ src/sunstone/public/app/opennebula/support.js | 4 ++ src/sunstone/public/app/tabs/support-tab.js | 1 + .../public/app/tabs/support-tab/actions.js | 55 ++++++++++++++++++- .../app/tabs/support-tab/utils/common.js | 7 ++- src/sunstone/public/scss/_layout.scss | 7 +++ src/sunstone/routes/support.rb | 45 ++++++++++++++- src/sunstone/views/index.erb | 6 +- 8 files changed, 139 insertions(+), 8 deletions(-) diff --git a/src/sunstone/public/app/opennebula/action.js b/src/sunstone/public/app/opennebula/action.js index 3e96720369b..64d4dd07994 100644 --- a/src/sunstone/public/app/opennebula/action.js +++ b/src/sunstone/public/app/opennebula/action.js @@ -142,6 +142,28 @@ define(function(require) { } }, + "checkversion": function(params, path){ + if(params && + params.success && + typeof params.success === "function" && + params && + params.error && + typeof params.error === "function"){ + var reqPath = path.toLowerCase(); + $.ajax({ + url: reqPath, + type: "GET", + success: function(response) { + params.success(response); + return false; + }, + error: function(response) { + params.error(response); + return false; + } + }); + } + }, "list": function(params, resource, path, process) { var callback = params.success; var callbackError = params.error; diff --git a/src/sunstone/public/app/opennebula/support.js b/src/sunstone/public/app/opennebula/support.js index cad1052baf5..32fb2bab96e 100644 --- a/src/sunstone/public/app/opennebula/support.js +++ b/src/sunstone/public/app/opennebula/support.js @@ -20,6 +20,7 @@ define(function(require) { var RESOURCE = "REQUEST"; var PATH = "support/request"; var PATH_CHECK_SUPPORT = "support/check"; + var PATH_CHECK_VERSION = "support/check/version"; var CACHE_NAME = "REQUEST"; var Support = { @@ -33,6 +34,9 @@ define(function(require) { "check": function(params){ OpenNebulaAction.check(params, PATH_CHECK_SUPPORT); }, + "checkversion": function(params){ + OpenNebulaAction.checkversion(params, PATH_CHECK_VERSION); + }, "list" : function(params) { params.cache_name = CACHE_NAME; OpenNebulaAction.clear_cache(params.cache_name); diff --git a/src/sunstone/public/app/tabs/support-tab.js b/src/sunstone/public/app/tabs/support-tab.js index d14d061c28e..1d4a3a8e9b8 100644 --- a/src/sunstone/public/app/tabs/support-tab.js +++ b/src/sunstone/public/app/tabs/support-tab.js @@ -66,6 +66,7 @@ define(function(require) { function _setup(context) { //SupportUtils.startIntervalRefresh(); //esto de debe de borrar porque me esta listando el login de un usuario SupportUtils.checkValidateOfficialSupport(); + SupportUtils.checkLastVersionSupport(); $("#li_support-tab > a").on("click", function(e){ e.preventDefault(); }); diff --git a/src/sunstone/public/app/tabs/support-tab/actions.js b/src/sunstone/public/app/tabs/support-tab/actions.js index 668f37c21e1..69fc912456f 100644 --- a/src/sunstone/public/app/tabs/support-tab/actions.js +++ b/src/sunstone/public/app/tabs/support-tab/actions.js @@ -24,7 +24,26 @@ define(function(require) { var TAB_ID = require("./tabId"); var CREATE_DIALOG_ID = require("./form-panels/create/formPanelId"); var UPLOAD_DIALOG_ID = require("./dialogs/upload/dialogId"); - + var majorVersion = function(version){ + var r = 0; + if(version && version.length){ + var major = version.substring(0, version.lastIndexOf(".")); + if(major && major.length){ + r = parseFloat(major); + } + } + return r; + }; + var minorVersion = function(version){ + var r = 0; + if(version && version.length){ + var minor = version.substring(version.lastIndexOf(".")+1); + if(minor && minor.length){ + r = parseFloat(minor); + } + } + return r; + }; var _actions = { "Support.check":{ type: "list", @@ -39,6 +58,40 @@ define(function(require) { SupportUtils.hideSupportConnect(); } }, + "Support.checkversion":{ + type: "list", + call: OpenNebulaSupport.checkversion, + callback: function(req, lst, res){ + if($("#footer>a").length){ + var localVersion = $("#footer>a").text().replace("OpenNebula ", ""); + if(req && req.version && req.version!=="0" && localVersion.length){ + var version = req.version; + var remoteMajorVersion = majorVersion(version); + var remoteMinorVersion = minorVersion(version); + var localMajorVersion = majorVersion(localVersion); + var localMinorVersion = minorVersion(localVersion); + var link = $("", {href:"https://opennebula.org/software/"}).text( + "(new version available: " + version + ")" + ); + if(remoteMajorVersion > localMajorVersion){ + $("#latest_version").show().empty().append(link); + return; + } + if(remoteMajorVersion === localMajorVersion && remoteMinorVersion > localMinorVersion){ + $("#latest_version").show().empty().append(link); + return; + } + } + } + $("#latest_version").hide().empty(); + }, + error: function(request){ + if (request && request.status && request.status >= 400) { + SupportUtils.stopIntervalRefresh(); + } + $("#latest_version").hide().empty(); + } + }, "Support.list" : { type: "list", call: OpenNebulaSupport.list, diff --git a/src/sunstone/public/app/tabs/support-tab/utils/common.js b/src/sunstone/public/app/tabs/support-tab/utils/common.js index 4a810f09756..2f3557be233 100644 --- a/src/sunstone/public/app/tabs/support-tab/utils/common.js +++ b/src/sunstone/public/app/tabs/support-tab/utils/common.js @@ -45,6 +45,10 @@ define(function(require) { Sunstone.runAction("Support.check"); } + function _check_last_version_support(){ + Sunstone.runAction("Support.checkversion"); + } + function _show_support_list() { $(".support_info").show(); $(".support_connect").hide(); @@ -70,6 +74,7 @@ define(function(require) { "hideSupportConnect": _hide_support_connect, "startIntervalRefresh": _startIntervalRefresh, "stopIntervalRefresh": _stopIntervalRefresh, - "checkValidateOfficialSupport": _check_validate_official_support + "checkValidateOfficialSupport": _check_validate_official_support, + "checkLastVersionSupport": _check_last_version_support }; }); diff --git a/src/sunstone/public/scss/_layout.scss b/src/sunstone/public/scss/_layout.scss index efd60c8a19f..919e6ae78a5 100644 --- a/src/sunstone/public/scss/_layout.scss +++ b/src/sunstone/public/scss/_layout.scss @@ -94,6 +94,13 @@ a { color: $dark-gray; } + + #latest_version{ + a{ + color: map-get($foundation-palette, primary); + font-weight: bold; + } + } } .action_blocks { diff --git a/src/sunstone/routes/support.rb b/src/sunstone/routes/support.rb index 05160bed961..542008932a2 100644 --- a/src/sunstone/routes/support.rb +++ b/src/sunstone/routes/support.rb @@ -194,7 +194,7 @@ def check_zendesk_api_gem !$conf[:check_remote_support].empty? && !$conf[:token_remote_support].nil? && !$conf[:token_remote_support].empty?) - !$conf[:opennebula_support] = !$conf[:opennebula_support].nil? ? $conf[:opennebula_support] : 0 + $conf[:opennebula_support] = !$conf[:opennebula_support].nil? ? $conf[:opennebula_support] : 0 now = Time.now.to_i validateTime = now - $conf[:opennebula_support] if(validateTime > 86400) @@ -214,18 +214,57 @@ def check_zendesk_api_gem $conf[:opennebula_support] = now [200, JSON.pretty_generate({:pass => true})] else - session["opennebula_support"] = 0 [400, JSON.pretty_generate({:pass => false})] end else [200, JSON.pretty_generate({:pass => true})] end else - session["opennebula_support"] = 0 [400, JSON.pretty_generate({:pass => false})] end end +get '/support/check/version' do + if(!$conf[:url_check_last_release].nil? && !$conf[:url_check_last_release].empty?) + $conf[:opennebula_support_date_version] = !$conf[:opennebula_support_date_version].nil? ? $conf[:opennebula_support_date_version] : 0 + $conf[:opennebula_last_version] = !$conf[:opennebula_last_version].nil? ? $conf[:opennebula_last_version] : 0; + find = 'release-' + now = Time.now.to_i + validateTime = now - $conf[:opennebula_support_date_version] + if(validateTime > 86400) + begin + http = Curl.get($conf[:url_check_last_release]) do |http| + http.headers['User-Agent'] = 'One' + end + rescue Exception => e + raise e + end + if !http.nil? && http.response_code === 200 + JSON.parse(http.body_str).each do |tag| + if(tag && tag['name'] && !tag['name'].nil? && !tag['name'].empty? && tag['name'].start_with?(find)) + version = tag['name'].tr(find,'') + memoryVersion = $conf[:opennebula_last_version] + if(version.to_f > memoryVersion.to_f) + $conf[:opennebula_last_version]=version + end + if(version.to_f === memoryVersion.to_f && version.slice(version.rindex('.')+1..-1).to_i >= memoryVersion.slice(memoryVersion.rindex('.')+1..-1).to_i) + $conf[:opennebula_last_version]=version + end + end + end + $conf[:opennebula_support_date_version] = now + [200, JSON.pretty_generate({:version => $conf[:opennebula_last_version]})] + else + [400, JSON.pretty_generate({:version => 0})] + end + else + [200, JSON.pretty_generate({:version => $conf[:opennebula_last_version]})] + end + else + [400, JSON.pretty_generate({:version => 0})] + end +end + post '/support/request/:id/action' do check_zendesk_api_gem diff --git a/src/sunstone/views/index.erb b/src/sunstone/views/index.erb index a9ba4eb164f..b2f5d829682 100644 --- a/src/sunstone/views/index.erb +++ b/src/sunstone/views/index.erb @@ -85,9 +85,9 @@