All files / ext.wikilambda.edit/components App.vue

83.7% Statements 113/135
83.33% Branches 5/6
100% Functions 3/3
83.7% Lines 113/135

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 1361x 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 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 8x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 1x 1x 1x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x                                             8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
<!--
	WikiLambda Vue interface module for generic ZObject manipulation.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div id="ext-wikilambda-app" class="ext-wikilambda-edit">
		<wl-clipboard-manager
			:class-names="[
				'ext-wikilambda-viewpage-header-zid',
				'ext-wikilambda-editpage-header-zid'
			]">
		</wl-clipboard-manager>
		<template v-if="isInitialized && isAppSetup">
			<!-- Append wl- prefix to the router current view, to help reference component correctly -->
			<component
				:is="`wl-${getCurrentView}`"
				@mounted="newViewMounted"
			></component>
		</template>
		<span v-else>
			{{ $i18n( 'wikilambda-loading' ).text() }}
		</span>
	</div>
</template>
 
<script>
const { defineComponent } = require( 'vue' );
const mapGetters = require( 'vuex' ).mapGetters,
	mapActions = require( 'vuex' ).mapActions,
	ClipboardManager = require( './base/ClipboardManager.vue' ),
	eventLogUtils = require( '../mixins/eventLogUtils.js' ),
	urlUtils = require( '../mixins/urlUtils.js' ),
	FunctionEvaluator = require( '../views/FunctionEvaluator.vue' ),
	FunctionEditor = require( '../views/FunctionEditor.vue' ),
	FunctionViewer = require( '../views/FunctionViewer.vue' ),
	DefaultView = require( '../views/DefaultView.vue' );
 
const startTime = Date.now();
 
module.exports = exports = defineComponent( {
	name: 'app',
	components: {
		'wl-function-evaluator': FunctionEvaluator,
		'wl-function-editor': FunctionEditor,
		'wl-function-viewer': FunctionViewer,
		'wl-default-view': DefaultView,
		'wl-clipboard-manager': ClipboardManager
	},
	mixins: [ eventLogUtils, urlUtils ],
	inject: {
		viewmode: { default: false }
	},
	data: function () {
		return {
			isAppSetup: false
		};
	},
	computed: Object.assign(
		mapGetters( [
			'isInitialized',
			'isCreateNewPage',
			'getCurrentView'
		] )
	),
	methods: Object.assign(
		mapActions( [
			'initializeView',
			'prefetchZids',
			'fetchUserRights',
			'evaluateUri'
		] ),
		{
			/**
			 * Instrument how long our view took to load, split by type of view
			 */
			newViewMounted: function () {
				// Log using Metrics Platform
				// Pending to remove due to T350495
				const customData = {
					viewname: this.getCurrentView || null,
					isnewzobject: this.isCreateNewPage,
					loadtime: Date.now() - startTime
				};
				this.dispatchEvent( 'wf.ui.newView.mounted', customData );
				// T350495 Update the WikiLambda instrumentation to use core interaction events
				// We should remove this event after migration (it's a performance event)
			}
		}
	),
	created: function () {
		// Set zobject
		this.fetchUserRights();
		this.prefetchZids().then( () => {
			this.initializeView().then( () => {
				this.evaluateUri();
				this.isAppSetup = true;
			} );
		} );
 
		window.onpopstate = function ( event ) {
			/**
			 * Prevent reinitializing the view when there is a hash in the URL,
			 * this is most likely when using a a11y SkipLink.
			 */
			if ( window.location.hash && event.state === null ) {
				event.preventDefault();
				// Remove hash from url so it does not persist after navigation
				this.removeHashFromURL();
				return false;
			}

			// Reinitialize zObject if current page/zObject is new and user changes route
			if ( this.isCreateNewPage ) {
				this.initializeView().then(
					() => {
						this.evaluateUri();
					}
				);
				return;
			}

			this.evaluateUri();
		}.bind( this );
	}
} );
</script>
 
<style lang="less">
.ext-wikilambda-view-nojsfallback,
.ext-wikilambda-editor-nojswarning {
	display: none;
}
</style>