All files / ext.wikilambda.edit/components/default-view-types ZBoolean.vue

100% Statements 113/113
100% Branches 5/5
100% Functions 5/5
100% Lines 113/113

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 1141x 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 1x 1x 1x 15x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x 1x 1x  
<!--
	WikiLambda Vue component for boolean values
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div class="ext-wikilambda-boolean">
		<template v-if="!edit">
			<a
				class="ext-wikilambda-edit-link"
				:href="valueUrl"
				:lang="valueLabelData.langCode"
				:dir="valueLabelData.langDir"
			>{{ valueLabelData.label }}</a>
		</template>
		<template v-else>
			<cdx-radio
				v-for="radio in radioChoices"
				:key="'radio-' + radio.value"
				v-model="value"
				:input-value="radio.value"
				:name="'boolean-radios-' + rowId"
				:inline="true"
			>
				<span
					:lang="radio.labelData.langCode"
					:dir="radio.labelData.langDir"
				>{{ radio.labelData.label }}</span>
			</cdx-radio>
		</template>
	</div>
</template>
 
<script>
const { defineComponent } = require( 'vue' );
const CdxRadio = require( '@wikimedia/codex' ).CdxRadio,
	Constants = require( '../../Constants.js' ),
	mapGetters = require( 'vuex' ).mapGetters;
 
module.exports = exports = defineComponent( {
	name: 'wl-z-boolean',
	components: {
		'cdx-radio': CdxRadio
	},
	props: {
		rowId: {
			type: Number,
			required: false,
			default: 0
		},
		edit: {
			type: Boolean,
			required: true
		}
	},
	computed: Object.assign( mapGetters( [
		'getLabelData',
		'getZBooleanValue',
		'getUserLangCode'
	] ),
	{
		value: {
			get: function () {
				return this.getZBooleanValue( this.rowId );
			},
			set: function ( value ) {
				this.$emit( 'set-value', {
					keyPath: [
						Constants.Z_BOOLEAN_IDENTITY,
						Constants.Z_REFERENCE_ID
					],
					value
				} );
			}
		},
		/**
		 * Returns the LabelData object for the selected value of the boolean
		 *
		 * @return {LabelData}
		 */
		valueLabelData: function () {
			return this.getLabelData( this.value );
		},
		/**
		 * Returns the url for the selected boolean value
		 *
		 * @return {string}
		 */
		valueUrl: function () {
			return '/view/' + this.getUserLangCode + '/' + this.value;
		},
		/**
		 * Returns the radio choices for True and False, with their value
		 * and their LabelData object
		 *
		 * @return {Array}
		 */
		radioChoices: function () {
			return [
				{
					labelData: this.getLabelData( Constants.Z_BOOLEAN_TRUE ),
					value: Constants.Z_BOOLEAN_TRUE
				},
				{
					labelData: this.getLabelData( Constants.Z_BOOLEAN_FALSE ),
					value: Constants.Z_BOOLEAN_FALSE
				}
			];
		}
	} )
} );
</script>