From 9bb9cb84c1a30c909dbcc6273e685daece08abf1 Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Tue, 11 Apr 2017 13:12:20 +0200
Subject: [PATCH] list of publications contain also information about element

---
 .../src/main/js/gui/PublicationListDialog.js  | 78 +++++++++++++------
 .../src/test/js/gui/ProjectInfoPanel-test.js  | 12 +--
 .../test/js/gui/PublicationListDialog-test.js | 26 ++++---
 ...9171&projectId=sample&token=MOCK_TOKEN_ID& |  1 +
 .../projectId=sample&token=MOCK_TOKEN_ID&     |  2 +-
 ...3508&projectId=sample&token=MOCK_TOKEN_ID& |  1 +
 6 files changed, 77 insertions(+), 43 deletions(-)
 create mode 100644 frontend-js/testFiles/apiCalls/project/getElements/columns=&id=329166,329171&projectId=sample&token=MOCK_TOKEN_ID&
 create mode 100644 frontend-js/testFiles/apiCalls/project/getReactions/columns=&id=153508&projectId=sample&token=MOCK_TOKEN_ID&

diff --git a/frontend-js/src/main/js/gui/PublicationListDialog.js b/frontend-js/src/main/js/gui/PublicationListDialog.js
index e77cde3e39..a377671f60 100644
--- a/frontend-js/src/main/js/gui/PublicationListDialog.js
+++ b/frontend-js/src/main/js/gui/PublicationListDialog.js
@@ -1,9 +1,14 @@
 "use strict";
 
+var Promise = require("bluebird");
+
 /* exported logger */
 
 var AbstractGuiElement = require('./AbstractGuiElement');
+var Alias = require('../map/data/Alias');
 var GuiConnector = require('../GuiConnector');
+var IdentifiedElement = require('../map/data/IdentifiedElement');
+var Reaction = require('../map/data/Reaction');
 
 var Functions = require('../functions');
 var logger = require('../logger');
@@ -15,6 +20,8 @@ function PublicationListDialog(params) {
   $(self.getElement()).dialog({
     autoOpen : false,
     resizable : false,
+    width : window.innerWidth / 2,
+    height : window.innerHeight / 2,
   });
 }
 
