Skip to content
Snippets Groups Projects
Commit 47b4cd75 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

publication list uses data from api

parent f070416a
No related branches found
No related tags found
1 merge request!5Frontend refactor
......@@ -25,11 +25,16 @@ PublicationListDialog.prototype.createPublicationListDialogGui = function() {
var self = this;
var head = Functions.createElement({
type : "thead",
content : "<tr><th>Pubmed ID</th></tr>"
content : "<tr>" + "<th>Pubmed ID</th>" + //
"<th>Title</th>" + //
"<th>Authors</th>" + //
"<th>Journal</th>" + //
"<th>Year</th>" + //
"<th>Elements on map</th>" + //
"</tr>"//
});
var body = Functions.createElement({
type : "tbody",
content : "<tr><td>1234</td></tr><tr><td>2</td></tr><tr><td>4</td></tr>"
});
var tableElement = Functions.createElement({
type : "table",
......@@ -42,6 +47,38 @@ PublicationListDialog.prototype.createPublicationListDialogGui = function() {
self.tableElement = tableElement;
self.getElement().appendChild(tableElement);
};
PublicationListDialog.prototype._dataTableAjaxCall = function(data, callback, settings) {
logger.debug(data);
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;
});
};
PublicationListDialog.prototype.show = function() {
var self = this;
$(self.getElement()).dialog("open");
......@@ -52,19 +89,7 @@ PublicationListDialog.prototype.show = function() {
ordering : false,
searching : false,
ajax : function(data, callback, settings) {
var out = [];
for (var i = data.start, ien = data.start + data.length; i < ien; i++) {
out.push([ i + '-1' ]);
}
ServerConnector.getPublications({start: data.start, length:data.length}).then(function(publicationList){
console.log(publicationList);
callback({
draw : data.draw,
recordsTotal : data.totalSize,
recordsFiltered : data.totalSize,
data : out,
});
})
self._dataTableAjaxCall(data, callback, settings);
},
});
}
......
"use strict";
var Helper = require('../helper');
require("../mocha-config.js");
var PublicationListDialog = require('../../../main/js/gui/PublicationListDialog');
var chai = require('chai');
var assert = chai.assert;
var logger = require('../logger');
describe('PublicationListDialog', function() {
var helper;
before(function() {
helper = new Helper();
});
it('contructor', function() {
var div = testDiv;
var map = helper.createCustomMap();
var dialog = new PublicationListDialog({
element : div,
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();
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment