From 6cf673d917c75b2a0160427adcdbd0aa92257099 Mon Sep 17 00:00:00 2001 From: James Hunt Date: Wed, 13 Jun 2018 10:46:13 -0400 Subject: [PATCH] Re-apply Task Pagination PR #395 Changes made in #395 were accidentally reverted by #383, because code in #395 was mistakenly committed to the compiled javascript assets. This commit fixes that, and re-introduces the intended code changes to the source javascript file, and commits both copies. --- web2/htdocs/shield.js | 20 ++++++++++++++++++++ web2/src/js/shield.js | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/web2/htdocs/shield.js b/web2/htdocs/shield.js index 385f80574..68088ca60 100644 --- a/web2/htdocs/shield.js +++ b/web2/htdocs/shield.js @@ -2070,6 +2070,9 @@ function dispatch(page) { error: "Failed retrieving metadata for protected system from the SHIELD API.", success: function (data) { $('#main').html(template('system', { target: data })); + + oldest = data["tasks"][data.tasks.length-1]["requested_at"] + watchTasks($global.auth.tenant.uuid, data.uuid, function (r) { task = JSON.parse(r.data); for (var i = 0; i < data.tasks.length; i++) { @@ -2082,6 +2085,23 @@ function dispatch(page) { data.tasks.unshift(task); $('#main').html(template('system', { target: data })); }); + + $(document.body).on('click', 'a[href^="load_more"]', function (event) { + event.preventDefault(); + api({ + type: 'GET', + url: '/v2/tenants/' + $global.auth.tenant.uuid + '/systems/' + args.uuid + '?before=' + oldest, + error: "Failed retrieving metadata for protected system from the SHIELD API.", + success: function (older_tasks) { + data.tasks = $.merge(data.tasks, older_tasks.tasks); + $('#main').html(template('system', { target: data })); + oldest = data["tasks"][data.tasks.length - 1]["requested_at"] + if (older_tasks.tasks.length == 0) { + $(".paginated-loading").remove(); + } + } + }); + }); } }); break; /* #!/systems/system */ diff --git a/web2/src/js/shield.js b/web2/src/js/shield.js index 035b6a42b..dc90c9cb3 100644 --- a/web2/src/js/shield.js +++ b/web2/src/js/shield.js @@ -773,6 +773,9 @@ function dispatch(page) { error: "Failed retrieving metadata for protected system from the SHIELD API.", success: function (data) { $('#main').html(template('system', { target: data })); + + oldest = data["tasks"][data.tasks.length-1]["requested_at"] + watchTasks($global.auth.tenant.uuid, data.uuid, function (r) { task = JSON.parse(r.data); for (var i = 0; i < data.tasks.length; i++) { @@ -785,6 +788,23 @@ function dispatch(page) { data.tasks.unshift(task); $('#main').html(template('system', { target: data })); }); + + $(document.body).on('click', 'a[href^="load_more"]', function (event) { + event.preventDefault(); + api({ + type: 'GET', + url: '/v2/tenants/' + $global.auth.tenant.uuid + '/systems/' + args.uuid + '?before=' + oldest, + error: "Failed retrieving metadata for protected system from the SHIELD API.", + success: function (older_tasks) { + data.tasks = $.merge(data.tasks, older_tasks.tasks); + $('#main').html(template('system', { target: data })); + oldest = data["tasks"][data.tasks.length - 1]["requested_at"] + if (older_tasks.tasks.length == 0) { + $(".paginated-loading").remove(); + } + } + }); + }); } }); break; /* #!/systems/system */