@@ -49,34 +56,55 @@ PublicationListDialog.prototype.createPublicationListDialogGui = function() {
 };
 
 PublicationListDialog.prototype._dataTableAjaxCall = function(data, callback, settings) {
-  logger.debug(data);
+  var self = this;
   return ServerConnector.getPublications({
     start : data.start,
     length : data.length
-  }).then(function(publicationList) {
-    var out = [];
-    console.log(publicationList);
-    for (var i=0;i<publicationList.data.length;i++) {
-      var publication = publicationList.data[i].publication;
-      
-      var row = [];
-      row[0] = "<a href='"+publication.link+"'>"+publication.id+"</a>";
-      row[1] = publication.title;
-      row[2] = publication.authors.join();
-      row[3] = publication.journal;
-      row[4] = publication.year;
-      row[5] = "xxx";
-      out.push(row);
-    }
-    logger.debug(out);
-    callback({
-      draw : data.draw,
-      recordsTotal : publicationList.totalSize,
-      recordsFiltered : publicationList.totalSize,
-      data : out,
-    });
-    return null;
-  });  
+  })
+      .then(
+          function(publicationList) {
+            var out = [];
+            var allElements = [];
+            for (var i = 0; i < publicationList.data.length; i++) {
+              var publication = publicationList.data[i].publication;
+              var elements = publicationList.data[i].elements;
+
+              var row = [];
+              row[0] = "<a href='" + publication.link + "'>" + publication.id + "</a>";
+              row[1] = publication.title;
+              row[2] = publication.authors.join();
+              row[3] = publication.journal;
+              row[4] = publication.year;
+              row[5] = "<div>";
+              for (var j = 0; j < elements.length; j++) {
+                row[5] += "<a name='" + elements[j].id + "' href='#'>" + elements[j].type + ":" + elements[j].id
+                    + "</a>, ";
+                allElements.push(new IdentifiedElement(elements[j]));
+              }
+              row[5] += "</div>";
+              out.push(row);
+            }
+            callback({
+              draw : data.draw,
+              recordsTotal : publicationList.totalSize,
+              recordsFiltered : publicationList.totalSize,
+              data : out,
+            });
+            var promises = [];
+            allElements.forEach(function(element) {
+              promises.push(self.getMap().getSubmodelById(element.getModelId()).getModel().getByIdentifiedElement(
+                  element, true).then(function(elementData) {
+                var name = null
+                if (elementData instanceof Alias) {
+                  name = elementData.getName();
+                } else if (elementData instanceof Reaction) {
+                  name = elementData.getReactionId();
+                }
+                $("a[name=" + elementData.getId() + "]", $(self.getElement())).html(name);
+              }));
+            });
+            return Promise.all(promises);
+          });
 };
 
 PublicationListDialog.prototype.show = function() {
diff --git a/frontend-js/src/test/js/gui/ProjectInfoPanel-test.js b/frontend-js/src/test/js/gui/ProjectInfoPanel-test.js
index c1b6ac5cff..38661467d0 100644
--- a/frontend-js/src/test/js/gui/ProjectInfoPanel-test.js
+++ b/frontend-js/src/test/js/gui/ProjectInfoPanel-test.js
@@ -50,12 +50,14 @@ describe('ProjectInfoPanel', function() {
   });
 
   it('show publication list', function() {
-    var div = testDiv;
-    var panel = new ProjectInfoPanel({
-      element : div,
-      customMap : helper.createCustomMap(),
+    return ServerConnector.getProject().then(function(project) {
+      var div = testDiv;
+      var panel = new ProjectInfoPanel({
+        element : div,
+        customMap : helper.createCustomMap(project),
+      });
+      return panel.showPublicationListDialog();
     });
-    return panel.showPublicationListDialog();
   });
 
 });
diff --git a/frontend-js/src/test/js/gui/PublicationListDialog-test.js b/frontend-js/src/test/js/gui/PublicationListDialog-test.js
index da0de3e546..cdbf05695c 100644
--- a/frontend-js/src/test/js/gui/PublicationListDialog-test.js
+++ b/frontend-js/src/test/js/gui/PublicationListDialog-test.js
@@ -27,22 +27,24 @@ describe('PublicationListDialog', function() {
       customMap : map
     });
     assert.equal(logger.getWarnings().length, 0);
-    
+
     dialog.destroy();
   });
 
   it('_dataTableAjaxCall', function() {
-    var div = testDiv;
-    var dialog = new PublicationListDialog({
-      element : div,
-      customMap : helper.createCustomMap(),
-    });
-    return dialog._dataTableAjaxCall({
-      start : 0,
-      length : 10
-    }, function() {
-    }, {}).then(function(){
-      dialog.destroy();
+    return ServerConnector.getProject().then(function(project) {
+      var div = testDiv;
+      var dialog = new PublicationListDialog({
+        element : div,
+        customMap : helper.createCustomMap(project),
+      });
+      return dialog._dataTableAjaxCall({
+        start : 0,
+        length : 10
+      }, function() {
+      }, {}).then(function() {
+        dialog.destroy();
+      });
     });
   });
 
diff --git a/frontend-js/testFiles/apiCalls/project/getElements/columns=&id=329166,329171&projectId=sample&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/project/getElements/columns=&id=329166,329171&projectId=sample&token=MOCK_TOKEN_ID&
new file mode 100644
index 0000000000..5ddb6b2880
--- /dev/null
+++ b/frontend-js/testFiles/apiCalls/project/getElements/columns=&id=329166,329171&projectId=sample&token=MOCK_TOKEN_ID&
@@ -0,0 +1 @@
+[{"formerSymbols":[],"references":[],"modelId":15781,"synonyms":[],"description":"","type":"Protein","name":"gfsdhj","bounds":{"x":160.0,"y":332.0,"width":119.0,"height":63.0},"id":329171},{"symbol":"CNC","formerSymbols":[],"references":[{"name":"REACT_20130","type":"Reactome","link":"http://www.reactome.org/PathwayBrowser/#REACT_20130","idObject":860342},{"name":"2141","type":"HGNC","link":"http://www.genenames.org/cgi-bin/gene_symbol_report?hgnc_id\u003d2141","idObject":860343},{"name":"6546","type":"Kegg Genes","idObject":860344},{"name":"NP_001106272.1","type":"RefSeq","link":"http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?val\u003dNP_001106272.1","idObject":860345},{"name":"NP_001106271.1","type":"RefSeq","link":"http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?val\u003dNP_001106271.1","idObject":860346},{"name":"NP_001106273.1","type":"RefSeq","link":"http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?val\u003dNP_001106273.1","idObject":860347},{"name":"NP_001239553.1","type":"RefSeq","link":"http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?val\u003dNP_001239553.1","idObject":860348},{"name":"PA314","type":"PharmGKB Pathways","link":"http://www.pharmgkb.org/pathway/PA314","idObject":860349},{"name":"NP_066920.1","type":"RefSeq","link":"http://www.ncbi.nlm.nih.gov/entrez/viewer.fcgi?val\u003dNP_066920.1","idObject":860350},{"name":"6546","type":"Entrez Gene","link":"http://www.ncbi.nlm.nih.gov/gene/6546","idObject":860351}],"modelId":15781,"synonyms":["CNC","NCX1"],"description":"ymbol: CNC\r\nghfjkghfdjkghkdf\r\nfdghjkfdhgjkdfgjhdf\r\njdsfkljsdklfjsdf\r\nsjdkfjsdklfjkl\r\ndsjfkjl\r\nsdfkkjfskldjfkls\r\n\nRecName: Full\u003dSodium/calcium exchanger 1; AltName: Full\u003dNa(+)/Ca(2+)-exchange protein 1; Flags: Precursor;","fullName":"Carney complex, multiple neoplasia and lentiginosis","type":"Protein","name":"CNC","bounds":{"x":11.0,"y":236.0,"width":118.0,"height":66.0},"id":329166}]
\ No newline at end of file
diff --git a/frontend-js/testFiles/apiCalls/project/getMetaData/projectId=sample&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/project/getMetaData/projectId=sample&token=MOCK_TOKEN_ID&
index fa052d1df6..4a62ac3988 100644
--- a/frontend-js/testFiles/apiCalls/project/getMetaData/projectId=sample&token=MOCK_TOKEN_ID&
+++ b/frontend-js/testFiles/apiCalls/project/getMetaData/projectId=sample&token=MOCK_TOKEN_ID&
@@ -1 +1 @@
-{"version":"0","idObject":14898,"name":"UNKNOWN DISEASE MAP","projectId":"sample","description":"","map":{"name":"UNKNOWN DISEASE MAP2","idObject":15781,"tileSize":256,"width":1305,"height":473,"minZoom":2,"maxZoom":5,"layouts":[{"modelId":15781,"name":"Pathways and compartments","status":"Not available","progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/_nested0","creator":"","inputDataAvailable":"false","idObject":14081},{"modelId":15781,"name":"Network","status":"Not available","progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/_normal0","creator":"","inputDataAvailable":"false","idObject":14082},{"modelId":15781,"name":"Empty","status":"Not available","progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/_empty0","creator":"","inputDataAvailable":"false","idObject":14083}],"submodels":[],"centerLatLng":{"lat":79.18277721779353,"lng":-135.06093781915757},"topLeftLatLng":{"lat":85.05112877980659,"lng":-180.0},"bottomRightLatLng":{"lat":81.26928406550978,"lng":-90.0}},"overviewImageViews":[]}
\ No newline at end of file
+{"version":"0","idObject":15781,"name":"UNKNOWN DISEASE MAP","projectId":"sample","description":"","map":{"name":"UNKNOWN DISEASE MAP2","idObject":15781,"tileSize":256,"width":1305,"height":473,"minZoom":2,"maxZoom":5,"layouts":[{"modelId":15781,"name":"Pathways and compartments","status":"Not available","progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/_nested0","creator":"","inputDataAvailable":"false","idObject":14081},{"modelId":15781,"name":"Network","status":"Not available","progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/_normal0","creator":"","inputDataAvailable":"false","idObject":14082},{"modelId":15781,"name":"Empty","status":"Not available","progress":"0.00","directory":"5e8ff9bf55ba3508199d22e984129be6/_empty0","creator":"","inputDataAvailable":"false","idObject":14083}],"submodels":[],"centerLatLng":{"lat":79.18277721779353,"lng":-135.06093781915757},"topLeftLatLng":{"lat":85.05112877980659,"lng":-180.0},"bottomRightLatLng":{"lat":81.26928406550978,"lng":-90.0}},"overviewImageViews":[]}
\ No newline at end of file
diff --git a/frontend-js/testFiles/apiCalls/project/getReactions/columns=&id=153508&projectId=sample&token=MOCK_TOKEN_ID& b/frontend-js/testFiles/apiCalls/project/getReactions/columns=&id=153508&projectId=sample&token=MOCK_TOKEN_ID&
new file mode 100644
index 0000000000..3ecad6cdb4
--- /dev/null
+++ b/frontend-js/testFiles/apiCalls/project/getReactions/columns=&id=153508&projectId=sample&token=MOCK_TOKEN_ID&
@@ -0,0 +1 @@
+[{"modelId":15781,"reactants":"329166","reactionId":"re21","id":153508,"type":"State transition","lines":[{"start":{"x":129.00000000000003,"y":269.9853478599471},"end":{"x":217.3857151822324,"y":271.4614610007049},"type":"START"},{"start":{"x":217.3857151822324,"y":271.4614610007049},"end":{"x":217.98919008325365,"y":297.73178548394236},"type":"MIDDLE"},{"start":{"x":218.17291548409574,"y":305.7296755167626},"end":{"x":218.77639038511697,"y":332.0},"type":"END"}],"modifiers":"","centerPoint":{"x":218.0810527836747,"y":301.7307305003525},"products":"329171"}]
\ No newline at end of file
-- 
GitLab