blob: d4b2d7f8071f4ceba9c414eb54e80b48d834749e [file] [log] [blame]
Akron7dd32822018-10-01 19:38:31 +02001define(['match/corpusByMatch','util'], function (cbmClass) {
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
Akron0ad7cd22018-02-08 18:03:06 +010048 var fields = this._fields;
49
50 // TODO:
51 // This should only remember array positions by index
52 // and keep all other field information intact
53 var metaInfo = {};
54 for (var i in fields) {
hebasta24fbc9e2018-04-12 13:47:50 +020055 var value = fields[i].value;
56 metaInfo[fields[i].key] = value;
Akron0ad7cd22018-02-08 18:03:06 +010057 };
Akron7dd32822018-10-01 19:38:31 +020058
hebasta24fbc9e2018-04-12 13:47:50 +020059 // console.log(fields);
60
Akron24866cf2018-01-23 20:22:01 +010061 // TODO: Meta fields should be separated
hebasta24fbc9e2018-04-12 13:47:50 +020062 var keys = Object.keys(metaInfo);
63
Akron24866cf2018-01-23 20:22:01 +010064 for (var i in keys.sort()) {
65 var k = keys[i];
Akron7dd32822018-10-01 19:38:31 +020066
67 // Ignore internal IDs
Akron24866cf2018-01-23 20:22:01 +010068 if (k !== "UID" &&
69 k !== "corpusID" &&
70 k !== "docID" &&
71 k !== "textID" &&
Akron8b592d42018-01-26 18:33:06 +010072 /*
Akron7dd32822018-10-01 19:38:31 +020073 k !== "corpusSigle" &&
74 k !== "docSigle" &&
Akron8b592d42018-01-26 18:33:06 +010075 */
Akron24866cf2018-01-23 20:22:01 +010076 k !== "layerInfos") {
77
78 var metaL = document.createElement('div');
hebasta24fbc9e2018-04-12 13:47:50 +020079
Akronc4568382018-03-06 20:16:12 +010080 var dt = metaL.addE('dt');
81 dt.addT(k);
82 dt.setAttribute("title", k);
hebasta24fbc9e2018-04-12 13:47:50 +020083
84 var metaDescr = metaInfo[k];
85 metaDD = metaL.addE('dd');
86
87 if(metaDescr instanceof Array){
Akron7dd32822018-10-01 19:38:31 +020088 metaDD.classList.add("metakeyvalues");
89 for(i = 0; i < metaDescr.length; i++){
90 metaDD.addE('div').addT(metaDescr[i]);
91 }
hebasta24fbc9e2018-04-12 13:47:50 +020092 }
93 else{
Akron7dd32822018-10-01 19:38:31 +020094 metaDD.addT(metaInfo[k]);
hebasta24fbc9e2018-04-12 13:47:50 +020095 }
Akron7dd32822018-10-01 19:38:31 +020096
Akronbd342982018-01-25 18:01:46 +010097 metaDL.appendChild(metaL);
Akron24866cf2018-01-23 20:22:01 +010098 };
99 };
Akron7dd32822018-10-01 19:38:31 +0200100
101 this._corpusByMatch = cbmClass.create(this._element);
Akron24866cf2018-01-23 20:22:01 +0100102 return this._element;
Akronaeceda72018-02-02 20:44:06 +0100103 }
Akron24866cf2018-01-23 20:22:01 +0100104 };
Akron30ee5142015-06-26 01:50:14 +0200105});