-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: let users configure their first day of week
Signed-off-by: Richard Steinmetz <[email protected]>
- Loading branch information
Showing
13 changed files
with
159 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
apps/settings/src/components/PersonalInfo/FirstDayOfWeekSection.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<!-- | ||
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
- SPDX-License-Identifier: AGPL-3.0-or-later | ||
--> | ||
|
||
<template> | ||
<section class="fdow-section"> | ||
<HeaderBar :input-id="inputId" | ||
:readable="propertyReadable" /> | ||
|
||
<NcSelect :aria-label-listbox="t('settings', 'Days to use as the first day of week')" | ||
class="fdow-section__day-select" | ||
:clearable="false" | ||
:input-id="inputId" | ||
label="label" | ||
label-outside | ||
:options="dayOptions" | ||
:value="valueOption" | ||
@option:selected="updateFirstDayOfWeek" /> | ||
</section> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import HeaderBar from './shared/HeaderBar.vue' | ||
import NcSelect from '@nextcloud/vue/dist/Components/NcSelect.js' | ||
import { | ||
ACCOUNT_SETTING_PROPERTY_ENUM, | ||
ACCOUNT_SETTING_PROPERTY_READABLE_ENUM, | ||
} from '../../constants/AccountPropertyConstants' | ||
import { getDayNames, getFirstDay } from '@nextcloud/l10n' | ||
import { savePrimaryAccountProperty } from '../../service/PersonalInfo/PersonalInfoService' | ||
import { handleError } from '../../utils/handlers.ts' | ||
import { loadState } from '@nextcloud/initial-state' | ||
interface DayOption { | ||
value: number, | ||
label: string, | ||
} | ||
const { firstDayOfWeek } = loadState<{firstDayOfWeek?: string}>( | ||
'settings', | ||
'personalInfoParameters', | ||
{}, | ||
) | ||
export default { | ||
name: 'FirstDayOfWeekSection', | ||
components: { | ||
HeaderBar, | ||
NcSelect, | ||
}, | ||
data() { | ||
let firstDay = -1 | ||
if (firstDayOfWeek) { | ||
firstDay = parseInt(firstDayOfWeek) | ||
} | ||
return { | ||
firstDay, | ||
} | ||
}, | ||
computed: { | ||
inputId(): string { | ||
return 'account-property-fdow' | ||
}, | ||
propertyReadable(): string { | ||
return ACCOUNT_SETTING_PROPERTY_READABLE_ENUM.FIRST_DAY_OF_WEEK | ||
}, | ||
dayOptions(): DayOption[] { | ||
const options = [{ | ||
value: -1, | ||
label: t('settings', 'Derived from your locale ({weekDayName})', { | ||
weekDayName: getDayNames()[getFirstDay()], | ||
}), | ||
}] | ||
for (const [index, dayName] of getDayNames().entries()) { | ||
options.push({ value: index, label: dayName }) | ||
} | ||
return options | ||
}, | ||
valueOption(): DayOption | undefined { | ||
return this.dayOptions.find((option) => option.value === this.firstDay) | ||
}, | ||
}, | ||
methods: { | ||
async updateFirstDayOfWeek(option: DayOption): Promise<void> { | ||
try { | ||
const responseData = await savePrimaryAccountProperty( | ||
ACCOUNT_SETTING_PROPERTY_ENUM.FIRST_DAY_OF_WEEK, | ||
option.value.toString(), | ||
) | ||
this.handleResponse({ | ||
value: option.value, | ||
status: responseData.ocs?.meta?.status, | ||
}) | ||
window.location.reload() | ||
} catch (e) { | ||
this.handleResponse({ | ||
errorMessage: t('settings', 'Unable to update first day of week'), | ||
error: e, | ||
}) | ||
} | ||
}, | ||
handleResponse({ value, status, errorMessage, error }): void { | ||
if (status === 'ok') { | ||
this.firstDay = value | ||
} else { | ||
this.$emit('update:value', this.firstDay) | ||
handleError(error, errorMessage) | ||
} | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.fdow-section { | ||
padding: 10px; | ||
&__day-select { | ||
width: 100%; | ||
margin-top: 6px; // align with other inputs | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,7 @@ export default { | |
} | ||
&.setting-property { | ||
height: 44px; | ||
height: 34px; | ||
} | ||
label { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters