2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
|
|
|
<div @keydown.stop class="fixed-collection-parameter">
|
|
|
|
<div v-if="getProperties.length === 0" class="no-items-exist">
|
2021-12-15 04:16:53 -08:00
|
|
|
<n8n-text size="small">{{ $locale.baseText('fixedCollectionParameter.currentlyNoItemsExist') }}</n8n-text>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
|
2022-02-12 03:02:20 -08:00
|
|
|
<div
|
|
|
|
v-for="property in getProperties"
|
|
|
|
:key="property.name"
|
|
|
|
class="fixed-collection-parameter-property"
|
|
|
|
>
|
2021-10-27 12:55:37 -07:00
|
|
|
<n8n-input-label
|
2022-01-07 13:02:21 -08:00
|
|
|
:label="property.displayName === '' || parameter.options.length === 1 ? '' : $locale.nodeText().inputLabelDisplayName(property, path)"
|
2021-10-27 12:55:37 -07:00
|
|
|
:underline="true"
|
|
|
|
:labelHoverableOnly="true"
|
|
|
|
size="small"
|
|
|
|
>
|
|
|
|
<div v-if="multipleValues === true">
|
2022-02-12 03:02:20 -08:00
|
|
|
<div
|
|
|
|
v-for="(value, index) in values[property.name]"
|
|
|
|
:key="property.name + index"
|
|
|
|
class="parameter-item"
|
|
|
|
>
|
2021-10-27 12:55:37 -07:00
|
|
|
<div class="parameter-item-wrapper">
|
|
|
|
<div class="delete-option" v-if="!isReadOnly">
|
2022-02-12 03:02:20 -08:00
|
|
|
<font-awesome-icon
|
|
|
|
icon="trash"
|
|
|
|
class="reset-icon clickable"
|
|
|
|
:title="$locale.baseText('fixedCollectionParameter.deleteItem')"
|
|
|
|
@click="deleteOption(property.name, index)"
|
|
|
|
/>
|
2021-10-27 12:55:37 -07:00
|
|
|
<div v-if="sortable" class="sort-icon">
|
2022-02-12 03:02:20 -08:00
|
|
|
<font-awesome-icon
|
|
|
|
v-if="index !== 0"
|
|
|
|
icon="angle-up"
|
|
|
|
class="clickable"
|
|
|
|
:title="$locale.baseText('fixedCollectionParameter.moveUp')"
|
|
|
|
@click="moveOptionUp(property.name, index)"
|
|
|
|
/>
|
|
|
|
<font-awesome-icon
|
|
|
|
v-if="index !== (values[property.name].length - 1)"
|
|
|
|
icon="angle-down"
|
|
|
|
class="clickable"
|
|
|
|
:title="$locale.baseText('fixedCollectionParameter.moveDown')"
|
|
|
|
@click="moveOptionDown(property.name, index)"
|
|
|
|
/>
|
2021-10-27 12:55:37 -07:00
|
|
|
</div>
|
2020-12-26 15:15:33 -08:00
|
|
|
</div>
|
2022-02-12 03:02:20 -08:00
|
|
|
<parameter-input-list
|
|
|
|
:parameters="property.values"
|
|
|
|
:nodeValues="nodeValues"
|
|
|
|
:path="getPropertyPath(property.name, index)"
|
|
|
|
:hideDelete="true"
|
|
|
|
@valueChanged="valueChanged"
|
|
|
|
/>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-27 12:55:37 -07:00
|
|
|
<div v-else class="parameter-item">
|
|
|
|
<div class="parameter-item-wrapper">
|
|
|
|
<div class="delete-option" v-if="!isReadOnly">
|
2022-02-12 03:02:20 -08:00
|
|
|
<font-awesome-icon
|
|
|
|
icon="trash"
|
|
|
|
class="reset-icon clickable"
|
|
|
|
:title="$locale.baseText('fixedCollectionParameter.deleteItem')"
|
|
|
|
@click="deleteOption(property.name)"
|
|
|
|
/>
|
2021-10-27 12:55:37 -07:00
|
|
|
</div>
|
2022-02-12 03:02:20 -08:00
|
|
|
<parameter-input-list
|
|
|
|
:parameters="property.values"
|
|
|
|
:nodeValues="nodeValues"
|
|
|
|
:path="getPropertyPath(property.name)"
|
|
|
|
class="parameter-item"
|
|
|
|
@valueChanged="valueChanged"
|
|
|
|
:hideDelete="true"
|
|
|
|
/>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-10-27 12:55:37 -07:00
|
|
|
</n8n-input-label>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-if="parameterOptions.length > 0 && !isReadOnly">
|
2022-02-12 03:02:20 -08:00
|
|
|
<n8n-button
|
|
|
|
v-if="parameter.options.length === 1"
|
2022-05-23 08:56:15 -07:00
|
|
|
type="tertiary"
|
2022-02-12 03:02:20 -08:00
|
|
|
fullWidth
|
|
|
|
@click="optionSelected(parameter.options[0].name)"
|
|
|
|
:label="getPlaceholderText"
|
|
|
|
/>
|
2021-08-29 04:36:17 -07:00
|
|
|
<div v-else class="add-option">
|
2022-02-12 03:02:20 -08:00
|
|
|
<n8n-select
|
|
|
|
v-model="selectedOption"
|
|
|
|
:placeholder="getPlaceholderText"
|
|
|
|
size="small"
|
|
|
|
@change="optionSelected"
|
|
|
|
filterable
|
|
|
|
>
|
2021-08-29 04:36:17 -07:00
|
|
|
<n8n-option
|
|
|
|
v-for="item in parameterOptions"
|
|
|
|
:key="item.name"
|
2022-01-07 13:02:21 -08:00
|
|
|
:label="$locale.nodeText().collectionOptionDisplayName(parameter, item, path)"
|
2022-02-12 03:02:20 -08:00
|
|
|
:value="item.name"
|
|
|
|
></n8n-option>
|
2021-08-29 04:36:17 -07:00
|
|
|
</n8n-select>
|
|
|
|
</div>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import {
|
|
|
|
IUpdateInformation,
|
|
|
|
} from '@/Interface';
|
|
|
|
|
|
|
|
import {
|
|
|
|
INodeParameters,
|
|
|
|
INodePropertyCollection,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
import { get } from 'lodash';
|
|
|
|
|
|
|
|
import { genericHelpers } from '@/components/mixins/genericHelpers';
|
|
|
|
|
|
|
|
import mixins from 'vue-typed-mixins';
|
|
|
|
|
|
|
|
export default mixins(genericHelpers)
|
|
|
|
.extend({
|
|
|
|
name: 'FixedCollectionParameter',
|
|
|
|
props: [
|
|
|
|
'nodeValues', // INodeParameters
|
|
|
|
'parameter', // INodeProperties
|
|
|
|
'path', // string
|
|
|
|
'values', // INodeParameters
|
|
|
|
],
|
2022-02-12 03:02:20 -08:00
|
|
|
data() {
|
2019-06-23 03:35:23 -07:00
|
|
|
return {
|
|
|
|
selectedOption: undefined,
|
|
|
|
};
|
|
|
|
},
|
2022-01-30 05:56:39 -08:00
|
|
|
|
2019-06-23 03:35:23 -07:00
|
|
|
computed: {
|
2022-02-12 03:02:20 -08:00
|
|
|
getPlaceholderText(): string {
|
2022-01-07 13:02:21 -08:00
|
|
|
const placeholder = this.$locale.nodeText().placeholder(this.parameter, this.path);
|
2021-12-15 04:16:53 -08:00
|
|
|
return placeholder ? placeholder : this.$locale.baseText('fixedCollectionParameter.choose');
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2022-02-12 03:02:20 -08:00
|
|
|
getProperties(): INodePropertyCollection[] {
|
2019-06-23 03:35:23 -07:00
|
|
|
const returnProperties = [];
|
|
|
|
let tempProperties;
|
|
|
|
for (const name of this.propertyNames) {
|
|
|
|
tempProperties = this.getOptionProperties(name);
|
|
|
|
if (tempProperties !== undefined) {
|
|
|
|
returnProperties.push(tempProperties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return returnProperties;
|
|
|
|
},
|
2022-02-12 03:02:20 -08:00
|
|
|
multipleValues(): boolean {
|
2019-06-23 03:35:23 -07:00
|
|
|
if (this.parameter.typeOptions !== undefined && this.parameter.typeOptions.multipleValues === true) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2022-02-12 03:02:20 -08:00
|
|
|
parameterOptions(): INodePropertyCollection[] {
|
2019-06-23 03:35:23 -07:00
|
|
|
if (this.multipleValues === true) {
|
|
|
|
return this.parameter.options;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (this.parameter.options as INodePropertyCollection[]).filter((option) => {
|
|
|
|
return !this.propertyNames.includes(option.name);
|
|
|
|
});
|
|
|
|
},
|
2022-02-12 03:02:20 -08:00
|
|
|
propertyNames(): string[] {
|
2019-06-23 03:35:23 -07:00
|
|
|
if (this.values) {
|
|
|
|
return Object.keys(this.values);
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
},
|
2022-02-12 03:02:20 -08:00
|
|
|
sortable(): string {
|
2020-12-26 15:15:33 -08:00
|
|
|
return this.parameter.typeOptions && this.parameter.typeOptions.sortable;
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
methods: {
|
2022-02-12 03:02:20 -08:00
|
|
|
deleteOption(optionName: string, index?: number) {
|
|
|
|
const currentOptionsOfSameType = this.values[optionName];
|
|
|
|
if (!currentOptionsOfSameType || currentOptionsOfSameType.length > 1) {
|
|
|
|
// it's not the only option of this type, so just remove it.
|
|
|
|
this.$emit('valueChanged', {
|
|
|
|
name: this.getPropertyPath(optionName, index),
|
|
|
|
value: undefined,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// it's the only option, so remove the whole type
|
|
|
|
this.$emit('valueChanged', {
|
|
|
|
name: this.getPropertyPath(optionName),
|
|
|
|
value: undefined,
|
|
|
|
});
|
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
2022-02-12 03:02:20 -08:00
|
|
|
getPropertyPath(name: string, index?: number) {
|
2019-06-23 03:35:23 -07:00
|
|
|
return `${this.path}.${name}` + (index !== undefined ? `[${index}]` : '');
|
|
|
|
},
|
2022-02-12 03:02:20 -08:00
|
|
|
getOptionProperties(optionName: string): INodePropertyCollection | undefined {
|
2019-06-23 03:35:23 -07:00
|
|
|
for (const option of this.parameter.options) {
|
|
|
|
if (option.name === optionName) {
|
|
|
|
return option;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
|
|
|
},
|
2022-02-12 03:02:20 -08:00
|
|
|
moveOptionDown(optionName: string, index: number) {
|
2020-12-26 15:15:33 -08:00
|
|
|
this.values[optionName].splice(index + 1, 0, this.values[optionName].splice(index, 1)[0]);
|
|
|
|
|
|
|
|
const parameterData = {
|
|
|
|
name: this.getPropertyPath(optionName),
|
|
|
|
value: this.values[optionName],
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$emit('valueChanged', parameterData);
|
|
|
|
},
|
2022-02-12 03:02:20 -08:00
|
|
|
moveOptionUp(optionName: string, index: number) {
|
2020-12-26 15:15:33 -08:00
|
|
|
this.values[optionName].splice(index - 1, 0, this.values[optionName].splice(index, 1)[0]);
|
|
|
|
|
|
|
|
const parameterData = {
|
|
|
|
name: this.getPropertyPath(optionName),
|
|
|
|
value: this.values[optionName],
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$emit('valueChanged', parameterData);
|
|
|
|
},
|
2022-02-12 03:02:20 -08:00
|
|
|
optionSelected(optionName: string) {
|
2019-06-23 03:35:23 -07:00
|
|
|
const option = this.getOptionProperties(optionName);
|
|
|
|
if (option === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const name = `${this.path}.${option.name}`;
|
|
|
|
|
|
|
|
let parameterData;
|
|
|
|
|
|
|
|
const newParameterValue: INodeParameters = {};
|
|
|
|
|
|
|
|
for (const optionParameter of option.values) {
|
2019-10-04 03:36:42 -07:00
|
|
|
if (optionParameter.type === 'fixedCollection' && optionParameter.typeOptions !== undefined && optionParameter.typeOptions.multipleValues === true) {
|
2019-10-04 03:33:23 -07:00
|
|
|
newParameterValue[optionParameter.name] = {};
|
|
|
|
} else if (optionParameter.typeOptions !== undefined && optionParameter.typeOptions.multipleValues === true) {
|
2019-06-23 03:35:23 -07:00
|
|
|
// Multiple values are allowed so append option to array
|
|
|
|
newParameterValue[optionParameter.name] = get(this.nodeValues, `${this.path}.${optionParameter.name}`, []);
|
2021-05-19 17:26:29 -07:00
|
|
|
if (Array.isArray(optionParameter.default)) {
|
|
|
|
(newParameterValue[optionParameter.name] as INodeParameters[]).push(...JSON.parse(JSON.stringify(optionParameter.default)));
|
|
|
|
} else if (optionParameter.default !== '' && typeof optionParameter.default !== 'object') {
|
|
|
|
(newParameterValue[optionParameter.name] as INodeParameters[]).push(JSON.parse(JSON.stringify(optionParameter.default)));
|
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
} else {
|
|
|
|
// Add a new option
|
|
|
|
newParameterValue[optionParameter.name] = JSON.parse(JSON.stringify(optionParameter.default));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let newValue;
|
|
|
|
if (this.multipleValues === true) {
|
|
|
|
newValue = get(this.nodeValues, name, []);
|
|
|
|
|
|
|
|
newValue.push(newParameterValue);
|
|
|
|
} else {
|
|
|
|
newValue = newParameterValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
parameterData = {
|
|
|
|
name,
|
|
|
|
value: newValue,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.$emit('valueChanged', parameterData);
|
|
|
|
this.selectedOption = undefined;
|
|
|
|
},
|
2022-02-12 03:02:20 -08:00
|
|
|
valueChanged(parameterData: IUpdateInformation) {
|
2019-06-23 03:35:23 -07:00
|
|
|
this.$emit('valueChanged', parameterData);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
beforeCreate: function () { // tslint:disable-line
|
|
|
|
// Because we have a circular dependency on ParameterInputList import it here
|
|
|
|
// to not break Vue.
|
|
|
|
this.$options!.components!.ParameterInputList = require('./ParameterInputList.vue').default;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
.fixed-collection-parameter {
|
2021-10-27 12:55:37 -07:00
|
|
|
padding-left: var(--spacing-s);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.fixed-collection-parameter-property {
|
2021-10-27 12:55:37 -07:00
|
|
|
margin: var(--spacing-xs) 0;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
.delete-option {
|
|
|
|
display: none;
|
|
|
|
position: absolute;
|
|
|
|
z-index: 999;
|
|
|
|
color: #f56c6c;
|
|
|
|
left: 0;
|
2022-02-12 03:02:20 -08:00
|
|
|
top: 0.5em;
|
2019-07-16 22:42:45 -07:00
|
|
|
width: 15px;
|
|
|
|
height: 100%;
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
2021-10-27 12:55:37 -07:00
|
|
|
.parameter-item:hover > .parameter-item-wrapper > .delete-option {
|
2019-06-23 03:35:23 -07:00
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
|
|
|
.parameter-item {
|
|
|
|
position: relative;
|
|
|
|
padding: 0 0 0 1em;
|
|
|
|
|
|
|
|
+ .parameter-item {
|
|
|
|
.parameter-item-wrapper {
|
|
|
|
border-top: 1px dashed #999;
|
2021-10-27 12:55:37 -07:00
|
|
|
|
|
|
|
.delete-option {
|
|
|
|
top: 14px;
|
|
|
|
}
|
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
|
|
|
}
|
2021-08-29 04:36:17 -07:00
|
|
|
|
|
|
|
.sort-icon {
|
2021-10-27 12:55:37 -07:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
margin-left: 1px;
|
2022-02-12 03:02:20 -08:00
|
|
|
margin-top: 0.5em;
|
2021-08-29 04:36:17 -07:00
|
|
|
}
|
2019-06-23 03:35:23 -07:00
|
|
|
</style>
|