Skip to content
Snippets Groups Projects
Commit f5b63bf1 authored by Jan Mach's avatar Jan Mach
Browse files

Moved AODS JS code to Hawat module.

(Redmine issue: #5278)
parent 5de62c53
No related branches found
No related tags found
No related merge requests found
...@@ -162,22 +162,6 @@ $(function() { ...@@ -162,22 +162,6 @@ $(function() {
popup.toggleClass("hidden static-popover"); popup.toggleClass("hidden static-popover");
}); });
/*
$('body').popover({
selector: ".popover-html[data-toggle=popover]",
html: true,
trigger: 'hover click',
content: function() {
var content = $(this).attr("data-popover-content");
return $(content).children(".popover-body").html();
},
title: function() {
var title = $(this).attr("data-popover-content");
return $(title).children(".popover-heading").html();
}
});
*/
// Callback for triggering re-render of NVD3 charts within the bootstrap tabs. // Callback for triggering re-render of NVD3 charts within the bootstrap tabs.
// Without this function the charts on invisible tabs are rendered incorrectly. // Without this function the charts on invisible tabs are rendered incorrectly.
// References: // References:
...@@ -215,84 +199,6 @@ $(function() { ...@@ -215,84 +199,6 @@ $(function() {
//window.dispatchEvent(new Event('resize')); //window.dispatchEvent(new Event('resize'));
}); });
function get_additional_data(url, param, elem, ident, snippets) {
// Append element for query result and populate it with AJAX spinner.
$(elem).append(
'<div class="query-result ' + ident + '"><i class="fas fa-cog fa-spin" data-toggle="tooltip" title="' + ident + '"></i></div>'
);
// Obtain reference for recently created element for query result.
elem = $(elem).children('.query-result.' + ident);
// Perform asynchronous request.
console.log("Request URL" + url + ", snippets: " + snippets);
var jqxhr = $.get(url)
.done(function(data) {
if (data.search_result && ((Array.isArray(data.search_result) && data.search_result.length > 0) || !Array.isArray(data.search_result))) {
console.log("Result for " + ident + " query for: " + param);
console.debug(data);
$(elem).children().tooltip('destroy');
$(elem).empty();
snippets.forEach(function(snippet) {
$(elem).append(data.snippets[snippet]);
});
}
else {
console.log("Empty result for " + ident + " query for: " + param);
console.debug(data);
// Either insert information about empty query result.
//$(elem).html(
// '<i class="fas fa-check" data-toggle="tooltip" title="Empty result for ' + ident + ' query for ' + param + '"></i>'
//);
// Or remove the result element to reduce display clutter.
$(elem).children().tooltip('destroy');
$(elem).remove();
}
})
.fail(function(data) {
console.log("Failed " + ident + " query for: " + param);
console.debug(data);
// Either insert information about error query result.
$(elem).html(
'<i class="fas fa-times" data-toggle="tooltip" title="Error for ' + ident + ' query for ' + param + '"></i>'
);
// Or remove the result element to reduce display clutter.
//$(elem).children().tooltip('destroy');
//$(elem).remove();
})
.always(function() {
//console.log("Finished " + ident + " query for: " + param);
});
}
function fetch_aods(index, elem) {
obj_type = $(elem).data('object-type');
obj_name = $(elem).data('object-name');
aods = Hawat.get_aods(obj_type);
console.log("Fetching additional data for object '" + obj_type + " -- " + obj_name + "': " + aods.reduce(function(sum, item) { return sum + ' ' + item.endpoint }, ''));
console.debug(aods);
aods.forEach(function(aods_item) {
get_additional_data(
Flask.url_for(aods_item.endpoint, aods_item.params(obj_name)),
obj_name,
elem,
aods_item.ident,
aods_item.snippets
);
});
}
$(".object-additional-data.onload").each(fetch_aods);
$('.object-additional-data.ondemand').on("click", function() {
var ref = $(this);
ref.children().tooltip('destroy');
ref.removeClass('ondemand');
ref.empty();
ref.off('click');
fetch_aods(0, ref);
});
// Special handling of '__EMPTY__' and '__ANY__' options in event search form // Special handling of '__EMPTY__' and '__ANY__' options in event search form
// selects. This method stil can be improved, so that 'any' is capable of disabling // selects. This method stil can be improved, so that 'any' is capable of disabling
// 'empty'. // 'empty'.
......
// Global application module. // Global JS application module for Hawat.
var Hawat = (function () { var Hawat = (function () {
function _build_param_builder(skeleton, rules) { function _build_param_builder(skeleton, rules) {
...@@ -15,6 +15,55 @@ var Hawat = (function () { ...@@ -15,6 +15,55 @@ var Hawat = (function () {
} }
} }
function _get_aod(url, param, elem, ident, snippets) {
// Append element for query result and populate it with AJAX spinner.
$(elem).append(
'<div class="query-result ' + ident + '"><i class="fas fa-cog fa-spin" data-toggle="tooltip" title="' + ident + '"></i></div>'
);
// Obtain reference for recently created element for query result.
elem = $(elem).children('.query-result.' + ident);
// Perform asynchronous request.
console.log("Request URL" + url + ", snippets: " + snippets);
var jqxhr = $.get(url)
.done(function(data) {
if (data.search_result && ((Array.isArray(data.search_result) && data.search_result.length > 0) || !Array.isArray(data.search_result))) {
console.log("Result for " + ident + " query for: " + param);
console.debug(data);
$(elem).children().tooltip('destroy');
$(elem).empty();
snippets.forEach(function(snippet) {
$(elem).append(data.snippets[snippet]);
});
}
else {
console.log("Empty result for " + ident + " query for: " + param);
console.debug(data);
// Either insert information about empty query result.
//$(elem).html(
// '<i class="fas fa-check" data-toggle="tooltip" title="Empty result for ' + ident + ' query for ' + param + '"></i>'
//);
// Or remove the result element to reduce display clutter.
$(elem).children().tooltip('destroy');
$(elem).remove();
}
})
.fail(function(data) {
console.log("Failed " + ident + " query for: " + param);
console.debug(data);
// Either insert information about error query result.
$(elem).html(
'<i class="fas fa-times" data-toggle="tooltip" title="Error for ' + ident + ' query for ' + param + '"></i>'
);
// Or remove the result element to reduce display clutter.
//$(elem).children().tooltip('destroy');
//$(elem).remove();
})
.always(function() {
//console.log("Finished " + ident + " query for: " + param);
});
}
var _configs = { var _configs = {
'APPLICATION_ROOT': '{{ hawat_current_app.config['APPLICATION_ROOT'] }}' 'APPLICATION_ROOT': '{{ hawat_current_app.config['APPLICATION_ROOT'] }}'
}; };
...@@ -60,10 +109,14 @@ var Hawat = (function () { ...@@ -60,10 +109,14 @@ var Hawat = (function () {
}; };
return { return {
get_csags: function() { get_all_csags: function() {
return _csag; return _csag;
}, },
get_all_aodss: function() {
return _aods;
},
get_csag: function(name) { get_csag: function(name) {
try { try {
return _csag[name]; return _csag[name];
...@@ -73,10 +126,6 @@ var Hawat = (function () { ...@@ -73,10 +126,6 @@ var Hawat = (function () {
} }
}, },
get_aodss: function() {
return _aods;
},
get_aods: function(name) { get_aods: function(name) {
try { try {
return _aods[name]; return _aods[name];
...@@ -84,6 +133,36 @@ var Hawat = (function () { ...@@ -84,6 +133,36 @@ var Hawat = (function () {
catch (err) { catch (err) {
return null return null
} }
},
fetch_aods: function(index, elem) {
obj_type = $(elem).data('object-type');
obj_name = $(elem).data('object-name');
aods = Hawat.get_aods(obj_type);
console.log("Fetching additional data for object '" + obj_type + " -- " + obj_name + "': " + aods.reduce(function(sum, item) { return sum + ' ' + item.endpoint }, ''));
console.debug(aods);
aods.forEach(function(aods_item) {
_get_aod(
Flask.url_for(aods_item.endpoint, aods_item.params(obj_name)),
obj_name,
elem,
aods_item.ident,
aods_item.snippets
);
});
} }
}; };
})(); })();
$(function() {
$(".object-additional-data.onload").each(Hawat.fetch_aods);
$('.object-additional-data.ondemand').on("click", function() {
var ref = $(this);
ref.children().tooltip('destroy');
ref.removeClass('ondemand');
ref.empty();
ref.off('click');
Hawat.fetch_aods(0, ref);
});
});
...@@ -20,4 +20,4 @@ open-source project. ...@@ -20,4 +20,4 @@ open-source project.
__author__ = "Jan Mach <jan.mach@cesnet.cz>" __author__ = "Jan Mach <jan.mach@cesnet.cz>"
__credits__ = "Pavel Kácha <pavel.kacha@cesnet.cz>, Andrea Kropáčová <andrea.kropacova@cesnet.cz>" __credits__ = "Pavel Kácha <pavel.kacha@cesnet.cz>, Andrea Kropáčová <andrea.kropacova@cesnet.cz>"
__version__ = "2.4.10" __version__ = "2.4.11"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment