mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-24 23:59:45 +02:00
feat: sort by labels in shopping list copy if labels toggled (#3226)
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Docker Nightly Production / Backend Server Tests (push) Waiting to run
Docker Nightly Production / Frontend and End-to-End Tests (push) Waiting to run
Docker Nightly Production / Build Tagged Release (push) Blocked by required conditions
Docker Nightly Production / Notify Discord (push) Blocked by required conditions
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Docker Nightly Production / Backend Server Tests (push) Waiting to run
Docker Nightly Production / Frontend and End-to-End Tests (push) Waiting to run
Docker Nightly Production / Build Tagged Release (push) Blocked by required conditions
Docker Nightly Production / Notify Discord (push) Blocked by required conditions
* feat: sort by labels in shopping list copy if labels toggled * fix: call parent validator in shopping list item out (#3227) * fix: add a unit test for (#3227) * fixed messy post_validate logic * feat: label headings in shopping list copy * feat: blank line for each group in shopping list copy --------- Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
parent
2809b87ab0
commit
52de8afe2d
5 changed files with 83 additions and 14 deletions
|
@ -337,21 +337,50 @@ export default defineComponent({
|
|||
const copy = useCopyList();
|
||||
|
||||
function copyListItems(copyType: CopyTypes) {
|
||||
const items = shoppingList.value?.listItems?.filter((item) => !item.checked);
|
||||
const text: string[] = [];
|
||||
|
||||
if (!items) {
|
||||
return;
|
||||
if (preferences.value.viewByLabel) {
|
||||
// if we're sorting by label, we want the copied text in subsections
|
||||
Object.entries(itemsByLabel.value).forEach(([label, items], idx) => {
|
||||
// for every group except the first, add a blank line
|
||||
if (idx) {
|
||||
text.push("")
|
||||
}
|
||||
|
||||
// add an appropriate heading for the label depending on the copy format
|
||||
text.push(formatCopiedLabelHeading(copyType, label))
|
||||
|
||||
// now add the appropriately formatted list items with the given label
|
||||
items.forEach((item) => text.push(formatCopiedListItem(copyType, item)))
|
||||
})
|
||||
} else {
|
||||
// labels are toggled off, so just copy in the order they come in
|
||||
const items = shoppingList.value?.listItems?.filter((item) => !item.checked)
|
||||
|
||||
items?.forEach((item) => {
|
||||
text.push(formatCopiedListItem(copyType, item))
|
||||
});
|
||||
}
|
||||
|
||||
const text: string[] = items.map((itm) => itm.display || "");
|
||||
copy.copyPlain(text);
|
||||
}
|
||||
|
||||
function formatCopiedListItem(copyType: CopyTypes, item: ShoppingListItemOut): string {
|
||||
const display = item.display || ""
|
||||
switch (copyType) {
|
||||
case "markdown":
|
||||
copy.copyMarkdownCheckList(text);
|
||||
break;
|
||||
return `- [ ] ${display}`
|
||||
default:
|
||||
copy.copyPlain(text);
|
||||
break;
|
||||
return display
|
||||
}
|
||||
}
|
||||
|
||||
function formatCopiedLabelHeading(copyType: CopyTypes, label: string): string {
|
||||
switch (copyType) {
|
||||
case "markdown":
|
||||
return `# ${label}`
|
||||
default:
|
||||
return `[${label}]`
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue