Browse Source

code cleanup

code-review
Stephan Richter 3 months ago
parent
commit
fccec9865a
  1. 4
      frontend/src/App.svelte
  2. 3
      frontend/src/Components/Menu.svelte
  3. 4
      frontend/src/routes/document/List.svelte
  4. 8
      frontend/src/routes/document/PositionList.svelte
  5. 2
      frontend/src/routes/document/TimeList.svelte
  6. 8
      frontend/src/routes/document/View.svelte
  7. 9
      frontend/src/routes/notes/List.svelte
  8. 7
      frontend/src/routes/project/Create.svelte
  9. 5
      frontend/src/routes/project/Kanban.svelte
  10. 4
      frontend/src/routes/project/List.svelte
  11. 8
      frontend/src/routes/project/View.svelte
  12. 3
      frontend/src/routes/search/Search.svelte
  13. 6
      frontend/src/routes/task/Add.svelte
  14. 8
      frontend/src/routes/task/ListTask.svelte
  15. 14
      frontend/src/routes/task/View.svelte
  16. 11
      frontend/src/routes/user/ConnectedServices.svelte
  17. 15
      frontend/src/routes/user/EditPassword.svelte
  18. 14
      frontend/src/routes/user/EditService.svelte
  19. 19
      frontend/src/routes/user/EditUser.svelte
  20. 14
      frontend/src/routes/user/List.svelte
  21. 33
      frontend/src/routes/user/LoginServices.svelte
  22. 14
      frontend/src/routes/user/OidcCallback.svelte
  23. 7
      frontend/src/routes/user/Profile.svelte
  24. 10
      frontend/src/routes/user/ResetPw.svelte
  25. 6
      frontend/src/routes/user/User.svelte

4
frontend/src/App.svelte

@ -1,8 +1,10 @@ @@ -1,8 +1,10 @@
<script>
import { onMount } from 'svelte';
import { Router, Route } from 'svelte-tiny-router';
import { loadTranslation } from './translations.svelte.js';
import { user } from './user.svelte.js';
import { Router, Route } from 'svelte-tiny-router';
import AddDoc from "./routes/document/Add.svelte";
import AddTask from "./routes/task/Add.svelte";
import Callback from "./routes/user/OidcCallback.svelte";

3
frontend/src/Components/Menu.svelte

