From b86ef6379a2e4b4df90dabefe2b48054035da800 Mon Sep 17 00:00:00 2001 From: rstular Date: Thu, 14 May 2020 13:31:33 +0200 Subject: Messaging redesign done DO NOT MERGE - redesigning messages CSS update DNM - css update DNM - hopefully last CSS update for now DNM - I take it back, one more DNM - debugging DNM - Still debugging DNM DNM DNM DNM - WIP tab interface DNM - better storage management DNM - tabs update DNM - messaging layout update Messaging layout update DNM - styling DNM - Starting to add "compose functionality" DNM - WIP FAB DNM - WIP - modal not dismissible DNM - Modal layout WIP DNM - Encryption checkbox DNM DNM DNM DNM DNM - Hopefully done? DNM - Removed comments --- css/styles.css | 27 +++++++++ js/lang/bundle.js | 6 +- js/messaging.js | 133 ++++++++++++++++++++++++++++++++++-------- pages-src/messaging.bvr | 152 ++++++++++++++++++++++++++++-------------------- pages/messaging.html | 152 ++++++++++++++++++++++++++++-------------------- 5 files changed, 320 insertions(+), 150 deletions(-) diff --git a/css/styles.css b/css/styles.css index a06c906..c728463 100644 --- a/css/styles.css +++ b/css/styles.css @@ -5,6 +5,7 @@ --color-primary-light: rgba(230, 250, 231, 1); --color-invalid: rgba(192, 0, 0, 1); --background-color: rgba(255, 255, 255, 1); + --background-accent: rgba(0, 156, 101, 0.2); } body { @@ -162,3 +163,29 @@ a.collection-item { text-align: center; z-index: 60; } + +/* Tabs */ +.tab a { + color: var(--color-secondary) !important; +} + +.tab a:hover { + color: var(--color-primary) !important; +} + +.tab a.active { + color: var(--color-primary) !important; +} + +.tab a:focus.active { + background-color: var(--background-accent) !important; +} + +.tabs .indicator { + background-color: var(--color-primary) !important; +} + +/* Floating action button */ +.fab-new-message { + background-color: var(--color-secondary) !important; +} diff --git a/js/lang/bundle.js b/js/lang/bundle.js index 6e6c5b6..bf1a361 100644 --- a/js/lang/bundle.js +++ b/js/lang/bundle.js @@ -181,6 +181,7 @@ var langstrings = { unauthorizedAbsence: "unauthorized", doesNotCount: "does not count", // messaging + loadingMessages: "Loading messages...", sendAMessage: "send a message", recipient: "recipient", messageSubject: "subject", @@ -189,6 +190,7 @@ var langstrings = { note: "note", largeImagesNote: "GimB servers don't like large messages, so only very small images may be attached or your message will not be delivered", attachedImages: "attached images", + encryptMessage: "Encrypt message", passwordForE2EE: "password for encrypting the message", messages: "messages", received: "received", @@ -361,6 +363,7 @@ var langstrings = { unauthorizedAbsence: "neopravičeno", doesNotCount: "ne šteje", // messaging + loadingMessages: "Nalagam sporočila...", sendAMessage: "pošlji sporočilo", recipient: "prejemnik", messageSubject: "zadeva", @@ -369,13 +372,14 @@ var langstrings = { note: "opomba", largeImagesNote: "GimB strežniki ne marajo velikih sporočil, zato lahko pošiljate le zelo majhne slike, v nasprotnem primeru sporočilo ne bo dostavljeno", attachedImages: "pripete slike", + encryptMessage: "Šifriraj sporočilo", passwordForE2EE: "geslo za šifriranje sporočila", messages: "sporočila", received: "prejeta", sent: "poslana", deleted: "izbrisana", messageStorageUsed: "zasedenost shrambe sporočil v tej mapi", - maxMessagesNote: "v vsaki mapi imate lahko največ sto dvajset sporočil. Starejša sporočila ne bodo prikazana. Redno brišite sporočila, da se izognete morebitnim težavam.", + maxMessagesNote: "v vsaki mapi imate lahko največ 120 sporočil. Starejša sporočila ne bodo prikazana. Redno brišite sporočila, da se izognete morebitnim težavam.", loadMessageBody: "naloži telo sporočila", thisMessageWasEncrypted: "to sporočilo je šifriral BežiApp", enterPassword: "vnesite geslo", diff --git a/js/messaging.js b/js/messaging.js index 145711d..a061ca9 100644 --- a/js/messaging.js +++ b/js/messaging.js @@ -3,8 +3,14 @@ const DIRECTORY_URL = "/directory.json"; const ENCRYPTED_MESSAGE_REGEX = /(\S+?)/g; -// "Global" object for name directory +// "Global" object for name directory and messages var directory = null; +var messages = { + "0": [], + "1": [], + "2": [] +} +var current_tab = 0; async function checkLogin() { localforage.getItem("logged_in").then(function (value) { @@ -85,10 +91,8 @@ function populateAutocomplete() { minLength: 0 }); - if(window.location.hash.length > 1) { + if (window.location.hash.length > 1 && !window.location.hash.substring(1).startsWith("beziapp")) { $("#full-name").val(decodeURIComponent(window.location.hash.substring(1))); - } else { - $("#full-name").val(getUrlParameter("m")); } M.updateTextFields(); @@ -105,7 +109,7 @@ function setLoading(state) { } // Function, responsible for fetching and displaying data -async function loadMessages(force_refresh = true, katera = 0) { +async function loadMessages(force_refresh = true, messageType = 0) { setLoading(true); // Load required data let promises_to_run = [ @@ -122,7 +126,7 @@ async function loadMessages(force_refresh = true, katera = 0) { Promise.all(promises_to_run).then(() => { - if (messages === null || force_refresh) { + if (messages[messageType] == null || messages[messageType].length === 0 || force_refresh) { $.ajax({ url: API_ENDPOINT, crossDomain: true, @@ -130,7 +134,7 @@ async function loadMessages(force_refresh = true, katera = 0) { "u": username, "p": password, "m": "fetchsporocilaseznam", - "a": katera // Message type, see API doc for details + "a": messageType // Message type, see API doc for details }, dataType: "json", cache: false, @@ -144,9 +148,9 @@ async function loadMessages(force_refresh = true, katera = 0) { } else { // Save messages & populate view // console.log(data); // debug - localforage.setItem("messages", data).then((value) => { - messages = value; - displayData(); + messages[messageType.toString()] = data; + localforage.setItem("messages", messages).then((value) => { + displayData(messageType); setLoading(false); }); } @@ -158,7 +162,7 @@ async function loadMessages(force_refresh = true, katera = 0) { } }) } else { - displayData(); + displayData(messageType); setLoading(false); } }); @@ -293,13 +297,27 @@ function displayMessage(id, data) { } // Function for displaying data -function displayData() { - let msg_list = $("#msg-list"); +function displayData(messageType) { + let div_selector = ""; + switch (messageType) { + case 0: + div_selector = "#beziapp-received"; + break; + case 1: + div_selector = "#beziapp-sent"; + break; + case 2: + div_selector = "#beziapp-deleted"; + break; + } + + let msg_list = $(div_selector); msg_list.html(""); - messages.forEach(element => { - if (element["zadeva"].substr(0, 14) != "beziapp-ctlmsg") { + messages[messageType].forEach(element => { + if (!element["zadeva"].startsWith("beziapp-ctlmsg")) { + msg_list.append(` -
+
@@ -311,8 +329,8 @@ function displayData() { onclick="loadMsg('${filterXSS(element["id"])}')" type="submit" > - Load message body - system_update + Load message + move_to_inbox

@@ -329,16 +347,30 @@ function displayData() { > reply - ${filterXSS(element["posiljatelj"])} » ${filterXSS(element["datum"]["dan"])}. ${filterXSS(element["datum"]["mesec"])}. ${filterXSS(element["datum"]["leto"])} at ${filterXSS(element["cas"]["ura"])} : ${filterXSS(element["cas"]["minuta"])} + ${filterXSS(element["posiljatelj"])} » ${filterXSS(element["datum"]["dan"])}. ${filterXSS(element["datum"]["mesec"])}. ${filterXSS(element["datum"]["leto"])} at ${filterXSS(element["cas"]["ura"]).padStart(2, "0")}:${filterXSS(element["cas"]["minuta"]).padStart(2, "0")}
`); - } + } }); + $("#storage-bar").show(); - $("#storage-progressbar").width(Number(Number(messages.length / 120) * 100).toFixed(2) + "%"); - $("#storage-desc").html( `${messages.length}/120 ${s("messages")} ${$("#storage-progressbar").width()}`); + $("#storage-progressbar").width(Number(Number(getNumMessages(messageType) / 120) * 100).toFixed(2) + "%"); + $("#storage-desc").html( `${getNumMessages(messageType)}/120 ${s("messages")} ${$("#storage-progressbar").width()}`); +} + +// -1 = cumulative +function getNumMessages(messageType = -1) { + if (messageType === -1) { + let sum = 0; + for (const [messageType, messageList] of Object.entries(messages)) { + sum += messageList.length; + } + return sum; + } else { + return (messages[messageType].length ?? 0); + } } async function sendMessage(recipient_number, subject, body) { @@ -442,6 +474,20 @@ function setupEventListeners() { // Verify recipient when input loses focus $("#full-name").on("blur", validateName); + // Setup refresh icon + $("#refresh-icon").click(() => { + loadMessages(true, current_tab); + }); + + // Setup checkbox handler + $("#encrypt-checkbox").change(function() { + if (this.checked) { + $("#encryption-key-input").prop("hidden", false); + } else { + $("#encryption-key-input").prop("hidden", true); + } + }); + // Button to send message $("#msg-send").click(() => { localforage.getItem("directory").then(function (value) { @@ -510,6 +556,48 @@ document.addEventListener("DOMContentLoaded", () => { loadDirectory(); setupEventListeners(); + // Setup tabs + const tabs = document.querySelectorAll(".tabs"); + const tab_options = { + // swipeable: true, // TODO: figure out how to fix height when it's enabled (it's good for UX to have it enabled) + onShow: (tab) => { + if ($(tab).hasClass("active")) { + switch (tab.id) { + case "beziapp-received": + current_tab = 0; + loadMessages(false, 0); + break; + case "beziapp-sent": + current_tab = 1; + loadMessages(false, 1); + break; + case "beziapp-deleted": + current_tab = 2; + loadMessages(false, 2); + break; + } + } + } + }; + var instance = M.Tabs.init(tabs, tab_options); + + // Setup floating action button + const fab_options = { + hoverEnabled: false, + toolbarEnabled: false + } + const fab_elem = document.querySelectorAll(".fixed-action-btn"); + var instances = M.FloatingActionButton.init(fab_elem, fab_options); + + // Setup modals + const modal_elems = document.querySelectorAll('.modal'); + const modal_options = { + onOpenStart: () => { $("#fab-new").hide() }, + onCloseEnd: () => { $("#fab-new").show() }, + dismissible: false + }; + var instances = M.Modal.init(modal_elems, modal_options); + var receivedmessages = null; loadMessages(true, 0); M.updateTextFields(); @@ -517,5 +605,4 @@ document.addEventListener("DOMContentLoaded", () => { // Setup side menu const menus = document.querySelectorAll(".side-menu"); M.Sidenav.init(menus, { edge: "right", draggable: true }); - }); \ No newline at end of file diff --git a/pages-src/messaging.bvr b/pages-src/messaging.bvr index ad1d33a..dff3d00 100644 --- a/pages-src/messaging.bvr +++ b/pages-src/messaging.bvr @@ -39,75 +39,18 @@ menu + + refresh + - <@?i navigation@> + <@?i navigation@>
-

sendAMessage

-
-
-
- account_circle - - -
-
- subject - - -
-
- -
-
-
-
- mode_edit - - -
-
- -
-
- -
-
- -
-
-
-

messages

- - - -
-

+

messageStorageUsed: @@ -124,7 +67,90 @@ maxMessagesNote

-

+ +
+ +
+
+

loadingMessages

+

loadingMessages

+

loadingMessages

+
+
+ + +
+ + mode_edit + +
+ + + diff --git a/pages/messaging.html b/pages/messaging.html index 515770a..31c4749 100644 --- a/pages/messaging.html +++ b/pages/messaging.html @@ -42,12 +42,15 @@ menu + + refresh + - +