code cleanup

This commit is contained in:
2025-07-30 09:03:47 +02:00
parent a77efb4e41
commit 631a527a5d
18 changed files with 257 additions and 184 deletions

View File

@@ -1,9 +1,11 @@
<script>
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
import { user } from '../../user.svelte.js';
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import {api} from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import { user } from '../../user.svelte.js';
import LineEditor from '../../Components/LineEditor.svelte';
import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
import MultilineEditor from '../../Components/MultilineEditor.svelte';
@@ -13,23 +15,22 @@
import StateSelector from './StateSelector.svelte';
import TemplateSelector from './TemplateSelector.svelte';
const router = useTinyRouter();
let { id } = $props();
let error = $state(null);
let doc = $state(null);
let pdfDisabled = $state(false);
let sndDisabled = $state(false);
let doc = $state(null);
let editable = $derived(doc.state == 1);
let error = $state(null);
let { id } = $props();
let pdfDisabled = $state(false);
let position_select = $state(false);
let editable = $derived(doc.state == 1);
const router = useTinyRouter();
let sndDisabled = $state(false);
async function loadDoc(){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${id}`;
const url = api(`document/${id}`;
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
doc = await resp.json();
doc = await resp.json();
error = null;
} else {
error = await resp.text();
@@ -45,8 +46,8 @@
doc.state = newVal;
} else {
const dummy = doc.state;
doc.state = null; // we need to alter in between,
doc.state = dummy; // otherwise the state will not be re-set
doc.state = null; // we need to alter in between,
doc.state = dummy; // otherwise the state will not be re-set
}
}
@@ -55,16 +56,16 @@
if (parts.length<1) return false;
let data = newValue;
while (parts.length > 0){
const inner = data;
data = {};
const inner = data;
data = {};
data[parts.pop()] = inner;
}
try {
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${doc.id}`;
const url = api(`document/${doc.id}`;
const resp = await fetch(url,{
credentials:'include',
method:'PATCH',
body:JSON.stringify(data)
credentials : 'include',
method : 'PATCH',
body : JSON.stringify(data)
});
return resp.ok;
} catch (err){
@@ -73,15 +74,15 @@
}
async function addPosition(selected){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${doc.id}/position`;
const url = api(`document/${doc.id}/position`;
const resp = await fetch(url,{
method: 'POST',
credentials:'include',
body:JSON.stringify(selected)
method : 'POST',
credentials : 'include',
body : JSON.stringify(selected)
});
if (resp.ok){
doc.positions = await resp.json();
error = null;
error = null;
} else {
error = await resp.text();
}
@@ -90,15 +91,15 @@
async function render(ev){
pdfDisabled = true;
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${doc.id}/pdf`;
const resp = await fetch(url,{credentials:'include'});
const url = api(`document/${doc.id}/pdf`;
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
error = null;
const blob = await resp.blob();
const parts = resp.headers.get("Content-disposition").split(";");
const filename = parts[1].split('=')[1].split('"').join('');
var fileLink = document.createElement('a');
fileLink.href = URL.createObjectURL(blob);
error = null;
const blob = await resp.blob();
const parts = resp.headers.get("Content-disposition").split(";");
const filename = parts[1].split('=')[1].split('"').join('');
var fileLink = document.createElement('a');
fileLink.href = URL.createObjectURL(blob);
fileLink.download = filename;
fileLink.click();
} else {