-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
feat: let users configure their first day of week #46592
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() | ||
artonge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic number 102?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like the other properties. For some reason they all return 102 in case of invalid values 🤷♂️