2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
|
|
|
<div @keydown.stop class="duplicate-parameter">
|
2021-10-27 12:55:37 -07:00
|
|
|
<n8n-input-label
|
2021-12-07 08:28:10 -08:00
|
|
|
:label="$i.nodeText().topParameterDisplayName(parameter)"
|
|
|
|
:tooltipText="$i.nodeText().topParameterDescription(parameter)"
|
2021-10-27 12:55:37 -07:00
|
|
|
:underline="true"
|
|
|
|
:labelHoverableOnly="true"
|
|
|
|
size="small"
|
|
|
|
>
|
|
|
|
|
|
|
|
<div v-for="(value, index) in values" :key="index" class="duplicate-parameter-item" :class="parameter.type">
|
|
|
|
<div class="delete-item clickable" v-if="!isReadOnly">
|
2021-12-07 08:28:10 -08:00
|
|
|
<font-awesome-icon icon="trash" :title="$i.baseText('multipleParameter.deleteItem')" @click="deleteItem(index)" />
|
2021-10-27 12:55:37 -07:00
|
|
|
<div v-if="sortable">
|
2021-12-07 08:28:10 -08:00
|
|
|
<font-awesome-icon v-if="index !== 0" icon="angle-up" class="clickable" :title="$i.baseText('multipleParameter.moveUp')" @click="moveOptionUp(index)" />
|
|
|
|
<font-awesome-icon v-if="index !== (values.length -1)" icon="angle-down" class="clickable" :title="$i.baseText('multipleParameter.moveDown')" @click="moveOptionDown(index)" />
|
2021-10-27 12:55:37 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div v-if="parameter.type === 'collection'">
|
|
|
|
<collection-parameter :parameter="parameter" :values="value" :nodeValues="nodeValues" :path="getPath(index)" :hideDelete="hideDelete" @valueChanged="valueChanged" />
|
|
|
|
</div>
|
|
|
|
<div v-else>
|
|
|
|
<parameter-input class="duplicate-parameter-input-item" :parameter="parameter" :value="value" :displayOptions="true" :path="getPath(index)" @valueChanged="valueChanged" inputSize="small" :isReadOnly="isReadOnly" />
|
2020-12-26 15:15:33 -08:00
|
|
|
</div>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
|
2021-10-27 12:55:37 -07:00
|
|
|
<div class="add-item-wrapper">
|
|
|
|
<div v-if="values && Object.keys(values).length === 0 || isReadOnly" class="no-items-exist">
|
2021-12-07 08:28:10 -08:00
|
|
|
<n8n-text size="small">{{ $i.baseText('multipleParameter.currentlyNoItemsExist') }}</n8n-text>
|
2021-10-27 12:55:37 -07:00
|
|
|
</div>
|
|
|
|
<n8n-button v-if="!isReadOnly" fullWidth @click="addItem()" :label="addButtonText" />
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
|
2021-10-27 12:55:37 -07:00
|
|
|
</n8n-input-label>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import {
|
|
|
|
IUpdateInformation,
|
|
|
|
} from '@/Interface';
|
|
|
|
|
|
|
|
import CollectionParameter from '@/components/CollectionParameter.vue';
|
|
|
|
import ParameterInput from '@/components/ParameterInput.vue';
|
|
|
|
|
|
|
|
import { get } from 'lodash';
|
|
|
|
|
|
|
|
import { genericHelpers } from '@/components/mixins/genericHelpers';
|
|
|
|
|
|
|
|
import mixins from 'vue-typed-mixins';
|
|
|
|
|
|
|
|
export default mixins(genericHelpers)
|
|
|
|
.extend({
|
|
|
|
name: 'MultipleParameter',
|
|
|
|
components: {
|
|
|
|
CollectionParameter,
|
|
|
|
ParameterInput,
|
|
|
|
},
|
|
|
|
props: [
|
|
|
|
'nodeValues', // NodeParameters
|
|
|
|
'parameter', // NodeProperties
|
|
|
|
'path', // string
|
|
|
|
'values', // NodeParameters[]
|
|
|
|
],
|
|
|
|
computed: {
|
|
|
|
addButtonText (): string {
|
2021-11-15 02:19:43 -08:00
|
|
|
if (
|
|
|
|
!this.parameter.typeOptions &&
|
|
|
|
!this.parameter.typeOptions.multipleValueButtonText
|
|
|
|
) {
|
2021-12-07 08:28:10 -08:00
|
|
|
return this.$i.baseText('multipleParameter.addItem');
|
2021-11-15 02:19:43 -08:00
|
|
|
}
|
|
|
|
|
2021-12-07 08:28:10 -08:00
|
|
|
return this.$i.nodeText().multipleValueButtonText(this.parameter);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
hideDelete (): boolean {
|
|
|
|
return this.parameter.options.length === 1;
|
|
|
|
},
|
2020-12-26 15:15:33 -08:00
|
|
|
sortable (): string {
|
|
|
|
return this.parameter.typeOptions && this.parameter.typeOptions.sortable;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
addItem () {
|
|
|
|
const name = this.getPath();
|
|
|
|
let currentValue = get(this.nodeValues, name);
|
|
|
|
|
|
|
|
if (currentValue === undefined) {
|
|
|
|
currentValue = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
currentValue.push(JSON.parse(JSON.stringify(this.parameter.default)));
|
|
|
|
|
|
|
|
const parameterData = {
|
|
|
|
name,
|
|
|
|
value: currentValue,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$emit('valueChanged', parameterData);
|
|
|
|
},
|
|
|
|
deleteItem (index: number) {
|
|
|
|
const parameterData = {
|
|
|
|
name: this.getPath(index),
|
2019-07-14 05:10:16 -07:00
|
|
|
value: undefined,
|
2019-06-23 03:35:23 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
this.$emit('valueChanged', parameterData);
|
|
|
|
},
|
|
|
|
getPath (index?: number): string {
|
|
|
|
return this.path + (index !== undefined ? `[${index}]` : '');
|
|
|
|
},
|
2020-12-26 15:28:51 -08:00
|
|
|
moveOptionDown (index: number) {
|
2020-12-26 15:15:33 -08:00
|
|
|
this.values.splice(index + 1, 0, this.values.splice(index, 1)[0]);
|
|
|
|
|
|
|
|
const parameterData = {
|
|
|
|
name: this.path,
|
|
|
|
value: this.values,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$emit('valueChanged', parameterData);
|
|
|
|
},
|
2020-12-26 15:28:51 -08:00
|
|
|
moveOptionUp (index: number) {
|
2020-12-26 15:15:33 -08:00
|
|
|
this.values.splice(index - 1, 0, this.values.splice(index, 1)[0]);
|
|
|
|
|
|
|
|
const parameterData = {
|
|
|
|
name: this.path,
|
|
|
|
value: this.values,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$emit('valueChanged', parameterData);
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
valueChanged (parameterData: IUpdateInformation) {
|
|
|
|
this.$emit('valueChanged', parameterData);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
|
|
|
.duplicate-parameter-item ~.add-item-wrapper {
|
2021-10-27 12:55:37 -07:00
|
|
|
margin-top: var(--spacing-xs);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.delete-item {
|
|
|
|
display: none;
|
|
|
|
position: absolute;
|
|
|
|
left: 0.1em;
|
|
|
|
top: .3em;
|
|
|
|
z-index: 999;
|
|
|
|
color: #f56c6c;
|
2020-12-26 15:15:33 -08:00
|
|
|
width: 15px;
|
2021-10-27 12:55:37 -07:00
|
|
|
font-size: var(--font-size-2xs);
|
2019-06-23 03:35:23 -07:00
|
|
|
|
|
|
|
:hover {
|
|
|
|
color: #ff0000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 08:36:23 -08:00
|
|
|
::v-deep .duplicate-parameter-item {
|
2019-06-23 03:35:23 -07:00
|
|
|
position: relative;
|
|
|
|
|
|
|
|
.multi > .delete-item{
|
|
|
|
top: 0.1em;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-07 08:36:23 -08:00
|
|
|
::v-deep .duplicate-parameter-input-item {
|
2019-07-07 07:32:28 -07:00
|
|
|
margin: 0.5em 0 0.25em 2em;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
2020-02-07 08:36:23 -08:00
|
|
|
::v-deep .duplicate-parameter-item + .duplicate-parameter-item {
|
2019-06-23 03:35:23 -07:00
|
|
|
.collection-parameter-wrapper {
|
|
|
|
border-top: 1px dashed #999;
|
2021-10-27 12:55:37 -07:00
|
|
|
margin-top: var(--spacing-xs);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.no-items-exist {
|
2021-10-27 12:55:37 -07:00
|
|
|
margin: var(--spacing-xs) 0;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.duplicate-parameter-item:hover > .delete-item {
|
|
|
|
display: inline;
|
|
|
|
}
|
|
|
|
|
|
|
|
.duplicate-parameter-item .multi > .delete-item{
|
|
|
|
top: 0.1em;
|
|
|
|
}
|
|
|
|
</style>
|