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