Fixed sorting/adding bug
This commit is contained in:
parent
793f8ba79a
commit
a57ca025f5
3 changed files with 15 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
<div class="rounded-md shadow-md">
|
<div class="rounded-md shadow-md">
|
||||||
<SortableGroup
|
<SortableGroup
|
||||||
@model={{this.items}}
|
@model={{this.sortedItems}}
|
||||||
@onChange={{action this.reorderItems}}
|
@onChange={{action this.reorderMeals}}
|
||||||
as |group|>
|
as |group|>
|
||||||
{{#each group.model as |meal|}}
|
{{#each group.model as |meal|}}
|
||||||
<group.item
|
<group.item
|
||||||
|
|
|
@ -13,13 +13,23 @@ export default class RecipeListComponent extends Component {
|
||||||
this.assignExistingItems();
|
this.assignExistingItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get sortedItems() {
|
||||||
|
console.log('sorted items called');
|
||||||
|
return this.items.sortBy('listOrder');
|
||||||
|
}
|
||||||
|
|
||||||
async assignExistingItems() {
|
async assignExistingItems() {
|
||||||
let items = await this.store.peekAll('meal');
|
let items = await this.store.peekAll('meal');
|
||||||
this.items = items;
|
this.items = items;
|
||||||
}
|
}
|
||||||
|
|
||||||
@action
|
@action
|
||||||
reorderItems(reorderedItems) {
|
async reorderMeals(reorderedMeals) {
|
||||||
this.items = reorderedItems;
|
let orderedIds = reorderedMeals.map(meal => meal.id);
|
||||||
|
|
||||||
|
for (let index = 0; index < orderedIds.length; index++) {
|
||||||
|
let meal = await this.store.peekRecord('meal', orderedIds[index]);
|
||||||
|
meal.listOrder = index;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,4 +11,5 @@ export default class MealModel extends Model {
|
||||||
@attr tags;
|
@attr tags;
|
||||||
@attr youtube;
|
@attr youtube;
|
||||||
@attr source;
|
@attr source;
|
||||||
|
@attr('number', { defaultValue: Infinity }) listOrder;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue