Skip to content
This repository has been archived by the owner on Jun 26, 2022. It is now read-only.

Commit

Permalink
RF: improve table content loading and processing
Browse files Browse the repository at this point in the history
Table content loading and processing is now done
asynchronously. Table data is dynamically added
after processing.
  • Loading branch information
christian-monch committed Jun 25, 2020
1 parent c7482ed commit 275e29d
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 deletions assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,36 +455,6 @@ function directory(jQuery) {
return;
}

let poster_json = null;

$.ajax({
async: false,
type: 'GET',
url: md5Url,
success: function(poster) {
$.ajax({
async: false,
type: 'GET',
url: md5OverrideUrl,
success: function(overrides) {
poster["posters"].map(
function (e, i) {
Object.assign(e, overrides["posters"][i]);
});
poster_json = poster;
}
});
}
});

if (poster_json == null) {
errorMsg(
jQuery,
"Could not load metadata and/or metadata overrides"
);
return;
}

// Embed the table placeholder
jQuery('#content').prepend('<table id="directory" class="display"></table>');

Expand All @@ -497,14 +467,9 @@ function directory(jQuery) {
'<P> More and info and feel welcome to send PRs for <a href="https://github.com/datalad-datasets/ohbm2020-posters" target="_github">https://github.com/datalad-datasets/ohbm2020-posters</a> since I know no JS</p>'
);

var table = jQuery('#directory').dataTable({
var table = jQuery('#directory').DataTable({
async: true, // async get json
paging: false, // ensure scrolling instead of pages
data: poster_json["posters"],
//ajax: { // specify url to get json from ajax
// url: md5Url,
// dataSrc: "posters"
//},
//order: [[6, "desc"], [0, 'asc']],
columns: [ // select columns and their names from json
{data: "number", title: "#", width: "5%"},
Expand Down Expand Up @@ -581,6 +546,27 @@ function directory(jQuery) {
// '</span>');
// }
});

$.ajax({
async: false,
type: 'GET',
url: md5Url,
success: function(poster) {
$.ajax({
async: false,
type: 'GET',
url: md5OverrideUrl,
success: function(overrides) {
poster["posters"].map(
function (e, i) {
Object.assign(e, overrides["posters"][i]);
});
table.rows.add(poster["posters"]).draw();
}
});
}
});

localStorage['ntCache'] = JSON.stringify(ntCache);
return table;
}

0 comments on commit 275e29d

Please sign in to comment.