diff --git a/frontend/src/views/TimeRecords.vue b/frontend/src/views/TimeRecords.vue index bb49961..002a5ee 100644 --- a/frontend/src/views/TimeRecords.vue +++ b/frontend/src/views/TimeRecords.vue @@ -7,6 +7,20 @@ v-on:edit-timeRecord="editTimeRecord" /> + + + + + mdi-arrow-left + + + + + mdi-arrow-right + + + + @@ -14,6 +28,7 @@ mdi-plus + @@ -30,7 +45,10 @@ export default { }, data() { return { - timeRecords: "" + timeRecords: "", + page: sessionStorage.getItem("page"), + haveNextPage: "", + havePrevPage: "" }; }, methods: { @@ -63,16 +81,33 @@ export default { sessionStorage.setItem("timeRecordEditSelfLink", selfLink); this.$router.push("/createtimerecord"); + }, + nextPage() { + var pageTMP = parseInt(this.page) + 1; + sessionStorage.setItem("page", pageTMP); + location.reload(); + }, + prevPage() { + var pageTMP = parseInt(this.page) - 1; + sessionStorage.setItem("page", pageTMP); + location.reload(); } }, created() { var xhttp = new XMLHttpRequest(); var records; + var recordLinks; + + if (this.page == null) { + this.page = 0; + } + sessionStorage.removeItem("page"); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { var recordsDB = JSON.parse(xhttp.responseText); records = recordsDB._embedded.records; + recordLinks = recordsDB._links; } }; xhttp.open( @@ -80,6 +115,8 @@ export default { baseUri + "/records/search/allForUser?username=" + sessionStorage.getItem("username") + + "&sort=startdate,desc&page=" + + this.page + "&projection=overview", false ); @@ -87,6 +124,12 @@ export default { xhttp.setRequestHeader("Authorization", sessionStorage.getItem("jwt")); xhttp.send(null); + if (recordLinks.next != undefined) { + this.haveNextPage = true; + } + if (recordLinks.prev != undefined) { + this.havePrevPage = true; + } for (let index = 0; index < records.length; index++) { var record = records[index]; @@ -97,7 +140,7 @@ export default { var min = time % 60; record.duration = hours + "h " + min + "min"; var start = record.startdate; - records[index].completeStartDate = start; + records[index].completeStartDate = start; start = start.split("T"); records[index].startdate = start[1]; records[index].date = start[0]; @@ -110,11 +153,7 @@ export default { records[index].enddate = "pending"; } } - records.sort(function(a, b) { - a = new Date(a.completeStartDate); - b = new Date(b.completeStartDate); - return a>b ? -1 : a