From 97b0fbc4be7cd1a9e30ec0bcec286a52f1a1c7d9 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Tue, 18 Jul 2017 16:43:48 +0200
Subject: [PATCH] client dialog for publication supports sorting and searching

---
 .../annotation/services/PubmedParser.java     |  8 ++++-
 frontend-js/src/main/css/global.css           |  4 +++
 frontend-js/src/main/js/ServerConnector.js    |  3 ++
 .../js/gui/leftPanel/PublicationListDialog.js | 31 ++++++++++++++++---
 .../leftPanel/PublicationListDialog-test.js   |  4 ++-
 ...sortOrder=asc&start=0&token=MOCK_TOKEN_ID& |  1 +
 6 files changed, 45 insertions(+), 6 deletions(-)
 create mode 100644 frontend-js/testFiles/apiCalls/projects/sample/models/all/publications/length=10&sortColumn=pubmedId&sortOrder=asc&start=0&token=MOCK_TOKEN_ID&

diff --git a/annotation/src/main/java/lcsb/mapviewer/annotation/services/PubmedParser.java b/annotation/src/main/java/lcsb/mapviewer/annotation/services/PubmedParser.java
index 4c2ea656fa..f676f785ac 100644
--- a/annotation/src/main/java/lcsb/mapviewer/annotation/services/PubmedParser.java
+++ b/annotation/src/main/java/lcsb/mapviewer/annotation/services/PubmedParser.java
@@ -10,6 +10,7 @@ import javax.xml.xpath.XPathConstants;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
 
+import org.apache.commons.lang3.SerializationException;
 import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.w3c.dom.Document;
