Skip to content

Commit

Permalink
refactor: rename settings-i18n to view-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
caro3801 committed Oct 25, 2024
1 parent 30d386d commit c0edda1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 38 deletions.
34 changes: 0 additions & 34 deletions src/composables/settings-i18n.js

This file was deleted.

35 changes: 35 additions & 0 deletions src/composables/view-settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
const SORT_ORDER_KEY = Object.freeze({
ASC: 'asc',
DESC: 'desc'
})
const SORT_TYPE_KEY = Object.freeze({
DEFAULT: 'default',
ALPHA: 'alpha',
NUMBER: 'number',
QUANTITY: 'quantity',
DATE: 'date'
})

export function useViewSettings() {
const { t } = useI18n()
const sortByLabel = computed(() => t('viewSettings.sortBy.label'))
const visiblePropertiesLabel = computed(() => t('viewSettings.properties'))

function tSortByOption(name, order = SORT_ORDER_KEY.ASC, type = SORT_TYPE_KEY.DEFAULT) {
return computed(() =>
t(`viewSettings.sortBy.format`, {
name: t(`viewSettings.options.${name}`),
order: t(`viewSettings.order.${type}.${order}`)
})
)
}
const tLayout = {
label: computed((_) => t('viewSettings.view.label')),
grid: computed((_) => t('viewSettings.view.grid')),
table: computed((_) => t('viewSettings.view.table'))
}
const perPageLabel = (titleKey) => computed((_) => t('viewSettings.perPage', { title: t(titleKey) }))
return { SORT_ORDER_KEY, SORT_TYPE_KEY, tSortByOption, sortByLabel, visiblePropertiesLabel, tLayout, perPageLabel }
}
36 changes: 32 additions & 4 deletions src/views/Task/TasksListSettings.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<script setup>
import { noop } from 'lodash'
import { ref } from 'vue'
import { computed, ref } from 'vue'
import { useCore } from '@/composables/core'
import { useUrlParamWithStore, useUrlParamsWithStore } from '@/composables/url-params'
import PageSettings from '@/components/PageSettings/PageSettings'
import PageSettingsSection from '@/components/PageSettings/PageSettingsSection'
import { useSettingsI18n } from '@/composables/settings-i18n'
import { useViewSettings } from '@/composables/view-settings'
import { useTaskSettings } from '@/composables/task-settings'
const { core } = useCore()
const { SORT_ORDER_KEY, SORT_TYPE_KEY, sortByLabel, tSortByOption, perPageLabel } = useSettingsI18n()
const { SORT_ORDER_KEY, SORT_TYPE_KEY, sortByLabel, tSortByOption, perPageLabel, visiblePropertiesLabel } =
useViewSettings()
const settingName = 'taskList'
const perPage = ref({
label: perPageLabel('tasks.title'),
label: perPageLabel('task.title'),
type: 'radio',
open: true,
modelValue: useUrlParamWithStore('perPage', {
Expand Down Expand Up @@ -79,6 +81,24 @@ const sortBy = ref({
}
]
})
const { propertiesOrder, propertiesLabel, propertiesIcon } = useTaskSettings()
const properties = ref({
label: visiblePropertiesLabel,
type: 'checkbox',
open: true,
modelValue: computed({
get: () => core?.store.getters['app/getSettings']('settingName', 'properties'),
set: (properties) => core?.store.commit('app/setSettings', { view: 'search', properties })
}),
options: computed(() => {
return propertiesOrder.map((value) => {
const text = propertiesLabel.value[value]
const icon = propertiesIcon[value]
return { value, icon, text }
})
})
})
defineProps({
hide: {
Expand Down Expand Up @@ -110,5 +130,13 @@ defineProps({
:options="perPage.options"
:label="perPage.label"
/>
<page-settings-section
v-model="properties.modelValue"
v-model:open="properties.open"
:type="properties.type"
:options="properties.options"
:label="properties.label"
/>
</page-settings>
</template>

0 comments on commit c0edda1

Please sign in to comment.