Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 1 | define(['match/corpusByMatch','util'], function (cbmClass) { |
Akron | d4b000b | 2018-01-28 18:33:14 +0100 | [diff] [blame] | 2 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 3 | // Localization values |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 4 | const loc = KorAP.Locale; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 5 | loc.METADATA = loc.METADATA || 'Metadata'; |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 6 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 7 | return { |
8 | |||||
9 | /** | ||||
10 | * Create new match object | ||||
11 | */ | ||||
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 12 | create : function (match, fields) { |
13 | return Object.create(this)._init(match, fields); | ||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 14 | }, |
15 | |||||
16 | /** | ||||
17 | * Initialize object | ||||
18 | */ | ||||
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 19 | _init : function (match, fields) { |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 20 | this._match = match; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 21 | this._fields = fields; |
22 | // this.opened = false; | ||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 23 | 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 | */ | ||||
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 36 | element : function () { |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 37 | if (this._element !== undefined) |
38 | return this._element; | ||||
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 39 | |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 40 | if (this._fields === null) |
41 | return; | ||||
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 42 | |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 43 | var metaDL = document.createElement('dl'); |
Akron | 2f97912 | 2018-07-25 17:00:23 +0200 | [diff] [blame] | 44 | metaDL.classList.add("flex"); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 45 | |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 46 | this._element = metaDL; |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 47 | |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 48 | 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) { | ||||
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 55 | var value = fields[i].value; |
56 | metaInfo[fields[i].key] = value; | ||||
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 57 | }; |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 58 | |
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 59 | // console.log(fields); |
60 | |||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 61 | // TODO: Meta fields should be separated |
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 62 | var keys = Object.keys(metaInfo); |
63 | |||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 64 | for (var i in keys.sort()) { |
65 | var k = keys[i]; | ||||
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 66 | |
67 | // Ignore internal IDs | ||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 68 | if (k !== "UID" && |
69 | k !== "corpusID" && | ||||
70 | k !== "docID" && | ||||
71 | k !== "textID" && | ||||
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 72 | /* |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 73 | k !== "corpusSigle" && |
74 | k !== "docSigle" && | ||||
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 75 | */ |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 76 | k !== "layerInfos") { |
77 | |||||
78 | var metaL = document.createElement('div'); | ||||
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 79 | |
Akron | c456838 | 2018-03-06 20:16:12 +0100 | [diff] [blame] | 80 | var dt = metaL.addE('dt'); |
81 | dt.addT(k); | ||||
82 | dt.setAttribute("title", k); | ||||
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 83 | |
84 | var metaDescr = metaInfo[k]; | ||||
85 | metaDD = metaL.addE('dd'); | ||||
86 | |||||
87 | if(metaDescr instanceof Array){ | ||||
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 88 | metaDD.classList.add("metakeyvalues"); |
89 | for(i = 0; i < metaDescr.length; i++){ | ||||
90 | metaDD.addE('div').addT(metaDescr[i]); | ||||
91 | } | ||||
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 92 | } |
93 | else{ | ||||
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 94 | metaDD.addT(metaInfo[k]); |
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 95 | } |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 96 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 97 | metaDL.appendChild(metaL); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 98 | }; |
99 | }; | ||||
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 100 | |
101 | this._corpusByMatch = cbmClass.create(this._element); | ||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 102 | return this._element; |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 103 | } |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 104 | }; |
Akron | 30ee514 | 2015-06-26 01:50:14 +0200 | [diff] [blame] | 105 | }); |