enrecipes/app/components/settings/Interface.vue

140 lines
3.5 KiB
Vue
Raw Normal View History

2021-03-21 17:02:04 +00:00
<template>
2021-06-08 11:43:54 +00:00
<Page @loaded="pgLoad" actionBarHidden="true">
<RGridLayout :isRtl="RTL" rows="*, auto" columns="auto, *">
2021-05-25 14:32:53 +00:00
<OptionsList title="intf" :items="items" />
2021-06-08 11:43:54 +00:00
<GridLayout
:isRtl="RTL"
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-06-08 11:43:54 +00:00
</RGridLayout>
2021-03-21 17:02:04 +00:00
</Page>
</template>
<script>
2021-04-01 10:55:35 +00:00
import {
ApplicationSettings,
Observable,
Device,
Frame,
} from "@nativescript/core";
2021-06-08 11:43:54 +00:00
import { localize } from "@nativescript/localize";
2021-05-25 14:32:53 +00:00
import Action from "../modals/Action";
import Confirm from "../modals/Confirm";
import OptionsList from "../sub/OptionsList";
2021-03-21 17:02:04 +00:00
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 {
2021-05-25 14:32:53 +00:00
components: { OptionsList },
2021-03-21 17:02:04 +00:00
data() {
return {
2021-06-08 11:43:54 +00:00
applang: 0,
2021-03-21 17:02:04 +00:00
};
},
computed: {
2021-06-08 11:43:54 +00:00
...mapState(["icon", "language", "appTheme", "layout", "RTL"]),
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
{
2021-05-25 14:32:53 +00:00
type: "list",
2021-03-21 17:02:04 +00:00
icon: "lang",
title: "lang",
2021-06-08 11:43:54 +00:00
subTitle: this.applang,
action: this.setAppLang,
2021-03-21 17:02:04 +00:00
},
{
2021-05-25 14:32:53 +00:00
type: "list",
2021-03-21 17:02:04 +00:00
icon: "theme",
title: "Theme",
2021-06-08 11:43:54 +00:00
subTitle: ApplicationSettings.getString("appTheme", "sysDef"),
2021-03-21 17:02:04 +00:00
action: this.selectThemes,
},
{
2021-05-25 14:32:53 +00:00
type: "list",
2021-04-12 18:09:48 +00:00
icon: "layout",
2021-03-21 17:02:04 +00:00
title: "listVM",
2021-06-08 11:43:54 +00:00
subTitle: this.layout,
2021-03-21 17:02:04 +00:00
action: this.setLayoutMode,
},
2021-04-01 10:55:35 +00:00
{},
2021-03-21 17:02:04 +00:00
];
},
},
methods: {
2021-06-08 11:43:54 +00:00
...mapActions(["setTheme", "setLayout", "setRTL"]),
pgLoad({ object }) {
2021-05-25 14:32:53 +00:00
object.bindingContext = new Observable();
2021-03-21 17:02:04 +00:00
},
// LANGUAGE SELECTION
2021-06-08 11:43:54 +00:00
setAppLang() {
2021-03-21 17:02:04 +00:00
let languages = this.language.map((e) => e.title);
2021-05-25 14:32:53 +00:00
this.$showModal(Action, {
2021-03-21 17:02:04 +00:00
props: {
title: "lang",
list: [...languages],
},
}).then((action) => {
2021-06-08 11:43:54 +00:00
if (action && this.applang !== action) {
let currentLocale = ApplicationSettings.getString(
"appLocale",
"none"
).split("-");
2021-03-21 17:02:04 +00:00
let locale = this.language.filter((e) => e.title === action)[0]
.locale;
if (currentLocale !== locale) {
2021-06-08 11:43:54 +00:00
this.applang = action;
ApplicationSettings.setString("applang", action);
ApplicationSettings.setString("appLocale", locale);
utils.updateLocale();
this.setRTL();
2021-03-21 17:02:04 +00:00
}
}
});
},
// THEME SELECTION
selectThemes() {
2021-05-25 14:32:53 +00:00
this.$showModal(Action, {
2021-03-21 17:02:04 +00:00
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
2021-06-08 11:43:54 +00:00
? 1
2021-04-23 19:50:32 +00:00
: 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() {
2021-05-25 14:32:53 +00:00
this.$showModal(Action, {
2021-03-21 17:02:04 +00:00
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) => {
2021-05-22 08:56:31 +00:00
if (action && this.layoutMode !== action) {
2021-03-21 17:02:04 +00:00
let act = action.toLowerCase();
ApplicationSettings.setString("layout", act);
this.setLayout(act);
}
});
},
},
2021-05-25 14:32:53 +00:00
created() {
2021-06-08 11:43:54 +00:00
this.applang = ApplicationSettings.getString("applang", "sysDef");
2021-03-21 17:02:04 +00:00
},
};
</script>