| 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', | 
| hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 56 | 'panel/vcpanel', | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 57 | 'view/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) { | 
|  | 181 | if (json !== undefined) { | 
|  | 182 | // Parse root document | 
|  | 183 | if (json['@type'] == 'koral:doc') { | 
|  | 184 | this._root = docClass.create(this, json); | 
| hebasta | a79d69d | 2018-07-24 12:13:02 +0200 | [diff] [blame] | 185 | } | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 186 | // parse root group | 
|  | 187 | else if (json['@type'] == 'koral:docGroup') { | 
|  | 188 | this._root = docGroupClass.create(this, json); | 
|  | 189 | } | 
|  | 190 |  | 
|  | 191 | // parse root reference | 
|  | 192 | else if (json['@type'] == 'koral:docGroupRef') { | 
|  | 193 | this._root = docGroupRefClass.create(this, json); | 
|  | 194 | } | 
|  | 195 |  | 
|  | 196 | // Unknown collection type | 
|  | 197 | else { | 
|  | 198 | KorAP.log(813, "Collection type is not supported"); | 
|  | 199 | return; | 
|  | 200 | }; | 
|  | 201 | } | 
|  | 202 |  | 
|  | 203 | else { | 
|  | 204 | // Add unspecified object | 
|  | 205 | this._root = unspecDocClass.create(this); | 
| Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 206 | }; | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 207 |  | 
|  | 208 | // Init element and update | 
|  | 209 | this.update(); | 
|  | 210 |  | 
|  | 211 | return this; | 
|  | 212 | }, | 
| Akron | d2474aa | 2018-08-28 12:06:27 +0200 | [diff] [blame] | 213 |  | 
|  | 214 |  | 
|  | 215 | // Check if the virtual corpus contains a rerite | 
|  | 216 | wasRewritten : function (obj) { | 
|  | 217 |  | 
|  | 218 | var obj; | 
|  | 219 | if (arguments.length === 1) { | 
|  | 220 | obj = arguments[0]; | 
|  | 221 | } | 
|  | 222 | else { | 
|  | 223 | obj = this._root; | 
|  | 224 | }; | 
|  | 225 |  | 
|  | 226 | // Check for rewrite | 
|  | 227 | if (obj.rewrites() && obj.rewrites().length() > 0) { | 
|  | 228 | return true; | 
|  | 229 | } | 
|  | 230 |  | 
|  | 231 | // Check recursively | 
|  | 232 | else if (obj.ldType() === 'docGroup') { | 
|  | 233 | for (var i in obj.operands()) { | 
|  | 234 | if (this.wasRewritten(obj.getOperand(i))) { | 
|  | 235 | return true; | 
|  | 236 | } | 
|  | 237 | }; | 
|  | 238 | }; | 
|  | 239 |  | 
|  | 240 | return false; | 
|  | 241 | }, | 
| Akron | 43c5cc6 | 2018-08-28 13:10:25 +0200 | [diff] [blame] | 242 |  | 
| Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame] | 243 |  | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 244 | /** | 
| hebasta | 3f4be92 | 2018-12-11 10:41:46 +0100 | [diff] [blame] | 245 | * Clean the virtual document to unspecified doc. | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 246 | */ | 
|  | 247 | clean : function() { | 
|  | 248 | if (this._root.ldType() !== "non") { | 
|  | 249 | this._root.destroy(); | 
|  | 250 | this.root(unspecDocClass.create(this)); | 
|  | 251 | }; | 
| hebasta | 3f4be92 | 2018-12-11 10:41:46 +0100 | [diff] [blame] | 252 | //update for graying corpus statistic by deleting the first line of the vc builder | 
|  | 253 | this.update(); | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 254 | return this; | 
|  | 255 | }, | 
|  | 256 |  | 
|  | 257 | /** | 
| Akron | cd42a14 | 2019-07-12 18:55:37 +0200 | [diff] [blame] | 258 | * Get or set the root object of the virtual corpus | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 259 | */ | 
|  | 260 | root : function(obj) { | 
|  | 261 | if (arguments.length === 1) { | 
| Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 262 | var e = this.builder(); | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 263 |  | 
|  | 264 | if (e.firstChild !== null) { | 
| Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 265 |  | 
|  | 266 | // Object not yet set | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 267 | if (e.firstChild !== obj.element()) { | 
|  | 268 | e.replaceChild(obj.element(), e.firstChild); | 
|  | 269 | }; | 
|  | 270 | } | 
|  | 271 |  | 
|  | 272 | // Append root element | 
|  | 273 | else { | 
|  | 274 | e.appendChild(obj.element()); | 
|  | 275 | }; | 
|  | 276 |  | 
|  | 277 | // Update parent child relations | 
|  | 278 | this._root = obj; | 
|  | 279 | obj.parent(this); | 
|  | 280 |  | 
|  | 281 | this.update(); | 
|  | 282 | }; | 
|  | 283 | return this._root; | 
|  | 284 | }, | 
|  | 285 |  | 
| Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 286 |  | 
|  | 287 | /** | 
|  | 288 | * Get the wrapper element associated with the vc | 
|  | 289 | */ | 
|  | 290 | builder : function () { | 
|  | 291 |  | 
|  | 292 | // Initialize if necessary | 
|  | 293 | if (this._builder !== undefined) | 
|  | 294 | return this._builder; | 
|  | 295 |  | 
|  | 296 | this.element(); | 
|  | 297 | return this._builder; | 
|  | 298 | }, | 
|  | 299 |  | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 300 | /** | 
| Akron | 68d2832 | 2018-08-27 15:02:42 +0200 | [diff] [blame] | 301 | * Get the element associated with the virtual corpus | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 302 | */ | 
|  | 303 | element : function() { | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 304 | if (this._element !== undefined) { | 
|  | 305 | return this._element; | 
|  | 306 | }; | 
|  | 307 |  | 
|  | 308 | this._element = document.createElement('div'); | 
| Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 309 | this._element.classList.add('vc'); | 
|  | 310 |  | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 311 |  | 
| Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 312 | this._builder = this._element.addE('div'); | 
|  | 313 | this._builder.setAttribute('class', 'builder'); | 
|  | 314 |  | 
| Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 315 | var btn = buttonGroupClass.create( | 
|  | 316 | ['action','button-view'] | 
|  | 317 | ); | 
|  | 318 | var that = this; | 
|  | 319 | btn.add(loc.MINIMIZE, ['button-icon','minimize'], function () { | 
|  | 320 | that.minimize(); | 
|  | 321 | }); | 
|  | 322 | this._element.appendChild(btn.element()); | 
|  | 323 |  | 
|  | 324 |  | 
|  | 325 |  | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 326 | // Initialize root | 
| Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 327 | this._builder.appendChild(this._root.element()); | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 328 |  | 
|  | 329 | // Add panel to display corpus statistic, ... | 
|  | 330 | this.addVcInfPanel(); | 
|  | 331 |  | 
| hebasta | 4dd77bc | 2019-02-07 12:57:57 +0100 | [diff] [blame] | 332 | //Adds EventListener for corpus changes | 
|  | 333 | this._element.addEventListener('vcChange', function (e) { | 
|  | 334 | that.checkStatActive(e.detail); | 
|  | 335 | }, false); | 
|  | 336 |  | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 337 | return this._element; | 
|  | 338 | }, | 
|  | 339 |  | 
| Akron | ec6bb8e | 2018-08-29 13:07:56 +0200 | [diff] [blame] | 340 |  | 
|  | 341 | /** | 
|  | 342 | * Check, if the VC is open | 
|  | 343 | */ | 
|  | 344 | isOpen : function () { | 
|  | 345 | if (!this._element) | 
|  | 346 | return false; | 
|  | 347 | return this._element.classList.contains('active'); | 
|  | 348 | }, | 
|  | 349 |  | 
|  | 350 | /** | 
|  | 351 | * Open the VC view | 
|  | 352 | */ | 
|  | 353 | open : function () { | 
|  | 354 | this.element().classList.add('active'); | 
|  | 355 | if (this.onOpen) | 
|  | 356 | this.onOpen(); | 
|  | 357 | }, | 
|  | 358 |  | 
|  | 359 |  | 
|  | 360 | /** | 
|  | 361 | * Minimize the VC view | 
|  | 362 | */ | 
|  | 363 | minimize : function () { | 
|  | 364 | this.element().classList.remove('active'); | 
|  | 365 | if (this.onMinimize) | 
|  | 366 | this.onMinimize(); | 
|  | 367 | }, | 
|  | 368 |  | 
|  | 369 |  | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 370 | /** | 
|  | 371 | * Update the whole object based on the underlying data structure | 
| hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 372 | */ | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 373 | update : function() { | 
|  | 374 | this._root.update(); | 
| hebasta | 4dd77bc | 2019-02-07 12:57:57 +0100 | [diff] [blame] | 375 | if (KorAP.vc){ | 
|  | 376 | var vcchevent = new CustomEvent('vcChange', {'detail':this}); | 
|  | 377 | this.element().dispatchEvent(vcchevent); | 
|  | 378 | }; | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 379 | return this; | 
|  | 380 | }, | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 381 | /** | 
|  | 382 | * Make the vc persistant by injecting the current timestamp as a | 
|  | 383 | * creation date limit criterion. | 
|  | 384 | * THIS IS CURRENTLY NOT USED | 
|  | 385 | */ | 
|  | 386 | makePersistant : function() { | 
|  | 387 | // this.root().wrapOnRoot('and'); | 
|  | 388 | var todayStr = KorAP._vcDatePicker.today(); | 
|  | 389 | var doc = docClass.create(); | 
|  | 390 | var root = this.root(); | 
|  | 391 |  | 
|  | 392 | if (root.ldType() === 'docGroup' && root.operation === 'and') { | 
|  | 393 | root.append(cond); | 
|  | 394 | } else { | 
|  | 395 | root.wrapOnRoot('and'); | 
|  | 396 | root.append(doc); | 
|  | 397 | }; | 
|  | 398 |  | 
|  | 399 | doc.key("creationDate"); | 
|  | 400 | doc.type("date"); | 
|  | 401 | doc.matchop("leq"); | 
|  | 402 | doc.value(todayStr); | 
|  | 403 |  | 
|  | 404 | /* | 
|  | 405 | * { "@type" : "koral:doc", "key" : "creationDate", "type" : | 
|  | 406 | * "type:date", "match" : "match:leq", "value" : todayStr } | 
|  | 407 | * this.root().append(cond); | 
|  | 408 | */ | 
|  | 409 | this.update(); | 
|  | 410 | }, | 
|  | 411 |  | 
| Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame] | 412 |  | 
|  | 413 | // Get the reference name | 
|  | 414 | getName : function () { | 
|  | 415 | if (this._root.ldType() === 'non') { | 
|  | 416 | return loc.VC_allCorpora; | 
|  | 417 | } | 
|  | 418 | else if (this._root.ldType() === 'docGroupRef') { | 
|  | 419 | return this._root.ref(); | 
|  | 420 | } | 
|  | 421 | else { | 
|  | 422 | return loc.VC_oneCollection; | 
|  | 423 | } | 
|  | 424 | }, | 
|  | 425 |  | 
| Akron | 4feec9d | 2018-11-20 17:00:50 +0100 | [diff] [blame] | 426 | // Add "and" constraint to VC | 
|  | 427 | addRequired : function (doc) { | 
|  | 428 |  | 
|  | 429 | let root = this.root(); | 
|  | 430 | let ldType = root.ldType(); | 
|  | 431 |  | 
|  | 432 | let parent = root.parent(); | 
|  | 433 | if (ldType === 'non') { | 
|  | 434 | parent.root(doc); | 
|  | 435 | } | 
|  | 436 |  | 
|  | 437 | // root is doc | 
|  | 438 | else if ( | 
|  | 439 | ldType === 'doc' || | 
|  | 440 | ldType === 'docGroupRef' || | 
|  | 441 | (ldType === 'docGroup' && | 
|  | 442 | root.operation() === 'or' | 
|  | 443 | )) { | 
|  | 444 | let group = require('vc/docgroup').create( | 
|  | 445 | parent | 
|  | 446 | ); | 
|  | 447 | group.operation("and"); | 
|  | 448 | group.append(root); | 
|  | 449 | group.append(doc); | 
|  | 450 | group.element(); // Init (seems to be necessary) | 
|  | 451 | parent.root(group); | 
|  | 452 | } | 
|  | 453 |  | 
|  | 454 | // root is a docGroup | 
|  | 455 | // and is already an 'and'-Group | 
|  | 456 | else if (ldType === 'docGroup') { | 
|  | 457 | root.append(doc); | 
|  | 458 | } | 
|  | 459 |  | 
|  | 460 | // Unknown | 
|  | 461 | else { | 
|  | 462 | console.log("Unknown root object"); | 
|  | 463 | }; | 
|  | 464 |  | 
|  | 465 | // Init element and update | 
|  | 466 | this.update(); | 
|  | 467 | }, | 
| Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame] | 468 |  | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 469 | /** | 
|  | 470 | * Get the generated json string | 
|  | 471 | */ | 
|  | 472 | toJson : function() { | 
|  | 473 | return this._root.toJson(); | 
|  | 474 | }, | 
|  | 475 |  | 
|  | 476 | /** | 
|  | 477 | * Get the generated query string | 
|  | 478 | */ | 
|  | 479 | toQuery : function() { | 
|  | 480 | return this._root.toQuery(); | 
|  | 481 | }, | 
|  | 482 |  | 
| hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 483 |  | 
|  | 484 | /** | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 485 | * Add panel to display virtual corpus information | 
|  | 486 | */ | 
|  | 487 | addVcInfPanel : function() { | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 488 | var dv = this._element.addE('div'); | 
| hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 489 | //Create panel | 
|  | 490 | this.panel = vcPanelClass.create(this); | 
|  | 491 | dv.appendChild(this.panel.element()); | 
| hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 492 |  | 
| hebasta | 2535c76 | 2018-11-21 16:27:33 +0100 | [diff] [blame] | 493 | }, | 
|  | 494 |  | 
| hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 495 | /** | 
| hebasta | 48842cf | 2018-12-11 12:57:38 +0100 | [diff] [blame] | 496 | * Checks if corpus statistic has to be disabled, | 
| hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 497 | * and to be updated after clicking at the "reload-button" | 
|  | 498 | */ | 
| hebasta | 48842cf | 2018-12-11 12:57:38 +0100 | [diff] [blame] | 499 | checkStatActive : function(){ | 
| hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 500 | if(this.panel !== undefined && this.panel.statView !==undefined){ | 
| hebasta | 48842cf | 2018-12-11 12:57:38 +0100 | [diff] [blame] | 501 | this.panel.statView.checkStatActive(); | 
| hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 502 | } | 
|  | 503 | } | 
| Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 504 | }; | 
|  | 505 | }); |