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

Commit

Permalink
Merge pull request #16 from syreal17/master
Browse files Browse the repository at this point in the history
Fix pagination on View Records
  • Loading branch information
LT "syreal" Jones authored Apr 16, 2020
2 parents 681aebd + f189596 commit 70a4672
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 48 deletions.
1 change: 0 additions & 1 deletion atlas-web-app/views/layouts/layout.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@
-->

<!--SCRIPTS-->
<script src="/dependencies/sails.io.js"></script>
<script src="/js/all.js"></script>
<script src="/js/api-request-delete-record.js"></script>
<script src="/js/api-request-view-records.js"></script>
Expand Down
71 changes: 24 additions & 47 deletions atlas-web-app/views/pages/view-records.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Start off View Records with first page of records with default page size
-->

<!--<script type="text/javascript" src="/dependencies/sails.io.js"></script>-->

<script>
// TODO : figure how to use a listener for Record updates
Expand All @@ -22,67 +21,45 @@ Start off View Records with first page of records with default page size
var rn_pg = -1; // this *_pg var is more for post-init stuff...
var req_pg = getParameterByName('start-pg');
var goto_pg = -1; // this *_pg var is the page we'll go to for init.
window.onload = function () {
// TODO : socket code failing specifically, switched to XHR version below
// io.socket.get('/record', function gotResponse(body, response) {
// //[Deposit dataset in invisible part of doc]
// document.getElementById("records-all").innerHTML = JSON.stringify(body);
//
// //[Get dataset from document]
// var records = JSON.parse(document.getElementById("records-all").innerHTML);
// var last_page = Math.ceil(records.length / recs_per_pg);
//
// console.log("req_pg is str");
// req_pg = parseInt(req_pg);
// if ( Number.isInteger(req_pg) ) {
// console.log("req_pg is int");
// if ( req_pg >= 1 && req_pg <= last_page ) {
// console.log("req_pg is in page range");
// goto_pg = req_pg;
// }
// } else {
// goto_pg = 1;
// }
//
// //[Display goto page]
// rn_pg = gotoCachedPage(rn_pg, goto_pg, recs_per_pg);
// document.getElementById("pg-input").placeholder = rn_pg;
//
// refreshPageNav(last_page, rn_pg);
// })
window.onload = function () {
var xhr = new XMLHttpRequest();
xhr.open('GET', '/record' );
xhr.open('GET', '/record');
xhr.onload = function () {
if ( xhr.readyState == 4 && xhr.status == '200') {
if (xhr.readyState == 4 && xhr.status == '200') {
//[Deposit dataset in invisible part of doc]
document.getElementById("records-all").innerHTML = xhr.responseText;
//[Get dataset from document]
var records = JSON.parse(document.getElementById("records-all").innerHTML);
var last_page = Math.ceil(records.length / recs_per_pg);
console.log("req_pg is str");
req_pg = parseInt(req_pg);
if ( Number.isInteger(req_pg) ) {
console.log("req_pg is int");
if ( req_pg >= 1 && req_pg <= last_page ) {
console.log("req_pg is in page range");
goto_pg = req_pg;
console.log("req_pg is str");
req_pg = parseInt(req_pg);
if (Number.isInteger(req_pg)) {
console.log("req_pg is int");
if (req_pg >= 1 && req_pg <= last_page) {
console.log("req_pg is in page range");
goto_pg = req_pg;
}
} else {
goto_pg = 1;
}
} else {
goto_pg = 1;
}
//[Display goto page]
rn_pg = gotoCachedPage(rn_pg, goto_pg, recs_per_pg);
document.getElementById("pg-input").placeholder = rn_pg;
//[Display goto page]
rn_pg = gotoCachedPage(rn_pg, goto_pg, recs_per_pg);
document.getElementById("pg-input").placeholder = rn_pg;
refreshPageNav(last_page, rn_pg);
}
refreshPageNav(last_page, rn_pg);
} else {
// [Set error message and display]
console.log("view-record window.on-load GET request had other than 200 status");
}
};
xhr.send(null);
};
// TODO : investigate using this for button logic as well?
Expand Down

0 comments on commit 70a4672

Please sign in to comment.