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 | 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 61x 103x 103x 103x 103x 103x 103x 103x 103x 103x 33x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 37x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 18x 103x 103x 103x 103x 103x 103x 103x 103x 103x 39x 39x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 25x 103x 103x 103x 103x 103x 103x 103x 103x 103x 13x 103x 103x 103x 103x 103x 103x 103x 103x 25x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 50x 50x 8x 8x 8x 8x 8x 8x 8x 8x 8x 50x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 103x 12x 12x 12x 12x 9x 9x 9x 9x 9x 12x 12x 12x 12x 12x 12x 12x 103x 103x 103x 103x 103x 103x 103x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 103x 103x | /*!
* WikiLambda Pinia store to manipulate the state of the current page.
*
* @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
* @license MIT
*/
'use strict';
const Constants = require( '../../Constants.js' );
const eventLogUtils = require( '../../utils/eventLogUtils.js' );
const { canonicalToHybrid } = require( '../../utils/schemata.js' );
const { isTruthyOrEqual } = require( '../../utils/typeUtils.js' );
module.exports = {
state: {
currentZid: Constants.NEW_ZID_PLACEHOLDER,
createNewPage: false,
initialized: false,
dirty: false,
multilingualDataCopy: null
},
getters: {
/**
* Returns whether the root ZObject is initialized
*
* @param {Object} state
* @return {boolean}
*/
isInitialized: function ( state ) {
return state.initialized;
},
/**
* Returns whether we are creating a new page.
*
* @param {Object} state
* @return {boolean}
*/
isCreateNewPage: function ( state ) {
return state.createNewPage;
},
/**
* Returns whether the page has had any
* changes that need saving.
*
* @param {Object} state
* @return {boolean}
*/
isDirty: function ( state ) {
return state.dirty;
},
/**
* Returns the multilingual data initial copy
* saved on initialization
*
* @param {Object} state
* @return {Object}
*/
getMultilingualDataCopy: function ( state ) {
return state.multilingualDataCopy;
},
/**
* Return the root ZObjectId, equivalend to the Z_REFERENCE_ID of Z_PERSISTENTOBJECT_ID
*
* @param {Object} state
* @return {string} currentZObjectId
*/
getCurrentZObjectId: function ( state ) {
return state.currentZid || Constants.NEW_ZID_PLACEHOLDER;
}
},
actions: {
/**
* Sets the flag state.initialized once the
* root zobject state has been initialized.
*
* @param {boolean} value
*/
setInitialized: function ( value ) {
this.initialized = value;
},
/**
* Sets the state flag createNewPage, which reflects
* whether we are creating a new page.
*
* @param {boolean} payload
*/
setCreateNewPage: function ( payload ) {
this.createNewPage = payload;
},
/**
* Set the value of the current Zid
*
* @param {string} currentZid
*/
setCurrentZid: function ( currentZid ) {
this.currentZid = currentZid;
},
/**
* Sets the value of the isDirty flag,
* which is true if there's been any changes
* in the page that will need saving.
*
* @param {boolean} value
*/
setDirty: function ( value = true ) {
// sending the 'change' event for the first change
if ( value === true && !this.isDirty ) {
const interactionData = {
zobjectid: this.getCurrentZObjectId,
zobjecttype: this.getCurrentZObjectType || null,
implementationtype: this.getCurrentZImplementationType || null,
zlang: this.getUserLangZid || null
};
// Submit interaction event via eventLogUtils
eventLogUtils.submitInteraction( 'change', interactionData );
}
this.dirty = value;
},
/**
* Save initial multilingual data values so that the
* About widget can reset everything to its original
* state in the case of an edit cancelation.
*
* NOTE: Objects are stored in canonical form. We pass
* the canonical object as input, because the root object
* might not be set in the store. This is okay because we
* only save the multilingual data copy on initialization.
*
* @param {Object} zobject
*/
saveMultilingualDataCopy: function ( zobject ) {
const inputLabels = [];
const path = [ Constants.Z_PERSISTENTOBJECT_VALUE, Constants.Z_OBJECT_TYPE ];
if ( isTruthyOrEqual( zobject, path, Constants.Z_FUNCTION ) ) {
const inputs = zobject[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_FUNCTION_ARGUMENTS ]
.slice( 1 );
// We create an array of input labels, ignoring benjaming item
inputLabels.push( ...inputs.map( ( arg ) => arg[ Constants.Z_ARGUMENT_LABEL ] ) );
}
this.multilingualDataCopy = {
names: zobject[ Constants.Z_PERSISTENTOBJECT_LABEL ],
descriptions: zobject[ Constants.Z_PERSISTENTOBJECT_DESCRIPTION ],
aliases: zobject[ Constants.Z_PERSISTENTOBJECT_ALIASES ],
inputs: inputLabels
};
},
/**
* Resets the initial state of the multilingual
* data of the current object.
*/
resetMultilingualData: function () {
const initialData = this.getMultilingualDataCopy;
this.setValueByKeyPath( {
keyPath: [
Constants.STORED_OBJECTS.MAIN,
Constants.Z_PERSISTENTOBJECT_LABEL
],
value: canonicalToHybrid( initialData.names )
} );
this.setValueByKeyPath( {
keyPath: [
Constants.STORED_OBJECTS.MAIN,
Constants.Z_PERSISTENTOBJECT_DESCRIPTION
],
value: canonicalToHybrid( initialData.descriptions )
} );
this.setValueByKeyPath( {
keyPath: [
Constants.STORED_OBJECTS.MAIN,
Constants.Z_PERSISTENTOBJECT_ALIASES
],
value: canonicalToHybrid( initialData.aliases )
} );
if ( this.getCurrentZObjectType === Constants.Z_FUNCTION && Array.isArray( initialData.inputs ) ) {
initialData.inputs.forEach( ( labelData, index ) => {
const keyPath = [
Constants.STORED_OBJECTS.MAIN,
Constants.Z_PERSISTENTOBJECT_VALUE,
Constants.Z_FUNCTION_ARGUMENTS,
index + 1,
Constants.Z_ARGUMENT_LABEL
];
this.setValueByKeyPath( {
keyPath,
value: canonicalToHybrid( labelData )
} );
} );
}
}
}
};
|