2019-06-23 03:35:23 -07:00
|
|
|
<template>
|
|
|
|
<div @keydown.stop class="collection-parameter">
|
|
|
|
<div class="collection-parameter-wrapper">
|
|
|
|
<div v-if="getProperties.length === 0" class="no-items-exist">
|
2021-12-15 04:16:53 -08:00
|
|
|
<n8n-text size="small">{{ $locale.baseText('collectionParameter.noProperties') }}</n8n-text>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
|
2021-10-27 12:55:37 -07:00
|
|
|
<parameter-input-list :parameters="getProperties" :nodeValues="nodeValues" :path="path" :hideDelete="hideDelete" :indent="true" @valueChanged="valueChanged" />
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2021-08-29 04:36:17 -07:00
|
|
|
<div v-if="parameterOptions.length > 0 && !isReadOnly" class="param-options">
|
|
|
|
<n8n-button
|
|
|
|
v-if="parameter.options.length === 1"
|
2022-05-23 08:56:15 -07:00
|
|
|
type="tertiary"
|
2022-07-20 08:50:39 -07:00
|
|
|
block
|
2021-08-29 04:36:17 -07:00
|
|
|
@click="optionSelected(parameter.options[0].name)"
|
|
|
|
:label="getPlaceholderText"
|
|
|
|
/>
|
|
|
|
<div v-else class="add-option">
|
|
|
|
<n8n-select v-model="selectedOption" :placeholder="getPlaceholderText" size="small" @change="optionSelected" filterable>
|
|
|
|
<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)"
|
2021-08-29 04:36:17 -07:00
|
|
|
:value="item.name">
|
|
|
|
</n8n-option>
|
|
|
|
</n8n-select>
|
|
|
|
</div>
|
2019-06-23 03:35:23 -07:00
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import {
|
2022-04-28 10:04:09 -07:00
|
|
|
INodeUi,
|
2019-06-23 03:35:23 -07:00
|
|
|
IUpdateInformation,
|
|
|
|
} from '@/Interface';
|
|
|
|
|
|
|
|
import {
|
2022-10-18 04:33:31 -07:00
|
|
|
deepCopy,
|
2019-06-23 03:35:23 -07:00
|
|
|
INodeProperties,
|
|
|
|
INodePropertyOptions,
|
|
|
|
} from 'n8n-workflow';
|
|
|
|
|
|
|
|
import { genericHelpers } from '@/components/mixins/genericHelpers';
|
|
|
|
import { nodeHelpers } from '@/components/mixins/nodeHelpers';
|
|
|
|
|
|
|
|
import { get } from 'lodash';
|
|
|
|
|
|
|
|
import mixins from 'vue-typed-mixins';
|
2022-09-23 07:14:28 -07:00
|
|
|
import {Component} from "vue";
|
2019-06-23 03:35:23 -07:00
|
|
|
|
|
|
|
export default mixins(
|
|
|
|
genericHelpers,
|
|
|
|
nodeHelpers,
|
|
|
|
)
|
|
|
|
.extend({
|
|
|
|
name: 'CollectionParameter',
|
|
|
|
props: [
|
|
|
|
'hideDelete', // boolean
|
|
|
|
'nodeValues', // NodeParameters
|
|
|
|
'parameter', // INodeProperties
|
|
|
|
'path', // string
|
|
|
|
'values', // NodeParameters
|
|
|
|
],
|
2022-09-23 07:14:28 -07:00
|
|
|
components: {
|
|
|
|
ParameterInputList: () => import('./ParameterInputList.vue') as Promise<Component>,
|
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
selectedOption: undefined,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
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('collectionParameter.choose');
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
getProperties (): INodeProperties[] {
|
|
|
|
const returnProperties = [];
|
|
|
|
let tempProperties;
|
|
|
|
for (const name of this.propertyNames) {
|
|
|
|
tempProperties = this.getOptionProperties(name);
|
|
|
|
if (tempProperties !== undefined) {
|
2021-05-28 16:13:15 -07:00
|
|
|
returnProperties.push(...tempProperties);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return returnProperties;
|
|
|
|
},
|
|
|
|
// Returns all the options which should be displayed
|
|
|
|
filteredOptions (): Array<INodePropertyOptions | INodeProperties> {
|
|
|
|
return (this.parameter.options as Array<INodePropertyOptions | INodeProperties>).filter((option) => {
|
|
|
|
return this.displayNodeParameter(option as INodeProperties);
|
|
|
|
});
|
|
|
|
},
|
2022-04-28 10:04:09 -07:00
|
|
|
node (): INodeUi {
|
2022-10-24 02:35:03 -07:00
|
|
|
return this.$store.getters['ndv/activeNode'];
|
2022-04-28 10:04:09 -07:00
|
|
|
},
|
2019-06-23 03:35:23 -07:00
|
|
|
// Returns all the options which did not get added already
|
|
|
|
parameterOptions (): Array<INodePropertyOptions | INodeProperties> {
|
|
|
|
return (this.filteredOptions as Array<INodePropertyOptions | INodeProperties>).filter((option) => {
|
|
|
|
return !this.propertyNames.includes(option.name);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
propertyNames (): string[] {
|
|
|
|
if (this.values) {
|
|
|
|
return Object.keys(this.values);
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getArgument (argumentName: string): string | number | boolean | undefined {
|
|
|
|
if (this.parameter.typeOptions === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.parameter.typeOptions[argumentName] === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.parameter.typeOptions[argumentName];
|
|
|
|
},
|
2021-05-28 16:13:15 -07:00
|
|
|
getOptionProperties (optionName: string): INodeProperties[] {
|
|
|
|
const properties: INodeProperties[] = [];
|
2019-06-23 03:35:23 -07:00
|
|
|
for (const option of this.parameter.options) {
|
|
|
|
if (option.name === optionName) {
|
2021-05-28 16:13:15 -07:00
|
|
|
properties.push(option);
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-28 16:13:15 -07:00
|
|
|
return properties;
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
displayNodeParameter (parameter: INodeProperties) {
|
|
|
|
if (parameter.displayOptions === undefined) {
|
|
|
|
// If it is not defined no need to do a proper check
|
|
|
|
return true;
|
|
|
|
}
|
2022-04-28 10:04:09 -07:00
|
|
|
return this.displayParameter(this.nodeValues, parameter, this.path, this.node);
|
2019-06-23 03:35:23 -07:00
|
|
|
},
|
|
|
|
optionSelected (optionName: string) {
|
2021-05-28 16:13:15 -07:00
|
|
|
const options = this.getOptionProperties(optionName);
|
|
|
|
if (options.length === 0) {
|
2019-06-23 03:35:23 -07:00
|
|
|
return;
|
|
|
|
}
|
2021-05-28 16:13:15 -07:00
|
|
|
|
|
|
|
const option = options[0];
|
2019-06-23 03:35:23 -07:00
|
|
|
const name = `${this.path}.${option.name}`;
|
|
|
|
|
|
|
|
let parameterData;
|
|
|
|
|
|
|
|
if (option.typeOptions !== undefined && option.typeOptions.multipleValues === true) {
|
|
|
|
// Multiple values are allowed
|
|
|
|
|
|
|
|
let newValue;
|
|
|
|
if (option.type === 'fixedCollection') {
|
|
|
|
// The "fixedCollection" entries are different as they save values
|
|
|
|
// in an object and then underneath there is an array. So initialize
|
|
|
|
// them differently.
|
|
|
|
newValue = get(this.nodeValues, `${this.path}.${optionName}`, {});
|
|
|
|
} else {
|
|
|
|
// Everything else saves them directly as an array.
|
|
|
|
newValue = get(this.nodeValues, `${this.path}.${optionName}`, []);
|
2022-10-18 04:33:31 -07:00
|
|
|
newValue.push(deepCopy(option.default));
|
2019-06-23 03:35:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
parameterData = {
|
|
|
|
name,
|
|
|
|
value: newValue,
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Add a new option
|
|
|
|
parameterData = {
|
|
|
|
name,
|
2022-10-18 04:33:31 -07:00
|
|
|
value: deepCopy(option.default),
|
2019-06-23 03:35:23 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$emit('valueChanged', parameterData);
|
|
|
|
this.selectedOption = undefined;
|
|
|
|
},
|
|
|
|
valueChanged (parameterData: IUpdateInformation) {
|
|
|
|
this.$emit('valueChanged', parameterData);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
|
|
|
.collection-parameter {
|
2021-10-27 12:55:37 -07:00
|
|
|
padding-left: var(--spacing-s);
|
2019-06-23 03:35:23 -07:00
|
|
|
|
2021-08-29 04:36:17 -07:00
|
|
|
.param-options {
|
2021-10-27 12:55:37 -07:00
|
|
|
margin-top: var(--spacing-xs);
|
2022-07-20 08:50:39 -07:00
|
|
|
|
|
|
|
.button {
|
|
|
|
--button-background-color: var(--color-background-base);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
.option {
|
|
|
|
position: relative;
|
|
|
|
padding: 0.25em 0 0.25em 1em;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</style>
|