6 changed files with 127 additions and 6 deletions
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
<script> |
||||
import { onMount } from 'svelte'; |
||||
import { t } from '../../translations.svelte.js'; |
||||
import { useTinyRouter } from 'svelte-tiny-router'; |
||||
|
||||
let { serviceName } = $props(); |
||||
let service = $state({}) |
||||
let caption = $state(t('user.save_service')); |
||||
let message = $state(t('user.loading_data')); |
||||
let router = useTinyRouter(); |
||||
let disabled = $state(false); |
||||
|
||||
onMount(async () => { |
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/service/${serviceName}`; |
||||
const resp = await fetch(url,{credentials:'include'}); |
||||
if (resp.ok){ |
||||
const json = await resp.json(); |
||||
for (let key of Object.keys(json)) service[key] = json[key]; |
||||
} else { |
||||
message = await resp.text(); |
||||
if (!message) message = t(resp); |
||||
} |
||||
}); |
||||
|
||||
async function update(){ |
||||
caption = t('user.data_sent'); |
||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/service/${serviceName}`; |
||||
const resp = await fetch(url,{ |
||||
credentials: 'include', |
||||
method: 'PATCH', |
||||
body: JSON.stringify(service) |
||||
}); |
||||
if (resp.ok){ |
||||
caption = t('user.saved'); |
||||
router.navigate('/user'); |
||||
} else { |
||||
caption = await resp.text(); |
||||
if (!caption) caption = t(resp); |
||||
} |
||||
} |
||||
</script> |
||||
|
||||
<fieldset> |
||||
<legend>{t('user.edit_service',serviceName)}</legend> |
||||
{#if service.name} |
||||
<table> |
||||
<tbody> |
||||
<tr> |
||||
<th>{t('user.name')}</th> |
||||
<td> |
||||
<input type="text" bind:value={service.name} /> |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<th>{t('user.client_id')}</th> |
||||
<td> |
||||
<input type="text" bind:value={service.client_id} /> |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<th>{t('user.client_secret')}</th> |
||||
<td> |
||||
<input type="text" bind:value={service.client_secret} /> |
||||
</td> |
||||
</tr> |
||||
<tr> |
||||
<th>{t('user.base_url')}</th> |
||||
<td> |
||||
<input type="text" bind:value={service.url} /> |
||||
</td> |
||||
</tr> |
||||
</tbody> |
||||
</table> |
||||
<button onclick={update} {disabled}>{caption}</button> |
||||
<button onclick={() => router.navigate('/user')} {disabled}>{t('user.abort')}</button> |
||||
{:else} |
||||
{message} |
||||
{/if} |
||||
</fieldset> |
||||
Loading…
Reference in new issue