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

98.8% Statements 165/167
83.33% Branches 5/6
83.33% Functions 5/6
98.8% Lines 165/167

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 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 1681x 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 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 14x 14x 14x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 14x 14x 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  
<!--
	WikiLambda Vue component for a Typed List set of items.
 
	@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
	@license MIT
-->
<template>
	<div class="ext-wikilambda-ztyped-list-items ext-wikilambda-key-value">
		<!-- if expanded, show toggle button -->
		<div
			v-if="expanded"
			class="ext-wikilambda-key-value-pre"
		>
			<wl-expanded-toggle
				class="ext-wikilambda-key-value-pre-button"
				:has-expanded-mode="false"
				:expanded="true"
			></wl-expanded-toggle>
		</div>
 
		<div class="ext-wikilambda-key-value-main">
			<!-- if expanded, show key label -->
			<div
				v-if="expanded"
				:class="listItemsEditClass"
				class="ext-wikilambda-ztyped-list-items-label ext-wikilambda-key-block"
			>
				<wl-localized-label :label-data="itemsLabel"></wl-localized-label>
			</div>
			<!-- else, simply show list of items -->
			<div class="ext-wikilambda-ztyped-list-items-block ext-wikilambda-value-block">
				<wl-z-object-key-value
					v-for="item in listItemsRowIds"
					:key="'list-item-' + item"
					:row-id="item"
					:edit="edit"
					:list-item-type="listItemType"
				></wl-z-object-key-value>
			</div>
 
			<!-- Button to add a new item -->
			<div
				v-if="edit"
				class="ext-wikilambda-ztyped-list-add-button"
			>
				<cdx-button
					data-testid="typed-list-add-item"
					:title="$i18n( 'wikilambda-editor-zlist-additem-tooltip' ).text()"
					:aria-label="$i18n( 'wikilambda-editor-zlist-additem-tooltip' ).text()"
					@click="addListItem"
				>
					<cdx-icon :icon="icons.cdxIconAdd"></cdx-icon>
				</cdx-button>
			</div>
		</div>
	</div>
</template>
 
<script>
const { defineComponent } = require( 'vue' );
const ExpandedToggle = require( '../base/ExpandedToggle.vue' ),
	LocalizedLabel = require( '../base/LocalizedLabel.vue' ),
	CdxButton = require( '@wikimedia/codex' ).CdxButton,
	CdxIcon = require( '@wikimedia/codex' ).CdxIcon,
	LabelData = require( '../../store/classes/LabelData.js' ),
	icons = require( '../../../lib/icons.json' ),
	mapGetters = require( 'vuex' ).mapGetters;
 
module.exports = exports = defineComponent( {
	name: 'wl-z-typed-list-items',
	components: {
		'wl-expanded-toggle': ExpandedToggle,
		'wl-localized-label': LocalizedLabel,
		'cdx-button': CdxButton,
		'cdx-icon': CdxIcon
	},
	props: {
		edit: {
			type: Boolean,
			required: true
		},
		expanded: {
			type: Boolean,
			required: true
		},
		listItemType: {
			type: [ String, Object ],
			required: true
		},
		listItemsRowIds: {
			type: Array,
			default() {
				return [];
			}
		}
	},
	data: function () {
		return {
			icons: icons
		};
	},
	computed: Object.assign(
		mapGetters( [
			'getUserLangZid'
		] ),
		{
 
			/**
			 * Returns the key label for the list of items.
			 * Since the FE represents typed lists as benjamin arrays, this must be hardcoded
			 *
			 * @return {string}
			 */
			itemsLabel: function () {
				return new LabelData(
					null,
					this.$i18n( 'wikilambda-list-items-label' ).text(),
					this.getUserLangZid
				);
			},
 
			/**
			 * Returns all the conditional class names for the
			 * the list items label
			 *
			 * @return {string}
			 */
			listItemsEditClass: function () {
				return this.edit ?
					'ext-wikilambda-key-block-edit' :
					'ext-wikilambda-key-block-view';
			}
		}
	),
	methods: {
		addListItem: function () {
			this.$emit( 'add-list-item' );
		}
	},
	beforeCreate: function () {
		this.$options.components[ 'wl-z-object-key-value' ] = require( './ZObjectKeyValue.vue' );
	}
} );
</script>
 
<style lang="less">
@import '../../ext.wikilambda.edit.variables.less';
 
.ext-wikilambda-ztyped-list-items {
	margin-bottom: 0;
 
	.ext-wikilambda-ztyped-list-add-button {
		margin-left: -@spacing-50;
		margin-top: @spacing-75;
	}
 
	.ext-wikilambda-ztyped-list-items-block {
		margin-left: -@spacing-25;
	}
 
	.ext-wikilambda-ztyped-list-items-label {
		label {
			line-height: @spacing-200;
		}
	}
}
</style>