working on editor for polls

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2026-02-15 10:59:19 +01:00
parent dbc4525e80
commit a25736eff3
9 changed files with 277 additions and 16 deletions

View File

@@ -14,6 +14,7 @@
import ContactList from "./routes/contact/Index.svelte";
import DocList from "./routes/document/List.svelte";
import EasyList from "./routes/task/EasyList.svelte";
import EditPoll from "./routes/poll/Edit.svelte";
import EditService from "./routes/user/EditService.svelte";
import EditUser from "./routes/user/EditUser.svelte";
import FileIndex from "./routes/files/Index.svelte";
@@ -25,6 +26,7 @@
import Menu from "./Components/Menu.svelte";
import NewPage from "./routes/wiki/AddPage.svelte";
import Notes from "./routes/notes/Index.svelte";
import PollList from "./routes/poll/Index.svelte";
import ProjectList from "./routes/project/List.svelte";
import ProjectAdd from "./routes/project/Create.svelte";
import ResetPw from "./routes/user/ResetPw.svelte";
@@ -95,6 +97,8 @@
<Route path="/message" component={Messages} />
<Route path="/message/settings" component={MsgSettings} />
<Route path="/notes" component={Notes} />
<Route path="/poll" component={PollList} />
<Route path="/poll/:id/edit" component={EditPoll} />
<Route path="/project" component={ProjectList} />
<Route path="/project/add" component={ProjectAdd} />
<Route path="/project/:project_id/add_task" component={AddTask} />

View File

@@ -0,0 +1,88 @@
<script>
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import LineEditor from '../../Components/LineEditor.svelte';
import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
import { api, get } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte';
import { user } from '../../user.svelte.js';
let { id } = $props();
let poll = $state(null);
async function load(){
let url = api('poll/'+id);
let res = await get(url);
if (res.ok){
poll = await res.json();
yikes();
} else error(res);
}
onMount(load);
</script>
<fieldset>
<legend>{t('edit poll',{id:id})}</legend>
{#if poll && poll.name}
<fieldset>
<legend>{t('name')}</legend>
<LineEditor bind:value={poll.name} editable={true} />
</fieldset>
<fieldset>
<legend>{t('description')}</legend>
<MarkdownEditor bind:value={poll.description} />
</fieldset>
<fieldset>
<legend>{t('options')}</legend>
<table>
<thead>
<tr>
<th>{t('name')}</th>
<th>{t('description')}</th>
</tr>
</thead>
<tbody>
{#each poll.options as option}
<tr>
<td>
<input type="text" value={option.name} />
</td>
<td>
<MarkdownEditor bind:value={option.description} />
</td>
</tr>
{/each}
</tbody>
</table>
</fieldset>
<fieldset>
<legend>{t('weights')}</legend>
<table>
<thead>
<tr>
<th>{t('weight')}</th>
<th>{t('description')}</th>
</tr>
</thead>
<tbody>
{#each Object.entries(poll.weights) as [weight,descr]}
<tr>
<td>
<input type="number" value={weight} />
</td>
<td>
<input type="text" value={descr} />
</td>
</tr>
{/each}
</tbody>
</table>
</fieldset>
{/if}
</fieldset>

View File

@@ -0,0 +1,66 @@
<script>
import { onMount } from 'svelte';
import { useTinyRouter } from 'svelte-tiny-router';
import { api, get } from '../../urls.svelte';
import { error, yikes } from '../../warn.svelte';
import { t } from '../../translations.svelte';
import { user } from '../../user.svelte.js';
let polls = [];
let router = useTinyRouter();
function edit(poll){
router.navigate(`/poll/${poll.id}/edit`);
}
function evaluate(poll){
router.navigate(`/poll/${poll.id}/evaluate`);
}
async function load(){
let url = api('poll/list');
let res = await get(url);
if (res.ok){
polls = await res.json();
yikes();
} else error(res);
}
function share(poll){
}
onMount(load);
</script>
<fieldset>
<legend>{t('polls')}</legend>
<table>
<thead>
<tr>
<th>{t('name')}</th>
<th>{t('description')}</th>
<th>{t('owner')}</th>
<th>{t('actions')}</th>
</tr>
</thead>
<tbody>
{#each polls as poll}
<tr>
<td>{poll.name}</td>
<td>{@html poll.description.rendered}</td>
<td>{poll.owner.name}</td>
<td>
{#if user.id == poll.owner.id || poll.shares[user.id].permission == 2}
<button onclick={e => edit(poll)}>{t('edit')}</button>
{/if}
{#if user.id == poll.owner.id || poll.shares[user.id].permission > 0}
<button onclick={e => evaluate(poll)}>{t('evaluate')}</button>
{/if}
<button onclick={e => share(poll)}>{t('share')}</button>
</td>
</tr>
{/each}
</tbody>
</table>
</fieldset>