blob: c4cd63f124326ddaeb05a4ae5e3c348b78a1704e [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 = {};
53 for (let i = 0; i < fields.length; i++) {
54 posInMetaArray[fields[i]["key"]] = i;
55
Akron0ad7cd22018-02-08 18:03:06 +010056 };
Akron7dd32822018-10-01 19:38:31 +020057
Akron24866cf2018-01-23 20:22:01 +010058 // TODO: Meta fields should be separated
Akronabd6e352018-11-19 15:36:42 +010059 const keys = Object.keys(posInMetaArray);
60
61 // Sort all meta keys alphabetically
62 for (let i in keys.sort()) {
63 let k = keys[i]; // This is the title
64 let field = fields[posInMetaArray[keys[i]]]; // This is the object
Akron7dd32822018-10-01 19:38:31 +020065
66 // Ignore internal IDs
Akron24866cf2018-01-23 20:22:01 +010067 if (k !== "UID" &&
68 k !== "corpusID" &&
69 k !== "docID" &&
70 k !== "textID" &&
Akron8b592d42018-01-26 18:33:06 +010071 /*
Akron7dd32822018-10-01 19:38:31 +020072 k !== "corpusSigle" &&
73 k !== "docSigle" &&
Akron8b592d42018-01-26 18:33:06 +010074 */
Akron24866cf2018-01-23 20:22:01 +010075 k !== "layerInfos") {
76
Akronabd6e352018-11-19 15:36:42 +010077 const metaL = document.createElement('div');
hebasta24fbc9e2018-04-12 13:47:50 +020078
Akronabd6e352018-11-19 15:36:42 +010079 const dt = metaL.addE('dt');
Akronc4568382018-03-06 20:16:12 +010080 dt.addT(k);
81 dt.setAttribute("title", k);
hebasta24fbc9e2018-04-12 13:47:50 +020082
Akronabd6e352018-11-19 15:36:42 +010083 let metaDescr = field["value"];
Akrond45a1702018-11-19 18:15:17 +010084 metaDD = metaL.addE('dd');
85 metaDD.setAttribute('data-type', field["type"]);
Akrona0ea3c32018-12-14 18:33:48 +010086
hebasta24fbc9e2018-04-12 13:47:50 +020087 if(metaDescr instanceof Array){
Akron7dd32822018-10-01 19:38:31 +020088 metaDD.classList.add("metakeyvalues");
Akrona0ea3c32018-12-14 18:33:48 +010089 for (i = 0; i < metaDescr.length; i++){
90
91 if (field["type"] === 'type:attachement') {
92 let att = attClass.create(metaDescr[i]);
93 if (att)
94 metaDD.addE('div').appendChild(att.inline());
95 }
96 else {
97 metaDD.addE('div').addT(metaDescr[i]);
98 }
Akron7dd32822018-10-01 19:38:31 +020099 }
hebasta24fbc9e2018-04-12 13:47:50 +0200100 }
101 else{
Akrona0ea3c32018-12-14 18:33:48 +0100102 if (field["type"] === 'type:attachement') {
103 let att = attClass.create(field["value"]);
104 if (att)
105 metaDD.appendChild(att.inline());
106 }
107 else {
108 metaDD.addT(field["value"]);
109 };
hebasta24fbc9e2018-04-12 13:47:50 +0200110 }
Akron7dd32822018-10-01 19:38:31 +0200111
Akronbd342982018-01-25 18:01:46 +0100112 metaDL.appendChild(metaL);
Akron24866cf2018-01-23 20:22:01 +0100113 };
114 };
Akron7dd32822018-10-01 19:38:31 +0200115
Akronabd6e352018-11-19 15:36:42 +0100116 // Add corpusByMatch assistant
Akron7dd32822018-10-01 19:38:31 +0200117 this._corpusByMatch = cbmClass.create(this._element);
Akronabd6e352018-11-19 15:36:42 +0100118
Akron24866cf2018-01-23 20:22:01 +0100119 return this._element;
Akronaeceda72018-02-02 20:44:06 +0100120 }
Akron24866cf2018-01-23 20:22:01 +0100121 };
Akron30ee5142015-06-26 01:50:14 +0200122});