summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Luka Šijanec <sijanecantonluka@gmail.com>2020-03-10 19:54:09 +0100
committerAnton Luka Šijanec <sijanecantonluka@gmail.com>2020-03-10 19:54:09 +0100
commit23b17dda901e5df3b9c73fc4d9129243cbf60a15 (patch)
tree9d9003929912ad999ca540a407ab486dfa40fbe7
parent1.0.12-beta: podpora za jezike (diff)
downloadbeziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.tar
beziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.tar.gz
beziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.tar.bz2
beziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.tar.lz
beziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.tar.xz
beziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.tar.zst
beziapp-23b17dda901e5df3b9c73fc4d9129243cbf60a15.zip
-rw-r--r--index.html1
-rw-r--r--js/initialize.js28
-rw-r--r--js/setup-storage.js36
-rw-r--r--js/timetable.js2
-rw-r--r--pages/changelog.html1
-rw-r--r--pages/messaging.html4
-rw-r--r--sw.js15
7 files changed, 49 insertions, 38 deletions
diff --git a/index.html b/index.html
index 95d57dc..2a861a1 100644
--- a/index.html
+++ b/index.html
@@ -8,6 +8,7 @@
<title>BežiApp</title>
<script type="text/javascript" src="/js/lib/localforage.min.js"></script>
+ <script type="text/javascript" src="/js/setup-storage.js"></script>
<script type="text/javascript" src="/js/initialize.js"></script>
<link rel="manifest" href="/manifest.json">
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 @@
<div class="collapsible-header">Version 1.0.12-beta</div>
<div class="collapsible-body">
<ul class="collection">
+ <li class="collection-item">1.0.12.28-beta: Now update does not clear whole database => you stay logged in</li>
<li class="collection-item">Added multilanguage support</li>
</ul>
</div>
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 @@
<li><a href="/pages/settings.html" class="waves-effect"><i class="material-icons">settings</i><x-su>settings</x-su></a></li>
</ul>
<div class="container">
- <h4>Send a message</h4>
+ <h4><x-su>sendAMessage</x-su></h4>
<div class="row">
<div class="col s12">
<div class="row">
@@ -105,7 +105,7 @@
</div>
<div id="msg-added-image"></div>
</div>
- <h4>Messages</h4>
+ <h4><x-su>messages</x-su></h4>
<button class="btn waves-effect waves-light" id="msg-load-btn" onclick="loadMessages(true, 0);" type="button">
<x-su>received</x-su>
<i class="material-icons right">system_update</i>
diff --git a/sw.js b/sw.js
index ca1697e..9f9daea 100644
--- a/sw.js
+++ b/sw.js
@@ -1,15 +1,8 @@
// Change version to cause cache refresh
-const static_cache_name = "site-static-v1.0.12";
-
-// Tukej ne met notr directory namov, samo imena fajlov,
-// ker v primeru index.html to prpele do double-cachinga, oz. do velik 404
-
+const static_cache_name = "site-static-v1.0.12.28";
// Got them with find . -not -path '*/\.*' | sed "s/.*/\"&\",/" | grep -v sw.js
// sw.js NE SME BITI CACHAN, ker vsebuje verzijo!
const assets = [
-
-
-
"/css/materialize.min.css",
"/css/fontawesome.min.css",
"/css/materialicons.css",
@@ -48,6 +41,7 @@ const assets = [
"/js/meals.js",
"/js/settings.js",
"/js/lang/bundle.js",
+ "/js/setup-storage.js",
"/js/lib/materialize.min.js",
"/js/lib/jquery.min.js",
@@ -86,11 +80,12 @@ const assets = [
];
importScripts("/js/lib/localforage.min.js");
-
+importScripts("/js/setup-storage.js");
self.addEventListener("install", (evt) => {
// Add localforage.clear() if storage purge is required
evt.waitUntil(
- localforage.clear()
+ // localforage.clear()
+ setupStorage()
);
evt.waitUntil(