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

23.07% Statements 6/26
0% Branches 0/6
0% Functions 0/8
23.07% Lines 6/26

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                                                                            18x 18x 18x 18x 18x     18x                                                                                                                                                                          
<template>
	<!--
		WikiLambda Vue component for ZObject references to ZImplementations in ZLists.
 
		@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
		@license MIT
	-->
	<li class="ext-wikilambda-ZImplementationListItem">
		<cdx-button
			v-if="!( getViewMode || readonly )"
			class="z-list-item-remove"
			:destructive="true"
			:title="tooltipRemoveListItem"
			@click="$emit( 'remove-item', zobjectId )"
		>
			{{ $i18n( 'wikilambda-editor-removeitem' ).text() }}
		</cdx-button>
		<select v-if="!hasReference" @change="selectImplementation">
			<option disabled selected>
				{{ $i18n( "wikilambda-implementation-selector" ).text() }}
			</option>
			<option
				v-for="zImplementationId in getUnattachedZImplementations"
				:key="zImplementationId"
				:value="zImplementationId"
			>
				{{ getZkeyLabels[ zImplementationId ] }}
			</option>
		</select>
		<h4 class="ext-wikilambda-inline-list-item-title">
			<a :href="zImplementationLink">
				{{ zImplementationLabel }}
			</a>
		</h4>
	</li>
</template>
 
<script>
var Constants = require( '../../Constants.js' ),
	ZListItem = require( '../main-types/ZListItem.vue' ),
	CdxButton = require( '@wikimedia/codex' ).CdxButton,
	mapGetters = require( 'vuex' ).mapGetters,
	mapActions = require( 'vuex' ).mapActions;
 
// @vue/component
module.exports = exports = {
	name: 'wl-z-implementation-list-item',
	components: {
		'cdx-button': CdxButton
	},
	extends: ZListItem,
	computed: $.extend( mapGetters( [
		'getZObjectById',
		'getUnattachedZImplementations',
		'getZkeyLabels',
		'getZkeys',
		'getViewMode'
	] ),
	{
		zImplementationId: function () {
			return this.findKeyInArray( Constants.Z_REFERENCE_ID, this.zobject ).value;
		},
		hasReference: function () {
			return !!this.zImplementationId;
		},
		zImplementationLabel: function () {
			return this.getZkeyLabels[ this.zImplementationId ];
		},
		zImplementation: function () {
			return this.getZkeys[ this.zImplementationId ];
		},
		zImplementationLink: function () {
			return new mw.Title( this.zImplementationId ).getUrl();
		}
	}
	),
	methods: $.extend( mapActions( [ 'fetchZKeys', 'removeGenericTypeItem' ] ), {
		selectImplementation: function ( event ) {
			this.$store.dispatch( 'injectZObject', {
				zobject: {
					Z1K1: Constants.Z_REFERENCE,
					Z9K1: event.target.value
				},
				key: Constants.Z_IMPLEMENTATION_FUNCTION,
				id: this.zobjectId,
				parent: this.getZObjectById( this.zobjectId ).parent
			} );
		},
		findMissingZids: function ( zobject ) {
			var zids = [],
				zIdRegex = new RegExp( /Z[1-9]\d*/ );
 
			for ( var key in zobject ) {
				Iif ( zIdRegex.test( key ) ) {
					zids.push( key );
				}
 
				if ( Array.isArray( zobject[ key ] ) ) {
					zids = zids.concat( zobject[ key ].map( this.findMissingZids ) );
				} else if ( typeof zobject[ key ] === 'object' ) {
					zids = zids.concat( this.findMissingZids( zobject[ key ] ) );
				} else {
					Iif ( zIdRegex.test( zobject[ key ] ) ) {
						zids.push( zobject[ key ] );
					}
				}
			}
 
			return zids;
		},
		removeItem: function () {
 
			var item = this.getZObjectById( this.zobjectId );
			this.removeGenericTypeItem( item );
 
		}
	} )
};
</script>
 
<style lang="less">
.ext-wikilambda-ZImplementationListItem {
	margin-top: 1em;
	margin-bottom: 1em;
 
	.ext-wikilambda-inline-list-item-title {
		display: inline;
	}
}
</style>