diff options
Diffstat (limited to 'assets/js')
-rw-r--r-- | assets/js/colors.js | 46 | ||||
-rw-r--r-- | assets/js/gradings.js | 20 | ||||
-rw-r--r-- | assets/js/gsec.js | 4 | ||||
-rw-r--r-- | assets/js/lang/bundle.js.bvr | 10 | ||||
-rw-r--r-- | assets/js/settings.js | 21 | ||||
-rw-r--r-- | assets/js/setup-storage.js.bvr | 1 | ||||
-rw-r--r-- | assets/js/timetable.js | 40 |
7 files changed, 91 insertions, 51 deletions
diff --git a/assets/js/colors.js b/assets/js/colors.js new file mode 100644 index 0000000..d06861a --- /dev/null +++ b/assets/js/colors.js @@ -0,0 +1,46 @@ +/* adapted from https://git.šijanec.eu/siska/beziapp-sam-lepo */ + +function linMap(c, mn, mx) { + return c*(mx-mn)+mn; +} +function getDecimal(n) { + return (n-Math.floor(n)); +} +function mapColorPalete(c, palete) { + let poz = c*(palete.length-1); + let col1 = palete[Math.floor(poz)]; /* https://git.šijanec.eu/siska/beziapp-sam-lepo */ + let col2 = palete[Math.ceil(poz)]; /* made by siska */ + return (Math.floor(linMap(getDecimal(poz),col1[0],col2[0])).toString(16).padStart(2,0)+ + Math.floor(linMap(getDecimal(poz),col1[1],col2[1])).toString(16).padStart(2,0)+ + Math.floor(linMap(getDecimal(poz),col1[2],col2[2])).toString(16).padStart(2,0)).toUpperCase(); +} +/** + * + * Convert last 3 bytes of an integer to RGB color + * @param {integer} input_integer Integer that will be converted to RGB color + * @returns {string} Hex color code + * + */ +function intToRGB(i, palete = null) { + if (palete == null) { + var c = (i & 0x00FFFFFF) + .toString(16) + .toUpperCase(); + + return "00000".substring(0, 6 - c.length) + c; + } else return mapColorPalete((i & 0xFF) / 0xFF, palete); +} + + +/** + * + * Convert a given string to hex color + * @param {string} input_string Input string + * @returns {string} Hex RGB color + */ +function getHexColorFromString(str) { + if (urnikTheme == "privzeta") + return "#" + intToRGB(hashCode(str)); + else + return "#" + intToRGB(hashCode(str), [[38, 70, 83], [42, 157, 143], [233, 196, 106], [244, 162, 97], [231, 111, 81]]); +} diff --git a/assets/js/gradings.js b/assets/js/gradings.js index 92e696d..7db4c98 100644 --- a/assets/js/gradings.js +++ b/assets/js/gradings.js @@ -32,14 +32,6 @@ function hashCode(str) { // java String#hashCode return hash; } -function intToRGB(i) { - var c = (i & 0x00FFFFFF) - .toString(16) - .toUpperCase(); - - return "00000".substring(0, 6 - c.length) + c; -} - // http://www.w3.org/TR/AERT#color-contrast function getForegroundFromBackground(background_color) { let color_hex = background_color.replace("#", ""); @@ -56,11 +48,6 @@ function getForegroundFromBackground(background_color) { } } -function getHexColorFromString(str) { - return "#" + intToRGB(hashCode(str)); -} -// -------------------------------------------------- - function getDateString() { let date = new Date(); @@ -171,9 +158,12 @@ function setupPickers() { instances = M.Datepicker.init(elems, options); } +var urnikTheme = "privzeta"; - -document.addEventListener("DOMContentLoaded", () => { +document.addEventListener("DOMContentLoaded", async function () { + urnikTheme = await localforage.getItem("urnikTheme"); + if (urnikTheme == null || urnikTheme == undefined || urnikTheme == false) + urnikTheme = "privzeta"; checkLogin(); // Calendar setup var calendarEl = document.getElementById("calendar"); diff --git a/assets/js/gsec.js b/assets/js/gsec.js index 3dcde88..2f5400d 100644 --- a/assets/js/gsec.js +++ b/assets/js/gsec.js @@ -236,12 +236,14 @@ class gsec { var razred = desc[2]; var teacher = desc[3]; var place = desc[4]; + var nadomescanje = urnikElement.parentElement.classList.contains("flagS"); urnik[day][period] = { "subject": subject, "acronym": abkurzung, "class": razred, "teacher": teacher, - "place": place + "place": place, + "substitution": nadomescanje }; } resolve(urnik); diff --git a/assets/js/lang/bundle.js.bvr b/assets/js/lang/bundle.js.bvr index 125d3c6..c75e965 100644 --- a/assets/js/lang/bundle.js.bvr +++ b/assets/js/lang/bundle.js.bvr @@ -159,6 +159,7 @@ var langstrings = { settings: "settings", // timetable noPeriods: "no periods in selected week", + substitution: "substitution", // gradings date: "date", description: "description", @@ -244,7 +245,7 @@ var langstrings = { mealsUsageNote: "click on a date to open the collapsible menu with choices and click on a specific meal to select it. Reload the meals when you're done and check the entries.", lunchesNote: "app was not tested with lunches in mind. Meals probably won't work with lunches and having a lunch subscription may even break its functionality.", mealNotShownNote: "editable meals are highlighted in gold, read-only meals are highlighted in grey and cannot be changed. Meals that provide no options for menus are not shown for clarity, same applies for days where there are no meals", - mealsContributeNote: "you are welcome to contribute to the LopolisAPI project and add features, such as checkouts.", + mealsContributeNote: "you are welcome to contribute to the BežiApp project.", authenticationError: "authentication error", lopolisAPIConnectionError: "LopolisAPI server connection error", errorGettingMenus: "error getting menus", @@ -315,6 +316,7 @@ var langstrings = { on: "on", off: "off", selectErrorReporting: "should error reports be submitted to the developers?", + urnikTheme: "timetable theme", // gsec gsecErrNet: "GimSIS connection error", gsecErrLogin: "GimSIS login error (bad password?), try logging out", @@ -361,6 +363,7 @@ var langstrings = { browserNotSupported: "BežiApp ne bo deloval na vaši napravi, če ne posodobite vašega Internetnega brskalnika", // timetable noPeriods: "ni ur v izbranem tednu", + substitution: "nadomeščanje", // index timetable: "urnik", gradings: "ocenjevanja", @@ -457,7 +460,7 @@ var langstrings = { mealsUsageNote: "kliknite na datum za prikaz menijev, nato pa si enega izberite s klikom na ime menija. Po nastavitvi menijev ponovno naložite menije in se prepričajte o pravilnih nastavitvah.", lunchesNote: "aplikacija ni testirana za naročanje na kosila, zato verjetno to ne deluje. Če ste naročeni na kosila lahko naročanje na menije sploh ne deluje ali pa deluje narobe.", mealNotShownNote: "obroki, označeni z zlato so nastavljivi, tisti, označeni s sivo, niso, če pa pri kakšnem dnevu obroka ni, pa pomeni, da ga ni moč nastaviti ali pa da ne obrok ne obstaja", - mealsContributeNote: "vabimo vas k urejanju LopolisAPI programa za upravljanje z meniji.", + mealsContributeNote: "vabimo vas k urejanju BežiApp programa.", authenticationError: "napaka avtentikacije", lopolisAPIConnectionError: "napaka povezave na LopolisAPI strežnik", errorGettingMenus: "napaka branja menijev", @@ -517,7 +520,7 @@ var langstrings = { themeLight: "svetel izgled (privzeto)", themeDark: "temen izgled", themeNight: "nočni izgled", - themeSet: "izgled nastavljen, odprite neko drugo stran da se spremembe uveljavijo", + themeSet: "izgled nastavljen, odprite neko drugo stran, da se spremembe uveljavijo", selectTheme: "izberite željen izgled", errorReportingSet: "nastavitev pošiljanja napak izbrana", errorReporting: "pošiljanje napak", @@ -528,6 +531,7 @@ var langstrings = { triggerAgreement: "strinjam se z zgoraj navedenimi pogoji", triggerWarningSet: "spremenili ste stanje dodatnih nastavitev", additionalOptions: "dodatne nastavitve", + urnikTheme: "izgled urnika", // gsec gsecErrNet: "napaka povezave na GimSIS", gsecErrLogin: "prijava v GimSIS ni uspela (napačno geslo?), poskusite se odjaviti", diff --git a/assets/js/settings.js b/assets/js/settings.js index 3106f14..2a721d7 100644 --- a/assets/js/settings.js +++ b/assets/js/settings.js @@ -14,6 +14,13 @@ async function setTheme(targetTheme) { }); } +async function setUrnikTheme(targetTheme) { + localforage.setItem("urnikTheme", targetTheme).then((value) => { + console.log("Urnik theme set" + value); + UIAlert(D("themeSet"), "setUrnikTheme(): themeSet") + }); +} + async function setErrorReporting(targetE) { localforage.setItem("errorReporting", targetE).then((value) => { console.log("ErrorReporing set: " + value); @@ -82,7 +89,9 @@ document.addEventListener("DOMContentLoaded", async () => { $("#select-errorreporting").on("change", function() { setErrorReporting($(this).find(":selected").val()); }); - + $("#select-urniktheme").on("change", function() { + setUrnikTheme($(this).find(":selected").val()); + }); localforage.getItem("chosenLang").then((value) => { let selectedLanguage = value; if(value == null || value.length < 1) { @@ -90,7 +99,12 @@ document.addEventListener("DOMContentLoaded", async () => { } $(`#option-${selectedLanguage}`).attr("selected", true); }).catch(() => {}); - + localforage.getItem("urnikTheme").then((value) => { + if (value == null || value.length < 1) { + value = "privzeta"; + } + $(`#option-${value}`).attr("selected", true); + }).catch(()=>{}); localforage.getItem("theme").then((value) => { let selectedTheme = value; if(value == null || value.length < 1) { @@ -124,6 +138,9 @@ document.addEventListener("DOMContentLoaded", async () => { var elems = document.querySelectorAll(".errorreporting-select"); M.FormSelect.init(elems, {}); + var elems = document.querySelectorAll(".urniktheme-select"); + M.FormSelect.init(elems, {}); + // Setup language select dropdown var elems = document.querySelectorAll(".lang-select"); M.FormSelect.init(elems, {}); diff --git a/assets/js/setup-storage.js.bvr b/assets/js/setup-storage.js.bvr index 3d3b554..75dfdf8 100644 --- a/assets/js/setup-storage.js.bvr +++ b/assets/js/setup-storage.js.bvr @@ -21,6 +21,7 @@ async function setupStorage(force = false) { localforage.setItem("directory", {}), //\\ well I could remember my own code but I didn't. localforage.setItem("meals", {}), localforage.setItem("lastUpdate", 0), + localforage.setItem("urnikTheme", "privzeta"), localforage.setItem("triggerWarningAccepted", false) ]; diff --git a/assets/js/timetable.js b/assets/js/timetable.js index 85c555a..f4fa01d 100644 --- a/assets/js/timetable.js +++ b/assets/js/timetable.js @@ -42,21 +42,6 @@ function hashCode(str) { // java String#hashCode return hash; } -/** - * - * Convert last 3 bytes of an integer to RGB color - * @param {integer} input_integer Integer that will be converted to RGB color - * @returns {string} Hex color code - * - */ -function intToRGB(i) { - var c = (i & 0x00FFFFFF) - .toString(16) - .toUpperCase(); - - return "00000".substring(0, 6 - c.length) + c; -} - // http://www.w3.org/TR/AERT#color-contrast /** * @@ -78,16 +63,6 @@ function getForegroundFromBackground(background_color) { return "#ffffff"; } } - -/** - * - * Convert a given string to hex color - * @param {string} input_string Input string - * @returns {string} Hex RGB color - */ -function getHexColorFromString(str) { - return "#" + intToRGB(hashCode(str)); -} // -------------------------------------------------- // ---------DATE FUNCTION------------- @@ -214,6 +189,7 @@ function displayTimetable(weekly_timetable, date_object) { class: lesson["class"], teacher: lesson["teacher"], classroom: lesson["place"], + substitution: lesson["substitution"], start: lesson_times[0].substring(0, 5), end: lesson_times[1].substring(0, 5) } @@ -224,9 +200,10 @@ function displayTimetable(weekly_timetable, date_object) { start: date_string + " " + lesson_times[0], end: date_string + " " + lesson_times[1], backgroundColor: bg_color, - textColor: fg_color + textColor: fg_color, }; - + if (lesson["substitution"]) + lesson_object.borderColor = "red"; transformed_timetable.push(lesson_object); }); @@ -246,7 +223,7 @@ function eventClickHandler(eventClickInfo) { let lesson_class = lesson_metadata["class"]; let lesson_duration = lesson_metadata["start"] + " - " + lesson_metadata["end"]; - $("#lesson-subject").text(lesson_subject); + $("#lesson-subject").text(lesson_subject + (lesson_metadata["substitution"] ? (" (" + s("substitution") + ")") : "")); $("#lesson-teacher").text(lesson_teacher); $("#lesson-class").text(lesson_class); $("#lesson-classroom").text(lesson_classroom); @@ -256,10 +233,13 @@ function eventClickHandler(eventClickInfo) { M.Sidenav.getInstance(modal).open(); } +var urnikTheme = "privzeta"; -document.addEventListener("DOMContentLoaded", () => { +document.addEventListener("DOMContentLoaded", async function() { + urnikTheme = await localforage.getItem("urnikTheme"); + if (urnikTheme == null || urnikTheme == undefined || urnikTheme == false) + urnikTheme = "privzeta"; checkLogin(); - let calendarEl = document.getElementById("calendar"); calendar_obj = new FullCalendar.Calendar(calendarEl, { plugins: ["timeGrid"], |