All files / ext.wikilambda.edit/components ZObjectGeneric.vue

37.5% Statements 6/16
0% Branches 0/1
0% Functions 0/8
37.5% Lines 6/16

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 139 140                                                                                      23x 23x 23x 23x 23x     23x                                                                                                                                                                                  
<template>
	<!--
		WikiLambda Vue interface module for generic ZObject manipulation.
 
		@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
		@license MIT
	-->
	<div class="ext-wikilambda-zobject-generic">
		<span>{{ z1k1label }}: </span>
 
		<span v-if="persistent">
			<a
				v-if="type !== zobjectId && ( viewmode || readonly )"
				:href="typeLink"
				:target="!viewmode ? '_blank' : ''"
			>
				<span>{{ typeLabel }}</span>
			</a>
			<span v-else>{{ typeLabel }}</span>
			<ul><li> {{ z2k1label }}: {{ z2K1Value }} </li></ul>
		</span>
 
		<span v-else>
			<span v-if="viewmode || readonly || type">
				<a :href="typeLink" :target="!viewmode ? '_blank' : ''">{{ typeLabel }}</a>
			</span>
			<wl-z-object-selector
				v-else
				:type="Constants.Z_TYPE"
				:return-type="Constants.Z_TYPE"
				:placeholder="$i18n( 'wikilambda-typeselector-label' ).text()"
				:selected-id="type"
				@input="onTypeChange"
			></wl-z-object-selector>
		</span>
		<wl-z-object-key-list
			:zobject-id="zobjectId"
			:readonly="readonly"
		></wl-z-object-key-list>
	</div>
</template>
 
<script>
var Constants = require( '../Constants.js' ),
	ZObjectSelector = require( './ZObjectSelector.vue' ),
	ZObjectKeyList = require( './ZObjectKeyList.vue' ),
	mapActions = require( 'vuex' ).mapActions,
	mapGetters = require( 'vuex' ).mapGetters;
 
// @vue/component
module.exports = exports = {
	name: 'wl-z-object-generic',
	components: {
		'wl-z-object-key-list': ZObjectKeyList,
		'wl-z-object-selector': ZObjectSelector
	},
	inject: {
		viewmode: { default: false }
	},
	props: {
		zobjectId: {
			type: Number,
			required: true
		},
		type: {
			type: String,
			required: true
		},
		persistent: {
			type: Boolean,
			required: true
		},
		readonly: {
			type: Boolean,
			default: false
		}
	},
	data: function () {
		return {
			Constants: Constants
		};
	},
	computed: $.extend( {},
		mapGetters( [
			'getCurrentZObjectId',
			'getZkeyLabels'
		] ),
		{
			typeLabel: function () {
				return this.getZkeyLabels[ this.type ];
			},
			z1k1label: function () {
				return this.getZkeyLabels[ Constants.Z_OBJECT_TYPE ];
			},
			z2k1label: function () {
				return this.getZkeyLabels[ Constants.Z_PERSISTENTOBJECT_ID ];
			},
			z2K1Value: function () {
				return this.getCurrentZObjectId;
			},
			typeLink: function () {
				return new mw.Title( this.type ).getUrl();
			}
		}
	),
	methods: $.extend( {},
		mapActions( [ 'fetchZKeys', 'changeType' ] ),
		{
			/**
			 * Sets the type of a ZObject key.
			 *
			 * @param {string} type
			 * @param {number} id
			 */
			onTypeChange: function ( type ) {
				var payload = {
					id: this.zobjectId,
					type: type
				};
				this.changeType( payload );
			}
		}
	),
	mounted: function () {
		Iif ( this.type !== 'root' ) {
			this.fetchZKeys( { zids: [ this.type ] } );
		}
	}
};
 
</script>
 
<style lang="less">
.ext-wikilambda-zobject-generic {
	background: #fff;
	outline: 2px dashed #808080;
	padding: 1em;
}
</style>