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

98.55% Statements 136/138
89.47% Branches 17/19
100% Functions 5/5
98.55% Lines 136/138

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 1391x 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 22x 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 9x 9x 3x 3x 6x 6x 6x 9x 4x 4x 4x 4x 4x 4x 9x 1x 1x 1x 12x 7x 7x 7x 7x 7x 7x 7x 12x 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-app-function-editor-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/Publish.vue' ),
	Constants = require( '../../../Constants.js' ),
	{ mapActions, mapGetters } = require( 'vuex' ),
	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.app.variables.less';
 
.ext-wikilambda-app-function-editor-footer {
	padding: 0;
	margin-top: @spacing-150;
}
</style>