All files / ext.wikilambda.edit/components/function ZFunctionCallRunner.vue

100% Statements 18/18
100% Branches 1/1
100% Functions 5/5
100% Lines 18/18

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                                                                                                                      20x 20x 20x 20x     20x             8x                   1x 1x   1x 1x       1x   1x       1x   1x   1x   1x     1x       99x                              
<template>
	<!--
		WikiLambda Vue component for ZFunctionCall objects.
 
		@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
		@license MIT
	-->
	<div v-if="selectedFunction" class="ext-wikilambda-function-call-block ext-wikilambda-function-call-block__runner">
		{{ zFunctionCallKeyLabels[ Constants.Z_FUNCTION_CALL_FUNCTION ] }}:
		<wl-z-reference
			:zobject-key="selectedFunctionPersistentValue"
			:search-type="Constants.Z_FUNCTION"
			:readonly="true"
		></wl-z-reference>
		<ul>
			<li v-for="argument in zFunctionArguments" :key="argument.key">
				<wl-z-object-key
					:zobject-id="findArgumentId( argument.key )"
					:persistent="false"
					:parent-type="Constants.Z_FUNCTION_CALL"
					:z-key="argument.key"
					:readonly="hasNoImplementations()"
				></wl-z-object-key>
			</li>
		</ul>
		<cdx-button :disabled="hasNoImplementations()" @click="callFunctionHandler">
			<label> {{ $i18n( 'wikilambda-call-function' ).text() }} </label>
		</cdx-button>
		<div v-if="resultZObject || orchestrating" class="ext-wikilambda-orchestrated-result">
			<template v-if="resultZObject">
				<span>{{ $i18n( 'wikilambda-orchestrated' ).text() }}</span>
				<wl-z-key-mode-selector
					:mode="orchestratedMode"
					:parent-type="Constants.Z_FUNCTION_CALL"
					:available-modes="displayModes"
					@change="orchestratedMode = $event"
				></wl-z-key-mode-selector>
				<div>
					<wl-z-object-json
						v-if="orchestratedMode === Constants.Z_KEY_MODES.JSON"
						:readonly="true"
						:zobject-id="resultId"
					></wl-z-object-json>
					<wl-z-object-key
						v-else
						:zobject-id="resultId"
						:parent-type="Constants.Z_RESPONSEENVELOPE"
						:readonly="true"
					></wl-z-object-key>
				</div>
			</template>
			<template v-else-if="orchestrating">
				<em>{{ $i18n( 'wikilambda-orchestrated-loading' ).text() }}</em>
			</template>
		</div>
	</div>
</template>
 
<script>
var Constants = require( '../../Constants.js' ),
	CdxButton = require( '@wikimedia/codex' ).CdxButton,
	ZFunctionCall = require( '../main-types/ZFunctionCall.vue' ),
	mapGetters = require( 'vuex' ).mapGetters;
 
// @vue/component
module.exports = exports = {
	name: 'wl-z-function-call-runner',
	components: {
		'cdx-button': CdxButton
	},
	extends: ZFunctionCall,
	provide: function () {
		return {
			viewmode: false
		};
	},
	computed: mapGetters( {
		getCurrentZObjectType: 'getCurrentZObjectType',
		getZObjectAsJson: 'getZObjectAsJson'
	} ),
	methods: {
		callFunctionHandler: function () {
			var self = this,
				zFunctionCallObject = this.getZObjectAsJsonById( this.zobjectId );
 
			if ( this.getCurrentZObjectType === Constants.Z_IMPLEMENTATION ) {
				var zFunctionId = this.getZObjectAsJson[
					Constants.Z_PERSISTENTOBJECT_VALUE ][
					Constants.Z_IMPLEMENTATION_FUNCTION ][
					Constants.Z_REFERENCE_ID ];
				zFunctionCallObject[ Constants.Z_FUNCTION_CALL_FUNCTION ] =
					this.getZkeys[ zFunctionId ][ Constants.Z_PERSISTENTOBJECT_VALUE ];
				zFunctionCallObject[ Constants.Z_FUNCTION_CALL_FUNCTION ][ Constants.Z_FUNCTION_IMPLEMENTATIONS ] =
					[ Constants.Z_IMPLEMENTATION, this.getZObjectAsJson[ Constants.Z_PERSISTENTOBJECT_VALUE ] ];
			}
 
			this.orchestrating = true;
 
			this.initializeResultId( this.resultId )
				.then( function ( resultId ) {
					self.resultId = resultId;
 
					return self.callZFunction( { zobject: zFunctionCallObject, resultId: self.resultId } );
				} )
				.then( function () {
					self.orchestrating = false;
				} );
		},
		hasNoImplementations: function () {
			return this.zImplementations.length === 0;
		}
	}
};
</script>
 
<style lang="less">
.ext-wikilambda-function-call-block__runner {
	max-width: 40vw;
 
	@media ( max-width: 1200px ) {
		max-width: 100%;
	}
}
</style>