@@ -116,7 +117,12 @@ public class PubmedParser extends CachableInterface implements IExternalService
 	 */
 	public Article getPubmedArticleById(Integer id) throws PubmedSearchException {
 		String queryString = "pubmed: " + id;
-		Article result = articleSerializer.xmlToObject(getCacheNode(queryString));
+		Article result = null;
+		try {
+			result = articleSerializer.xmlToObject(getCacheNode(queryString));
+		} catch (SerializationException e) {
+			logger.warn("Problem with deserialization of the string: " + queryString);
+		}
 		if (result != null && result.getTitle() != null) {
 			return result;
 		} else {
diff --git a/frontend-js/src/main/css/global.css b/frontend-js/src/main/css/global.css
index da6f6288d1..a6b0e2f6d9 100644
--- a/frontend-js/src/main/css/global.css
+++ b/frontend-js/src/main/css/global.css
@@ -377,4 +377,8 @@ table.mapInfoBoxResultsTable, table.mapInfoBoxResultsTable th, table.mapInfoBoxR
 .minerva-export-dual-listbox-container {
 	padding: 10px;
 	float: left;
+}
+
+table.minerva-publication-table td {
+	padding: 0px;
 }
\ No newline at end of file
diff --git a/frontend-js/src/main/js/ServerConnector.js b/frontend-js/src/main/js/ServerConnector.js
index a12a922ce8..d109546174 100644
--- a/frontend-js/src/main/js/ServerConnector.js
+++ b/frontend-js/src/main/js/ServerConnector.js
@@ -1248,6 +1248,9 @@ ServerConnector.getPublications = function(params) {
   var filterParams = {
     start : params.start,
     length : params.length,
+    sortColumn : params.sortColumn,
+    sortOrder : params.sortOrder,
+    search : params.search,
   };
   return self.getProjectId(params.projectId).then(function(result) {
     queryParams.projectId = result;
diff --git a/frontend-js/src/main/js/gui/leftPanel/PublicationListDialog.js b/frontend-js/src/main/js/gui/leftPanel/PublicationListDialog.js
index 20b4711ee3..1ea977520e 100644
--- a/frontend-js/src/main/js/gui/leftPanel/PublicationListDialog.js
+++ b/frontend-js/src/main/js/gui/leftPanel/PublicationListDialog.js
@@ -17,10 +17,11 @@ function PublicationListDialog(params) {
   var self = this;
   self.createPublicationListDialogGui();
   $(self.getElement()).dialog({
+    title : "Publication list",
     autoOpen : false,
     resizable : false,
-    width : window.innerWidth / 2,
-    height : window.innerHeight / 2,
+    width : Math.max(window.innerWidth / 2, window.innerWidth - 100),
+    height : Math.max(window.innerHeight / 2, window.innerHeight - 100),
   });
 }
 
@@ -44,6 +45,7 @@ PublicationListDialog.prototype.createPublicationListDialogGui = function() {
   });
   var tableElement = Functions.createElement({
     type : "table",
+    className : "minerva-publication-table",
     style : "width: 100%",
   });
 
@@ -56,9 +58,13 @@ PublicationListDialog.prototype.createPublicationListDialogGui = function() {
 
 PublicationListDialog.prototype._dataTableAjaxCall = function(data, callback) {
   var self = this;
+  logger.info(data);
   return ServerConnector.getPublications({
     start : data.start,
     length : data.length,
+    sortColumn : self.getColumnsDefinition()[data.order[0].column].name,
+    sortOrder : data.order[0].dir,
+    search : data.search.value,
   })
       .then(
           function(publicationList) {
@@ -114,11 +120,12 @@ PublicationListDialog.prototype.show = function() {
     return new Promise(function(resolve) {
       $(self.tableElement).dataTable({
         serverSide : true,
-        ordering : false,
-        searching : false,
+        ordering : true,
+        searching : true,
         ajax : function(data, callback, settings) {
           resolve(self._dataTableAjaxCall(data, callback, settings));
         },
+        columns : self.getColumnsDefinition(),
       });
     });
   } else {
@@ -127,6 +134,22 @@ PublicationListDialog.prototype.show = function() {
 
 };
 
+PublicationListDialog.prototype.getColumnsDefinition = function() {
+  return [ {
+    name : "pubmedId"
+  }, {
+    name : "authors"
+  }, {
+    name : "journal"
+  }, {
+    name : "year"
+  }, {
+    orderable : false,
+    searchable : false,
+    name : "elemnts"
+  } ]
+};
+
 PublicationListDialog.prototype.destroy = function() {
   $(this.getElement()).dialog("destroy");
 };
diff --git a/frontend-js/src/test/js/gui/leftPanel/PublicationListDialog-test.js b/frontend-js/src/test/js/gui/leftPanel/PublicationListDialog-test.js
index 7810667ba3..33f51cd844 100644
--- a/frontend-js/src/test/js/gui/leftPanel/PublicationListDialog-test.js
+++ b/frontend-js/src/test/js/gui/leftPanel/PublicationListDialog-test.js
@@ -36,7 +36,9 @@ describe('PublicationListDialog', function() {
       });
       return dialog._dataTableAjaxCall({
         start : 0,
-        length : 10
+        length : 10,
+        order: [ { column: 0, dir: 'asc' } ],
+        search: { value: '', regex: false }
       }, function(){
         callbackCalled = true;
       });
diff --git a/frontend-js/testFiles/apiCalls/projects/sample/models/all/publications/length=10&sortColumn=pubmedId&sortOrder=asc&start=0&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/projects/sample/models/all/publications/length=10&sortColumn=pubmedId&sortOrder=asc&start=0&token=MOCK_TOKEN_ID&
new file mode 100644
index 0000000000..c4097f530a
--- /dev/null
+++ b/frontend-js/testFiles/apiCalls/projects/sample/models/all/publications/length=10&sortColumn=pubmedId&sortOrder=asc&start=0&token=MOCK_TOKEN_ID&
@@ -0,0 +1 @@
+{"totalSize":1,"data":[{"elements":[{"modelId":15781,"id":153508,"type":"REACTION"}],"publication":{"resource":"123","link":"http://www.ncbi.nlm.nih.gov/pubmed/123","id":860355,"type":"PUBMED","article":{"title":"The importance of an innervated and intact antrum and pylorus in preventing postoperative duodenogastric reflux and gastritis.","authors":["Keighley MR"," Asquith P"," Edwards JA"," Alexander-Williams J."],"journal":"The British journal of surgery","year":1975,"link":"http://www.ncbi.nlm.nih.gov/pubmed/123","id":"123","citationCount":12,"stringAuthors":"Keighley MR,  Asquith P,  Edwards JA,  Alexander-Williams J."}}}],"start":0,"length":1}
\ No newline at end of file
-- 
GitLab