103 lines
2.9 KiB
Vue
103 lines
2.9 KiB
Vue
<template>
|
|
<div v-if="valid" class="grid gap-2">
|
|
<ul v-if="isArrayInited" class="grid gap-1.5">
|
|
<li v-for="(_, index) in array" :key="index" class="flex items-center gap-1.5">
|
|
<UiNativeSelect v-model="array[index]" :aria-label="displayName" class="min-w-0 flex-1">
|
|
<option value="">{{ $t("Select a network...") }}</option>
|
|
<option v-for="option in options" :key="option" :value="option">{{ option }}</option>
|
|
</UiNativeSelect>
|
|
<UiButton type="button" variant="ghost" size="icon" class="text-destructive" :aria-label="$t('removeEntry')" @click="remove(index)">
|
|
<AppIcon name="x" />
|
|
</UiButton>
|
|
</li>
|
|
</ul>
|
|
<UiButton type="button" variant="outline" size="sm" class="justify-self-start" @click="addField">
|
|
<AppIcon name="plus" /> {{ $t("addListItem", [ displayName ]) }}
|
|
</UiButton>
|
|
</div>
|
|
<p v-else class="text-sm text-muted-foreground">{{ $t("LongSyntaxNotSupported") }}</p>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
inject: { containerEditor: { default: null },
|
|
composePage: {} },
|
|
props: {
|
|
name: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
placeholder: {
|
|
type: String,
|
|
default: "",
|
|
},
|
|
displayName: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
options: {
|
|
type: Array,
|
|
required: true,
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
|
|
};
|
|
},
|
|
computed: {
|
|
array() {
|
|
// Create the array if not exists, it should be safe.
|
|
if (!this.service[this.name]) {
|
|
return [];
|
|
}
|
|
return this.service[this.name];
|
|
},
|
|
|
|
/**
|
|
* Check if the array is inited before called v-for.
|
|
* Prevent empty arrays inserted to the YAML file.
|
|
* @return {boolean}
|
|
*/
|
|
isArrayInited() {
|
|
return this.service[this.name] !== undefined;
|
|
},
|
|
|
|
service() {
|
|
return this.containerEditor.service;
|
|
},
|
|
|
|
valid() {
|
|
// Check if the array is actually an array
|
|
if (!Array.isArray(this.array)) {
|
|
return false;
|
|
}
|
|
|
|
// Check if the array contains non-object only.
|
|
for (let item of this.array) {
|
|
if (typeof item === "object") {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
},
|
|
created() {
|
|
|
|
},
|
|
methods: {
|
|
addField() {
|
|
// Create the array if not exists.
|
|
if (!this.service[this.name]) {
|
|
this.service[this.name] = [];
|
|
}
|
|
this.array.push("");
|
|
},
|
|
remove(index) {
|
|
this.array.splice(index, 1);
|
|
},
|
|
}
|
|
};
|
|
</script>
|