Adopt API for meta data
Change-Id: I1615261a765325516a1b838bd87075de480556f3
diff --git a/dev/js/src/api.js b/dev/js/src/api.js
index 89534be..b87eb1f 100644
--- a/dev/js/src/api.js
+++ b/dev/js/src/api.js
@@ -57,6 +57,25 @@
/**
+ * Retrieve information about a document.
+ */
+ KorAP.API.getTextInfo = function (doc, param, cb) {
+
+ // doc is a KorAP.Match object
+ var url = KorAP.URL;
+ url += '/' + match.textSigle;
+
+ if (param['fields'] !== undefined) {
+ url += '?fields='; // TODO!
+ }
+ else {
+ url += '?fields=@all';
+ }
+ KorAP.API.getJSON(url, cb);
+ };
+
+
+ /**
* Retrieve information about collections
*/
KorAP.API.getCollections = function (cb) {
diff --git a/dev/js/src/match.js b/dev/js/src/match.js
index 63fa55a..bca7f09 100644
--- a/dev/js/src/match.js
+++ b/dev/js/src/match.js
@@ -190,19 +190,23 @@
var ops = d.createElement('div');
ops.classList.add('action', 'bottom', 'button-group');
-
+
+ /*
+ Temporarily disabled
var meta = ops.addE('span');
meta.addT('Meta');
meta.setAttribute('title', loc.SHOW_META);
meta.classList.add('meta');
+ */
+ // TODO: Rename anno
var info = ops.addE('span');
- info.addT('Anno');
+ info.addT(loc.SHOWINFO);
info.setAttribute('title', loc.SHOWINFO);
info.classList.add('info');
var tree = ops.addE('span');
- tree.addT('+ Tree');
+ tree.addT(loc.ADDTREE);
tree.setAttribute('title', loc.ADDTREE);
tree.classList.add('tree');
@@ -213,12 +217,14 @@
);
// Click on meta - add meta (unless already there)
+ /*
meta.addEventListener(
'click', function (e) {
e.halt();
that.info().showMeta();
}
);
+ */
// Click on token annotations - add token annotations (unless already there)
info.addEventListener(
diff --git a/dev/js/src/match/info.js b/dev/js/src/match/info.js
index a72b66f..ba7214e 100644
--- a/dev/js/src/match/info.js
+++ b/dev/js/src/match/info.js
@@ -141,8 +141,35 @@
},
- getMetaData : function (metaInfo, cb) {
- // ...
+ getMetaData : function (cb) {
+ KorAP.API.getTextInfo(
+ this._match, {}, function (textResponse) {
+
+ if (textResponse === undefined) {
+ cb(null);
+ return;
+ };
+
+ var doc = textResponse["document"];
+
+
+ if (doc === undefined) {
+ cb(null);
+ return;
+ };
+
+ var fields = doc["fields"];
+ if (fields === undefined) {
+ cb(null);
+ return;
+ };
+
+ // Add metainfo to matchview
+ cb(matchMetaClass.create(
+ this._match, fields
+ ));
+ }
+ );
},
@@ -160,6 +187,11 @@
'layer' : layer
},
function (matchResponse) {
+ if (matchResponse === undefined) {
+ cb(null);
+ return;
+ };
+
// Get snippet from match info
if (matchResponse["snippet"] !== undefined) {
// Todo: This should be cached somehow
@@ -284,33 +316,29 @@
metaTable.classList.add('metatable', 'loading');
this.element().appendChild(metaTable);
- // TODO: This is part of the getMeta!
+ /*
+ * This was temporary
var metaInfo = this._match.element().getAttribute('data-info');
-
if (metaInfo)
metaInfo = JSON.parse(metaInfo);
-
+ */
var that = this;
- // There is metainfo
- if (metaInfo) {
-
+ this.getMetaData(function (meta) {
// Load data
metaTable.classList.remove('loading');
- // Add metainfo to matchview
- var metaElem = matchMetaClass.create(this._match).element(metaInfo);
- metaTable.appendChild(metaElem);
+ metaTable.appendChild(meta.element());
// Add button
- this._addButton('close', metaTable, function (e) {
+ that._addButton('close', metaTable, function (e) {
this.parentNode.removeChild(this);
that._visibleMeta = false;
e.halt();
});
- };
+ });
- // Load data
+ // Do not load any longer
metaTable.classList.remove('loading');
},
diff --git a/dev/js/src/match/meta.js b/dev/js/src/match/meta.js
index 8237935..05e1f3b 100644
--- a/dev/js/src/match/meta.js
+++ b/dev/js/src/match/meta.js
@@ -27,23 +27,24 @@
// Localization values
const loc = KorAP.Locale;
- loc.METADATA = loc.METADATA || 'Metadata';
+ loc.METADATA = loc.METADATA || 'Metadata';
return {
/**
* Create new match object
*/
- create : function (match) {
- return Object.create(this)._init(match);
+ create : function (match, fields) {
+ return Object.create(this)._init(match, fields);
},
/**
* Initialize object
*/
- _init : function (match) {
+ _init : function (match, fields) {
this._match = match;
- this.opened = false;
+ this._fields = fields;
+ // this.opened = false;
return this;
},
@@ -57,26 +58,35 @@
/**
* Create match reference view.
*/
- element : function (metaInfo) {
+ element : function () {
if (this._element !== undefined)
return this._element;
-
- /*
- var header = metaTable.appendChild(
- document.createElement('h6')
- );
- header.appendChild(
- document.createElement('div')
- ).appendChild(
- document.createTextNode(loc.METADATA)
- );
- */
+ if (this._fields === null)
+ return;
var metaDL = document.createElement('dl');
this._element = metaDL;
+ var fields = this._fields;
+
+ // TODO:
+ // This should only remember array positions by index
+ // and keep all other field information intact
+ var metaInfo = {};
+ for (var i in fields) {
+ var value = fields[i].value;
+ if (value instanceof Array) {
+ metaInfo[fields[i].key] = value.join(", ");
+ }
+ else {
+ metaInfo[fields[i].key] = value;
+ };
+ };
+
+ // console.log(fields);
+
// TODO: Meta fields should be separated
var keys = Object.keys(metaInfo);
for (var i in keys.sort()) {