2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
|
|
|
<div class="item">
|
|
|
|
<div v-if="item.options" class="options">
|
2022-12-14 01:04:10 -08:00
|
|
|
<div v-if="item.options.length" class="headline clickable" @click="extended = !extended">
|
2019-06-23 03:35:23 -07:00
|
|
|
<div class="options-toggle" v-if="extendAll !== true">
|
|
|
|
<font-awesome-icon v-if="extended" icon="angle-down" />
|
|
|
|
<font-awesome-icon v-else icon="angle-right" />
|
|
|
|
</div>
|
|
|
|
<div class="option-title" :title="item.key">
|
2022-12-14 01:04:10 -08:00
|
|
|
{{ item.name }}
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
<el-dropdown
|
|
|
|
trigger="click"
|
|
|
|
@click.stop
|
|
|
|
@command="optionSelected($event, item)"
|
|
|
|
v-if="allowParentSelect === true"
|
|
|
|
>
|
2019-06-23 03:35:23 -07:00
|
|
|
<span class="el-dropdown-link clickable" @click.stop>
|
2022-12-14 01:04:10 -08:00
|
|
|
<font-awesome-icon
|
|
|
|
icon="dot-circle"
|
|
|
|
:title="$locale.baseText('variableSelectorItem.selectItem')"
|
|
|
|
/>
|
2019-06-23 03:35:23 -07:00
|
|
|
</span>
|
2022-11-18 05:59:31 -08:00
|
|
|
<template #dropdown>
|
|
|
|
<el-dropdown-menu>
|
2022-12-14 01:04:10 -08:00
|
|
|
<el-dropdown-item
|
|
|
|
:command="operation.command"
|
|
|
|
v-for="operation in itemAddOperations"
|
|
|
|
:key="operation.command"
|
|
|
|
>{{ operation.displayName }}</el-dropdown-item
|
|
|
|
>
|
2022-11-18 05:59:31 -08:00
|
|
|
</el-dropdown-menu>
|
|
|
|
</template>
|
2019-06-23 03:35:23 -07:00
|
|
|
</el-dropdown>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-if="item.options && (extended === true || extendAll === true)">
|
2022-12-14 01:04:10 -08:00
|
|
|
<variable-selector-item
|
|
|
|
v-for="option in item.options"
|
|
|
|
:item="option"
|
|
|
|
:key="option.key"
|
|
|
|
:extendAll="extendAll"
|
|
|
|
:allowParentSelect="option.allowParentSelect"
|
|
|
|
class="sub-level"
|
|
|
|
@itemSelected="forwardItemSelected"
|
|
|
|
></variable-selector-item>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-else class="value clickable" @click="selectItem(item)">
|
2023-03-23 03:20:11 -07:00
|
|
|
<div class="item-title" :title="item.key">
|
2022-12-14 01:04:10 -08:00
|
|
|
{{ item.name }}:
|
2019-06-23 03:35:23 -07:00
|
|
|
<font-awesome-icon icon="dot-circle" title="Select Item" />
|
|
|
|
</div>
|
2023-03-23 03:20:11 -07:00
|
|
|
<div class="item-value ph-no-capture">
|
2022-12-14 01:04:10 -08:00
|
|
|
{{ item.value !== undefined ? item.value : $locale.baseText('variableSelectorItem.empty') }}
|
|
|
|
</div>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-05-16 02:43:46 -07:00
|
|
|
import { defineComponent } from 'vue';
|
2023-04-24 03:18:24 -07:00
|
|
|
import type { IVariableSelectorOption, IVariableItemSelected } from '@/Interface';
|
2022-12-14 01:04:10 -08:00
|
|
|
import { externalHooks } from '@/mixins/externalHooks';
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2023-05-16 02:43:46 -07:00
|
|
|
export default defineComponent({
|
2019-06-23 03:35:23 -07:00
|
|
|
name: 'VariableSelectorItem',
|
2023-05-16 02:43:46 -07:00
|
|
|
mixins: [externalHooks],
|
2022-12-14 01:04:10 -08:00
|
|
|
props: ['allowParentSelect', 'extendAll', 'item'],
|
2022-12-01 04:26:22 -08:00
|
|
|
mounted() {
|
|
|
|
if (this.extended) return;
|
|
|
|
|
2022-12-14 01:04:10 -08:00
|
|
|
const shouldAutoExtend =
|
|
|
|
[
|
|
|
|
this.$locale.baseText('variableSelectorItem.currentNode'),
|
|
|
|
this.$locale.baseText('variableSelectorItem.inputData'),
|
|
|
|
this.$locale.baseText('variableSelectorItem.binary'),
|
|
|
|
this.$locale.baseText('variableSelectorItem.json'),
|
|
|
|
].includes(this.item.name) && this.item.key === undefined;
|
2022-12-01 04:26:22 -08:00
|
|
|
|
|
|
|
if (shouldAutoExtend) {
|
|
|
|
this.extended = true;
|
|
|
|
}
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
computed: {
|
2022-12-14 01:04:10 -08:00
|
|
|
itemAddOperations() {
|
2019-06-23 03:35:23 -07:00
|
|
|
const returnOptions = [
|
|
|
|
{
|
|
|
|
command: 'raw',
|
|
|
|
displayName: 'Raw value',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
if (this.item.dataType === 'array') {
|
|
|
|
returnOptions.push({
|
|
|
|
command: 'arrayLength',
|
|
|
|
displayName: 'Length',
|
|
|
|
});
|
|
|
|
returnOptions.push({
|
|
|
|
command: 'arrayValues',
|
|
|
|
displayName: 'Values',
|
|
|
|
});
|
|
|
|
} else if (this.item.dataType === 'object') {
|
|
|
|
returnOptions.push({
|
|
|
|
command: 'objectKeys',
|
|
|
|
displayName: 'Keys',
|
|
|
|
});
|
|
|
|
returnOptions.push({
|
|
|
|
command: 'objectValues',
|
|
|
|
displayName: 'Values',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnOptions;
|
|
|
|
},
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
data() {
|
2019-06-23 03:35:23 -07:00
|
|
|
return {
|
|
|
|
extended: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
2022-12-14 01:04:10 -08:00
|
|
|
optionSelected(command: string, item: IVariableSelectorOption) {
|
2019-06-23 03:35:23 -07:00
|
|
|
// By default it is raw
|
|
|
|
let variable = item.key;
|
|
|
|
if (command === 'arrayValues') {
|
|
|
|
variable = `${item.key}.join(', ')`;
|
|
|
|
} else if (command === 'arrayLength') {
|
|
|
|
variable = `${item.key}.length`;
|
|
|
|
} else if (command === 'objectKeys') {
|
|
|
|
variable = `Object.keys(${item.key}).join(', ')`;
|
|
|
|
} else if (command === 'objectValues') {
|
|
|
|
variable = `Object.values(${item.key}).join(', ')`;
|
|
|
|
}
|
|
|
|
this.$emit('itemSelected', { variable });
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
selectItem(item: IVariableSelectorOption) {
|
2019-06-23 03:35:23 -07:00
|
|
|
this.$emit('itemSelected', { variable: item.key });
|
|
|
|
},
|
2022-12-14 01:04:10 -08:00
|
|
|
forwardItemSelected(eventData: IVariableItemSelected) {
|
2019-06-23 03:35:23 -07:00
|
|
|
this.$emit('itemSelected', eventData);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
.option-title {
|
|
|
|
position: relative;
|
|
|
|
display: inline-block;
|
|
|
|
font-size: 0.9em;
|
|
|
|
font-weight: 600;
|
|
|
|
padding: 0.2em 1em 0.2em 0.4em;
|
|
|
|
}
|
|
|
|
.item-title {
|
|
|
|
font-weight: 600;
|
|
|
|
font-size: 0.8em;
|
|
|
|
white-space: nowrap;
|
2021-08-29 04:36:17 -07:00
|
|
|
overflow: hidden;
|
2019-06-23 03:35:23 -07:00
|
|
|
text-overflow: ellipsis;
|
|
|
|
}
|
|
|
|
.headline {
|
|
|
|
position: relative;
|
|
|
|
margin: 2px;
|
|
|
|
margin-top: 10px;
|
2022-09-23 07:14:28 -07:00
|
|
|
color: $color-primary;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
.options-toggle {
|
|
|
|
position: relative;
|
|
|
|
top: 1px;
|
|
|
|
margin: 0 3px 0 8px;
|
|
|
|
display: inline;
|
|
|
|
}
|
|
|
|
.value {
|
|
|
|
margin: 0.2em;
|
|
|
|
padding: 0.1em 0.3em;
|
|
|
|
}
|
|
|
|
.item-value {
|
|
|
|
font-size: 0.6em;
|
|
|
|
overflow-x: auto;
|
|
|
|
}
|
|
|
|
.sub-level {
|
|
|
|
padding-left: 20px;
|
|
|
|
}
|
|
|
|
</style>
|