Added UI setting for in which format date and time is displayed

This commit is contained in:
CasVT
2023-07-01 00:05:56 +02:00
parent 4bee7a0965
commit 34a0ef3e88
6 changed files with 88 additions and 9 deletions

View File

@@ -25,6 +25,12 @@
box-shadow: var(--default-shadow);
}
.settings-container input,
.settings-container textarea,
.settings-container select {
max-width: 20rem;
}
#change-password-form {
display: flex;
flex-direction: column;
@@ -33,10 +39,6 @@
gap: 1rem;
}
#change-password-form > input {
max-width: 20rem;
}
#delete-account-button {
background-color: var(--color-error);
}

View File

@@ -47,15 +47,20 @@ function logout() {
'method': 'POST'
})
.then(response => {
localStorage.removeItem('MIND_api_key');
const new_stor = JSON.parse(localStorage.getItem('MIND'))
new_stor.api_key = null
localStorage.setItem('MIND', JSON.stringify(new_stor));
window.location.href = `${url_prefix}/`;
});
};
// code run on load
if (localStorage.getItem('MIND') === null)
localStorage.setItem('MIND', JSON.stringify({'api_key': null, 'locale': 'en-GB'}))
const url_prefix = document.getElementById('url_prefix').dataset.value;
const api_key = localStorage.getItem('MIND_api_key');
const api_key = JSON.parse(localStorage.getItem('MIND')).api_key;
if (api_key === null) {
window.location.href = `${url_prefix}/`;
};

View File

@@ -58,7 +58,7 @@ function fillTable(table, results) {
const time = document.createElement('p');
var offset = new Date(r.time * 1000).getTimezoneOffset() * -60;
var d = new Date((r.time + offset) * 1000);
var formatted_date = d.toLocaleString('en-CA').slice(0,10) + ' ' + d.toTimeString().slice(0,5);
var formatted_date = d.toLocaleString(JSON.parse(localStorage.getItem('MIND')).locale);
if (r.repeat_interval !== null) {
if (r.repeat_interval === 1) {
var quantity = r.repeat_quantity.endsWith('s') ? r.repeat_quantity.slice(0, -1) : r.repeat_quantity;

View File

@@ -44,7 +44,9 @@ function login(data=null) {
return response.json();
})
.then(json => {
localStorage.setItem('MIND_api_key', json.result.api_key);
const new_stor = JSON.parse(localStorage.getItem('MIND'));
new_stor.api_key = json.result.api_key;
localStorage.setItem('MIND', JSON.stringify(new_stor));
window.location.href = `${url_prefix}/reminders`;
})
.catch(e => {
@@ -93,7 +95,7 @@ function create() {
};
function checkLogin() {
fetch(`${url_prefix}/api/auth/status?api_key=${localStorage.getItem('MIND_api_key')}`)
fetch(`${url_prefix}/api/auth/status?api_key=${JSON.parse(localStorage.getItem('MIND')).api_key}`)
.then(response => {
if (!response.ok) return Promise.reject(response.status);
window.location.href = '/reminders';

View File

@@ -1,3 +1,7 @@
function loadSettings() {
document.getElementById('locale-input').value = JSON.parse(localStorage.getItem('MIND')).locale;
};
function changePassword() {
const data = {
'new_password': document.getElementById('password-input').value
@@ -19,6 +23,13 @@ function changePassword() {
});
};
function updateLocale(e) {
const new_stor = JSON.parse(localStorage.getItem('MIND'));
new_stor.locale = e.target.value;
localStorage.setItem('MIND', JSON.stringify(new_stor));
window.location.reload();
};
function deleteAccount() {
fetch(`${url_prefix}/api/user?api_key=${api_key}`, {
'method': 'DELETE'
@@ -30,5 +41,8 @@ function deleteAccount() {
// code run on load
loadSettings();
document.getElementById('change-password-form').setAttribute('action', 'javascript:changePassword()');
document.getElementById('locale-input').addEventListener('change', updateLocale);
document.getElementById('delete-account-button').addEventListener('click', e => deleteAccount());

View File

@@ -269,6 +269,62 @@
<input type="password" id="password-input" autocomplete="new-password" required>
<button type="submit">Change</button>
</form>
<h3>Locale</h3>
<select id="locale-input">
<option value="ar-SA">ar-SA</option>
<option value="bn-BD">bn-BD</option>
<option value="bn-IN">bn-IN</option>
<option value="cs-CZ">cs-CZ</option>
<option value="da-DK">da-DK</option>
<option value="de-AT">de-AT</option>
<option value="de-CH">de-CH</option>
<option value="de-DE">de-DE</option>
<option value="el-GR">el-GR</option>
<option value="en-AU">en-AU</option>
<option value="en-CA">en-CA</option>
<option value="en-GB" selected>en-GB</option>
<option value="en-IE">en-IE</option>
<option value="en-IN">en-IN</option>
<option value="en-NZ">en-NZ</option>
<option value="en-US">en-US</option>
<option value="en-ZA">en-ZA</option>
<option value="es-AR">es-AR</option>
<option value="es-CL">es-CL</option>
<option value="es-CO">es-CO</option>
<option value="es-ES">es-ES</option>
<option value="es-MX">es-MX</option>
<option value="es-US">es-US</option>
<option value="fi-FI">fi-FI</option>
<option value="fr-BE">fr-BE</option>
<option value="fr-CA">fr-CA</option>
<option value="fr-CH">fr-CH</option>
<option value="fr-FR">fr-FR</option>
<option value="he-IL">he-IL</option>
<option value="hi-IN">hi-IN</option>
<option value="hu-HU">hu-HU</option>
<option value="id-ID">id-ID</option>
<option value="it-CH">it-CH</option>
<option value="it-IT">it-IT</option>
<option value="ja-JP">ja-JP</option>
<option value="ko-KR">ko-KR</option>
<option value="nl-BE">nl-BE</option>
<option value="nl-NL">nl-NL</option>
<option value="no-NO">no-NO</option>
<option value="pl-PL">pl-PL</option>
<option value="pt-BR">pt-BR</option>
<option value="pt-PT">pt-PT</option>
<option value="ro-RO">ro-RO</option>
<option value="ru-RU">ru-RU</option>
<option value="sk-SK">sk-SK</option>
<option value="sv-SE">sv-SE</option>
<option value="ta-IN">ta-IN</option>
<option value="ta-LK">ta-LK</option>
<option value="th-TH">th-TH</option>
<option value="tr-TR">tr-TR</option>
<option value="zh-CN">zh-CN</option>
<option value="zh-HK">zh-HK</option>
<option value="zh-TW">zh-TW</option>
</select>
<h3>Delete Account</h3>
<button id="delete-account-button">Delete Account</button>
</div>