You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2021/12/10 19:29:21 UTC

[incubator-ponymail-foal] 01/02: Add in treeview list mode

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git

commit ad20497fbef6b7a1175b0743a6e1b67469b7ed28
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Fri Dec 10 20:27:59 2021 +0100

    Add in treeview list mode
    
    This fixes #153.
---
 webui/js/source/listview-header.js   |  8 +++---
 webui/js/source/listview-treeview.js | 51 ++++++++++++++++++++++++++++++++++++
 webui/js/source/primer.js            |  4 +++
 3 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/webui/js/source/listview-header.js b/webui/js/source/listview-header.js
index 7b3192d..bd0cd26 100644
--- a/webui/js/source/listview-header.js
+++ b/webui/js/source/listview-header.js
@@ -29,7 +29,7 @@ function listview_header(state, json) {
         list_title = "Virtual inbox, past 30 days";
     }
     let blobs = json.emails ? json.emails : [];
-    if (G_current_listmode == 'threaded') blobs = json.thread_struct;
+    if (G_current_listmode == 'threaded' || G_current_listmode == 'treeview') blobs = json.thread_struct;
 
     if (G_current_year && G_current_month) {
         list_title += ", %s %u".format(MONTHS[G_current_month - 1], G_current_year);
@@ -105,12 +105,14 @@ function listview_header(state, json) {
         class: 'glyphicon glyphicon-refresh'
     }, " "));
     chevrons.inject(crefresh);
-
+    console.log(G_current_listmode)
     if (state && state.pos != undefined) {
         if (G_current_listmode == 'threaded') {
             listview_threaded(json, state.pos);
-        } else {
+        } else if (G_current_listmode == 'flat') {
             listview_flat(json, state.pos);
+        } else {
+            listview_treeview(json, state.pos);
         }
     }
 
diff --git a/webui/js/source/listview-treeview.js b/webui/js/source/listview-treeview.js
new file mode 100644
index 0000000..7677e97
--- /dev/null
+++ b/webui/js/source/listview-treeview.js
@@ -0,0 +1,51 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+function find_email(json, id) {
+    for (let eml of json.emails) {
+        if (id === eml.id) return eml
+    }
+}
+
+function listview_treeview(json, start) {
+    let list = document.getElementById('emails');
+    list.innerHTML = "";
+    let s = start || 0;
+    let email_ordered = [];
+    for (let thread of json.thread_struct) {
+        email_ordered.push(find_email(json, thread.tid));
+        for (let child of thread.children) email_ordered.push(find_email(json, child.tid));
+    }
+    if (email_ordered.length) {
+        for (let n = s; n < (s + G_current_per_page); n++) {
+            let z = email_ordered.length - n - 1; // reverse order by default
+            if (email_ordered[z]) {
+                let item = listview_flat_element(email_ordered[z], z);
+                list.inject(item);
+
+                // Hidden placeholder for expanding email(s)
+                let placeholder = new HTML('div', {
+                    class: G_chatty_layout ? 'email_placeholder_chatty' : 'email_placeholder',
+                    id: 'email_%u'.format(z)
+                });
+                list.inject(placeholder);
+            }
+        }
+    } else {
+        list.inject(txt("No emails found..."));
+    }
+}
diff --git a/webui/js/source/primer.js b/webui/js/source/primer.js
index b058415..f83bd56 100644
--- a/webui/js/source/primer.js
+++ b/webui/js/source/primer.js
@@ -33,6 +33,8 @@ function renderListView(state, json) {
     listview_header(state, json);
     if (G_current_listmode == 'threaded') {
         listview_threaded(json, 0);
+    } else if (G_current_listmode == 'treeview') {
+        listview_treeview(json, 0);
     } else {
         listview_flat(json, 0);
     }
@@ -189,6 +191,8 @@ function render_virtual_inbox(state, json) {
         listview_header(state, G_current_json);
         if (G_current_listmode == 'threaded') {
             listview_threaded(G_current_json, 0);
+        } else if (G_current_listmode == 'treeview') {
+            listview_treeview(G_current_json, 0);
         } else {
             listview_flat(G_current_json, 0);
         }