Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

171 user settings #182

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
"vuetify": "^2.6.15",
"vuex": "^3.4.0",
"vuex-class": "^0.3.2",
"vuex-module-decorators": "^1.2.0"
"vuex-module-decorators": "^1.2.0",
"vuex-persistedstate": "^4.1.0"
},
"devDependencies": {
"@intlify/vue-i18n-loader": "^1.0.0",
Expand Down
4 changes: 4 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import Empty from '@/layouts/Empty.vue'
import { namespace } from 'vuex-class'
import { WebOcComponent } from '@/store/modules/fews-config/types'
import { routesViews } from '@/router'
import { UserSettingsItem } from '@/store/modules/user-settings/types'

const fewsConfigModule = namespace('fewsconfig')
const userSettingsModule = namespace('userSettings')

@Component({
components: {
Expand All @@ -25,6 +27,8 @@ export default class App extends Vue {
webOcComponents!: { [key: string]: WebOcComponent }
@fewsConfigModule.Action('setFewsConfig')
setFewsConfig!: () => Promise<void>
@userSettingsModule.Mutation('add')
addUserSetting!: (item: UserSettingsItem) => void

async created(): Promise<void> {
if (this.$config.authenticationIsEnabled) {
Expand Down
101 changes: 101 additions & 0 deletions src/assets/DefaultUserSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
[
{
"id": "units.displayUnits",
"type": "oneOfMultiple",
"label": "Display Units",
"value": "display",
"items": [
{
"value": "stored",
"icon": "mdi-database"
},
{
"value": "display",
"icon": "mdi-monitor"
},
{
"value": "custom",
"icon": "mdi-monitor-edit",
"disabled": true
}
],
"group": "Units"
},
{
"id": "units.parameterGroup.Discharge",
"type": "oneOfMultiple",
"label": "Discharge",
"value": "ML/d",
"disabled": true,
"items": [
{
"value": "m³/s"
},
{
"value": "ML/d"
}
],
"group": "Units"
},
{
"id": "units.parameterGroup.Volume",
"type": "oneOfMultiple",
"label": "Volume",
"value": "ML",
"disabled": true,
"items": [
{
"value": "m³"
},
{
"value": "ML"
}
],
"group": "Units"
},
{
"id": "datum.verticalDatum",
"type": "boolean",
"label": "Absolute vertical datum",
"value": true,
"group": "Datum"
},
{
"id": "ui.theme",
"type": "oneOfMultiple",
"label": "Theme",
"value": "auto",
"items": [
{
"value": "auto",
"icon": "mdi-theme-light-dark"
},
{
"value": "light",
"icon": "mdi-weather-sunny"
},
{
"value": "dark",
"icon": "mdi-weather-night"
}
],
"group": "UI"
},
{
"id": "locale.language",
"type": "oneOfMultiple",
"label": "Language",
"value": "en-au",
"items": [
{
"icon": "fi-au",
"value": "en-au"
},
{
"icon": "fi-nl",
"value": "nl-nl"
}
],
"group": "Locale"
}
]
80 changes: 49 additions & 31 deletions src/components/CogMenu.vue
Original file line number Diff line number Diff line change
@@ -1,51 +1,69 @@
<template>
<v-menu left bottom class="menu">
<v-menu left bottom
:close-on-content-click="false"
class="menu"
>
<template v-slot:activator="{ on, attrs }">
<v-btn icon v-bind="attrs" v-on="on">
<v-icon>mdi-cog</v-icon>
</v-btn>
</template>
<v-list>
<v-subheader>Theme</v-subheader>
<v-list-item>
<v-list-item-action>
<v-list-item-action>
<ThemeSelector v-model="theme" @input="onThemeChange"/>
</v-list-item-action>
<v-list-item dense v-for="(s, i) of listFavorite" :key="i">
<v-list-item-content>
<v-list-item-action-text>
{{ s.label }}
</v-list-item-action-text>
<v-list-item-action v-if="s.type === 'oneOfMultiple'">
<v-btn-toggle dense v-model="s.value" @change="onValueChange(s)">
<v-btn v-for="item of s.items" :key="item.value" :value="item.value" :disabled="item.disabled">
<v-icon v-if="item.icon">{{ item.icon }}</v-icon>
<span v-else>{{ item.value }}</span>
</v-btn>
</v-btn-toggle>
</v-list-item-action>
</v-list-item>
<v-subheader>Language</v-subheader>
<v-list-item>
<v-list-item-action>
<v-list-item-action>
<locale-control/>
</v-list-item-action>
<v-list-item-action v-else-if="s.type === 'boolean'">
<v-switch dense inset v-model="s.value" :disabled="s.disabled"
@change="onValueChange(s)">
</v-switch>
</v-list-item-action>
</v-list-item>
<v-list-item>
<v-list-item-content>
<v-list-item-title>Version {{ packageVersion }}</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-divider />
<v-list-item :to="{ name: 'UserSettingsView'}">All Settings ...</v-list-item>
</v-list>
</v-menu>
</template>

<script lang="ts">
import { Component, Mixins } from 'vue-property-decorator'
import ThemeMixin from '@/mixins/ThemeMixin'
import ThemeSelector from '@/components/ThemeSelector.vue'
import LocaleControl from './LocaleControl.vue'
import packageConfig from '../../package.json'

@Component({
components: {
ThemeSelector,
LocaleControl
import {
Component,
Vue
} from 'vue-property-decorator'

import { namespace } from 'vuex-class'
import { UserSettingsItem } from '@/store/modules/user-settings/types'
import "flag-icons/css/flag-icons.min.css"

const userSettingsModule = namespace('userSettings')

@Component
export default class CogMenu extends Vue {
@userSettingsModule.Getter('listFavorite')
listFavorite!: UserSettingsItem[]
@userSettingsModule.Mutation('add')
addUserSetting!: (item: UserSettingsItem) => void

items: UserSettingsItem[] = []

created(): void {
console.log(this.listFavorite)

Check warning on line 60 in src/components/CogMenu.vue

View workflow job for this annotation

GitHub Actions / build (16)

Unexpected console statement

Check warning on line 60 in src/components/CogMenu.vue

View workflow job for this annotation

GitHub Actions / build (18.3)

Unexpected console statement
this.items = this.listFavorite
}

onValueChange(item: UserSettingsItem) {
this.addUserSetting(item)
}
})
export default class CogMenu extends Mixins(ThemeMixin) {
packageVersion = packageConfig.version
}
</script>

Expand Down
32 changes: 30 additions & 2 deletions src/layouts/Default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,19 @@
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { Component, Mixins } from 'vue-property-decorator'
import CogMenu from '@/components/CogMenu.vue'
import TimeControl from '@/components/timecontrol/TimeControl.vue'
import LoginComponent from '@/components/LoginComponent.vue'
import { namespace } from 'vuex-class'
import { Alert } from '@/store/modules/alerts/types'
import type { WebOcComponent } from '@/store/modules/fews-config/types'
import { ComponentTypeEnum } from '@/store/modules/fews-config/types'
import ThemeMixin from '@/mixins/ThemeMixin'

const alertsModule = namespace('alerts')
const fewsConfigModule = namespace('fewsconfig')
const userSettingsModule = namespace('userSettings')

@Component({
components: {
Expand All @@ -74,7 +76,7 @@ const fewsConfigModule = namespace('fewsconfig')
TimeControl,
}
})
export default class Default extends Vue {
export default class Default extends Mixins(ThemeMixin) {
@alertsModule.Getter('listActive')
activeAlerts!: Alert[]
@alertsModule.State('alerts')
Expand All @@ -83,6 +85,32 @@ export default class Default extends Vue {
webOcComponents!: { [key: string]: WebOcComponent }
@fewsConfigModule.Action('loadConfig')
loadConfig!: () => void
@userSettingsModule.Action('changeUseDisplayUnits')
changeUseDisplayUnits!: (value: string) => void
@userSettingsModule.Mutation('setConvertDatum')
setConvertDatum!: (value: boolean) => void

created() {
this.$store.subscribe((mutation, state) => {
if (mutation.type.startsWith('userSettings/add')) {
switch(mutation.payload.id) {
case 'ui.theme':
this.changeTheme(mutation.payload.value)
break
case 'locale.language':
this.$i18n.locale = mutation.payload.value
break
case 'units.displayUnits':
this.changeUseDisplayUnits(mutation.payload.value)
break
case 'datum.verticalDatum':
this.setConvertDatum(mutation.payload.value)
break
default:
}
}
})
}

mounted(): void {
this.loadConfig()
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"settings": {
"nl": "Dutch",
"en": "English"
"en": "English",
"en-au": "Australian English"
}
}
3 changes: 2 additions & 1 deletion src/locales/nl.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"settings" : {
"nl": "Nederlands",
"en": "Engels"
"en": "Engels",
"en-au": "Australisch-Engels"
}
}
5 changes: 3 additions & 2 deletions src/mixins/ThemeMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ export default class ThemeMixin extends Vue {
// Then listen for changes for user theme preferences.
this.mqDark.addEventListener('change', this.setThemeFromMediaQueryEvent)
// Make sure the theme is set correctly upon creation of this component.
this.onThemeChange()
this.changeTheme(this.theme)
}

onThemeChange(): void {
changeTheme(theme: ColourTheme): void {
this.theme = theme
if (this.theme === ColourTheme.Auto) {
this.setTheme(this.mqDark.matches)
} else {
Expand Down
Loading
Loading