blob: 78b14300f0c953011cb1e18e382ac73a4b55f986 [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 // Sort all meta keys alphabetically
Akron678c26f2020-10-09 08:52:50 +020060 Object.keys(posInMetaArray).sort().forEach(function(k) {
61 let field = fields[posInMetaArray[k]]; // This is the object
Akron7dd32822018-10-01 19:38:31 +020062
63 // Ignore internal IDs
Akron24866cf2018-01-23 20:22:01 +010064 if (k !== "UID" &&
65 k !== "corpusID" &&
66 k !== "docID" &&
67 k !== "textID" &&
Akron8b592d42018-01-26 18:33:06 +010068 /*
Akron7dd32822018-10-01 19:38:31 +020069 k !== "corpusSigle" &&
70 k !== "docSigle" &&
Akron8b592d42018-01-26 18:33:06 +010071 */
Akron24866cf2018-01-23 20:22:01 +010072 k !== "layerInfos") {
73
Akronabd6e352018-11-19 15:36:42 +010074 const metaL = document.createElement('div');
hebasta24fbc9e2018-04-12 13:47:50 +020075
Akronabd6e352018-11-19 15:36:42 +010076 const dt = metaL.addE('dt');
Akronc4568382018-03-06 20:16:12 +010077 dt.addT(k);
78 dt.setAttribute("title", k);
hebasta24fbc9e2018-04-12 13:47:50 +020079
Akronabd6e352018-11-19 15:36:42 +010080 let metaDescr = field["value"];
Akrond45a1702018-11-19 18:15:17 +010081 metaDD = metaL.addE('dd');
82 metaDD.setAttribute('data-type', field["type"]);
Akrona0ea3c32018-12-14 18:33:48 +010083
hebasta24fbc9e2018-04-12 13:47:50 +020084 if(metaDescr instanceof Array){
Akron7dd32822018-10-01 19:38:31 +020085 metaDD.classList.add("metakeyvalues");
Akrona0ea3c32018-12-14 18:33:48 +010086 for (i = 0; i < metaDescr.length; i++){
87
88 if (field["type"] === 'type:attachement') {
89 let att = attClass.create(metaDescr[i]);
90 if (att)
91 metaDD.addE('div').appendChild(att.inline());
92 }
93 else {
94 metaDD.addE('div').addT(metaDescr[i]);
95 }
Akron7dd32822018-10-01 19:38:31 +020096 }
hebasta24fbc9e2018-04-12 13:47:50 +020097 }
98 else{
Akrona0ea3c32018-12-14 18:33:48 +010099 if (field["type"] === 'type:attachement') {
100 let att = attClass.create(field["value"]);
101 if (att)
102 metaDD.appendChild(att.inline());
103 }
104 else {
105 metaDD.addT(field["value"]);
106 };
hebasta24fbc9e2018-04-12 13:47:50 +0200107 }
Akron7dd32822018-10-01 19:38:31 +0200108
Akronbd342982018-01-25 18:01:46 +0100109 metaDL.appendChild(metaL);
Akron24866cf2018-01-23 20:22:01 +0100110 };
Akron678c26f2020-10-09 08:52:50 +0200111 });
Akron7dd32822018-10-01 19:38:31 +0200112
Akronabd6e352018-11-19 15:36:42 +0100113 // Add corpusByMatch assistant
Akron7dd32822018-10-01 19:38:31 +0200114 this._corpusByMatch = cbmClass.create(this._element);
Akronabd6e352018-11-19 15:36:42 +0100115
Akron24866cf2018-01-23 20:22:01 +0100116 return this._element;
Akronaeceda72018-02-02 20:44:06 +0100117 }
Akron24866cf2018-01-23 20:22:01 +0100118 };
Akron30ee5142015-06-26 01:50:14 +0200119});