All files / ext.wikilambda.edit/store getters.js

100% Statements 27/27
90% Branches 9/10
100% Functions 8/8
100% Lines 26/26

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              14x   14x                 28x 52x 10x     42x 42x 42x               42x 9x   42x           17x 17x 17x   17x 9x 10x 10x   10x 10x   9x   8x       33x 33x     99x     1x      
/*!
 * WikiLambda Vue editor: Application store getters
 *
 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
 * @license MIT
 */
'use strict';
var Constants = require( '../Constants.js' );
 
module.exports = exports = {
	getZkeyLiteralType: function ( state, getters ) {
 
		/**
		 * Retrieve the literal type (actual type) of a specific ZKey. This is mainly used in the modeselector.
		 *
		 * @param {number} parentKey
		 * @return {string} LiteralType
		 */
		return function ( parentKey ) {
			if ( !parentKey ) {
				return;
			}
 
			const type = parentKey.match( /Z[1-9]\d*/ )[ 0 ];
			if ( getters.getZkeys[ type ] ) {
				const keysArray = getters.getZkeys[
					type
				][
					Constants.Z_PERSISTENTOBJECT_VALUE
				][
					Constants.Z_TYPE_KEYS
				];
 
				const keyFound = keysArray && keysArray.find(
					( key ) => key[ Constants.Z_KEY_ID ] === parentKey
				);
				return keyFound ? keyFound[ Constants.Z_KEY_TYPE ] : null;
			}
 
		};
	},
	paginateList: function () {
		return function ( items ) {
			var paginatedItems = {};
			var pageNum = 1;
 
			if ( items.length > 0 ) {
				for ( var i = 0; i < items.length; i += Constants.PAGINATION_SIZE ) {
					const endIndex = Math.min( items.length, i + Constants.PAGINATION_SIZE );
					const pageItems = items.slice( i, endIndex );
 
					paginatedItems[ pageNum ] = pageItems;
					pageNum++;
				}
				return paginatedItems;
			}
			return { 0: items };
		};
	},
	getViewMode: function () {
		var editingData = mw.config.get( 'wgWikiLambda' );
		return editingData.viewmode;
	},
	isExpertMode: function ( state ) {
		return state.expertMode;
	},
	isUserLoggedIn: function () {
		return !!mw.config.values.wgUserName;
	}
};