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)$"); |
Akron | 5d4f2e4 | 2024-12-16 09:10:27 +0100 | [diff] [blame^] | 77 | KorAP._validIntegerMatchRE = new RegExp("^(?:[gl]?eq|ne)$"); |
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 ], |
| 120 | [ 'leq', null ] |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 121 | ]) |
| 122 | }; |
| 123 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 124 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 125 | /** |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 126 | * Virtual corpus |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 127 | */ |
| 128 | return { |
| 129 | |
| 130 | /** |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 131 | * The JSON-LD type of the virtual corpus |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 132 | */ |
| 133 | ldType : function() { |
| 134 | return null; |
| 135 | }, |
| 136 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 137 | |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 138 | // Initialize virtual corpus |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 139 | _init : function(keyList) { |
| 140 | |
| 141 | // Inject localized css styles |
| 142 | if (!KorAP._overrideStyles) { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 143 | |
| 144 | const sheet = KorAP.newStyleSheet(); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 145 | |
| 146 | // Add css rule for OR operations |
| 147 | sheet.insertRule('.vc .docGroup[data-operation=or] > .doc::before,' |
| 148 | + '.vc .docGroup[data-operation=or] > .docGroup::before ' |
| 149 | + '{ content: "' + loc.OR + '" }', 0); |
| 150 | |
| 151 | // Add css rule for AND operations |
| 152 | sheet.insertRule( |
| 153 | '.vc .docGroup[data-operation=and] > .doc::before,' |
| 154 | + '.vc .docGroup[data-operation=and] > .docGroup::before ' |
| 155 | + '{ content: "' + loc.AND + '" }', 1); |
| 156 | |
| 157 | KorAP._overrideStyles = true; |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 158 | }; |
| 159 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 160 | let l; |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 161 | if (keyList) { |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 162 | l = keyList.slice(); |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 163 | l.unshift(['referTo', 'ref']); |
| 164 | } |
| 165 | else { |
| 166 | l = [['referTo', 'ref']]; |
| 167 | } |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 168 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 169 | // Create key menu |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 170 | KorAP._vcKeyMenu = menuClass.create(l); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 171 | KorAP._vcKeyMenu.limit(6); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 172 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 173 | return this; |
| 174 | }, |
Nils Diewald | 359a72c | 2015-04-20 17:40:29 +0000 | [diff] [blame] | 175 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 176 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 177 | /** |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 178 | * Create a new virtual corpus |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 179 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 180 | create : function (keyList) { |
| 181 | const obj = Object.create(this)._init(keyList); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 182 | obj._root = unspecDocClass.create(obj); |
| 183 | return obj; |
| 184 | }, |
Nils Diewald | d599d54 | 2015-01-08 20:41:34 +0000 | [diff] [blame] | 185 | |
Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame] | 186 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 187 | /** |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 188 | * Create and render a new virtual corpus based on a KoralQuery |
| 189 | * corpus document |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 190 | */ |
| 191 | fromJson : function(json) { |
Akron | 13af2f4 | 2019-07-25 15:06:21 +0200 | [diff] [blame] | 192 | |
| 193 | let obj; |
| 194 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 195 | if (json !== undefined) { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 196 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 197 | // Parse root document |
| 198 | if (json['@type'] == 'koral:doc') { |
Akron | 13af2f4 | 2019-07-25 15:06:21 +0200 | [diff] [blame] | 199 | obj = docClass.create(this, json); |
hebasta | a79d69d | 2018-07-24 12:13:02 +0200 | [diff] [blame] | 200 | } |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 201 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 202 | // parse root group |
| 203 | else if (json['@type'] == 'koral:docGroup') { |
Akron | 13af2f4 | 2019-07-25 15:06:21 +0200 | [diff] [blame] | 204 | obj = docGroupClass.create(this, json); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | // parse root reference |
| 208 | else if (json['@type'] == 'koral:docGroupRef') { |
Akron | 13af2f4 | 2019-07-25 15:06:21 +0200 | [diff] [blame] | 209 | obj = docGroupRefClass.create(this, json); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | // Unknown collection type |
| 213 | else { |
| 214 | KorAP.log(813, "Collection type is not supported"); |
| 215 | return; |
| 216 | }; |
| 217 | } |
| 218 | |
| 219 | else { |
| 220 | // Add unspecified object |
Akron | 13af2f4 | 2019-07-25 15:06:21 +0200 | [diff] [blame] | 221 | obj = unspecDocClass.create(this); |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 222 | }; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 223 | |
| 224 | // Init element and update |
Akron | 13af2f4 | 2019-07-25 15:06:21 +0200 | [diff] [blame] | 225 | this.root(obj); |
| 226 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 227 | return this; |
| 228 | }, |
Akron | d2474aa | 2018-08-28 12:06:27 +0200 | [diff] [blame] | 229 | |
| 230 | |
| 231 | // Check if the virtual corpus contains a rerite |
| 232 | wasRewritten : function (obj) { |
| 233 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 234 | if (arguments.length !== 1) { |
Akron | d2474aa | 2018-08-28 12:06:27 +0200 | [diff] [blame] | 235 | obj = this._root; |
| 236 | }; |
| 237 | |
| 238 | // Check for rewrite |
| 239 | if (obj.rewrites() && obj.rewrites().length() > 0) { |
| 240 | return true; |
| 241 | } |
| 242 | |
| 243 | // Check recursively |
| 244 | else if (obj.ldType() === 'docGroup') { |
Akron | 678c26f | 2020-10-09 08:52:50 +0200 | [diff] [blame] | 245 | |
| 246 | // If there was a rewritten object |
| 247 | if (obj.operands().find(op => this.wasRewritten(op)) !== undefined) { |
| 248 | return true; |
Akron | d2474aa | 2018-08-28 12:06:27 +0200 | [diff] [blame] | 249 | }; |
| 250 | }; |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 251 | |
Akron | d2474aa | 2018-08-28 12:06:27 +0200 | [diff] [blame] | 252 | return false; |
| 253 | }, |
Akron | 43c5cc6 | 2018-08-28 13:10:25 +0200 | [diff] [blame] | 254 | |
Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame] | 255 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 256 | /** |
hebasta | 3f4be92 | 2018-12-11 10:41:46 +0100 | [diff] [blame] | 257 | * Clean the virtual document to unspecified doc. |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 258 | */ |
| 259 | clean : function() { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 260 | const t = this; |
| 261 | if (t._root.ldType() !== "non") { |
| 262 | t._root.destroy(); |
| 263 | t.root(unspecDocClass.create(t)); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 264 | }; |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 265 | |
| 266 | // update for graying corpus statistic by deleting the first line of the vc builder |
| 267 | t.update(); |
| 268 | return t; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 269 | }, |
| 270 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 271 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 272 | /** |
Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 273 | * Get or set the root object of the virtual corpus |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 274 | */ |
| 275 | root : function(obj) { |
| 276 | if (arguments.length === 1) { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 277 | const e = this.builder(); |
| 278 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 279 | if (e.firstChild !== null) { |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 280 | |
| 281 | // Object not yet set |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 282 | if (e.firstChild !== obj.element()) { |
| 283 | e.replaceChild(obj.element(), e.firstChild); |
| 284 | }; |
| 285 | } |
| 286 | |
| 287 | // Append root element |
| 288 | else { |
| 289 | e.appendChild(obj.element()); |
| 290 | }; |
| 291 | |
| 292 | // Update parent child relations |
| 293 | this._root = obj; |
| 294 | obj.parent(this); |
| 295 | |
| 296 | this.update(); |
| 297 | }; |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 298 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 299 | return this._root; |
| 300 | }, |
| 301 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 302 | |
| 303 | /** |
| 304 | * Get the wrapper element associated with the vc |
| 305 | */ |
| 306 | builder : function () { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 307 | const t = this; |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 308 | |
| 309 | // Initialize if necessary |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 310 | if (t._builder !== undefined) |
| 311 | return t._builder; |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 312 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 313 | t.element(); |
| 314 | return t._builder; |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 315 | }, |
| 316 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 317 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 318 | /** |
Akron | 68d2832 | 2018-08-27 15:02:42 +0200 | [diff] [blame] | 319 | * Get the element associated with the virtual corpus |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 320 | */ |
| 321 | element : function() { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 322 | const t = this; |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 323 | let e = t._el; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 324 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 325 | if (e !== undefined) |
| 326 | return e; |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 327 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 328 | |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 329 | e = t._el = document.createElement('div'); |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 330 | e.classList.add('vc'); |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 331 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 332 | |
| 333 | t._builder = e.addE('div'); |
| 334 | t._builder.setAttribute('class', 'builder'); |
| 335 | |
| 336 | const btn = buttonGroupClass.create( |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 337 | ['action','button-view'] |
| 338 | ); |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 339 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 340 | btn.add(loc.MINIMIZE, {'cls':['button-icon','minimize']}, function () { |
| 341 | this.minimize(); |
| 342 | }.bind(t)); |
| 343 | |
| 344 | e.appendChild(btn.element()); |
| 345 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 346 | // Initialize root |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 347 | t._builder.appendChild(t._root.element()); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 348 | |
| 349 | // Add panel to display corpus statistic, ... |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 350 | t.addVcInfPanel(); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 351 | |
hebasta | 4dd77bc | 2019-02-07 12:57:57 +0100 | [diff] [blame] | 352 | //Adds EventListener for corpus changes |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 353 | t._el.addEventListener('vcChange', function (e) { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 354 | this.checkStatActive(e.detail); |
| 355 | }.bind(t), false); |
hebasta | 4dd77bc | 2019-02-07 12:57:57 +0100 | [diff] [blame] | 356 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 357 | return e; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 358 | }, |
| 359 | |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 360 | |
| 361 | /** |
| 362 | * Check, if the VC is open |
| 363 | */ |
| 364 | isOpen : function () { |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 365 | if (!this._el) |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 366 | return false; |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 367 | return this._el.classList.contains('active'); |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 368 | }, |
| 369 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 370 | |
Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 371 | /** |
| 372 | * Open the VC view |
| 373 | */ |
| 374 | open : function () { |
| 375 | this.element().classList.add('active'); |
| 376 | if (this.onOpen) |
| 377 | this.onOpen(); |
| 378 | }, |
| 379 | |
| 380 | |
| 381 | /** |
| 382 | * Minimize the VC view |
| 383 | */ |
| 384 | minimize : function () { |
| 385 | this.element().classList.remove('active'); |
| 386 | if (this.onMinimize) |
| 387 | this.onMinimize(); |
| 388 | }, |
| 389 | |
| 390 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 391 | /** |
| 392 | * Update the whole object based on the underlying data structure |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 393 | */ |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 394 | update : function() { |
| 395 | this._root.update(); |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 396 | if (KorAP.vc) { |
| 397 | this.element().dispatchEvent( |
| 398 | new CustomEvent('vcChange', {'detail':this}) |
| 399 | ); |
hebasta | 4dd77bc | 2019-02-07 12:57:57 +0100 | [diff] [blame] | 400 | }; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 401 | return this; |
| 402 | }, |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 403 | |
| 404 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 405 | /** |
| 406 | * Make the vc persistant by injecting the current timestamp as a |
| 407 | * creation date limit criterion. |
| 408 | * THIS IS CURRENTLY NOT USED |
| 409 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 410 | /* |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 411 | makePersistant : function() { |
| 412 | // this.root().wrapOnRoot('and'); |
| 413 | var todayStr = KorAP._vcDatePicker.today(); |
| 414 | var doc = docClass.create(); |
| 415 | var root = this.root(); |
| 416 | |
| 417 | if (root.ldType() === 'docGroup' && root.operation === 'and') { |
| 418 | root.append(cond); |
| 419 | } else { |
| 420 | root.wrapOnRoot('and'); |
| 421 | root.append(doc); |
| 422 | }; |
| 423 | |
| 424 | doc.key("creationDate"); |
| 425 | doc.type("date"); |
| 426 | doc.matchop("leq"); |
| 427 | doc.value(todayStr); |
| 428 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 429 | // { "@type" : "koral:doc", "key" : "creationDate", "type" : |
| 430 | // "type:date", "match" : "match:leq", "value" : todayStr } |
| 431 | // this.root().append(cond); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 432 | this.update(); |
| 433 | }, |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 434 | */ |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 435 | |
Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame] | 436 | |
| 437 | // Get the reference name |
| 438 | getName : function () { |
| 439 | if (this._root.ldType() === 'non') { |
| 440 | return loc.VC_allCorpora; |
| 441 | } |
| 442 | else if (this._root.ldType() === 'docGroupRef') { |
| 443 | return this._root.ref(); |
| 444 | } |
| 445 | else { |
| 446 | return loc.VC_oneCollection; |
| 447 | } |
| 448 | }, |
| 449 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 450 | |
Akron | 4feec9d | 2018-11-20 17:00:50 +0100 | [diff] [blame] | 451 | // Add "and" constraint to VC |
| 452 | addRequired : function (doc) { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 453 | const root = this.root(); |
| 454 | const ldType = root.ldType(); |
| 455 | const parent = root.parent(); |
Akron | 4feec9d | 2018-11-20 17:00:50 +0100 | [diff] [blame] | 456 | |
Akron | 4feec9d | 2018-11-20 17:00:50 +0100 | [diff] [blame] | 457 | if (ldType === 'non') { |
| 458 | parent.root(doc); |
| 459 | } |
| 460 | |
| 461 | // root is doc |
| 462 | else if ( |
| 463 | ldType === 'doc' || |
| 464 | ldType === 'docGroupRef' || |
| 465 | (ldType === 'docGroup' && |
| 466 | root.operation() === 'or' |
| 467 | )) { |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 468 | const group = require('vc/docgroup').create( |
Akron | 4feec9d | 2018-11-20 17:00:50 +0100 | [diff] [blame] | 469 | parent |
| 470 | ); |
| 471 | group.operation("and"); |
| 472 | group.append(root); |
| 473 | group.append(doc); |
| 474 | group.element(); // Init (seems to be necessary) |
| 475 | parent.root(group); |
| 476 | } |
| 477 | |
| 478 | // root is a docGroup |
| 479 | // and is already an 'and'-Group |
| 480 | else if (ldType === 'docGroup') { |
| 481 | root.append(doc); |
| 482 | } |
| 483 | |
| 484 | // Unknown |
| 485 | else { |
| 486 | console.log("Unknown root object"); |
| 487 | }; |
| 488 | |
| 489 | // Init element and update |
| 490 | this.update(); |
| 491 | }, |
Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame] | 492 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 493 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 494 | /** |
| 495 | * Get the generated json string |
| 496 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 497 | toJson : function () { |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 498 | return this._root.toJson(); |
| 499 | }, |
| 500 | |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 501 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 502 | /** |
| 503 | * Get the generated query string |
| 504 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 505 | toQuery : function () { |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 506 | return this._root.toQuery(); |
| 507 | }, |
| 508 | |
hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 509 | |
| 510 | /** |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 511 | * Add panel to display virtual corpus information |
| 512 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 513 | addVcInfPanel : function () { |
| 514 | // Create panel |
hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 515 | this.panel = vcPanelClass.create(this); |
Akron | 24aa005 | 2020-11-10 11:00:34 +0100 | [diff] [blame] | 516 | this._el.addE('div').appendChild(this.panel.element()); |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 517 | |
hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 518 | }, |
| 519 | |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 520 | /** |
hebasta | 48842cf | 2018-12-11 12:57:38 +0100 | [diff] [blame] | 521 | * Checks if corpus statistic has to be disabled, |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 522 | * and to be updated after clicking at the "reload-button" |
| 523 | */ |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 524 | checkStatActive : function (){ |
| 525 | if (this.panel !== undefined && this.panel.statView !== undefined){ |
hebasta | 48842cf | 2018-12-11 12:57:38 +0100 | [diff] [blame] | 526 | this.panel.statView.checkStatActive(); |
Akron | 88d237e | 2020-10-21 08:05:18 +0200 | [diff] [blame] | 527 | }; |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 528 | } |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 529 | }; |
| 530 | }); |