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 | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame^] | 48 | let fields = this._fields; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 49 | |
Akron | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame^] | 50 | // 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 | |||||
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 56 | }; |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 57 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 58 | // TODO: Meta fields should be separated |
Akron | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame^] | 59 | 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 | ||||
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 65 | |
66 | // Ignore internal IDs | ||||
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 67 | if (k !== "UID" && |
68 | k !== "corpusID" && | ||||
69 | k !== "docID" && | ||||
70 | k !== "textID" && | ||||
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 71 | /* |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 72 | k !== "corpusSigle" && |
73 | k !== "docSigle" && | ||||
Akron | 8b592d4 | 2018-01-26 18:33:06 +0100 | [diff] [blame] | 74 | */ |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 75 | k !== "layerInfos") { |
76 | |||||
Akron | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame^] | 77 | const metaL = document.createElement('div'); |
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 78 | |
Akron | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame^] | 79 | const dt = metaL.addE('dt'); |
Akron | c456838 | 2018-03-06 20:16:12 +0100 | [diff] [blame] | 80 | dt.addT(k); |
81 | dt.setAttribute("title", k); | ||||
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 82 | |
Akron | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame^] | 83 | let metaDescr = field["value"]; |
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 84 | metaDD = metaL.addE('dd'); |
85 | |||||
86 | if(metaDescr instanceof Array){ | ||||
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 87 | metaDD.classList.add("metakeyvalues"); |
88 | for(i = 0; i < metaDescr.length; i++){ | ||||
89 | metaDD.addE('div').addT(metaDescr[i]); | ||||
90 | } | ||||
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 91 | } |
92 | else{ | ||||
Akron | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame^] | 93 | metaDD.addT(field["value"]); |
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 94 | } |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 95 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 96 | metaDL.appendChild(metaL); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 97 | }; |
98 | }; | ||||
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 99 | |
Akron | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame^] | 100 | // Add corpusByMatch assistant |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 101 | this._corpusByMatch = cbmClass.create(this._element); |
Akron | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame^] | 102 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 103 | return this._element; |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 104 | } |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 105 | }; |
Akron | 30ee514 | 2015-06-26 01:50:14 +0200 | [diff] [blame] | 106 | }); |