mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
Bulk Dialog
This commit is contained in:
parent
0dbb837dff
commit
a5d722e8e5
1 changed files with 72 additions and 85 deletions
|
@ -4,9 +4,9 @@
|
||||||
v-model="dialog"
|
v-model="dialog"
|
||||||
width="800"
|
width="800"
|
||||||
>
|
>
|
||||||
<template #activator="{ props }">
|
<template #activator="{ props: activatorProps }">
|
||||||
<BaseButton
|
<BaseButton
|
||||||
v-bind="props"
|
v-bind="activatorProps"
|
||||||
@click="inputText = inputTextProp"
|
@click="inputText = inputTextProp"
|
||||||
>
|
>
|
||||||
{{ $t("new-recipe.bulk-add") }}
|
{{ $t("new-recipe.bulk-add") }}
|
||||||
|
@ -89,28 +89,27 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
export default defineNuxtComponent({
|
interface Props {
|
||||||
props: {
|
inputTextProp?: string;
|
||||||
inputTextProp: {
|
}
|
||||||
type: String,
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
required: false,
|
inputTextProp: "",
|
||||||
default: "",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
emits: ["bulk-data"],
|
|
||||||
setup(props, context) {
|
|
||||||
const state = reactive({
|
|
||||||
dialog: false,
|
|
||||||
inputText: props.inputTextProp,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
"bulk-data": [data: string[]];
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const dialog = ref(false);
|
||||||
|
const inputText = ref(props.inputTextProp);
|
||||||
|
|
||||||
function splitText() {
|
function splitText() {
|
||||||
return state.inputText.split("\n").filter(line => !(line === "\n" || !line));
|
return inputText.value.split("\n").filter(line => !(line === "\n" || !line));
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeFirstCharacter() {
|
function removeFirstCharacter() {
|
||||||
state.inputText = splitText()
|
inputText.value = splitText()
|
||||||
.map(line => line.substring(1))
|
.map(line => line.substring(1))
|
||||||
.join("\n");
|
.join("\n");
|
||||||
}
|
}
|
||||||
|
@ -119,11 +118,11 @@ export default defineNuxtComponent({
|
||||||
|
|
||||||
function splitByNumberedLine() {
|
function splitByNumberedLine() {
|
||||||
// Split inputText by numberedLineRegex
|
// Split inputText by numberedLineRegex
|
||||||
const matches = state.inputText.match(numberedLineRegex);
|
const matches = inputText.value.match(numberedLineRegex);
|
||||||
|
|
||||||
matches?.forEach((match, idx) => {
|
matches?.forEach((match, idx) => {
|
||||||
const replaceText = idx === 0 ? "" : "\n";
|
const replaceText = idx === 0 ? "" : "\n";
|
||||||
state.inputText = state.inputText.replace(match, replaceText);
|
inputText.value = inputText.value.replace(match, replaceText);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,12 +133,12 @@ export default defineNuxtComponent({
|
||||||
splitLines[index] = element.trim();
|
splitLines[index] = element.trim();
|
||||||
});
|
});
|
||||||
|
|
||||||
state.inputText = splitLines.join("\n");
|
inputText.value = splitLines.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
context.emit("bulk-data", splitText());
|
emit("bulk-data", splitText());
|
||||||
state.dialog = false;
|
dialog.value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const i18n = useI18n();
|
const i18n = useI18n();
|
||||||
|
@ -161,16 +160,4 @@ export default defineNuxtComponent({
|
||||||
action: splitByNumberedLine,
|
action: splitByNumberedLine,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
return {
|
|
||||||
utilities,
|
|
||||||
splitText,
|
|
||||||
trimAllLines,
|
|
||||||
removeFirstCharacter,
|
|
||||||
splitByNumberedLine,
|
|
||||||
save,
|
|
||||||
...toRefs(state),
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue