Skip to content

Commit

Permalink
Size display changes
Browse files Browse the repository at this point in the history
Improves the filesize display and now displays the size of file after loading failture.
  • Loading branch information
ItIsJordan committed Nov 9, 2023
1 parent de500f0 commit 5668f63
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 22 deletions.
46 changes: 34 additions & 12 deletions hepdata/modules/records/assets/js/hepdata_tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ HEPDATA.switch_table = function (listId, table_requested, table_name, status) {
$('#' + table_requested).addClass("active");


HEPDATA.render_loader("#table_loader", [
HEPDATA.render_loader("#main_table_loader", [
{x: 26, y: 30, color: "#955BA5"},
{x: -60, y: 55, color: "#2C3E50"},
{x: 37, y: -10, color: "#955BA5"},
{x: -60, y: 10, color: "#955BA5"},
{x: -27, y: -30, color: "#955BA5"},
{x: 60, y: -55, color: "#2C3E50"}],
{"width": 200, "height": 200}
);

HEPDATA.render_loader("#filesize_table_loader", [
{x: 26, y: 30, color: "#955BA5"},
{x: -60, y: 55, color: "#2C3E50"},
{x: 37, y: -10, color: "#955BA5"},
Expand All @@ -42,10 +52,17 @@ HEPDATA.switch_table = function (listId, table_requested, table_name, status) {
$(".copy-btn").attr('data-clipboard-text', direct_link);
HEPDATA.setup_clipboard();


$("#hepdata_table_loading").removeClass("hidden");
$("#hepdata_table_loading_failed").addClass("hidden");
$("#hepdata_table_loader").removeClass("hidden");
$("#hepdata_table_content").addClass("hidden");
// Reset filesize loader state
$("#hepdata_filesize_loader").addClass("hidden");
$("filesize_table_confirm").removeClass("hidden");
$("filesize_table_loading").addClass("hidden");
$("#filesize_table_loading_failed").addClass("hidden");
$("#hep_table").addClass("hidden");

HEPDATA.current_table_id = table_requested;

Expand All @@ -58,9 +75,14 @@ HEPDATA.switch_table = function (listId, table_requested, table_name, status) {
var web_url = '/record/data/' + HEPDATA.current_record_id + '/' + table_requested + "/" + HEPDATA.current_table_version + "/";
HEPDATA.table_renderer.display_table_headers(web_url, 0);

var load_button = $("#hepdata_filesize_loading_button");
load_button.on('click', function() {
HEPDATA.table_renderer.display_table(web_url, '#data_table_region','#data_visualization_region',1);
$("#hepdata_filesize_loading_button").on('click', function() {
$("#filesize_table_confirm").addClass("hidden");
$("#filesize_table_loading").removeClass("hidden");
HEPDATA.table_renderer.display_table(
web_url,
'#data_table_region',
'#data_visualization_region', 1
);
});

$(".data_download_link").each(function () {
Expand All @@ -85,6 +107,7 @@ HEPDATA.table_renderer = {
processData: false,
cache: true,
success: function (table_data) {
HEPDATA.reset_stats();
d3.select('#data_table_region').html('');
d3.select("#table_options_region").html('');

Expand All @@ -98,15 +121,15 @@ HEPDATA.table_renderer = {
// Initiates rendering of both related DOI table areas
HEPDATA.table_renderer.render_related_dois(table_data.related_tables, "#related-tables");
HEPDATA.table_renderer.render_related_dois(table_data.related_to_this, "#related-to-this-tables");

HEPDATA.table_renderer.render_keywords(table_data.keywords, "#table_keywords");

$("#hepdata_table_loader").addClass("hidden");
$("#hepdata_table_content").removeClass("hidden");

if(table_data.values.length == 0) {
$("#hepdata_table_loader").addClass("hidden");
$("#hepdata_filesize_fail").removeClass("hidden");
$("#hep_table").addClass("hidden");
d3.select("#filesize_table_size").html('Table size is:' + table_data.size);
$("#hepdata_filesize_loader").removeClass("hidden");
$("filesize_table_confirm").removeClass("hidden");
}
else {
HEPDATA.table_renderer.display_table(url,
Expand Down Expand Up @@ -164,14 +187,13 @@ HEPDATA.table_renderer = {
}

$("#hep_table").removeClass("hidden");
$("#hepdata_filesize_fail").addClass("hidden");
$("#hepdata_filesize_loader").addClass("hidden");
HEPDATA.typeset($("#hepdata_table_content").get());
},
error: function (data, error) {
// TODO - Improve this error message
console.error(error);
$("#hepdata_filesize_fail").removeClass("hidden");
d3.select("#hepdata_table_loading_failed_text").html('Failed to load table data defined by ' + url + load_all);
$("#filesize_table_loading_failed").removeClass("hidden");
d3.select("#filesize_table_failed_text").html('Failed to load table data defined by ' + url + load_all);
}
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<div id="hepdata_table_loader" style="width: 200px; height: 200px; margin: 0 auto">
<div id="hepdata_table_loading">
<div id="table_loader"></div>
<div id="main_table_loader"></div>
<p align="center" style="font-weight: bolder; color: #2C3E50; padding-top: 0px">Loading Data...</p>
</div>
<div id="hepdata_table_loading_failed" class="hidden">
Expand Down Expand Up @@ -125,11 +125,21 @@ <h5>This table is referred to by:</h5>
<div class="clearfix"></div>

<div class="clearfix"></div>
<div id="hepdata_filesize_fail" class="hidden">
<div id="hepdata_filesize_fail_text" align="center" style="font-weight: bolder; color: #2C3E50; padding-top: 0px">

<div id="hepdata_filesize_loader" class="hidden">
<div id="filesize_table_confirm" align="center">
<p align="center" style="font-weight: bolder; color: #2C3E50; padding-top: 0px">This table is too large to load automatically.</p>
<p id="filesize_table_size"></p>
<button id="hepdata_filesize_loading_button" class="btn btn-primary btn-sm">Load Table</button>
</div>
<div id="filesize_table_loading" class="hidden" align="center">
<div id="filesize_table_loader"></div>
<p align="center" style="font-weight: bolder; color: #2C3E50; padding-top: 0px">Loading Data...</p>
</div>
<div id="filesize_table_loading_failed" class="hidden">
<p id="filesize_table_failed_text" align="center" style="font-weight: bolder; color: #2C3E50; padding-top: 0px"></p>
<p align="center">Please try again later, or email [email protected] if this error persists.</p>
</div>
<div><p>This table is too large to load automatically.</p></div>
<button id="hepdata_filesize_loading_button" class="btn btn-primary btn-sm">Load Table</button>
</div>
<div id="hep_table" class="row">
<div id="hep_table_data" class="col-md-7 hidden-xs">
Expand Down
6 changes: 4 additions & 2 deletions hepdata/modules/records/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ def file_size_check(file_location, load_all):
:param load_all: If the check should be run
:return bool: Pass or fail
"""
size_check = { "status": True, "size": 0 }
size_check["size"] = os.path.getsize(file_location)
# We do the check only if told to
if load_all == 0:
return os.path.getsize(file_location) <= SIZE_LOAD_CHECK_THRESHOLD
return True
size_check["status"] = size_check["size"] <= SIZE_LOAD_CHECK_THRESHOLD
return size_check
3 changes: 2 additions & 1 deletion hepdata/modules/records/utils/data_processing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ def generate_table_structure(table_contents):
"review": table_contents["review"],
"associated_files": table_contents["associated_files"],
"keywords": {},
"values": []}
"values": [],
"size": table_contents["size"]}

record["description"] = sanitize_html(table_contents["title"])

Expand Down
6 changes: 4 additions & 2 deletions hepdata/modules/records/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def get_latest():


@blueprint.route('/data/<int:recid>/<int:data_recid>/<int:version>/<int:load_all>', methods=['GET'])
def get_table_details(recid, data_recid, version, load_all):
def get_table_details(recid, data_recid, version, load_all=1):
"""
Get the table details.
Expand All @@ -314,7 +314,8 @@ def get_table_details(recid, data_recid, version, load_all):
file_location = data_record.file_location
load_fail = True

if file_size_check(file_location, load_all):
size_check = file_size_check(file_location, load_all)
if size_check["status"]:
attempts = 0
while True:
try:
Expand All @@ -341,6 +342,7 @@ def get_table_details(recid, data_recid, version, load_all):
table_contents["related_to_this"] = [r.doi for r in datasub_record.get_related_datasubmissions()]
table_contents["doi"] = datasub_record.doi
table_contents["location"] = datasub_record.location_in_publication
table_contents["size"] = size_check["size"]

# we create a map of files mainly to accommodate the use of thumbnails for images where possible.
tmp_assoc_files = {}
Expand Down

0 comments on commit 5668f63

Please sign in to comment.