From 0d993d68207764100b3c47dc7c646c5862f03245 Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Thu, 3 Dec 2020 14:01:49 +0100
Subject: [PATCH] Bookmarks: Add name and recordtype to export data

---
 src/core/js/ext_bookmarks.js             | 28 ++++++++++++++++++++++--
 test/core/js/modules/ext_bookmarks.js.js |  2 +-
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/core/js/ext_bookmarks.js b/src/core/js/ext_bookmarks.js
index 1e858203..2bd37df6 100644
--- a/src/core/js/ext_bookmarks.js
+++ b/src/core/js/ext_bookmarks.js
@@ -662,19 +662,43 @@ $(document).ready(function () {
             return $(await transaction.retrieveEntityById(id)).find("Version").attr("id");
         }
 
+        const get_name = async function (id) {
+            if (id.indexOf("@") > -1) {
+              const entity = $(`[data-bmval='${id}']`);
+              if (entity.length > 0) {
+                  return getEntityName(entity[0]) || "";
+              }
+            }
+            return $(await transaction.retrieveEntityById(id)).attr("name");
+        }
+
+        const get_rt = async function (id) {
+            if (id.indexOf("@") > -1) {
+              const entity = $(`[data-bmval='${id}']`);
+              if (entity.length > 0) {
+                  return getParents(entity[0]).join("/");
+              }
+            }
+            const parent_names = $(await transaction.retrieveEntityById(id))
+                .find("Parent").toArray().map(x => x.getAttribute("name"))
+            return parent_names.join("/");
+        }
+
         // these columns will be in the export
-        const tsv_columns = ["ID", "Version", "URI", "Path"];
+        const tsv_columns = ["ID", "Version", "URI", "Path", "Name", "RecordType"];
         // functions for collecting the export data for a particular bookmarked id.
         const data_getters = {
             "ID": (id) => id.indexOf("@") > -1 ? id.split("@")[0] : id,
             "Version": async (id) => id.indexOf("@") > -1 ? id.split("@")[1] : await get_version(id),
             "Path": get_path,
             "URI": async (id) => get_context_root() + id + (id.indexOf("@") > -1 ? "" : ("@" + await get_version(id))),
+            "Name": get_name,
+            "RecordType": get_rt,
         };
 
         // we cannot cache these because the the values might change unnoticed
         // when the head moves to a newer version.
-        const data_no_cache = ["ID", "Version", "URI", "Path"];
+        const data_no_cache = ["ID", "Version", "URI", "Path", "Name", "RecordType"];
 
         const config = {
             get_context_root: get_context_root,
diff --git a/test/core/js/modules/ext_bookmarks.js.js b/test/core/js/modules/ext_bookmarks.js.js
index fe880621..831df742 100644
--- a/test/core/js/modules/ext_bookmarks.js.js
+++ b/test/core/js/modules/ext_bookmarks.js.js
@@ -69,7 +69,7 @@ QUnit.test("get_export_table", async function (assert) {
     var table = await ext_bookmarks.get_export_table(
       ["123@ver1", "456@ver2", "789@ver3", "101112", "@131415"]);
     assert.equal(table,
-      `data:text/csv;charset=utf-8,ID${TAB}Version${TAB}URI${TAB}Path${NEWL}123${TAB}ver1${TAB}${context_root}123@ver1${TAB}testpath_123@ver1${NEWL}456${TAB}ver2${TAB}${context_root}456@ver2${TAB}testpath_456@ver2${NEWL}789${TAB}ver3${TAB}${context_root}789@ver3${TAB}testpath_789@ver3${NEWL}101112${TAB}abcHead${TAB}${context_root}101112@abcHead${TAB}testpath_101112${NEWL}${TAB}131415${TAB}${context_root}@131415${TAB}testpath_@131415`);
+      `data:text/csv;charset=utf-8,ID${TAB}Version${TAB}URI${TAB}Path${TAB}Name${TAB}RecordType${NEWL}123${TAB}ver1${TAB}${context_root}123@ver1${TAB}testpath_123@ver1${TAB}${TAB}${NEWL}456${TAB}ver2${TAB}${context_root}456@ver2${TAB}testpath_456@ver2${TAB}${TAB}${NEWL}789${TAB}ver3${TAB}${context_root}789@ver3${TAB}testpath_789@ver3${TAB}${TAB}${NEWL}101112${TAB}abcHead${TAB}${context_root}101112@abcHead${TAB}testpath_101112${TAB}${TAB}${NEWL}${TAB}131415${TAB}${context_root}@131415${TAB}testpath_@131415${TAB}${TAB}`);
 
 });
 
-- 
GitLab