mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 22:43:34 -07:00
shuffle + icons
This commit is contained in:
parent
45b7667814
commit
65d6e4560a
3 changed files with 57 additions and 6 deletions
|
@ -7,26 +7,50 @@
|
||||||
<v-toolbar-title class="headline"> {{ title }} </v-toolbar-title>
|
<v-toolbar-title class="headline"> {{ title }} </v-toolbar-title>
|
||||||
<v-spacer></v-spacer>
|
<v-spacer></v-spacer>
|
||||||
<v-btn text @click="navigateRandom">
|
<v-btn text @click="navigateRandom">
|
||||||
Random
|
<v-icon left>
|
||||||
|
mdi-dice-multiple
|
||||||
|
</v-icon>
|
||||||
|
{{ $t("general.random") }}
|
||||||
</v-btn>
|
</v-btn>
|
||||||
<v-menu offset-y v-if="$listeners.sort">
|
<v-menu offset-y left v-if="$listeners.sort">
|
||||||
<template v-slot:activator="{ on, attrs }">
|
<template v-slot:activator="{ on, attrs }">
|
||||||
<v-btn text v-bind="attrs" v-on="on">
|
<v-btn text v-bind="attrs" v-on="on" :loading="sortLoading">
|
||||||
|
<v-icon left>
|
||||||
|
mdi-sort
|
||||||
|
</v-icon>
|
||||||
{{ $t("general.sort") }}
|
{{ $t("general.sort") }}
|
||||||
</v-btn>
|
</v-btn>
|
||||||
</template>
|
</template>
|
||||||
<v-list>
|
<v-list>
|
||||||
<v-list-item @click="sortRecipes(EVENTS.az)">
|
<v-list-item @click="sortRecipes(EVENTS.az)">
|
||||||
|
<v-icon left>
|
||||||
|
mdi-order-alphabetical-ascending
|
||||||
|
</v-icon>
|
||||||
<v-list-item-title>{{ $t("general.sort-alphabetically") }}</v-list-item-title>
|
<v-list-item-title>{{ $t("general.sort-alphabetically") }}</v-list-item-title>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
<v-list-item @click="sortRecipes(EVENTS.rating)">
|
<v-list-item @click="sortRecipes(EVENTS.rating)">
|
||||||
|
<v-icon left>
|
||||||
|
mdi-star
|
||||||
|
</v-icon>
|
||||||
<v-list-item-title>{{ $t("general.rating") }}</v-list-item-title>
|
<v-list-item-title>{{ $t("general.rating") }}</v-list-item-title>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
|
<v-list-item @click="sortRecipes(EVENTS.created)">
|
||||||
|
<v-icon left>
|
||||||
|
mdi-new-box
|
||||||
|
</v-icon>
|
||||||
|
<v-list-item-title>{{ $t("general.created") }}</v-list-item-title>
|
||||||
|
</v-list-item>
|
||||||
<v-list-item @click="sortRecipes(EVENTS.updated)">
|
<v-list-item @click="sortRecipes(EVENTS.updated)">
|
||||||
|
<v-icon left>
|
||||||
|
mdi-update
|
||||||
|
</v-icon>
|
||||||
<v-list-item-title>{{ $t("general.updated") }}</v-list-item-title>
|
<v-list-item-title>{{ $t("general.updated") }}</v-list-item-title>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
<v-list-item @click="sortRecipes(EVENTS.created)">
|
<v-list-item @click="sortRecipes(EVENTS.shuffle)">
|
||||||
<v-list-item-title>{{ $t("general.created") }}</v-list-item-title>
|
<v-icon left>
|
||||||
|
mdi-shuffle-variant
|
||||||
|
</v-icon>
|
||||||
|
<v-list-item-title>{{ $t("general.shuffle") }}</v-list-item-title>
|
||||||
</v-list-item>
|
</v-list-item>
|
||||||
</v-list>
|
</v-list>
|
||||||
</v-menu>
|
</v-menu>
|
||||||
|
@ -114,6 +138,7 @@ export default {
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
sortLoading: false,
|
||||||
cardLimit: 30,
|
cardLimit: 30,
|
||||||
loading: false,
|
loading: false,
|
||||||
EVENTS: {
|
EVENTS: {
|
||||||
|
@ -121,6 +146,7 @@ export default {
|
||||||
rating: "rating",
|
rating: "rating",
|
||||||
created: "created",
|
created: "created",
|
||||||
updated: "updated",
|
updated: "updated",
|
||||||
|
shuffle: "shuffle",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -165,6 +191,7 @@ export default {
|
||||||
this.$router.push(`/recipe/${recipe.slug}`);
|
this.$router.push(`/recipe/${recipe.slug}`);
|
||||||
},
|
},
|
||||||
sortRecipes(sortType) {
|
sortRecipes(sortType) {
|
||||||
|
this.sortLoading = true;
|
||||||
let sortTarget = [...this.recipes];
|
let sortTarget = [...this.recipes];
|
||||||
switch (sortType) {
|
switch (sortType) {
|
||||||
case this.EVENTS.az:
|
case this.EVENTS.az:
|
||||||
|
@ -179,11 +206,16 @@ export default {
|
||||||
case this.EVENTS.updated:
|
case this.EVENTS.updated:
|
||||||
utils.recipe.sortByUpdated(sortTarget);
|
utils.recipe.sortByUpdated(sortTarget);
|
||||||
break;
|
break;
|
||||||
|
case this.EVENTS.shuffle:
|
||||||
|
utils.recipe.shuffle(sortTarget);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.log("Unknown Event", sortType);
|
console.log("Unknown Event", sortType);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$emit(SORT_EVENT, sortTarget);
|
this.$emit(SORT_EVENT, sortTarget);
|
||||||
|
this.sortLoading = false;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -74,11 +74,12 @@
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
"settings": "Settings",
|
"settings": "Settings",
|
||||||
"sort": "Sort",
|
"sort": "Sort",
|
||||||
"sort-alphabetically": "A-Z",
|
"sort-alphabetically": "Alphabetical",
|
||||||
"status": "Status",
|
"status": "Status",
|
||||||
"submit": "Submit",
|
"submit": "Submit",
|
||||||
"success-count": "Success: {count}",
|
"success-count": "Success: {count}",
|
||||||
"sunday": "Sunday",
|
"sunday": "Sunday",
|
||||||
|
"shuffle": "Shuffle",
|
||||||
"templates": "Templates:",
|
"templates": "Templates:",
|
||||||
"themes": "Themes",
|
"themes": "Themes",
|
||||||
"thursday": "Thursday",
|
"thursday": "Thursday",
|
||||||
|
|
|
@ -28,4 +28,22 @@ export const recipe = {
|
||||||
randomRecipe(list) {
|
randomRecipe(list) {
|
||||||
return list[Math.floor(Math.random() * list.length)];
|
return list[Math.floor(Math.random() * list.length)];
|
||||||
},
|
},
|
||||||
|
shuffle(list) {
|
||||||
|
let last = list.length;
|
||||||
|
let n;
|
||||||
|
while (last > 0) {
|
||||||
|
n = rand(last);
|
||||||
|
swap(list, n, --last);
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const rand = n =>
|
||||||
|
Math.floor(Math.random() * n)
|
||||||
|
|
||||||
|
function swap(t, i, j) {
|
||||||
|
let q = t[i];
|
||||||
|
t[i] = t[j];
|
||||||
|
t[j] = q;
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue