Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 | 13x 13x 13x 13x 4x 1x 4x 4x 4x 3x 13x 2x 2x 2x 2x 2x 6x 20x 20x 20x 20x 2x 18x 18x 18x 18x 18x 18x 18x 18x 18x 8x 8x 8x 8x 8x 8x 8x 8x 49x 49x 49x 49x 49x 1x 1x 1x 1x 1x 1x 1x 42x 42x 42x 42x 42x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 13x 13x 13x 13x 13x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 4x 4x 4x 4x 2x 2x 2x 2x 2x 2x 2x 45x 45x 45x 45x 45x 8x 21x 4x 2x 5x 2x 1x 2x | /*! * WikiLambda Vuex code to interact with the store to create and update ZObjects. * * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt * @license MIT */ var Constants = require( '../../../Constants.js' ), typeUtils = require( '../../../mixins/typeUtils.js' ).methods, zobjectTreeUtils = require( '../../../mixins/zobjectTreeUtils.js' ).methods, getParameterByName = require( '../../../mixins/urlUtils.js' ).methods.getParameterByName; function setDefaultFunctionReference( context, id, functionValue ) { if ( !functionValue || functionValue === Constants.NEW_ZID_PLACEHOLDER ) { context.dispatch( 'addZReference', { id: id, value: functionValue } ); } // fetch zkeys for the zid, then check whether Z2K2.Z1K1 is equal to Constants.Z_FUNCTION return context.dispatch( 'fetchZKeys', { zids: [ functionValue ] } ).then( function () { var keys = context.getters.getZkeys[ functionValue ]; if ( keys && keys[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_OBJECT_TYPE ] === Constants.Z_FUNCTION ) { context.dispatch( 'addZReference', { id: id, value: functionValue } ); } } ); } module.exports = exports = { actions: { /** * This method is used to generate a zObjectType (Z1K1) for a given object. * This can either be a simple string with a zId or a complex function call for functionToType * { Z1K1: Z123 } * or * { * Z1K1: { * "Z1K1":"Z7", * "Z7K1":"Z123", * "Z123K1":"Z13456", * } * } * * @param {Object} context * @param {Object} payload * @param {string} payload.objectId * @param {string} payload.type */ addZObjectType: function ( context, payload ) { var type, isPersistentObject = context .rootGetters .getZkeys[ payload.type ][ Constants.Z_OBJECT_TYPE ] === Constants.Z_PERSISTENTOBJECT, object = context.getters.getZObjectById( payload.objectId ); if ( isPersistentObject ) { type = context .rootGetters .getZkeys[ payload.type ][ Constants.Z_PERSISTENTOBJECT_ID ][ Constants.Z_STRING_VALUE ]; context.dispatch( 'addZObject', { key: Constants.Z_OBJECT_TYPE, value: type, parent: payload.objectId } ); } else E{ type = context .rootGetters .getZkeys[ payload.type ][ Constants.Z_TYPE_IDENTITY ]; // we need to wrap the object in Z1K1 (Z_OBJECT_TYPE) var Z_OBJECT_TYPE = {}; Z_OBJECT_TYPE[ Constants.Z_OBJECT_TYPE ] = type; context.dispatch( 'injectZObject', { zobject: Z_OBJECT_TYPE, key: Constants.Z_OBJECT_TYPE, id: payload.objectId, parent: object.parentId } ); } }, /** * Create the required entry in the zobject array for a zPersistenObject. * The entry will result in a json representation equal to: * { Z1K1: { Z1K1: 'Z9', Z9K1: 'Z2' }, * Z2K1: { Z1K1: 'Z9', Z9K1: 'Z0' }, * Z2K2: undefined, * Z2K3: { Z1K1: { * Z1K1: 'Z9', Z9K1: 'Z12' * }, Z12K1: [ Z11 ] }, * Z2K4: { Z1K1: { * Z1K1: 'Z9', Z9K1: 'Z32' * }, Z32K1: [ Z31 ] } * } * * @param {Object} context * @param {number} ObjectId */ addZPersistentObject: function ( context, ObjectId ) { context.dispatch( 'injectZObject', { zobject: { Z1K1: Constants.Z_PERSISTENTOBJECT, Z2K1: Constants.NEW_ZID_PLACEHOLDER, Z2K2: {}, Z2K3: { Z1K1: Constants.Z_MULTILINGUALSTRING, Z12K1: context.getters.getUserZlangZID ? [ Constants.Z_MONOLINGUALSTRING, { Z1K1: Constants.Z_MONOLINGUALSTRING, Z11K1: context.getters.getUserZlangZID, Z11K2: '' } ] : [ Constants.Z_MONOLINGUALSTRING ] }, Z2K4: { Z1K1: Constants.Z_MULTILINGUALSTRINGSET, Z32K1: [ Constants.Z_MONOLINGUALSTRINGSET ] } }, key: undefined, id: undefined, parent: ObjectId } ); }, /** * Create the required entry in the zobject array for a zMonolingualString. * The entry will result in a json representation equal to: * { Z1K1: Z11, Z11K1: { Z1K1: Z9, Z9K1: payload.lang }, Z11K2: { Z1K1: Z6, Z6K1: '' } } * * @param {Object} context * @param {Object} payload */ addZMonolingualString: function ( context, payload ) { var parentId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ), nextId, numberOfLanguageInArray = context.getters.getZObjectChildrenById( payload.parentId ).length, zObjectItems = []; if ( !payload.lang || !payload.parentId ) { return; } context.dispatch( 'fetchZKeys', { zids: [ payload.lang ] } ); // Create root object zObjectItems = [ { key: `${numberOfLanguageInArray}`, value: 'object', parent: payload.parentId }, { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_MONOLINGUALSTRING, parent: parentId } ]; context.dispatch( 'addZObjects', zObjectItems ); // Set language reference nextId = context.getters.getNextObjectId; context.dispatch( 'addZObject', { key: Constants.Z_MONOLINGUALSTRING_LANGUAGE, value: 'object', parent: parentId } ); context.dispatch( 'addZReference', { id: nextId, value: payload.lang } ); // Set default string nextId = context.getters.getNextObjectId; context.dispatch( 'addZObject', { key: Constants.Z_MONOLINGUALSTRING_VALUE, value: 'object', parent: parentId } ); context.dispatch( 'addZString', { id: nextId, value: payload.value } ); }, /** * Create the required entry in the zobject array for a zMultilingualString. * The entry will result in a json representation equal to: * { Z1K1: Z12, Z12K1: [ Z11 ] } * * @param {Object} context * @param {Object} payload */ addZMultilingualString: function ( context, payload ) { var nextId; context.dispatch( 'setZObjectValue', { id: payload.id, value: 'object' } ); context.dispatch( 'addZObject', { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_MULTILINGUALSTRING, parent: payload.id } ); nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_MULTILINGUALSTRING_VALUE, value: 'array', parent: payload.id } ); // Add ZMonolingualString // Add ZMonolingualString type var monolingualStringParentId = nextId + 1; var zObjectItems = [ { key: '0', value: 'object', parent: nextId }, { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_REFERENCE, parent: monolingualStringParentId }, { key: Constants.Z_REFERENCE_ID, value: Constants.Z_MONOLINGUALSTRING, parent: monolingualStringParentId } ]; context.dispatch( 'addZObjects', zObjectItems ); // Add ZMonolingualString items context.dispatch( 'addZMonolingualString', { parentId: nextId, lang: payload.lang || context.getters.getUserZlangZID, value: payload.value } ); }, /** * Create the required entry in the zobject array for a zList. * The entry will result in a json representation equal to: * { Z1K1: Z6, Z6K1: '' } * * @param {Object} context * @param {Object} payload */ addZString: function ( context, payload ) { var zObjectItems = [], value = payload.value || ''; context.dispatch( 'setZObjectValue', { id: payload.id, value: 'object' } ); zObjectItems = [ { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_STRING, parent: payload.id }, { key: Constants.Z_STRING_VALUE, value: value, parent: payload.id } ]; context.dispatch( 'addZObjects', zObjectItems ); }, /** * Create the required entry in the zobject array for a zList. * The entry will result in a json representation equal to: * [] * * @param {Object} context * @param {Object} payload */ addTypetoList: function ( context, payload ) { var listType = context.getters.getListTypeById( payload.objectId ); var zListTypeChildren; if ( !listType.id ) { var nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); var zObjectItems = [ { key: '0', value: 'object', parent: payload.objectId }, { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_REFERENCE, parent: nextId }, { key: Constants.Z_REFERENCE_ID, value: payload.type, parent: nextId } ]; context.dispatch( 'addZObjects', zObjectItems ); } else E{ zListTypeChildren = typeUtils.findKeyInArray( Constants.Z_REFERENCE_ID, context.getters.getZObjectChildrenById( listType.id ) ); context.dispatch( 'setZObjectValue', { id: zListTypeChildren.id, value: payload.type } ); } }, /** * Create the required entry in the object for a list of generics. * The entry will result in a json representation equal to: * [ 'Z1' ] * * @param {Object} context * @param {Object} payload * @param {string} payload.value * @param {number} payload.id */ addZTypedList: function ( context, payload ) { context.dispatch( 'setZObjectValue', { id: payload.id, value: 'array' } ); context.dispatch( 'addTypetoList', { objectId: payload.id, type: payload.value || Constants.Z_OBJECT } ); }, /** * Create the required entry in the object for a list of generics. * The entry will result in a json representation equal to: * { Z1K1: Z7, Z7K1: Z882, Z882K1: '', Z882K2: '' } * * @param {Object} context * @param {Object} payload * @param {string} payload.value * @param {number} payload.id * @param {boolean} payload.isDeclaration This is used know if the values need to be initialized or not */ addZTypedPair: function ( context, payload ) { var values = payload.values || [], isDeclaration = payload.isDeclaration || false, functionCallId; if ( isDeclaration ) { // the following creates: // { // "Z1K1": "Z7", // "Z7K1": "Z882", // "Z882K1": values[ 0 ], // "Z882K2": values[ 1 ] // } functionCallId = payload.id; context.dispatch( 'changeType', { id: functionCallId, type: Constants.Z_FUNCTION_CALL, value: Constants.Z_TYPED_PAIR } ) .then( function () { context.dispatch( 'addZObject', { key: Constants.Z_TYPED_PAIR_TYPE1, value: values[ 0 ] || '', parent: functionCallId } ); context.dispatch( 'addZObject', { key: Constants.Z_TYPED_PAIR_TYPE2, value: values[ 1 ] || '', parent: functionCallId } ); } ); } else { // the following creates: // "Z1K1": { // "Z1K1": "Z7", // "Z7K1": "Z882", // "Z882K1": values[ 0 ], // "Z882K2": values[ 1 ] // }, // "K1": initialization for value[ 0 ] // "K2": initialization for values[ 1 ] functionCallId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_OBJECT_TYPE, value: 'object', parent: payload.id } ); context.dispatch( 'changeType', { id: functionCallId, type: Constants.Z_FUNCTION_CALL, value: Constants.Z_TYPED_PAIR } ) .then( function () { context.dispatch( 'addZObject', { key: Constants.Z_TYPED_PAIR_TYPE1, value: values[ 0 ] || '', parent: functionCallId } ); context.dispatch( 'addZObject', { key: Constants.Z_TYPED_PAIR_TYPE2, value: values[ 1 ] || '', parent: functionCallId } ); } ); // when the object is not a declaration we also initialize its key/value pairs var nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_TYPED_OBJECT_ELEMENT_1, value: 'object', parent: payload.id } ); context.dispatch( 'changeType', { id: nextId, type: values[ 0 ] } ); nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_TYPED_OBJECT_ELEMENT_2, value: 'object', parent: payload.id } ); context.dispatch( 'changeType', { id: nextId, type: values[ 1 ] } ); } }, /** * Create the required entry in the object for a map list of typed pair. * The entry will result in a json representation equal to file stored in * function orchestrator test/features/v1/test_data/Z88303.json * Overall it is going to be a TypedMap, including a typedList including a typedPair. * * @param {Object} context * @param {Object} payload * @param {string} payload.value * @param {number} payload.id */ addZTypedMap: function ( context, payload ) { var values = payload.values || [], nextId; // Set the root of the object to be a Z1K1 (Object_type) nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_OBJECT_TYPE, value: 'object', parent: payload.id } ); // Set the Z1K1 to a ZtypedMap: // { Z1K1: Z7, Z7K1: Z883, Z883K1: values[ 0 ], Z883K2: values[ 0 ] } context.dispatch( 'changeType', { id: nextId, type: Constants.Z_FUNCTION_CALL, value: Constants.Z_TYPED_MAP } ) .then( function () { context.dispatch( 'addZObject', { key: Constants.Z_TYPED_MAP_TYPE1, value: values[ 0 ] || '', parent: nextId } ); context.dispatch( 'addZObject', { key: Constants.Z_TYPED_MAP_TYPE2, value: values[ 1 ] || '', parent: nextId } ); } ); }, /** * Create the required entry in the zobject array for a zReference. * The entry will result in a json representation equal to: * { Z1K1: Z9, Z9K1: '' } * * @param {Object} context * @param {Object} payload */ addZReference: function ( context, payload ) { var zObjectItems = [], value = payload.value || ''; context.dispatch( 'setZObjectValue', { id: payload.id, value: 'object' } ); zObjectItems = [ { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_REFERENCE, parent: payload.id }, { key: Constants.Z_REFERENCE_ID, value: value, parent: payload.id } ]; context.dispatch( 'addZObjects', zObjectItems ); }, /** * Create the required entry in the zobject array for a zArgument. * The entry will result in a json representation equal to: * { Z1K1: 'Z17', * Z17K1: { Z1K1: 'Z9', Z9K1: '' }, * Z17K2: { Z1K1: 'Z6', Z6K1: 'Z0K1' }, * Z17K3: { Z1K1: 'Z12', Z12K1: [ Z11 ] } * } * * @param {Object} context * @param {number} payload */ addZArgument: function ( context, payload ) { var objectId = payload.id, nextId; context.dispatch( 'setZObjectValue', { id: objectId, value: 'object' } ); context.dispatch( 'addZObject', { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_ARGUMENT, parent: objectId } ); nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_ARGUMENT_TYPE, value: 'object', parent: objectId } ); context.dispatch( 'addZReference', { id: nextId, value: '' } ); // We calculate the id again, and set the key nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); // we create the base object that will be used to scaffold the ZString context.dispatch( 'addZObject', { key: Constants.Z_ARGUMENT_KEY, value: 'object', parent: objectId } ); context.dispatch( 'addZString', { id: nextId, value: context.rootGetters.getNextKey } ); // We calculate the next id, and create the argument label nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); // we create the base object that will be used to scaffold the ZString context.dispatch( 'addZObject', { key: Constants.Z_ARGUMENT_LABEL, value: 'object', parent: objectId } ); // don't provide a default string: force the user to specify one context.dispatch( 'addZMultilingualString', { id: nextId, value: '', lang: payload.lang } ); }, /** * Create the required entry in the zobject array for a zArgument. * The entry will result in a json representation equal to: * { Z1K1: Z7, Z7K1: '' } * * @param {Object} context * @param {Object} payload */ addZFunctionCall: function ( context, payload ) { var zObjectItems = [], value = payload.value || ''; context.dispatch( 'setZObjectValue', { id: payload.id, value: 'object' } ); zObjectItems = [ { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_FUNCTION_CALL, parent: payload.id }, { key: Constants.Z_FUNCTION_CALL_FUNCTION, value: value, parent: payload.id } ]; context.dispatch( 'addZObjects', zObjectItems ); }, /** * Create the required entry in the zobject array for a zImplementation. * The entry will result in a json representation equal to: * { Z1K1: 'Z14', Z14K1: * { Z1K1: 'Z9', Z9K1: '' }, * Z14K2: undefined, * Z14K3: * { Z1K1: 'Z16', Z16K1: { Z1K1: 'Z61', Z61K1: { Z1K1: 'Z6', Z6K1: '' } }, Z16K2: { Z1K1: 'Z6', Z6K1: '' } } } * * @param {Object} context * @param {number} objectId */ addZImplementation: function ( context, objectId ) { var nextId, isPersistentImplementation = !typeUtils.findKeyInArray( Constants.Z_REFERENCE_ID, context.getters.getZObjectChildrenById( typeUtils.findKeyInArray( Constants.Z_OBJECT_TYPE, context.getters.getZObjectChildrenById( typeUtils.findKeyInArray( Constants.Z_PERSISTENTOBJECT_VALUE, context.rootState.zobjectModule.zobject ).id ) ).id ) ), defaultFunctionValue = isPersistentImplementation ? getParameterByName( Constants.Z_IMPLEMENTATION_FUNCTION ) || '' : context.getters.getCurrentZObjectId; context.dispatch( 'setZObjectValue', { id: objectId, value: 'object' } ); context.dispatch( 'addZObject', { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_IMPLEMENTATION, parent: objectId } ); // Add function nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_IMPLEMENTATION_FUNCTION, value: 'object', parent: objectId } ); setDefaultFunctionReference( context, nextId, defaultFunctionValue ); // Add Composition nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_IMPLEMENTATION_COMPOSITION, value: 'object', parent: objectId } ); context.dispatch( 'changeType', { id: nextId, type: Constants.Z_FUNCTION_CALL } ); }, addZFunction: function ( context, objectId ) { var nextId; context.dispatch( 'setZObjectValue', { id: objectId, value: 'object' } ); // Set type context.dispatch( 'addZObject', { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_FUNCTION, parent: objectId } ); // Add initial ZArgument nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_FUNCTION_ARGUMENTS, value: 'array', parent: objectId } ); // Add ZArgument Type to array var argumentTypeParentId = nextId + 1; var zObjectItems = [ { key: '0', value: 'object', parent: nextId }, { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_REFERENCE, parent: argumentTypeParentId }, { key: Constants.Z_REFERENCE_ID, value: Constants.Z_ARGUMENT, parent: argumentTypeParentId } ]; context.dispatch( 'addZObjects', zObjectItems ); // Add ZArgument to array var argumentsNextId = nextId + 4; context.dispatch( 'addZObject', { key: '1', value: 'object', parent: nextId } ); context.dispatch( 'addZArgument', { id: argumentsNextId } ); // Add return type nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_FUNCTION_RETURN_TYPE, value: 'object', parent: objectId } ); context.dispatch( 'addZReference', { id: nextId, value: '' } ); // Add tester nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_FUNCTION_TESTERS, value: 'array', parent: objectId } ); var testersNextId = nextId + 1; // Add tester type context.dispatch( 'addZObjects', [ { key: '0', value: 'object', parent: nextId }, { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_REFERENCE, parent: testersNextId }, { key: Constants.Z_REFERENCE_ID, value: Constants.Z_TESTER, parent: testersNextId } ] ); // Add implementation nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_FUNCTION_IMPLEMENTATIONS, value: 'array', parent: objectId } ); var implementationsNextId = nextId + 1; // Add implementation type context.dispatch( 'addZObjects', [ { key: '0', value: 'object', parent: nextId }, { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_REFERENCE, parent: implementationsNextId }, { key: Constants.Z_REFERENCE_ID, value: Constants.Z_IMPLEMENTATION, parent: implementationsNextId } ] ); // Set identity nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_FUNCTION_IDENTITY, value: 'object', parent: objectId } ); context.dispatch( 'addZObjects', [ { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_REFERENCE, parent: nextId }, { key: Constants.Z_REFERENCE_ID, value: context.getters.getCurrentZObjectId, parent: nextId } ] ); }, /** * Create the required entry for a ZTester * * @param {Object} context * @param {number} objectId */ addZTester: function ( context, objectId ) { var nextId, defaultFunctionValue = getParameterByName( Constants.Z_TESTER_FUNCTION ) || ''; context.dispatch( 'setZObjectValue', { id: objectId, value: 'object' } ); // Set type context.dispatch( 'addZObject', { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_TESTER, parent: objectId } ); // Set function and add default reference. nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_TESTER_FUNCTION, value: 'object', parent: objectId } ); setDefaultFunctionReference( context, nextId, defaultFunctionValue ); // Set call as a function call nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_TESTER_CALL, value: 'object', parent: objectId } ); context.dispatch( 'addZFunctionCall', { id: nextId } ); // Set validation as a reference nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_TESTER_VALIDATION, value: 'object', parent: objectId } ); context.dispatch( 'addZFunctionCall', { id: nextId } ); }, /** * Create the required entry for a generic object, * but reading the information from the zKeys store . * The entry will result in a json representation equal to the generic object * * @param {Object} context * @param {Object} payload * @param {string} payload.type * @param {string} payload.id */ addGenericObject: function ( context, payload ) { var object = {}, keys = [], objectKey, objectKeyType, nextId; context.dispatch( 'setZObjectValue', { id: payload.id, value: 'object' } ); // we fetch a list of keys within this generic object if ( payload.type !== Constants.Z_OBJECT && context.rootGetters.getZkeys[ payload.type ] ) { // Normal types are nested in a persistent object value, // dynamically generated types from functionToType are not object = context .rootGetters .getZkeys[ payload.type ][ Constants.Z_PERSISTENTOBJECT_VALUE ] || context .rootGetters .getZkeys[ payload.type ]; // the generic is either a straight type or a function that returns a type if ( object[ Constants.Z_OBJECT_TYPE ] === Constants.Z_TYPE ) { context.dispatch( 'addZObjectType', { type: payload.type, objectId: payload.id } ); // we add each key in the tree and also set its type keys = object[ Constants.Z_TYPE_KEYS ]; keys.forEach( function ( key ) { objectKey = key[ Constants.Z_KEY_ID ]; objectKeyType = key[ Constants.Z_KEY_TYPE ]; nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); if ( !objectKeyType ) { return; } if ( objectKey !== Constants.Z_OBJECT_TYPE ) { context.dispatch( 'addZObject', { key: objectKey, value: 'object', parent: payload.id } ); } // If we are adding a key of type Z4, we want to add a reference rather than Z4/Type literal. Iif ( objectKeyType === Constants.Z_TYPE ) { context.dispatch( 'changeType', { id: nextId, type: Constants.Z_REFERENCE } ); // We set the initial value of the Z_KEY_ID, which is based on the root z-object ID and key // index. } else Iif ( objectKey === Constants.Z_KEY_ID ) { context.dispatch( 'changeType', { id: nextId, type: objectKeyType, value: context.getters.getNextKey } ); // We need to stop recursiveness. } else if ( objectKeyType !== payload.type && typeof objectKeyType !== 'object' ) { context.dispatch( 'changeType', { id: nextId, type: objectKeyType } ); // If Z_OBJECT_TYPE is a function call, we infer the type and use it to create the object } else Eif ( typeof objectKeyType === 'object' && objectKeyType[ Constants.Z_OBJECT_TYPE ] === Constants.Z_FUNCTION_CALL && objectKeyType[ Constants.Z_FUNCTION_CALL_FUNCTION ] === Constants.Z_TYPED_LIST ) { context.dispatch( 'addZTypedList', { id: nextId, value: objectKeyType[ Constants.Z_TYPED_LIST_TYPE ] } ); // Sometimes the Type can be an object. In those instances // We will inject the complete object into the zobject tree } else if ( typeof objectKeyType === 'object' ) { context.dispatch( 'injectZObject', { zobject: objectKeyType, key: objectKey, id: nextId, parent: payload.id } ); } else { context.dispatch( 'changeType', { id: nextId, type: Constants.Z_REFERENCE } ); } } ); } else Eif ( object[ Constants.Z_OBJECT_TYPE ] === Constants.Z_FUNCTION ) { var functionCallObjectType = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_OBJECT_TYPE, value: 'object', parent: payload.id } ); context.dispatch( 'addZFunctionCall', { id: functionCallObjectType, value: object[ Constants.Z_FUNCTION_IDENTITY ] } ); keys = object[ Constants.Z_FUNCTION_ARGUMENTS ]; keys.forEach( function ( key ) { objectKey = key[ Constants.Z_ARGUMENT_KEY ]; objectKeyType = key[ Constants.Z_ARGUMENT_TYPE ]; nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); if ( objectKey !== Constants.Z_OBJECT_TYPE ) { context.dispatch( 'addZObject', { key: objectKey, value: 'object', parent: functionCallObjectType } ); } // We need to stop recursiveness. if ( objectKeyType !== payload.type && objectKeyType !== Constants.Z_TYPE ) { context.dispatch( 'changeType', { id: nextId, type: objectKeyType } ); // When the type is a Z4 // we prefix it to an empty string to force the object selector to be shown } else if ( objectKeyType === Constants.Z_TYPE ) { context.dispatch( 'setZObjectValue', { id: nextId, value: '' } ); } else { context.dispatch( 'changeType', { id: nextId, type: Constants.Z_REFERENCE } ); } } ); } } }, /** * Create the required entry in the zobject array for a zType. * This utilizes the generic object creator, then sets the identity value. * { "Z1K1": "Z4", "Z4K1": { "Z1K1": "Z9", "Z9K1": "Z0" }, "Z4K2": [], "Z4K3": { "Z1K1": "Z101" } } * * @param {Object} context * @param {number} objectId */ addZType: function ( context, objectId ) { var nextId; context.dispatch( 'setZObjectValue', { id: objectId, value: 'object' } ); // Set type context.dispatch( 'addZObject', { key: Constants.Z_OBJECT_TYPE, value: Constants.Z_TYPE, parent: objectId } ); // Set identity context.dispatch( 'addZObject', { key: Constants.Z_TYPE_IDENTITY, value: Constants.NEW_ZID_PLACEHOLDER, parent: objectId } ); // Set keys nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_TYPE_KEYS, value: 'object', parent: objectId } ); context.dispatch( 'changeType', { id: nextId, type: Constants.Z_TYPED_LIST, value: Constants.Z_KEY } ); // Set validator nextId = zobjectTreeUtils.getNextObjectId( context.rootState.zobjectModule.zobject ); context.dispatch( 'addZObject', { key: Constants.Z_TYPE_VALIDATOR, value: 'object', parent: objectId } ); context.dispatch( 'changeType', { id: nextId, type: Constants.Z_REFERENCE, value: Constants.Z_VALIDATE_OBJECT } ); }, /** * Changes the type of a specific zObject. * This is the central point for handling the object scaffolding * * @param {Object} context * @param {Object} payload * @return {Promise} */ changeType: function ( context, payload ) { // TODO the whole changeType function could be the following block: const value = typeUtils.getScaffolding( payload.type ); // FIXME I have added the following value check so that we can continue to re-use // this method from the old components. But as soon as we remove all the deprecated // components, we should not returned undefined from getScaffolding, but the // default case should be the Z_OBJECT one. Iif ( value ) { return context.dispatch( 'injectZObjectFromRowId', { rowId: payload.id, value } ); } context.dispatch( 'removeZObjectChildren', payload.id ); return context.dispatch( 'fetchZKeys', { zids: [ payload.type ] } ) .then( function () { switch ( payload.type ) { case Constants.Z_REFERENCE: return context.dispatch( 'addZReference', payload ); case Constants.Z_STRING: return context.dispatch( 'addZString', payload ); case Constants.Z_MULTILINGUALSTRING: return context.dispatch( 'addZMultilingualString', payload ); case Constants.Z_ARGUMENT: return context.dispatch( 'addZArgument', { id: payload.id } ); case Constants.Z_FUNCTION_CALL: return context.dispatch( 'addZFunctionCall', payload ); case Constants.Z_FUNCTION: return context.dispatch( 'addZFunction', payload.id ); case Constants.Z_PERSISTENTOBJECT: return context.dispatch( 'addZPersistentObject', payload.id ); case Constants.Z_TYPE: return context.dispatch( 'addZType', payload.id ); case Constants.Z_IMPLEMENTATION: return context.dispatch( 'addZImplementation', payload.id ); case Constants.Z_TESTER: return context.dispatch( 'addZTester', payload.id ); case Constants.Z_TYPED_LIST: return context.dispatch( 'addZTypedList', payload ); case Constants.Z_TYPED_PAIR: return context.dispatch( 'addZTypedPair', payload ); case Constants.Z_TYPED_MAP: return context.dispatch( 'addZTypedMap', payload ); default: return context.dispatch( 'addGenericObject', payload ); } } ); } } }; |