summaryrefslogtreecommitdiffstats
path: root/js/absences.js
diff options
context:
space:
mode:
authorrstular <rok@stular.eu>2020-05-16 20:30:14 +0200
committerrstular <rok@stular.eu>2020-05-16 20:30:29 +0200
commit4f8b436a281752fc13263cb46fe1329b1ee4e37c (patch)
tree89b580d3d270247d9eefa88764f7d95f150badb9 /js/absences.js
parentMerge branch 'dev' of github.com:beziapp/beziapp.github.io into dev (diff)
downloadbeziapp-4f8b436a281752fc13263cb46fe1329b1ee4e37c.tar
beziapp-4f8b436a281752fc13263cb46fe1329b1ee4e37c.tar.gz
beziapp-4f8b436a281752fc13263cb46fe1329b1ee4e37c.tar.bz2
beziapp-4f8b436a281752fc13263cb46fe1329b1ee4e37c.tar.lz
beziapp-4f8b436a281752fc13263cb46fe1329b1ee4e37c.tar.xz
beziapp-4f8b436a281752fc13263cb46fe1329b1ee4e37c.tar.zst
beziapp-4f8b436a281752fc13263cb46fe1329b1ee4e37c.zip
Diffstat (limited to '')
-rw-r--r--js/absences.js33
1 files changed, 19 insertions, 14 deletions
diff --git a/js/absences.js b/js/absences.js
index c0d08a7..9ff6059 100644
--- a/js/absences.js
+++ b/js/absences.js
@@ -59,30 +59,35 @@ async function loadAbsences(forceRefresh = false) {
Object.keys(date).map((key, index) => {
date[key] = new Date(Date.parse(date[key].reverse().join("-")));
});
- gsecInstance.fetchAbsences().then( (value) => {
- value.sort(function(a,b){
+ gsecInstance.fetchAbsences().then( (fetchedAbsences) => {
+ fetchedAbsences.sort((a, b) => {
// Turn your strings into dates, and then subtract them
// to get a value that is either negative, positive, or zero.
return new Date(b.date) - new Date(a.date);
});
- var fromKey = value.findIndex((processedElement, processedIndex) => {
- if(processedElement.date.getTime() >= date.from.getTime()) {
+
+ var fromKey = fetchedAbsences.findIndex((processedElement, processedIndex) => {
+ if (processedElement.date.getTime() >= date.from.getTime()) {
return true;
}
});
- var tillKey = value.reverse().findIndex((pE, pI) => {
- if(pE.date.getTime() <= date.till.getTime()) {
+
+ var tillKey = fetchedAbsences.findIndex((processedElement, processedIndex) => {
+ if (processedElement.date.getTime() > date.till.getTime()) {
return true;
}
});
- value.length = tillKey+1; // tillKey in
- value.splice(0, fromKey); // fromKey hočemo obdržati
- if (tillKey == 0 && fromKey == -1) {
- // očitno je karantena in ni nobenih izostnakov
- value.length = 0;
- }
- absences = value;
- localforage.setItem("absences", value).then((value) => {
+
+ // Both were -1, but we increased fromKey and decreased tillKey
+ // Means no absences in the provided timeframe
+ if (fromKey === 0 && tillKey === -2) {
+ fetchedAbsences = [];
+ } else {
+ fetchedAbsences = fetchedAbsences.slice(fromKey, tillKey);
+ }
+
+ absences = fetchedAbsences;
+ localforage.setItem("absences", fetchedAbsences).then((value) => {
displayData();
setLoading(false);
});