Skip to content

Commit

Permalink
Remake locale saving with Vue
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Aug 11, 2022
1 parent 257ab46 commit 8fa575c
Show file tree
Hide file tree
Showing 15 changed files with 332 additions and 127 deletions.
5 changes: 1 addition & 4 deletions apps/settings/css/settings.css

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

2 changes: 1 addition & 1 deletion apps/settings/css/settings.css.map

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

10 changes: 1 addition & 9 deletions apps/settings/css/settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ input {
display: inline-grid;
grid-template-columns: 1fr;
grid-template-rows: 1fr 1fr 1fr 2fr;

#locale {
h3 {
height: 32px;
}
}
}

.personal-show-container {
Expand All @@ -146,9 +140,7 @@ input {
}

select {
&#timezone,
&#languageinput,
&#localeinput {
&#timezone {
width: 100%;
}
}
Expand Down
58 changes: 0 additions & 58 deletions apps/settings/js/settings/personalInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,58 +213,6 @@ window.addEventListener('DOMContentLoaded', function () {
});
federationSettingsView.render();

var updateLanguage = function () {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(updateLanguage);
return;
}

var selectedLang = $("#languageinput").val(),
user = OC.getCurrentUser();

$.ajax({
url: OC.linkToOCS('cloud/users', 2) + user['uid'],
method: 'PUT',
data: {
key: 'language',
value: selectedLang
},
success: function() {
location.reload();
},
fail: function() {
OC.Notification.showTemporary(t('settings', 'An error occurred while changing your language. Please reload the page and try again.'));
}
});
};
$("#languageinput").change(updateLanguage);

var updateLocale = function () {
if (OC.PasswordConfirmation.requiresPasswordConfirmation()) {
OC.PasswordConfirmation.requirePasswordConfirmation(updateLocale);
return;
}

var selectedLocale = $("#localeinput").val(),
user = OC.getCurrentUser();

$.ajax({
url: OC.linkToOCS('cloud/users', 2) + user.uid,
method: 'PUT',
data: {
key: 'locale',
value: selectedLocale
},
success: function() {
moment.locale(selectedLocale);
},
fail: function() {
OC.Notification.showTemporary(t('settings', 'An error occurred while changing your locale. Please reload the page and try again.'));
}
});
};
$("#localeinput").change(updateLocale);

var uploadparms = {
pasteZone: null,
done: function (e, data) {
Expand Down Expand Up @@ -385,10 +333,4 @@ window.addEventListener('DOMContentLoaded', function () {
}, user.displayName);
});

window.setInterval(function() {
$('#localeexample-time').text(moment().format('LTS'))
$('#localeexample-date').text(moment().format('L'))
$('#localeexample-fdow').text(t('settings', 'Week starts on {fdow}', { fdow: dayNames[firstDay] }))
}, 1000)

OC.Settings.updateAvatar = updateAvatar;
25 changes: 9 additions & 16 deletions apps/settings/lib/Settings/Personal/PersonalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ public function getForm(): TemplateResponse {
$totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
}

$localeParameters = $this->getLocales($user);
$messageParameters = $this->getMessageParameters($account);

$parameters = [
Expand All @@ -157,14 +156,15 @@ public function getForm(): TemplateResponse {
'groups' => $this->getGroups($user),
'isFairUseOfFreePushService' => $this->isFairUseOfFreePushService(),
'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
] + $messageParameters + $localeParameters;
] + $messageParameters;

$personalInfoParameters = [
'userId' => $uid,
'displayName' => $this->getProperty($account, IAccountManager::PROPERTY_DISPLAYNAME),
'twitter' => $this->getProperty($account, IAccountManager::PROPERTY_TWITTER),
'emailMap' => $this->getEmailMap($account),
'languageMap' => $this->getLanguageMap($user),
'localeMap' => $this->getLocaleMap($user),
'profileEnabledGlobally' => $this->profileManager->isProfileEnabled(),
'profileEnabled' => $this->profileManager->isProfileEnabled($user),
'organisation' => $this->getProperty($account, IAccountManager::PROPERTY_ORGANISATION),
Expand Down Expand Up @@ -319,31 +319,24 @@ private function getLanguageMap(IUser $user): array {
);
}

private function getLocales(IUser $user): array {
private function getLocaleMap(IUser $user): array {
$forceLanguage = $this->config->getSystemValue('force_locale', false);
if ($forceLanguage !== false) {
return [];
}

$uid = $user->getUID();

$userLocaleString = $this->config->getUserValue($uid, 'core', 'locale', $this->l10nFactory->findLocale());

$userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());

$localeCodes = $this->l10nFactory->findAvailableLocales();

$userLocale = array_filter($localeCodes, function ($value) use ($userLocaleString) {
return $userLocaleString === $value['code'];
});
$userLocale = array_filter($localeCodes, fn ($value) => $userLocaleString === $value['code']);

if (!empty($userLocale)) {
$userLocale = reset($userLocale);
}

$localesForLanguage = array_filter($localeCodes, function ($localeCode) use ($userLang) {
return 0 === strpos($localeCode['code'], $userLang);
});
$localesForLanguage = array_values(array_filter($localeCodes, fn ($localeCode) => strpos($localeCode['code'], $userLang) === 0));
$otherLocales = array_values(array_filter($localeCodes, fn ($localeCode) => strpos($localeCode['code'], $userLang) !== 0));

if (!$userLocale) {
$userLocale = [
Expand All @@ -353,10 +346,10 @@ private function getLocales(IUser $user): array {
}

return [
'activelocaleLang' => $userLocaleString,
'activelocale' => $userLocale,
'locales' => $localeCodes,
'activeLocaleLang' => $userLocaleString,
'activeLocale' => $userLocale,
'localesForLanguage' => $localesForLanguage,
'otherLocales' => $otherLocales,
];
}

Expand Down
Loading

0 comments on commit 8fa575c

Please sign in to comment.