@ -2,7 +2,6 @@ @@ -2,7 +2,6 @@
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../urls.svelte.js';
import { logout, user } from '../user.svelte.js';
import { t } from '../translations.svelte.js';
@ -10,7 +9,7 @@ const router = useTinyRouter(); @@ -10,7 +9,7 @@ const router = useTinyRouter();
const modules = $state([]);
async function fetchModules(){
const url = api('/legacy/modules');
const url = `${location.protocol}//${location.host.replace('5173','8080')}/legacy/modules`;
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
const arr = await resp.json();

4
frontend/src/routes/document/List.svelte

@ -11,9 +11,9 @@ @@ -11,9 +11,9 @@
let error = null;
let companies = {};
let router = useTinyRouter();
let company_id = +router.query.company_id;
let documents = null;
let router = useTinyRouter();
let docType = 0;
let selected_company = null;
@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
async function deleteDoc(ev,doc){
if (confirm(t('really_delete',doc.number))){
const url = api(`document/${doc.id}`;
const url = api(`document/${doc.id}`);
const resp = await fetch(url,{
credentials: 'include',
method: 'DELETE'

8
frontend/src/routes/document/PositionList.svelte

@ -2,14 +2,14 @@ @@ -2,14 +2,14 @@
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte-js';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import Position from './Position.svelte';
var {
document = $bindable(null),
error = $bindable(null)
error = $bindable(null),
submit = (key,newVal) => {},
} = $props();
@ -23,7 +23,7 @@ @@ -23,7 +23,7 @@
}
async function movePos(number,step){
const url = api(`document/${document.id}/position`;
const url = api(`document/${document.id}/position`);
const resp = await fetch(url,{
method : 'PATCH',
credentials: 'include',
@ -39,7 +39,7 @@ @@ -39,7 +39,7 @@
async function drop(number){
let confirmed = confirm(t('confirm_deletion').replace('{pos}',document.positions[number].item));
if (!confirmed) return;
const url = api(`document/${document.id}/position`;
const url = api(`document/${document.id}/position`);
const resp = await fetch(url,{
method : 'DELETE',
credentials: 'include',

2
frontend/src/routes/document/TimeList.svelte

@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
let times = $state(null);
async function loadProjects(){
const url = api'project/list');
const url = api('project/list');
let data = { company_id: company_id };
const resp = await fetch(url,{
credentials : 'include',

8
frontend/src/routes/document/View.svelte

@ -27,7 +27,7 @@ @@ -27,7 +27,7 @@
async function loadDoc(){
const url = api(`document/${id}`;
const url = api(`document/${id}`);
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
doc = await resp.json();
@ -61,7 +61,7 @@ @@ -61,7 +61,7 @@
data[parts.pop()] = inner;
}
try {
const url = api(`document/${doc.id}`;
const url = api(`document/${doc.id}`);
const resp = await fetch(url,{
credentials : 'include',
method : 'PATCH',
@ -74,7 +74,7 @@ @@ -74,7 +74,7 @@
}
async function addPosition(selected){
const url = api(`document/${doc.id}/position`;
const url = api(`document/${doc.id}/position`);
const resp = await fetch(url,{
method : 'POST',
credentials : 'include',
@ -91,7 +91,7 @@ @@ -91,7 +91,7 @@
async function render(ev){
pdfDisabled = true;
const url = api(`document/${doc.id}/pdf`;
const url = api(`document/${doc.id}/pdf`);
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
error = null;

9
frontend/src/routes/notes/List.svelte

@ -1,15 +1,20 @@ @@ -1,15 +1,20 @@
<script>
import { onMount } from 'svelte';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import { user } from '../../user.svelte.js';
import Editor from '../../Components/MarkdownEditor.svelte';
let authors = $state(null);
let error = $state(null);
let { module = null, entity_id = null } = $props();
let note = $state({source:null,rendered:null});
let notes = $state(null);
let authors = $state(null);
let {
module = null,
entity_id = null
} = $props();
async function saveNote(){
const url = api(`notes/${module}/${entity_id}`);

7
frontend/src/routes/project/Create.svelte

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
<script>
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import CompanySelector from '../../Components/CompanySelector.svelte';
@ -16,15 +17,13 @@ @@ -16,15 +17,13 @@
let project = $state({
name : '',
description : { source : '', rendered : '' },
settings:{
show_closed:false
},
settings : { show_closed:false },
tags : []
});
async function onsubmit(ev){
ev.preventDefault();
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/project`;
const url = api('project');
var resp = await fetch(url,{
credentials : 'include',
method : 'POST',

5
frontend/src/routes/project/Kanban.svelte

@ -14,15 +14,14 @@ @@ -14,15 +14,14 @@
let dragged = null;
let error = $state(null);
let highlight = $state({});
let filter_input = $state('');
let filter = $derived(filter_input.toLowerCase());
let project = $state(null);
let ready = $state(false);
let router = useTinyRouter();
let states = $state(null);
let tasks = $state({});
let filter_input = $state('');
let filter = $derived(filter_input.toLowerCase());
let users = {};
let columns = $derived(states?Object.keys(states).length+1:1);
async function create(name,user_id,state){

4
frontend/src/routes/project/List.svelte

@ -1,9 +1,9 @@ @@ -1,9 +1,9 @@
<script>
import { useTinyRouter } from 'svelte-tiny-router';
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { t } from '../../translations.svelte.js';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
const router = useTinyRouter();
let error = $state(null);

8
frontend/src/routes/project/View.svelte

@ -13,13 +13,13 @@ @@ -13,13 +13,13 @@
import Tags from '../tags/TagList.svelte';
import TaskList from '../task/TaskList.svelte';
let router = useTinyRouter();
let { id } = $props();
let project = $state(null);
let error = $state(null);
let tasks = $state(null);
let estimated_time = $state({sum:0});
let project = $state(null);
let router = useTinyRouter();
let showSettings = $state(false);
let tasks = $state(null);
async function addMember(entry){
const ids = Object.keys(entry);
@ -41,7 +41,7 @@ @@ -41,7 +41,7 @@
async function getCandidates(text){
const url = api('user/search');
var resp = await fetch(url,{
const resp = await fetch(url,{
credentials : 'include',
method : 'POST',
body : text

3
frontend/src/routes/search/Search.svelte

@ -1,10 +1,11 @@ @@ -1,10 +1,11 @@
<script>
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
let key = "";
let fulltext = false;
let html = "";
let key = "";
async function doSearch(ev){
if (ev) ev.preventDefault();

6
frontend/src/routes/task/Add.svelte

@ -2,8 +2,8 @@ @@ -2,8 +2,8 @@
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { t } from '../../translations.svelte.js';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import { user } from '../../user.svelte.js';
import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
@ -58,7 +58,7 @@ @@ -58,7 +58,7 @@
}
async function loadProject(){
var url = api(`project/${project_id}`);
const url = api(`project/${project_id}`);
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
project = await resp.json();
@ -98,7 +98,7 @@ @@ -98,7 +98,7 @@
}
async function saveTask(){
var url = api('task/add');
const url = api('task/add');
const resp = await fetch(url,{
credentials : 'include',
method : 'POST',

8
frontend/src/routes/task/ListTask.svelte

@ -2,18 +2,18 @@ @@ -2,18 +2,18 @@
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { t } from '../../translations.svelte.js';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import TaskList from './TaskList.svelte';
import LineEditor from '../../Components/LineEditor.svelte';
const router = useTinyRouter();
let { estimated_time, show_closed, task } = $props();
let children = $state(null);
let deleted = $state(false);
let error = $state(null);
const router = useTinyRouter();
let start = 0;
let deleted = $state(false);
function addSubtask(){
router.navigate(`/task/${task.id}/add_subtask`);
@ -36,7 +36,7 @@ @@ -36,7 +36,7 @@
async function loadChildren(){
const url = api('task/list');
var data = {
const data = {
parent_task_id : +task.id,
show_closed : show_closed
};

14
frontend/src/routes/task/View.svelte

@ -2,8 +2,8 @@ @@ -2,8 +2,8 @@
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { t } from '../../translations.svelte.js';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import LineEditor from '../../Components/LineEditor.svelte';
import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
@ -13,15 +13,15 @@ @@ -13,15 +13,15 @@
import TagList from '../tags/TagList.svelte';
import TaskList from './TaskList.svelte';
const router = useTinyRouter();
let { id } = $props();
let task = $state(null);
let project = $state(null);
let error = $state(null);
let children = $state(null);
let estimated_time = $state({sum:0});
let dummy = $derived(updateOn(id));
let error = $state(null);
let estimated_time = $state({sum:0});
let project = $state(null);
const router = useTinyRouter();
let showSettings = $state(false);
let task = $state(null);
$effect(() => updateOn(id));
@ -53,7 +53,7 @@ @@ -53,7 +53,7 @@
async function loadChildren(){
const url = api('task/list');
var data = {
const data = {
parent_task_id : +task.id,
show_closed : task.show_closed
};

11
frontend/src/routes/user/ConnectedServices.svelte

@ -1,14 +1,15 @@ @@ -1,14 +1,15 @@
<script>
import { onMount } from 'svelte';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import { user } from '../../user.svelte.js';
import { onMount } from 'svelte';
let connections = $state([]);
async function loadConnections(){
let url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/connected`;
let resp = await fetch(url,{credentials:'include'});
const url = api('/user/oidc/connected');
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
const arr = await resp.json();
while (connections.length) connections.pop();
@ -19,7 +20,7 @@ @@ -19,7 +20,7 @@
onMount(loadConnections);
async function unlink(connection){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/connected`;
const url = api('user/oidc/connected');
const resp = await fetch(url,{
method : 'DELETE',
credentials : 'include',

15
frontend/src/routes/user/EditPassword.svelte

@ -1,18 +1,17 @@ @@ -1,18 +1,17 @@
<script>
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
let { editPassword = $bindable() } = $props();
let oldPass = $state("");
let newPass = $state("");
let repeat = $state("");
let caption = $state(t('update'));
let oldEmpty = $derived(!/\S/.test(oldPass));
let newEmpty = $derived(!/\S/.test(newPass));
let mismatch = $derived(newPass != repeat);
let error = $state("");
let newPass = $state("");
let mismatch = $derived(newPass != repeat);
let newEmpty = $derived(!/\S/.test(newPass));
let oldPass = $state("");
let oldEmpty = $derived(!/\S/.test(oldPass));
let repeat = $state("");
let sent = $state(false);
function abort(){

14
frontend/src/routes/user/EditService.svelte

@ -1,17 +1,19 @@ @@ -1,17 +1,19 @@
<script>
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
import { useTinyRouter } from 'svelte-tiny-router';
let { serviceName } = $props();
let service = $state({})
import { api } from '../../urls.svelte.js'
import { t } from '../../translations.svelte.js';
let caption = $state(t('save_service'));
let disabled = $state(false);
let service = $state({})
let { serviceName } = $props();
let message = $state(t('loading_data'));
let router = useTinyRouter();
let disabled = $state(false);
onMount(async () => {
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/${serviceName}`;
const url = api(`user/oidc/${serviceName}`);
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
const json = await resp.json();
@ -24,7 +26,7 @@ @@ -24,7 +26,7 @@
async function update(){
caption = t('data_sent');
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/${serviceName}`;
const url = api(`user/oidc/${serviceName}`);
const resp = await fetch(url,{
credentials : 'include',
method : 'PATCH',

19
frontend/src/routes/user/EditUser.svelte

@ -1,19 +1,18 @@ @@ -1,19 +1,18 @@
<script>
import { t } from '../../translations.svelte.js';
import { useTinyRouter } from 'svelte-tiny-router';
import { onMount } from 'svelte';
import { checkUser } from '../../user.svelte.js';
const router = useTinyRouter();
import { api } from '../../urls.svelte.js'
import { checkUser } from '../../user.svelte.js';
import { t } from '../../translations.svelte.js';
let { user_id } = $props();
let caption = $state(t('save_user'));
let editUser = $state(null);
let message = $state(t('loading_data'));
let options = $state([]);
const router = useTinyRouter();
let sent = $state(false);
let caption = $state(t('save_user'));
let message = $state(t('loading_data'));
onMount(async () => {
let url = `${location.protocol}//${location.host.replace('5173','8080')}/themes.json`;
@ -28,7 +27,7 @@ @@ -28,7 +27,7 @@
}
if (user_id) {
url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/${user_id}`;
url = api(`user/${user_id}`);
resp = await fetch(url,{credentials:'include'});
if (resp.ok) {
editUser = await resp.json();
@ -48,9 +47,9 @@ @@ -48,9 +47,9 @@
let method = 'PATCH';
let url = null;
if (user_id) {
url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/${user_id}`;
url = api(`user/${user_id}`);
} else {
url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/create`;
url = api('user/create');
method = 'POST';
}
let resp = await fetch(url,{

14
frontend/src/routes/user/List.svelte

@ -1,24 +1,25 @@ @@ -1,24 +1,25 @@
<script>
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import { user } from '../../user.svelte.js';
const router = useTinyRouter();
let users = $state([]);
onMount(async () => {
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/list`;
async function listUsers(){
const url = api('user/list');
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
const json = await resp.json();
for (let u of json) users.push(u);
}
});
}
async function impersonate(userId){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/${userId}/impersonate`;
const url = api(`user/${userId}/impersonate`);
const resp = await fetch(url,{
method : 'POST',
credentials : 'include'
@ -29,6 +30,7 @@ @@ -29,6 +30,7 @@
}
}
onMount(listUsers);
</script>
<fieldset tabindex="0">

33
frontend/src/routes/user/LoginServices.svelte

@ -1,27 +1,16 @@ @@ -1,27 +1,16 @@
<script>
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import { user } from '../../user.svelte.js';
const router = useTinyRouter();
let services = $state([]);
async function loadButtons(){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/buttons`;
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
const json = await resp.json();
while (services.length) services.pop();
for (let service of json) services.push(service);
}
}
onMount(loadButtons);
async function connect(service){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/redirect/${service}`;
const url = api(`user/oidc/redirect/${service}`);
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
var json = await resp.json();
@ -33,14 +22,26 @@ @@ -33,14 +22,26 @@
}
}
async function loadButtons(){
const url = api(`user/oidc/buttons`);
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
const json = await resp.json();
while (services.length) services.pop();
for (let service of json) services.push(service);
}
}
async function drop(service){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/${service}`;
const url = api(`user/oidc/${service}`);
const resp = await fetch(url,{
credentials : 'include',
method : 'DELETE'
});
if (resp.ok) loadButtons();
}
onMount(loadButtons);
</script>
<fieldset tabindex="0">

14
frontend/src/routes/user/OidcCallback.svelte

@ -1,17 +1,19 @@ @@ -1,17 +1,19 @@
<script>
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
import { useTinyRouter } from 'svelte-tiny-router';
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
import { checkUser } from '../../user.svelte.js';
const router = useTinyRouter();
let message = $state(t('processing_code'));
onMount(async () => {
async function process(){
let params = new URLSearchParams(location.search);
if (params.get('code')){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/oidc/token`;
const url = api('user/oidc/token');
const resp = await fetch(url,{
method : 'POST',
body : JSON.stringify(Object.fromEntries(params)),
@ -27,7 +29,9 @@ @@ -27,7 +29,9 @@
if (!message) message = t(resp);
}
}
});
}
onMount(process);
</script>
{message}

7
frontend/src/routes/user/Profile.svelte

@ -1,14 +1,15 @@ @@ -1,14 +1,15 @@
<script>
import { useTinyRouter } from 'svelte-tiny-router';
import { t } from '../../translations.svelte.js';
import { user } from '../../user.svelte.js';
import { useTinyRouter } from 'svelte-tiny-router';
import EditPassword from './EditPassword.svelte';
const router = useTinyRouter();
const router = useTinyRouter();
let editPassword = false;
</script>
<fieldset>
<legend>
{t('your_profile')}

10
frontend/src/routes/user/ResetPw.svelte

@ -1,16 +1,18 @@ @@ -1,16 +1,18 @@
<script>
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
import { useTinyRouter } from 'svelte-tiny-router';
let mail = "";
import { api } from '../../urls.svelte.js';
import { t } from '../../translations.svelte.js';
let caption = t('send_mail');
let error = null;
let mail = "";
const router = useTinyRouter();
async function submit(ev){
ev.preventDefault();
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/reset_pw`;
const url = api(`user/reset_pw`);
const resp = await fetch(url,{
method : 'POST',
body : mail
@ -26,7 +28,7 @@ @@ -26,7 +28,7 @@
const urlParams = new URLSearchParams(window.location.search);
const token = urlParams.get('token');
if (token) {
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/user/validate/${token}`;
const url = api(`user/validate/${token}`);
const resp = await fetch(url,{
credentials: 'include'
});

6
frontend/src/routes/user/User.svelte

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
<script>
import { t } from '../../translations.svelte.js';
import { user } from '../../user.svelte.js';
import { t } from '../../translations.svelte.js';
import Services from './ConnectedServices.svelte';
import LoginServiceList from './LoginServices.svelte';
@ -9,9 +9,7 @@ @@ -9,9 +9,7 @@
let params = new URLSearchParams(location.search);
let redirect = params.get('returnTo');
if (redirect && user.name){
location.href = redirect;
}
if (redirect && user.name) location.href = redirect;
</script>
<h1>{t('user_module')}</h1>

Loading…
Cancel
Save