From 1b6f3755fc714d1deb756997d6593c28bc57266d Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Wed, 3 Apr 2019 11:01:20 +0200
Subject: [PATCH] visualization list of authors in frontend implemented

---
 .../src/main/js/gui/leftPanel/GuiUtils.js     | 50 +++++++++++++++++++
 .../main/js/gui/leftPanel/ProjectInfoPanel.js | 14 ++++++
 .../src/main/js/gui/leftPanel/SubmapPanel.js  | 28 ++++++++---
 .../js/gui/leftPanel/ProjectInfoPanel-test.js | 16 ++++++
 4 files changed, 100 insertions(+), 8 deletions(-)

diff --git a/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js b/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js
index 2e3f3e6b30..7c0aa87ea1 100644
--- a/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js
+++ b/frontend-js/src/main/js/gui/leftPanel/GuiUtils.js
@@ -436,6 +436,56 @@ GuiUtils.prototype.createAnnotationList = function (annotations, options) {
   return result;
 };
 
+/**
+ *
+ * @param {Author[]} authors
+ * @returns {HTMLElement}
+ */
+GuiUtils.prototype.createAuthorsList = function (authors) {
+  var self = this;
+  var result = Functions.createElement({type: "div", className: "minerva-annotation-group"});
+
+  for (var i = 0; i < authors.length; i++) {
+    var author = authors[i];
+    var row = document.createElement("div");
+    if (i % 2 === 0) {
+      row.className = "minerva-annotation-row-odd";
+    } else {
+      row.className = "minerva-annotation-row-even";
+    }
+
+    row.appendChild(Functions.createElement({
+      type: "div",
+      className: "minerva-annotation-counter",
+      content: "[" + (i + 1) + "]"
+    }));
+
+    var body = Functions.createElement({
+      type: "div",
+      className: "minerva-annotation-body"
+    });
+
+    var desc = author.firstName + " " + author.lastName;
+
+    var link;
+    if (author.email !== undefined) {
+      link = Functions.createElement({type: "a", href: "mailto:" + author.email, content: desc});
+    } else {
+      link = Functions.createElement({type: "span", content: desc});
+    }
+    body.appendChild(link);
+
+    if (author.organisation !== undefined) {
+      body.appendChild(Functions.createElement({type: "span", content: ", " + author.organisation}));
+    }
+
+    row.appendChild(body);
+    result.appendChild(row);
+  }
+
+  return result;
+};
+
 /**
  *
  * @param {string} [value]
diff --git a/frontend-js/src/main/js/gui/leftPanel/ProjectInfoPanel.js b/frontend-js/src/main/js/gui/leftPanel/ProjectInfoPanel.js
index 2f40e5d36b..4c61b833f0 100644
--- a/frontend-js/src/main/js/gui/leftPanel/ProjectInfoPanel.js
+++ b/frontend-js/src/main/js/gui/leftPanel/ProjectInfoPanel.js
@@ -221,6 +221,20 @@ ProjectInfoPanel.prototype._createInfoPanelGui = function () {
     referencesTab.appendChild(guiUtils.createAnnotationList(self.getProject().getModels()[0].getReferences(), {groupAnnotations: false}));
   }
 
+  if (self.getProject().getModels()[0].getAuthors().length > 0) {
+    var authorsTab = Functions.createElement({
+      type: "div"
+    });
+    infoDiv.appendChild(authorsTab);
+
+    var authors = Functions.createElement({
+      type: "h4",
+      content: 'Authors:'
+    });
+    authorsTab.appendChild(authors);
+    authorsTab.appendChild(guiUtils.createAuthorsList(self.getProject().getModels()[0].getAuthors()));
+  }
+
 
 };
 
diff --git a/frontend-js/src/main/js/gui/leftPanel/SubmapPanel.js b/frontend-js/src/main/js/gui/leftPanel/SubmapPanel.js
index 1518437ae5..150c09f771 100644
--- a/frontend-js/src/main/js/gui/leftPanel/SubmapPanel.js
+++ b/frontend-js/src/main/js/gui/leftPanel/SubmapPanel.js
@@ -64,19 +64,30 @@ SubmapPanel.prototype.createRow = function (model) {
 
   var nameTd = Functions.createElement({type: "td", content: model.getName(), style: "position:relative"});
 
-  if (model.getReferences().length > 0) {
+  if (model.getReferences().length > 0 || model.getAuthors().length > 0) {
     var referencesTab = Functions.createElement({
       type: "div",
       className: "minerva-search-data-hidden"
     });
     nameTd.appendChild(referencesTab);
 
-    var references = Functions.createElement({
-      type: "div",
-      content: 'References:'
-    });
-    referencesTab.appendChild(references);
-    referencesTab.appendChild(guiUtils.createAnnotationList(self.getProject().getModels()[0].getReferences(), {groupAnnotations: false}));
+    if (model.getReferences().length > 0) {
+      var references = Functions.createElement({
+        type: "div",
+        content: 'References:'
+      });
+      referencesTab.appendChild(references);
+      referencesTab.appendChild(guiUtils.createAnnotationList(model.getReferences(), {groupAnnotations: false}));
+    }
+
+    if (model.getAuthors().length > 0) {
+      var authors = Functions.createElement({
+        type: "div",
+        content: 'Authors:'
+      });
+      referencesTab.appendChild(authors);
+      referencesTab.appendChild(guiUtils.createAuthorsList(model.getAuthors()));
+    }
 
     var expandButton = Functions.createElement({
       type: "button",
@@ -108,7 +119,8 @@ SubmapPanel.prototype.createRow = function (model) {
   result.appendChild(openTd);
 
   return result;
-};
+}
+;
 
 /**
  *
diff --git a/frontend-js/src/test/js/gui/leftPanel/ProjectInfoPanel-test.js b/frontend-js/src/test/js/gui/leftPanel/ProjectInfoPanel-test.js
index 91df012274..d293005b21 100644
--- a/frontend-js/src/test/js/gui/leftPanel/ProjectInfoPanel-test.js
+++ b/frontend-js/src/test/js/gui/leftPanel/ProjectInfoPanel-test.js
@@ -87,4 +87,20 @@ describe('ProjectInfoPanel', function () {
     panel.destroy();
   });
 
+  it('list authors', function () {
+    var map = helper.createCustomMap();
+    map.getModel().getAuthors().push({firstName: "Piotr", lastName: "G", organisation: "LCSB", email: "a@a.lu"});
+    map.getModel().getAuthors().push({firstName: "Joe", lastName: "G", organisation: "LCSB", email: "a@a.lu"});
+
+    var panel = new ProjectInfoPanel({
+      element: testDiv,
+      customMap: map
+    });
+
+    assert.ok(testDiv.innerHTML.indexOf("Piotr") >= 0);
+    assert.ok(testDiv.innerHTML.indexOf("Joe") >= 0);
+
+    panel.destroy();
+  });
+
 });
-- 
GitLab