From 23b17dda901e5df3b9c73fc4d9129243cbf60a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Tue, 10 Mar 2020 19:54:09 +0100 Subject: 1.0.12.28-beta: now auto update != all db clear --- index.html | 1 + js/initialize.js | 28 +++------------------------- js/setup-storage.js | 36 ++++++++++++++++++++++++++++++++++++ js/timetable.js | 2 +- pages/changelog.html | 1 + pages/messaging.html | 4 ++-- sw.js | 15 +++++---------- 7 files changed, 49 insertions(+), 38 deletions(-) create mode 100644 js/setup-storage.js diff --git a/index.html b/index.html index 95d57dc..2a861a1 100644 --- a/index.html +++ b/index.html @@ -8,6 +8,7 @@ BežiApp + diff --git a/js/initialize.js b/js/initialize.js index b64cbcc..7bd7cd9 100644 --- a/js/initialize.js +++ b/js/initialize.js @@ -8,38 +8,16 @@ function getUrlParameter(sParam) { } } -function setupStorage() { - promises_to_run = [ - localforage.setItem("logged_in", false), - localforage.setItem("username", ""), - localforage.setItem("password", ""), - localforage.setItem("profile", {}), - localforage.setItem("timetable", []), - localforage.setItem("teachers", []), - localforage.setItem("gradings", []), - localforage.setItem("grades", []), - localforage.setItem("absences", {}), - localforage.setItem("messages", {}), - localforage.setItem("directory", {}), - localforage.setItem("meals", {}), - // localforage.setItem("chosenCapitalize", true), // poor unused feature - localforage.setItem("chosenLang", "en") - ]; - - Promise.all(promises_to_run) - .then( - window.location.replace("/login.html") - ); -} localforage.getItem("logged_in") .then( function (value) { // This code runs once the value has been loaded // from the offline store. - if (value === null) { + if (value == null) { // Setup the storage if it doesn't exist - setupStorage(); + setupStorage(true); + window.location.replace("/login.html"); } else if (value === false) { // If storage exists, but user isn't logged in, redirect to login window.location.replace("/login.html"); diff --git a/js/setup-storage.js b/js/setup-storage.js new file mode 100644 index 0000000..8a6604c --- /dev/null +++ b/js/setup-storage.js @@ -0,0 +1,36 @@ +async function setupStorage(force = false) { + let logged_in, setup_promises; + promises_check_if_already_installed = [ + localforage.getItem("logged_in").then( function(val) { + console.log("[setupStorage] logged in status: "+val); + logged_in = val; + }) + ]; + await Promise.all(promises_check_if_already_installed); + let promises_update = [ + localforage.setItem("profile", {}), + localforage.setItem("timetable", []), + localforage.setItem("teachers", []), + localforage.setItem("gradings", []), + localforage.setItem("grades", []), + localforage.setItem("absences", {}), + localforage.setItem("messages", {}), + localforage.setItem("directory", {}), + localforage.setItem("meals", {}) + ]; + if(logged_in && force == false) { // torej, če je že bila prijava narejena, ne posodobi backwards-compatible vrednosti (username, password,...) + await Promise.all(promises_update); + console.log("[setupStorage] user logged in: only updated"); + } else { + let promises_first_install = [ + localforage.setItem("logged_in", false), + localforage.setItem("username", ""), + localforage.setItem("password", ""), + localforage.setItem("chosenLang", "en") + ]; + await localforage.clear(); + await Promises.all(promises_first_install); + console.log("[setupStorage] user not logged in: set up whole database"); + } +} + diff --git a/js/timetable.js b/js/timetable.js index 740731a..2aecdb0 100644 --- a/js/timetable.js +++ b/js/timetable.js @@ -8,7 +8,7 @@ function checkLogin() { localforage.getItem("logged_in").then((value) => { // This code runs once the value has been loaded // from the offline store. - if (value !== true) { + if (value != true) { window.location.replace("/index.html"); } }).catch((err) => { diff --git a/pages/changelog.html b/pages/changelog.html index ad4c9e8..4b34997 100644 --- a/pages/changelog.html +++ b/pages/changelog.html @@ -51,6 +51,7 @@
Version 1.0.12-beta
diff --git a/pages/messaging.html b/pages/messaging.html index 2740540..99f12db 100644 --- a/pages/messaging.html +++ b/pages/messaging.html @@ -58,7 +58,7 @@
  • settingssettings
  • -

    Send a message

    +

    sendAMessage

    @@ -105,7 +105,7 @@
    -

    Messages

    +

    messages