Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 1 | define(['match/corpusByMatch','match/attachement','util'], function (cbmClass, attClass) { |
Akron | d4b000b | 2018-01-28 18:33:14 +0100 | [diff] [blame] | 2 | |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 3 | "use strict"; |
| 4 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 5 | // Localization values |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 6 | const loc = KorAP.Locale; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 7 | loc.METADATA = loc.METADATA || 'Metadata'; |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 8 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 9 | return { |
| 10 | |
| 11 | /** |
| 12 | * Create new match object |
| 13 | */ |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 14 | create : function (match, fields) { |
| 15 | return Object.create(this)._init(match, fields); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 16 | }, |
| 17 | |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 18 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 19 | /** |
| 20 | * Initialize object |
| 21 | */ |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 22 | _init : function (match, fields) { |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 23 | this._match = match; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 24 | this._fields = fields; |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 25 | return this; |
| 26 | }, |
| 27 | |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 28 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 29 | /** |
| 30 | * Get match object |
| 31 | */ |
| 32 | match : function () { |
| 33 | return this._match; |
| 34 | }, |
| 35 | |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 36 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 37 | /** |
| 38 | * Create match reference view. |
| 39 | */ |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 40 | element : function () { |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 41 | if (this._element !== undefined) |
| 42 | return this._element; |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 43 | |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 44 | if (this._fields === null) |
| 45 | return; |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 46 | |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 47 | const metaDL = document.createElement('dl'); |
Akron | 2f97912 | 2018-07-25 17:00:23 +0200 | [diff] [blame] | 48 | metaDL.classList.add("flex"); |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 49 | |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 50 | this._element = metaDL; |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 51 | |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 52 | const fields = this._fields; |
Akron | 0ad7cd2 | 2018-02-08 18:03:06 +0100 | [diff] [blame] | 53 | |
Akron | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame] | 54 | // Copy original array position to object |
| 55 | // before sorting by key title |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 56 | const posInMetaArray = {}; |
Akron | b50964a | 2020-10-12 11:44:37 +0200 | [diff] [blame] | 57 | fields.forEach((f,i) => posInMetaArray[f["key"]] = i); |
Akron | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame] | 58 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 59 | // TODO: Meta fields should be separated |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 60 | |
Akron | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame] | 61 | // Sort all meta keys alphabetically |
Akron | 678c26f | 2020-10-09 08:52:50 +0200 | [diff] [blame] | 62 | Object.keys(posInMetaArray).sort().forEach(function(k) { |
| 63 | let field = fields[posInMetaArray[k]]; // This is the object |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 64 | |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 65 | let metaL, dt, metaDescr, metaDD, att; |
| 66 | |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 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 | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 72 | k !== "layerInfos") { |
| 73 | |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 74 | metaL = document.createElement('div'); |
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 75 | |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 76 | dt = metaL.addE('dt'); |
Akron | c456838 | 2018-03-06 20:16:12 +0100 | [diff] [blame] | 77 | dt.addT(k); |
| 78 | dt.setAttribute("title", k); |
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 79 | |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 80 | metaDescr = field["value"]; |
Akron | d45a170 | 2018-11-19 18:15:17 +0100 | [diff] [blame] | 81 | metaDD = metaL.addE('dd'); |
| 82 | metaDD.setAttribute('data-type', field["type"]); |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 83 | |
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 84 | if(metaDescr instanceof Array){ |
Akron | b50964a | 2020-10-12 11:44:37 +0200 | [diff] [blame] | 85 | metaDD.classList.add("metakeyvalues"); |
| 86 | metaDescr.forEach(function(md) { |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 87 | if (field["type"] === 'type:attachement') { |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 88 | att = attClass.create(md); |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 89 | if (att) |
| 90 | metaDD.addE('div').appendChild(att.inline()); |
| 91 | } |
| 92 | else { |
Akron | b50964a | 2020-10-12 11:44:37 +0200 | [diff] [blame] | 93 | metaDD.addE('div').addT(md); |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 94 | } |
Akron | b50964a | 2020-10-12 11:44:37 +0200 | [diff] [blame] | 95 | }); |
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 96 | } |
| 97 | else{ |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 98 | if (field["type"] === 'type:attachement') { |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 99 | att = attClass.create(field["value"]); |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 100 | if (att) |
Akron | ff1b1f3 | 2020-10-18 11:41:29 +0200 | [diff] [blame] | 101 | metaDD.appendChild(att.inline()); |
Akron | a0ea3c3 | 2018-12-14 18:33:48 +0100 | [diff] [blame] | 102 | } |
| 103 | else { |
| 104 | metaDD.addT(field["value"]); |
| 105 | }; |
hebasta | 24fbc9e | 2018-04-12 13:47:50 +0200 | [diff] [blame] | 106 | } |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 107 | |
Akron | bd34298 | 2018-01-25 18:01:46 +0100 | [diff] [blame] | 108 | metaDL.appendChild(metaL); |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 109 | }; |
Akron | 678c26f | 2020-10-09 08:52:50 +0200 | [diff] [blame] | 110 | }); |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 111 | |
Akron | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame] | 112 | // Add corpusByMatch assistant |
Akron | 7dd3282 | 2018-10-01 19:38:31 +0200 | [diff] [blame] | 113 | this._corpusByMatch = cbmClass.create(this._element); |
Akron | abd6e35 | 2018-11-19 15:36:42 +0100 | [diff] [blame] | 114 | |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 115 | return this._element; |
Akron | aeceda7 | 2018-02-02 20:44:06 +0100 | [diff] [blame] | 116 | } |
Akron | 24866cf | 2018-01-23 20:22:01 +0100 | [diff] [blame] | 117 | }; |
Akron | 30ee514 | 2015-06-26 01:50:14 +0200 | [diff] [blame] | 118 | }); |