blob: 3cc7512a1ab39efb2a9179e6d923a0456a27c3d0 [file] [log] [blame]
Akrona0ea3c32018-12-14 18:33:48 +01001define(['match/corpusByMatch','match/attachement','util'], function (cbmClass, attClass) {
Akrond4b000b2018-01-28 18:33:14 +01002
Akronbd342982018-01-25 18:01:46 +01003 // Localization values
Akron0b489ad2018-02-02 16:49:32 +01004 const loc = KorAP.Locale;
Akron0ad7cd22018-02-08 18:03:06 +01005 loc.METADATA = loc.METADATA || 'Metadata';
Akronbd342982018-01-25 18:01:46 +01006
Akron24866cf2018-01-23 20:22:01 +01007 return {
8
9 /**
10 * Create new match object
11 */
Akron0ad7cd22018-02-08 18:03:06 +010012 create : function (match, fields) {
13 return Object.create(this)._init(match, fields);
Akron24866cf2018-01-23 20:22:01 +010014 },
15
16 /**
17 * Initialize object
18 */
Akron0ad7cd22018-02-08 18:03:06 +010019 _init : function (match, fields) {
Akron24866cf2018-01-23 20:22:01 +010020 this._match = match;
Akron0ad7cd22018-02-08 18:03:06 +010021 this._fields = fields;
22 // this.opened = false;
Akron24866cf2018-01-23 20:22:01 +010023 return this;
24 },
25
26 /**
27 * Get match object
28 */
29 match : function () {
30 return this._match;
31 },
32
33 /**
34 * Create match reference view.
35 */
Akron0ad7cd22018-02-08 18:03:06 +010036 element : function () {
Akron24866cf2018-01-23 20:22:01 +010037 if (this._element !== undefined)
38 return this._element;
Akronbd342982018-01-25 18:01:46 +010039
Akron0ad7cd22018-02-08 18:03:06 +010040 if (this._fields === null)
41 return;
Akronbd342982018-01-25 18:01:46 +010042
Akronaeceda72018-02-02 20:44:06 +010043 var metaDL = document.createElement('dl');
Akron2f979122018-07-25 17:00:23 +020044 metaDL.classList.add("flex");
Akronbd342982018-01-25 18:01:46 +010045
Akronaeceda72018-02-02 20:44:06 +010046 this._element = metaDL;
Akron24866cf2018-01-23 20:22:01 +010047
Akronabd6e352018-11-19 15:36:42 +010048 let fields = this._fields;
Akron0ad7cd22018-02-08 18:03:06 +010049
Akronabd6e352018-11-19 15:36:42 +010050 // Copy original array position to object
51 // before sorting by key title
52 let posInMetaArray = {};
Akronb50964a2020-10-12 11:44:37 +020053 fields.forEach((f,i) => posInMetaArray[f["key"]] = i);
Akronabd6e352018-11-19 15:36:42 +010054
Akron7dd32822018-10-01 19:38:31 +020055
Akron24866cf2018-01-23 20:22:01 +010056 // TODO: Meta fields should be separated
Akronabd6e352018-11-19 15:36:42 +010057 // Sort all meta keys alphabetically
Akron678c26f2020-10-09 08:52:50 +020058 Object.keys(posInMetaArray).sort().forEach(function(k) {
59 let field = fields[posInMetaArray[k]]; // This is the object
Akron7dd32822018-10-01 19:38:31 +020060
61 // Ignore internal IDs
Akron24866cf2018-01-23 20:22:01 +010062 if (k !== "UID" &&
63 k !== "corpusID" &&
64 k !== "docID" &&
65 k !== "textID" &&
Akron8b592d42018-01-26 18:33:06 +010066 /*
Akron7dd32822018-10-01 19:38:31 +020067 k !== "corpusSigle" &&
68 k !== "docSigle" &&
Akron8b592d42018-01-26 18:33:06 +010069 */
Akron24866cf2018-01-23 20:22:01 +010070 k !== "layerInfos") {
71
Akronabd6e352018-11-19 15:36:42 +010072 const metaL = document.createElement('div');
hebasta24fbc9e2018-04-12 13:47:50 +020073
Akronabd6e352018-11-19 15:36:42 +010074 const dt = metaL.addE('dt');
Akronc4568382018-03-06 20:16:12 +010075 dt.addT(k);
76 dt.setAttribute("title", k);
hebasta24fbc9e2018-04-12 13:47:50 +020077
Akronabd6e352018-11-19 15:36:42 +010078 let metaDescr = field["value"];
Akrond45a1702018-11-19 18:15:17 +010079 metaDD = metaL.addE('dd');
80 metaDD.setAttribute('data-type', field["type"]);
Akrona0ea3c32018-12-14 18:33:48 +010081
hebasta24fbc9e2018-04-12 13:47:50 +020082 if(metaDescr instanceof Array){
Akronb50964a2020-10-12 11:44:37 +020083 metaDD.classList.add("metakeyvalues");
84 metaDescr.forEach(function(md) {
Akrona0ea3c32018-12-14 18:33:48 +010085 if (field["type"] === 'type:attachement') {
Akronb50964a2020-10-12 11:44:37 +020086 let att = attClass.create(md);
Akrona0ea3c32018-12-14 18:33:48 +010087 if (att)
88 metaDD.addE('div').appendChild(att.inline());
89 }
90 else {
Akronb50964a2020-10-12 11:44:37 +020091 metaDD.addE('div').addT(md);
Akrona0ea3c32018-12-14 18:33:48 +010092 }
Akronb50964a2020-10-12 11:44:37 +020093 });
hebasta24fbc9e2018-04-12 13:47:50 +020094 }
95 else{
Akrona0ea3c32018-12-14 18:33:48 +010096 if (field["type"] === 'type:attachement') {
97 let att = attClass.create(field["value"]);
98 if (att)
99 metaDD.appendChild(att.inline());
100 }
101 else {
102 metaDD.addT(field["value"]);
103 };
hebasta24fbc9e2018-04-12 13:47:50 +0200104 }
Akron7dd32822018-10-01 19:38:31 +0200105
Akronbd342982018-01-25 18:01:46 +0100106 metaDL.appendChild(metaL);
Akron24866cf2018-01-23 20:22:01 +0100107 };
Akron678c26f2020-10-09 08:52:50 +0200108 });
Akron7dd32822018-10-01 19:38:31 +0200109
Akronabd6e352018-11-19 15:36:42 +0100110 // Add corpusByMatch assistant
Akron7dd32822018-10-01 19:38:31 +0200111 this._corpusByMatch = cbmClass.create(this._element);
Akronabd6e352018-11-19 15:36:42 +0100112
Akron24866cf2018-01-23 20:22:01 +0100113 return this._element;
Akronaeceda72018-02-02 20:44:06 +0100114 }
Akron24866cf2018-01-23 20:22:01 +0100115 };
Akron30ee5142015-06-26 01:50:14 +0200116});