enrecipes/app/components/modal/ActionDialogWithSearch.vue

139 lines
3.6 KiB
Vue
Raw Normal View History

2020-11-15 10:51:10 +00:00
<template>
2021-03-10 15:59:50 +00:00
<Page @loaded="onPageLoad" backgroundColor="transparent">
2021-02-28 15:10:26 +00:00
<GridLayout
columns="*"
rows="auto, auto, auto, *, auto"
class="dialogContainer"
:class="appTheme"
>
2021-03-21 17:02:04 +00:00
<StackLayout row="0" class="dialogHeader" orientation="horizontal">
<Label class="er dialogIcon" :text="icon[helpIcon]" />
<Label
2021-03-23 06:16:25 +00:00
class="dialogTitle"
2021-03-21 17:02:04 +00:00
:text="`${title}` | L"
textWrap="true"
/>
</StackLayout>
2021-02-28 15:10:26 +00:00
<StackLayout
row="2"
v-if="filteredRecipes.length || searchQuery"
2021-03-21 17:02:04 +00:00
padding="0 24 8"
2021-02-28 15:10:26 +00:00
>
<TextField :hint="'Search' | L" v-model="searchQuery" />
</StackLayout>
2021-02-28 15:10:26 +00:00
<ScrollView row="3" width="100%" :height="height ? height : ''">
<StackLayout>
<MDButton
v-for="(recipe, index) in filteredRecipes"
:key="index"
class="actionItem"
variant="text"
:text="recipe.title"
@loaded="centerLabel"
@tap="tapAction(recipe)"
/>
<Label
padding="24"
lineHeight="6"
v-if="!filteredRecipes.length && !searchQuery"
:text="'recListEmp' | L"
textAlignment="center"
textWrap="true"
/>
<Label
padding="24"
lineHeight="6"
v-if="!filteredRecipes.length && searchQuery"
:text="'noRecs' | L"
textAlignment="center"
textWrap="true"
/>
</StackLayout>
</ScrollView>
<GridLayout
row="4"
rows="auto"
columns="auto, *, auto"
class="actionsContainer"
>
<MDButton
variant="text"
v-if="action"
col="0"
2021-03-23 06:16:25 +00:00
class="action tb pull-left"
2021-02-28 15:10:26 +00:00
:text="`${action}` | L"
@tap="$modal.close(action)"
/>
<MDButton
variant="text"
col="2"
2021-03-23 06:16:25 +00:00
class="action tb pull-right"
2021-02-28 15:10:26 +00:00
:text="'CANCEL' | L"
@tap="$modal.close(false)"
/>
</GridLayout>
</GridLayout>
2021-02-28 15:10:26 +00:00
</Page>
2020-11-15 10:51:10 +00:00
</template>
<script>
2021-02-28 15:10:26 +00:00
import { Application } from "@nativescript/core";
import { mapState } from "vuex";
2020-11-15 10:51:10 +00:00
export default {
2021-02-28 15:10:26 +00:00
props: ["title", "recipes", "height", "action", "helpIcon"],
2020-11-15 10:51:10 +00:00
data() {
return {
2020-12-29 10:35:19 +00:00
searchQuery: "",
2021-02-28 15:10:26 +00:00
};
2020-11-15 10:51:10 +00:00
},
computed: {
2021-02-28 15:10:26 +00:00
...mapState(["icon"]),
2020-11-15 10:51:10 +00:00
appTheme() {
2021-02-28 15:10:26 +00:00
return Application.systemAppearance();
2020-11-15 10:51:10 +00:00
},
filteredRecipes() {
2021-02-28 15:10:26 +00:00
return this.recipes
.map((e, i) => {
return {
id: e.id,
title: e.title,
cuisine: e.cuisine,
category: e.category,
tags: e.tags.map((e) => e.toLowerCase()).join(),
ingredients: e.ingredients.map((e) => e.item.toLowerCase()).join(),
};
})
.filter((e) => this.recipeFilter(e));
2020-11-15 10:51:10 +00:00
},
},
methods: {
2021-03-10 15:59:50 +00:00
onPageLoad(args) {
args.object._dialogFragment
.getDialog()
.getWindow()
.setBackgroundDrawable(
new android.graphics.drawable.ColorDrawable(
android.graphics.Color.TRANSPARENT
)
);
},
2021-02-28 15:10:26 +00:00
tapAction(recipe) {
this.$modal.close(recipe.id);
2020-11-15 10:51:10 +00:00
},
2021-02-28 15:10:26 +00:00
centerLabel(args) {
args.object.android.setGravity(16);
2020-11-15 10:51:10 +00:00
},
2021-02-28 15:10:26 +00:00
recipeFilter(e) {
let searchQuery = this.searchQuery.toLowerCase();
return (
e.title.includes(searchQuery) ||
e.cuisine.includes(searchQuery) ||
e.category.includes(searchQuery) ||
e.tags.includes(searchQuery) ||
e.ingredients.includes(searchQuery)
);
2020-12-29 10:35:19 +00:00
},
2020-11-15 10:51:10 +00:00
},
2021-02-28 15:10:26 +00:00
};
2020-11-15 10:51:10 +00:00
</script>