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

95.45% Statements 21/22
100% Branches 4/4
88.88% Functions 8/9
95.45% Lines 21/22

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    25x 25x 25x 25x 25x                                     15x     1x             12x     12x     3x                   25x   25x     25x 25x 25x     25x   15x 15x             6x       1x                       25x              
<!--
	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"
			>
				{{ valueLabel }}
			</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"
			>
				{{ radio.label }}
			</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( [
		'getLabel',
		'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
				} );
			}
		},
		valueLabel: function () {
			return this.getLabel( this.value );
		},
		valueUrl: function () {
			return '/view/' + this.getUserLangCode + '/' + this.value;
		},
		radioChoices: function () {
			return [
				{
					label: this.getLabel( Constants.Z_BOOLEAN_TRUE ),
					value: Constants.Z_BOOLEAN_TRUE
				},
				{
					label: this.getLabel( Constants.Z_BOOLEAN_FALSE ),
					value: Constants.Z_BOOLEAN_FALSE
				}
			];
		}
	} )
} );
</script>