enrecipes/app/components/Settings/Interface.vue

172 lines
4.7 KiB
Vue
Raw Permalink Normal View History

2021-03-21 17:02:04 +00:00
<template>
2021-04-01 10:55:35 +00:00
<Page @loaded="onPageLoad" actionBarHidden="true">
<GridLayout rows="*, auto" columns="auto, *">
<ListView
colSpan="2"
rowSpan="2"
class="options-list"
for="item in items"
>
<v-template if="$index == 0">
<Label class="pageTitle" :text="'intf' | L" />
</v-template>
<v-template if="$index == 4">
<StackLayout class="listSpace"> </StackLayout>
</v-template>
2021-03-21 17:02:04 +00:00
<v-template>
2021-04-01 10:55:35 +00:00
<GridLayout
columns="auto, *"
class="option"
@touch="touch($event, item.action)"
>
<Label class="ico" :text="icon[item.icon]" />
2021-03-21 17:02:04 +00:00
<StackLayout col="1">
2021-04-01 10:55:35 +00:00
<Label :text="item.title | L" class="info" />
<Label :text="item.subTitle" class="sub" />
2021-03-21 17:02:04 +00:00
</StackLayout>
</GridLayout>
</v-template>
</ListView>
2021-04-01 10:55:35 +00:00
<GridLayout row="1" class="appbar" rows="*" columns="auto, *">
2021-04-12 18:09:48 +00:00
<Button class="ico" :text="icon.back" @tap="$navigateBack()" />
2021-04-01 10:55:35 +00:00
</GridLayout>
2021-03-21 17:02:04 +00:00
</GridLayout>
</Page>
</template>
<script>
2021-04-01 10:55:35 +00:00
import {
ApplicationSettings,
Observable,
Device,
Frame,
} from "@nativescript/core";
2021-03-21 17:02:04 +00:00
import { localize, overrideLocale } from "@nativescript/localize";
import ActionDialog from "../modal/ActionDialog.vue";
import ConfirmDialog from "../modal/ConfirmDialog.vue";
import { mapState, mapActions } from "vuex";
2021-04-12 18:09:48 +00:00
import * as utils from "~/shared/utils";
2021-03-21 17:02:04 +00:00
export default {
data() {
return {
appLanguage: "English",
};
},
computed: {
2021-04-01 10:55:35 +00:00
...mapState(["icon", "language", "appTheme", "layout"]),
2021-03-21 17:02:04 +00:00
items() {
return [
2021-04-01 10:55:35 +00:00
{},
2021-03-21 17:02:04 +00:00
{
icon: "lang",
title: "lang",
subTitle: this.appLanguage,
action: this.selectAppLanguage,
},
{
icon: "theme",
title: "Theme",
2021-04-23 19:50:32 +00:00
subTitle: localize(
ApplicationSettings.getString("appTheme", "sysDef")
),
2021-03-21 17:02:04 +00:00
action: this.selectThemes,
},
{
2021-04-12 18:09:48 +00:00
icon: "layout",
2021-03-21 17:02:04 +00:00
title: "listVM",
subTitle: localize(this.layout),
action: this.setLayoutMode,
},
2021-04-01 10:55:35 +00:00
{},
2021-03-21 17:02:04 +00:00
];
},
},
methods: {
2021-04-01 10:55:35 +00:00
...mapActions(["setTheme", "setLayout"]),
2021-03-21 17:02:04 +00:00
onPageLoad(args) {
const page = args.object;
page.bindingContext = new Observable();
},
// LANGUAGE SELECTION
selectAppLanguage() {
let languages = this.language.map((e) => e.title);
this.$showModal(ActionDialog, {
props: {
title: "lang",
list: [...languages],
},
}).then((action) => {
if (action && action !== "Cancel" && this.appLanguage !== action) {
let currentLocale = Device.language.split("-")[0];
let locale = this.language.filter((e) => e.title === action)[0]
.locale;
if (currentLocale !== locale) {
this.$showModal(ConfirmDialog, {
props: {
title: "appRst",
description: localize("nLangInfo"),
cancelButtonText: "cBtn",
okButtonText: "rst",
},
}).then((result) => {
if (result) {
this.appLanguage = action;
ApplicationSettings.setString("appLanguage", action);
overrideLocale(locale);
setTimeout(utils.restartApp, 250);
}
});
}
}
});
},
// THEME SELECTION
selectThemes() {
this.$showModal(ActionDialog, {
props: {
title: "Theme",
2021-04-23 19:50:32 +00:00
list: ["Light", "Dark", "Black", "sysDef", "sysDefB"],
2021-03-21 17:02:04 +00:00
},
}).then((action) => {
2021-04-23 19:50:32 +00:00
if (
action &&
(ApplicationSettings.getString("appTheme") != this.appTheme
? true
: this.appTheme != action)
) {
2021-04-01 10:55:35 +00:00
this.setTheme(action);
Frame.reloadPage();
2021-03-21 17:02:04 +00:00
}
});
},
// LAYOUT MODE
setLayoutMode() {
this.$showModal(ActionDialog, {
props: {
2021-04-15 18:47:06 +00:00
title: "listVM",
2021-04-12 18:09:48 +00:00
list: ["detailed", "grid", "photogrid", "simple", "minimal"],
2021-03-21 17:02:04 +00:00
},
}).then((action) => {
if (action && action !== "Cancel" && this.layoutMode !== action) {
let act = action.toLowerCase();
ApplicationSettings.setString("layout", act);
this.setLayout(act);
}
});
},
2021-04-01 10:55:35 +00:00
// HELPERS
touch({ object, action }, method) {
object.className = action.match(/down|move/) ? "option fade" : "option";
if (action == "up") method();
},
2021-03-21 17:02:04 +00:00
},
mounted() {
this.appLanguage = ApplicationSettings.getString(
"appLanguage",
localize("sysDef")
);
},
};
</script>