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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | 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 118x 1x 1x 1x 1x 1x 1x 1x 1x 1x 44x 1x 1x 1x 1x 1x 1x 1x 1x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 23x 23x 23x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 56x 56x 56x 56x 56x 1x 1x 1x 1x 1x 1x 1x 1x 1x 74x 1x 1x 1x 1x 1x 1x 1x 1x 34x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 56x 56x 26x 56x 56x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 1x 1x 1x 1x | <!--
WikiLambda Vue component for Z9/Reference objects.
@copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
@license MIT
-->
<template>
<div class="ext-wikilambda-app-reference" data-testid="z-reference">
<template v-if="!edit">
<a
v-if="valueLabel"
class="ext-wikilambda-app-link"
data-testid="edit-link"
:lang="valueLabel.langCode"
:dir="valueLabel.langDir"
:href="valueUrl"
>{{ valueLabel.label }}</a>
</template>
<template v-else>
<wl-z-object-selector
:disabled="disabled"
:row-id="rowId"
:selected-zid="value"
:type="type"
:return-type="returnType"
:exclude-zids="excludeZids"
data-testid="z-reference-selector"
@input="setValue"
></wl-z-object-selector>
</template>
</div>
</template>
<script>
const { defineComponent } = require( 'vue' );
const Constants = require( '../../Constants.js' ),
ZObjectSelector = require( './../base/ZObjectSelector.vue' ),
typeUtils = require( '../../mixins/typeUtils.js' ),
{ mapGetters } = require( 'vuex' );
module.exports = exports = defineComponent( {
name: 'wl-z-reference',
components: {
'wl-z-object-selector': ZObjectSelector
},
mixins: [ typeUtils ],
props: {
rowId: {
type: Number,
required: false,
default: 0
},
edit: {
type: Boolean,
required: true
},
expectedType: {
type: [ String, Object ],
required: true
},
parentExpectedType: {
type: [ String, Object ],
required: false,
default: Constants.Z_OBJECT
},
disabled: {
type: Boolean,
default: false
}
},
computed: Object.assign(
mapGetters( [
'getLabelData',
'getParentRowId',
'getZObjectKeyByRowId',
'getZReferenceTerminalValue',
'getUserLangCode'
] ),
{
/**
* Returns the value of the selected reference.
*
* @return {string}
*/
value: function () {
return this.getZReferenceTerminalValue( this.rowId );
},
/**
* Returns the string value of the label for the selected reference.
* If no label is found, returns undefined.
*
* @return {LabelData|undefined}
*/
valueLabel: function () {
return this.value ? this.getLabelData( this.value ) : undefined;
},
/**
* Returns the link to the page of the selected reference.
*
* @return {string}
*/
valueUrl: function () {
return '/view/' + this.getUserLangCode + '/' + this.value;
},
/**
* Returns the bound type to configure the ZObjectSelector
* If `returnType` is not set and `expectedType` is a valid bound type (not `Z_OBJECT`),
* the bound type is returned as a string. Otherwise, returns an empty string.
* The type is converted to a string with no arguments if it is a generic type.
*
* @return {string} The bound type as a string, or an empty string if not applicable.
*/
type: function () {
return this.returnType || !this.expectedType || this.expectedType === Constants.Z_OBJECT ?
'' :
this.typeToString( this.expectedType, true );
},
/**
* Returns the bound return type to configure the ZObjectSelector
* If `key` is `Z_FUNCTION_CALL_FUNCTION` and `parentExpectedType` is a valid bound type
* the bound return type is returned as a string. Otherwise, returns an empty string.
* We understand that the parent type is unbound when it expects Z1/Object or a
* resolver type (Z7/Function call, Z9/Reference, Z18/Argument reference), as they
* can resolve to anything.
* The type is converted to a string with no arguments if it is a generic type.
*
* @return {string} The bound return type as a string, or an empty string if not applicable.
*/
returnType: function () {
const unboundTypes = [ Constants.Z_OBJECT, ...Constants.RESOLVER_TYPES ];
return ( this.key === Constants.Z_FUNCTION_CALL_FUNCTION &&
!unboundTypes.includes( this.parentExpectedType ) ) ?
this.typeToString( this.parentExpectedType, true ) :
'';
},
/**
* Returns the key that contains the reference value
* represented in this component.
*
* @return {string} The key associated with the reference value.
*/
key: function () {
return this.getZObjectKeyByRowId( this.rowId );
},
/**
* Returns the key of the parent
*
* @return {string}
*/
parentKey: function () {
return this.getZObjectKeyByRowId( this.getParentRowId( this.rowId ) );
},
/**
* Returns the list of excluded Zids to restrict in the lookup
* component depending on the current Key. Currently only for the
* content type of Z2K2, the keys from EXCLUDE_FROM_PERSISTENT_CONTENT
* are intentionally excluded.
*
* @return {Array}
*/
excludeZids: function () {
return (
( this.key === Constants.Z_OBJECT_TYPE ) &&
( this.parentKey === Constants.Z_PERSISTENTOBJECT_VALUE )
) ? Constants.EXCLUDE_FROM_PERSISTENT_CONTENT : [];
}
}
),
methods: {
/**
* Emits the event setValue so that ZObjectKey can update
* the terminal value in the ZObject data table. ZObjectSelector
* input event will always be called with a valid value from the
* lookup list, never with an empty value.
*
* @param {string} value
*/
setValue: function ( value ) {
const keyPath = ( this.key !== Constants.Z_REFERENCE_ID ) ?
[ Constants.Z_REFERENCE_ID ] :
[];
this.$emit( 'set-value', { keyPath, value } );
}
}
} );
</script>
|