All files / ext.wikilambda.edit/components/function/editor FunctionEditorFooter.vue

98.56% Statements 137/139
89.47% Branches 17/19
100% Functions 5/5
98.56% Lines 137/139

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 1401x 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 1x 1x 1x 1x 1x 1x 5x 1x 1x 1x 1x 1x 1x 1x 1x 14x 1x 1x 1x 1x 1x 1x 1x 1x 1x 4x 1x 4x 2x 2x 1x 1x     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 8x 8x 2x 2x 6x 6x 6x 8x 4x 4x 4x 4x 4x 4x 8x 1x 1x 1x 6x 4x 4x 4x 4x 4x 4x 4x 6x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
<!--
	WikiLambda Vue component footer for the Function Editor, including publish, cancel and implement buttons.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div class="ext-wikilambda-function-definition-footer">
		<wl-publish-widget
			:is-dirty="isFunctionDirty"
			:function-signature-changed="functionSignatureChanged"
			@start-publish="raiseFunctionWarnings"
		></wl-publish-widget>
	</div>
</template>
 
<script>
 
const { defineComponent } = require( 'vue' );
const PublishWidget = require( '../../widgets/Publish.vue' ),
	Constants = require( '../../../Constants.js' ),
	mapGetters = require( 'vuex' ).mapGetters,
	mapActions = require( 'vuex' ).mapActions,
	eventLogUtils = require( '../../../mixins/eventLogUtils.js' );
 
module.exports = exports = defineComponent( {
	name: 'wl-function-editor-footer',
	components: {
		'wl-publish-widget': PublishWidget
	},
	props: {
		functionInputChanged: {
			type: Boolean,
			required: false,
			default: false
		},
		functionOutputChanged: {
			type: Boolean,
			required: false,
			default: false
		},
		isFunctionDirty: {
			type: Boolean,
			required: false,
			default: false
		}
	},
	computed: Object.assign( mapGetters( [
		'isCreateNewPage',
		'getCurrentZObjectId',
		'getConnectedImplementations',
		'getConnectedTests',
		'getUserLangZid'
	] ), {
 
		/**
		 * Returns whether the function has connected objects (implementations or tests).
		 *
		 * @return {boolean}
		 */
		hasConnectedObjects: function () {
			return !!this.getConnectedImplementations().length || !!this.getConnectedTests().length;
		},
		/**
		 * Returns whether the function type signature (input types
		 * and output type) has changed from its initial value.
		 *
		 * @return {boolean}
		 */
		functionSignatureChanged: function () {
			return this.functionInputChanged || this.functionOutputChanged;
		},
		/**
		 * Returns the error code for the type of function
		 * signature warning to be shown to the user, depending on
		 * whether the inputs have changed, the output, or both.
		 *
		 * @return {string}
		 */
		signatureWarningCode: function () {
			if ( this.functionInputChanged && this.functionOutputChanged ) {
				return Constants.errorCodes.FUNCTION_INPUT_OUTPUT_CHANGED;
			} else if ( this.functionInputChanged ) {
				return Constants.errorCodes.FUNCTION_INPUT_CHANGED;
			} else if ( this.functionOutputChanged ) {
				return Constants.errorCodes.FUNCTION_OUTPUT_CHANGED;
			}
			return '';
		}
	} ),
	methods: Object.assign( mapActions( [
		'setError'
	] ), {
 
		/**
		 * Set warnings when there are changes in the function signature
		 * to announce that
		 */
		raiseFunctionWarnings: function () {
			// Only warn of changes if we are editing an existing function
			if ( this.isCreateNewPage ) {
				return;
			}
 
			// If there's changes in the function signature, warn that
			// implementations and testers will be detached
			if ( this.functionSignatureChanged && this.hasConnectedObjects ) {
				this.setError( {
					rowId: 0,
					errorType: Constants.errorTypes.WARNING,
					errorCode: this.signatureWarningCode
				} );
			}
		}
	} ),
	watch: {
		isFunctionDirty: function ( newValue ) {
			if ( newValue === true ) {
				const interactionData = {
					zobjectid: this.getCurrentZObjectId,
					zobjecttype: 'Z8',
					zlang: this.getUserLangZid || null
				};
				eventLogUtils.methods.submitInteraction( 'change', interactionData );
			}
		}
	}
} );
 
</script>
 
<style lang="less">
@import '../../../ext.wikilambda.edit.variables.less';
 
.ext-wikilambda-function-definition-footer {
	padding: 0;
	margin-top: @spacing-150;
}
</style>