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

50% Statements 10/20
0% Branches 0/3
0% Functions 0/9
50% Lines 10/20

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                                                          18x 18x 18x 18x 18x 18x 18x 18x 18x     18x                                                                                                                                                    
<template>
	<!--
		WikiLambda Vue component for the inline addition of ZTester objects.
 
		@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
		@license MIT
	-->
	<div v-if="zobject.length">
		<wl-z-multilingual-string
			:zobject-id="labelsId"
			:readonly="true"
		></wl-z-multilingual-string>
		<wl-z-inline-tester-call
			v-if="call"
			:zobject-id="call.id"
		></wl-z-inline-tester-call>
		<wl-z-inline-tester-validation
			v-if="validator"
			:zobject-id="validator.id"
		></wl-z-inline-tester-validation>
		<div>
			<cdx-button @click="saveAdHocTester">
				{{ submitButtonLabel }}
			</cdx-button>
		</div>
	</div>
</template>
 
<script>
var Constants = require( '../../Constants.js' ),
	mapGetters = require( 'vuex' ).mapGetters,
	mapActions = require( 'vuex' ).mapActions,
	typeUtils = require( '../../mixins/typeUtils.js' ),
	schemata = require( '../../mixins/schemata.js' ),
	CdxButton = require( '@wikimedia/codex' ).CdxButton,
	ZInlineTesterCall = require( './ZInlineTesterCall.vue' ),
	ZInlineTesterValidation = require( './ZInlineTesterValidation.vue' ),
	ZMultilingualString = require( '../main-types/ZMultilingualString.vue' );
 
// @vue/component
module.exports = exports = {
	name: 'wl-z-tester-ad-hoc',
	components: {
		'wl-z-inline-tester-call': ZInlineTesterCall,
		'wl-z-inline-tester-validation': ZInlineTesterValidation,
		'wl-z-multilingual-string': ZMultilingualString,
		'cdx-button': CdxButton
	},
	mixins: [ typeUtils, schemata ],
	props: {
		zobjectId: {
			type: Number,
			required: true
		},
		zTesterListId: {
			type: Number,
			required: true
		}
	},
	computed: $.extend( mapGetters( [
		'getZObjectChildrenById',
		'getZObjectAsJsonById',
		'getNestedZObjectById'
	] ), {
		zobject: function () {
			return this.getZObjectChildrenById( this.getNestedZObjectById( this.zobjectId, [
				Constants.Z_PERSISTENTOBJECT_VALUE
			] ).id );
		},
		zobjectJson: function () {
			return this.getZObjectAsJsonById( this.zobjectId );
		},
		labelsId: function () {
			return this.getNestedZObjectById( this.zobjectId, [
				Constants.Z_PERSISTENTOBJECT_LABEL
			] ).id;
		},
		zTesterList: function () {
			return this.getZObjectChildrenById( this.zTesterListId );
		},
		call: function () {
			return this.findKeyInArray( Constants.Z_TESTER_CALL, this.zobject );
		},
		validator: function () {
			return this.findKeyInArray( Constants.Z_TESTER_VALIDATION, this.zobject );
		},
		submitButtonLabel: function () {
			// Copied from ZObjectEditor; refactor, or use a different label for these?
			return mw.msg(
				mw.config.get( 'wgEditSubmitButtonLabelPublish' ) ?
					'wikilambda-publishnew' : 'wikilambda-savenew'
			);
		}
	} ),
	methods: $.extend( mapActions( [
		'saveNewTester'
	] ), {
		saveAdHocTester: function () {
			this.saveNewTester( {
				testerId: this.zobjectId,
				nextTesterIndex: this.zTesterList.length.toString(),
				parent: this.zTesterListId
			} );
		}
	} ),
	watch: {
		zobjectJson: function ( json, prevJson ) {
			Iif ( JSON.stringify( json ) !== JSON.stringify( prevJson ) ) {
				this.$store.dispatch( 'updateTesterLabel', { testerId: this.zobjectId } );
			}
		}
	}
};
</script>