Skip to content

Commit

Permalink
F #3167 add Sunstone Banner
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Lobo <jlobo@opennebula.systems>
(cherry picked from commit ecea41a)
  • Loading branch information
Jorge Lobo authored and tinova committed Apr 2, 2019
1 parent c9fdeb3 commit 2b4949e
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 8 deletions.
22 changes: 22 additions & 0 deletions src/sunstone/public/app/opennebula/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/sunstone/public/app/opennebula/support.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/sunstone/public/app/tabs/support-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
55 changes: 54 additions & 1 deletion src/sunstone/public/app/tabs/support-tab/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 = $("<a/>", {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,
Expand Down
7 changes: 6 additions & 1 deletion src/sunstone/public/app/tabs/support-tab/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
};
});
7 changes: 7 additions & 0 deletions src/sunstone/public/scss/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@
a {
color: $dark-gray;
}

#latest_version{
a{
color: map-get($foundation-palette, primary);
font-weight: bold;
}
}
}

.action_blocks {
Expand Down
45 changes: 42 additions & 3 deletions src/sunstone/routes/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/sunstone/views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
</ul>
</div>
<div id="footer" class="text-center large-12 columns">
<a href="http://opennebula.org" target="_blank">OpenNebula <%= OpenNebula::VERSION %></a>
<br> by
<a href="http://OpenNebula.systems" target="_blank">OpenNebula Systems</a>.
<a href="http://opennebula.org" target="_blank">OpenNebula 5.7.9</a>
<div id="latest_version" style="display:none;"></div>
<p>by <a href="http://OpenNebula.systems" target="_blank">OpenNebula Systems</a>.</p>
</div>
</div>

Expand Down

0 comments on commit 2b4949e

Please sign in to comment.