Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1 | /** |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 2 | * Create virtual corpora with a visual user interface. This resembles the |
| 3 | * corpus/collection type objects of a KoralQuery "collection"/"corpus" object. |
hebasta | a79d69d | 2018-07-24 12:13:02 +0200 | [diff] [blame] | 4 | * |
Nils Diewald | 4c22125 | 2015-04-21 20:19:25 +0000 | [diff] [blame] | 5 | * KoralQuery v0.3 is expected. |
hebasta | a79d69d | 2018-07-24 12:13:02 +0200 | [diff] [blame] | 6 | * |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 7 | * @author Nils Diewald |
| 8 | */ |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 9 | /* |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 10 | * This replaces a previous version written by Mengfei Zhou |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 11 | */ |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 12 | |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 13 | /* |
hebasta | 8675939 | 2018-07-25 15:44:37 +0200 | [diff] [blame] | 14 | TODO: Disable "and" or "or" in case it's followed |
| 15 | by an unspecified document |
| 16 | TODO: Add "and"-method to root to add further constraints |
| 17 | based on match-input (like clicking on a pubDate timestamp in a match) |
| 18 | TODO: Implement "persistence"-Option, injecting the current creation |
| 19 | date stamp |
| 20 | TODO: Implement vec-Type for document-id vectors like docID in [1,2,3,4 ...] |
| 21 | |
| 22 | Error codes: |
| 23 | 701: "JSON-LD group has no @type attribute" |
| 24 | 704: "Operation needs operand list" |
| 25 | 802: "Match type is not supported by value type" |
| 26 | 804: "Unknown value type" |
| 27 | 805: "Value is invalid" |
| 28 | 806: "Value is not a valid date string" |
| 29 | 807: "Value is not a valid regular expression" |
| 30 | 810: "Unknown document group operation" (like 711) |
| 31 | 811: "Document group expects operation" (like 703) |
| 32 | 812: "Operand not supported in document group" (like 744) |
| 33 | 813: "Collection type is not supported" (like 713) |
| 34 | 814: "Unknown rewrite operation" |
| 35 | 815: "Rewrite expects source" |
| 36 | |
| 37 | Localization strings: |
| 38 | KorAP.Locale = { |
| 39 | EMPTY : '...', |
| 40 | AND : 'and', |
| 41 | OR : 'or', |
| 42 | DELETE : 'x' } |
| 43 | |
| 44 | and various field names with the prefix 'VC_' |
hebasta | a79d69d | 2018-07-24 12:13:02 +0200 | [diff] [blame] | 45 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 46 | "use strict"; |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 47 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 48 | define([ |
| 49 | 'vc/unspecified', |
| 50 | 'vc/doc', |
| 51 | 'vc/docgroup', |
| 52 | 'vc/docgroupref', |
| 53 | 'vc/menu', |
| 54 | 'vc/statistic', |
| 55 | 'datepicker', |
| 56 | 'buttongroup', |
Akron | aa61322 | 2019-11-19 13:57:12 +0100 | [diff] [blame] | 57 | 'panel/vc', |
| 58 | 'view/vc/corpstatv', |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 59 | 'buttongroup', |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 60 | 'util' |
| 61 | ], function( |
| 62 | unspecDocClass, |
| 63 | docClass, |
| 64 | docGroupClass, |
| 65 | docGroupRefClass, |
| 66 | menuClass, |
| 67 | statClass, |
| 68 | dpClass, |
| 69 | buttonGrClass, |
hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 70 | vcPanelClass, |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 71 | corpStatVClass, |
| 72 | buttonGroupClass) { |
Nils Diewald | 1fcb2ad | 2015-04-20 19:19:18 +0000 | [diff] [blame] | 73 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 74 | KorAP._validUnspecMatchRE = new RegExp( |
| 75 | "^(?:eq|ne|contains(?:not)?|excludes)$"); |
| 76 | KorAP._validStringMatchRE = new RegExp("^(?:eq|ne)$"); |
Marc Kupietz | a5f79e6 | 2024-12-17 07:15:46 +0100 | [diff] [blame] | 77 | KorAP._validIntegerMatchRE = new RegExp("^(?:[gl]?eq|ne|[gl]t)$"); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 78 | KorAP._validTextMatchRE = KorAP._validUnspecMatchRE; |
| 79 | KorAP._validTextOnlyMatchRE = new RegExp( |
| 80 | "^(?:contains(?:not)?|excludes)$"); |
| 81 | KorAP._overrideStyles = false; |
| 82 | // KorAP._validDateMatchRE is defined in datepicker.js! |
Nils Diewald | d077049 | 2014-12-19 03:55:00 +0000 | [diff] [blame] | 83 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 84 | const loc = KorAP.Locale; |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 85 | loc.SHOW_STAT = loc.SHOW_STAT || 'Statistics'; |
| 86 | loc.VERB_SHOWSTAT = loc.VERB_SHOWSTAT || 'Corpus Statistics'; |
Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame] | 87 | loc.VC_allCorpora = loc.VC_allCorpora || 'all corpora'; |
| 88 | loc.VC_oneCollection = loc.VC_oneCollection || 'a virtual corpus'; |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 89 | loc.MINIMIZE = loc.MINIMIZE || 'Minimize'; |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 90 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 91 | KorAP._vcKeyMenu = undefined; |
| 92 | KorAP._vcDatePicker = dpClass.create(); |
Nils Diewald | 3a2d802 | 2014-12-16 02:45:41 +0000 | [diff] [blame] | 93 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 94 | // Create match menus .... |
| 95 | KorAP._vcMatchopMenu = { |
| 96 | 'string' : menuClass.create([ |
| 97 | [ 'eq', null ], |
| 98 | [ 'ne', null ] |
| 99 | ]), |
| 100 | 'text' : menuClass.create([ |
| 101 | [ 'eq', null ], // Requires exact match |
| 102 | [ 'ne', null ], |
| 103 | [ 'contains', null ], // Requires token sequence match |
| 104 | [ 'containsnot', null ] |
| 105 | ]), |
| 106 | 'date' : menuClass.create([ |
| 107 | [ 'eq', null ], |
| 108 | [ 'ne', null ], |
| 109 | [ 'geq', null ], |
| 110 | [ 'leq', null ] |
| 111 | ]), |
| 112 | 'regex' : menuClass.create([ |
| 113 | [ 'eq', null ], |
| 114 | [ 'ne', null ] |
Akron | 5d4f2e4 | 2024-12-16 09:10:27 +0100 | [diff] [blame] | 115 | ]), |
| 116 | 'integer' : menuClass.create([ |
| 117 | [ 'eq', null ], |
| 118 | [ 'ne', null ], |
| 119 | [ 'geq', null ], |
Marc Kupietz | a5f79e6 | 2024-12-17 07:15:46 +0100 | [diff] [blame] | 120 | [ 'leq', null ], |
| 121 | [ 'gt', null ], |
| 122 | [ 'lt', null ] |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 123 | ]) |
| 124 | }; |
| 125 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 126 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 127 | /** |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 128 | * Virtual corpus |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 129 | */ |
| 130 | return { |
| 131 | |
| 132 | /** |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 133 | * The JSON-LD type of the virtual corpus |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 134 | */ |
| 135 | ldType : function() { |
| 136 | return null; |
| 137 | }, |
| 138 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 139 | |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 140 | // Initialize virtual corpus |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 141 | _init : function(keyList) { |
| 142 | |
| 143 | // Inject localized css styles |
| 144 | if (!KorAP._overrideStyles) { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 145 | |
| 146 | const sheet = KorAP.newStyleSheet(); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 147 | |
| 148 | // Add css rule for OR operations |
| 149 | sheet.insertRule('.vc .docGroup[data-operation=or] > .doc::before,' |
| 150 | + '.vc .docGroup[data-operation=or] > .docGroup::before ' |
| 151 | + '{ content: "' + loc.OR + '" }', 0); |
| 152 | |
| 153 | // Add css rule for AND operations |
| 154 | sheet.insertRule( |
| 155 | '.vc .docGroup[data-operation=and] > .doc::before,' |
| 156 | + '.vc .docGroup[data-operation=and] > .docGroup::before ' |
| 157 | + '{ content: "' + loc.AND + '" }', 1); |
| 158 | |
| 159 | KorAP._overrideStyles = true; |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 160 | }; |
| 161 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 162 | let l; |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 163 | if (keyList) { |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 164 | l = keyList.slice(); |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 165 | l.unshift(['referTo', 'ref']); |
| 166 | } |
| 167 | else { |
| 168 | l = [['referTo', 'ref']]; |
| 169 | } |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 170 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 171 | // Create key menu |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 172 | KorAP._vcKeyMenu = menuClass.create(l); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 173 | KorAP._vcKeyMenu.limit(6); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 174 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 175 | return this; |
| 176 | }, |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 177 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 178 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 179 | /** |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 180 | * Create a new virtual corpus |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 181 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 182 | create : function (keyList) { |
| 183 | const obj = Object.create(this)._init(keyList); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 184 | obj._root = unspecDocClass.create(obj); |
| 185 | return obj; |
| 186 | }, |
Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 187 | |
Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame] | 188 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 189 | /** |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 190 | * Create and render a new virtual corpus based on a KoralQuery |
| 191 | * corpus document |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 192 | */ |
| 193 | fromJson : function(json) { |
Akron | 13af2f4 | 2019-07-25 15:06:21 +0200 | [diff] [blame] | 194 | |
| 195 | let obj; |
| 196 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 197 | if (json !== undefined) { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 198 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 199 | // Parse root document |
| 200 | if (json['@type'] == 'koral:doc') { |
Akron | 13af2f4 | 2019-07-25 15:06:21 +0200 | [diff] [blame] | 201 | obj = docClass.create(this, json); |
hebasta | a79d69d | 2018-07-24 12:13:02 +0200 | [diff] [blame] | 202 | } |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 203 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 204 | // parse root group |
| 205 | else if (json['@type'] == 'koral:docGroup') { |
Akron | 13af2f4 | 2019-07-25 15:06:21 +0200 | [diff] [blame] | 206 | obj = docGroupClass.create(this, json); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | // parse root reference |
| 210 | else if (json['@type'] == 'koral:docGroupRef') { |
Akron | 13af2f4 | 2019-07-25 15:06:21 +0200 | [diff] [blame] | 211 | obj = docGroupRefClass.create(this, json); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | // Unknown collection type |
| 215 | else { |
| 216 | KorAP.log(813, "Collection type is not supported"); |
| 217 | return; |
| 218 | }; |
| 219 | } |
| 220 | |
| 221 | else { |
| 222 | // Add unspecified object |
Akron | 13af2f4 | 2019-07-25 15:06:21 +0200 | [diff] [blame] | 223 | obj = unspecDocClass.create(this); |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 224 | }; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 225 | |
| 226 | // Init element and update |
Akron | 13af2f4 | 2019-07-25 15:06:21 +0200 | [diff] [blame] | 227 | this.root(obj); |
| 228 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 229 | return this; |
| 230 | }, |
Akron | d2474aa | 2018-08-28 12:06:27 +0200 | [diff] [blame] | 231 | |
| 232 | |
| 233 | // Check if the virtual corpus contains a rerite |
| 234 | wasRewritten : function (obj) { |
| 235 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 236 | if (arguments.length !== 1) { |
Akron | d2474aa | 2018-08-28 12:06:27 +0200 | [diff] [blame] | 237 | obj = this._root; |
| 238 | }; |
| 239 | |
| 240 | // Check for rewrite |
| 241 | if (obj.rewrites() && obj.rewrites().length() > 0) { |
| 242 | return true; |
| 243 | } |
| 244 | |
| 245 | // Check recursively |
| 246 | else if (obj.ldType() === 'docGroup') { |
Akron | 678c26f | 2020-10-09 08:52:50 +0200 | [diff] [blame] | 247 | |
| 248 | // If there was a rewritten object |
| 249 | if (obj.operands().find(op => this.wasRewritten(op)) !== undefined) { |
| 250 | return true; |
Akron | d2474aa | 2018-08-28 12:06:27 +0200 | [diff] [blame] | 251 | }; |
| 252 | }; |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 253 | |
Akron | d2474aa | 2018-08-28 12:06:27 +0200 | [diff] [blame] | 254 | return false; |
| 255 | }, |
Akron | 43c5cc6 | 2018-08-28 13:10:25 +0200 | [diff] [blame] | 256 | |
Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame] | 257 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 258 | /** |
hebasta | 3f4be92 | 2018-12-11 10:41:46 +0100 | [diff] [blame] | 259 | * Clean the virtual document to unspecified doc. |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 260 | */ |
| 261 | clean : function() { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 262 | const t = this; |
| 263 | if (t._root.ldType() !== "non") { |
| 264 | t._root.destroy(); |
| 265 | t.root(unspecDocClass.create(t)); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 266 | }; |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 267 | |
| 268 | // update for graying corpus statistic by deleting the first line of the vc builder |
| 269 | t.update(); |
| 270 | return t; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 271 | }, |
| 272 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 273 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 274 | /** |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 275 | * Get or set the root object of the virtual corpus |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 276 | */ |
| 277 | root : function(obj) { |
| 278 | if (arguments.length === 1) { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 279 | const e = this.builder(); |
| 280 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 281 | if (e.firstChild !== null) { |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 282 | |
| 283 | // Object not yet set |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 284 | if (e.firstChild !== obj.element()) { |
| 285 | e.replaceChild(obj.element(), e.firstChild); |
| 286 | }; |
| 287 | } |
| 288 | |
| 289 | // Append root element |
| 290 | else { |
| 291 | e.appendChild(obj.element()); |
| 292 | }; |
| 293 | |
| 294 | // Update parent child relations |
| 295 | this._root = obj; |
| 296 | obj.parent(this); |
| 297 | |
| 298 | this.update(); |
| 299 | }; |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 300 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 301 | return this._root; |
| 302 | }, |
| 303 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 304 | |
| 305 | /** |
| 306 | * Get the wrapper element associated with the vc |
| 307 | */ |
| 308 | builder : function () { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 309 | const t = this; |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 310 | |
| 311 | // Initialize if necessary |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 312 | if (t._builder !== undefined) |
| 313 | return t._builder; |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 314 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 315 | t.element(); |
| 316 | return t._builder; |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 317 | }, |
| 318 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 319 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 320 | /** |
Akron | 68d2832 | 2018-08-27 15:02:42 +0200 | [diff] [blame] | 321 | * Get the element associated with the virtual corpus |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 322 | */ |
| 323 | element : function() { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 324 | const t = this; |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 325 | let e = t._el; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 326 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 327 | if (e !== undefined) |
| 328 | return e; |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 329 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 330 | |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 331 | e = t._el = document.createElement('div'); |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 332 | e.classList.add('vc'); |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 333 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 334 | |
| 335 | t._builder = e.addE('div'); |
| 336 | t._builder.setAttribute('class', 'builder'); |
| 337 | |
| 338 | const btn = buttonGroupClass.create( |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 339 | ['action','button-view'] |
| 340 | ); |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 341 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 342 | btn.add(loc.MINIMIZE, {'cls':['button-icon','minimize']}, function () { |
| 343 | this.minimize(); |
| 344 | }.bind(t)); |
| 345 | |
| 346 | e.appendChild(btn.element()); |
| 347 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 348 | // Initialize root |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 349 | t._builder.appendChild(t._root.element()); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 350 | |
| 351 | // Add panel to display corpus statistic, ... |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 352 | t.addVcInfPanel(); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 353 | |
hebasta | 4dd77bc | 2019-02-07 12:57:57 +0100 | [diff] [blame] | 354 | //Adds EventListener for corpus changes |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 355 | t._el.addEventListener('vcChange', function (e) { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 356 | this.checkStatActive(e.detail); |
| 357 | }.bind(t), false); |
hebasta | 4dd77bc | 2019-02-07 12:57:57 +0100 | [diff] [blame] | 358 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 359 | return e; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 360 | }, |
| 361 | |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 362 | |
| 363 | /** |
| 364 | * Check, if the VC is open |
| 365 | */ |
| 366 | isOpen : function () { |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 367 | if (!this._el) |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 368 | return false; |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 369 | return this._el.classList.contains('active'); |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 370 | }, |
| 371 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 372 | |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 373 | /** |
| 374 | * Open the VC view |
| 375 | */ |
| 376 | open : function () { |
| 377 | this.element().classList.add('active'); |
| 378 | if (this.onOpen) |
| 379 | this.onOpen(); |
| 380 | }, |
| 381 | |
| 382 | |
| 383 | /** |
| 384 | * Minimize the VC view |
| 385 | */ |
| 386 | minimize : function () { |
| 387 | this.element().classList.remove('active'); |
| 388 | if (this.onMinimize) |
| 389 | this.onMinimize(); |
| 390 | }, |
| 391 | |
| 392 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 393 | /** |
| 394 | * Update the whole object based on the underlying data structure |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 395 | */ |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 396 | update : function() { |
| 397 | this._root.update(); |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 398 | if (KorAP.vc) { |
| 399 | this.element().dispatchEvent( |
| 400 | new CustomEvent('vcChange', {'detail':this}) |
| 401 | ); |
hebasta | 4dd77bc | 2019-02-07 12:57:57 +0100 | [diff] [blame] | 402 | }; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 403 | return this; |
| 404 | }, |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 405 | |
| 406 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 407 | /** |
| 408 | * Make the vc persistant by injecting the current timestamp as a |
| 409 | * creation date limit criterion. |
| 410 | * THIS IS CURRENTLY NOT USED |
| 411 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 412 | /* |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 413 | makePersistant : function() { |
| 414 | // this.root().wrapOnRoot('and'); |
| 415 | var todayStr = KorAP._vcDatePicker.today(); |
| 416 | var doc = docClass.create(); |
| 417 | var root = this.root(); |
| 418 | |
| 419 | if (root.ldType() === 'docGroup' && root.operation === 'and') { |
| 420 | root.append(cond); |
| 421 | } else { |
| 422 | root.wrapOnRoot('and'); |
| 423 | root.append(doc); |
| 424 | }; |
| 425 | |
| 426 | doc.key("creationDate"); |
| 427 | doc.type("date"); |
| 428 | doc.matchop("leq"); |
| 429 | doc.value(todayStr); |
| 430 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 431 | // { "@type" : "koral:doc", "key" : "creationDate", "type" : |
| 432 | // "type:date", "match" : "match:leq", "value" : todayStr } |
| 433 | // this.root().append(cond); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 434 | this.update(); |
| 435 | }, |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 436 | */ |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 437 | |
Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame] | 438 | |
| 439 | // Get the reference name |
| 440 | getName : function () { |
| 441 | if (this._root.ldType() === 'non') { |
| 442 | return loc.VC_allCorpora; |
| 443 | } |
| 444 | else if (this._root.ldType() === 'docGroupRef') { |
| 445 | return this._root.ref(); |
| 446 | } |
| 447 | else { |
| 448 | return loc.VC_oneCollection; |
| 449 | } |
| 450 | }, |
| 451 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 452 | |
Akron | 4feec9d | 2018-11-20 17:00:50 +0100 | [diff] [blame] | 453 | // Add "and" constraint to VC |
| 454 | addRequired : function (doc) { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 455 | const root = this.root(); |
| 456 | const ldType = root.ldType(); |
| 457 | const parent = root.parent(); |
Akron | 4feec9d | 2018-11-20 17:00:50 +0100 | [diff] [blame] | 458 | |
Akron | 4feec9d | 2018-11-20 17:00:50 +0100 | [diff] [blame] | 459 | if (ldType === 'non') { |
| 460 | parent.root(doc); |
| 461 | } |
| 462 | |
| 463 | // root is doc |
| 464 | else if ( |
| 465 | ldType === 'doc' || |
| 466 | ldType === 'docGroupRef' || |
| 467 | (ldType === 'docGroup' && |
| 468 | root.operation() === 'or' |
| 469 | )) { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 470 | const group = require('vc/docgroup').create( |
Akron | 4feec9d | 2018-11-20 17:00:50 +0100 | [diff] [blame] | 471 | parent |
| 472 | ); |
| 473 | group.operation("and"); |
| 474 | group.append(root); |
| 475 | group.append(doc); |
| 476 | group.element(); // Init (seems to be necessary) |
| 477 | parent.root(group); |
| 478 | } |
| 479 | |
| 480 | // root is a docGroup |
| 481 | // and is already an 'and'-Group |
| 482 | else if (ldType === 'docGroup') { |
| 483 | root.append(doc); |
| 484 | } |
| 485 | |
| 486 | // Unknown |
| 487 | else { |
| 488 | console.log("Unknown root object"); |
| 489 | }; |
| 490 | |
| 491 | // Init element and update |
| 492 | this.update(); |
| 493 | }, |
Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame] | 494 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 495 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 496 | /** |
| 497 | * Get the generated json string |
| 498 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 499 | toJson : function () { |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 500 | return this._root.toJson(); |
| 501 | }, |
| 502 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 503 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 504 | /** |
| 505 | * Get the generated query string |
| 506 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 507 | toQuery : function () { |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 508 | return this._root.toQuery(); |
| 509 | }, |
| 510 | |
hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 511 | |
| 512 | /** |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 513 | * Add panel to display virtual corpus information |
| 514 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 515 | addVcInfPanel : function () { |
| 516 | // Create panel |
hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 517 | this.panel = vcPanelClass.create(this); |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 518 | this._el.addE('div').appendChild(this.panel.element()); |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 519 | |
hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 520 | }, |
| 521 | |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 522 | /** |
hebasta | 48842cf | 2018-12-11 12:57:38 +0100 | [diff] [blame] | 523 | * Checks if corpus statistic has to be disabled, |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 524 | * and to be updated after clicking at the "reload-button" |
| 525 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 526 | checkStatActive : function (){ |
| 527 | if (this.panel !== undefined && this.panel.statView !== undefined){ |
hebasta | 48842cf | 2018-12-11 12:57:38 +0100 | [diff] [blame] | 528 | this.panel.statView.checkStatActive(); |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 529 | }; |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 530 | } |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 531 | }; |
| 532 | }); |