implemented storing selectedweights for logged-in user
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
import Times from "./routes/time/Index.svelte";
|
||||
import User from "./routes/user/User.svelte";
|
||||
import ViewDoc from "./routes/document/View.svelte";
|
||||
import ViewPoll from "./routes/poll/View.svelte";
|
||||
import ViewPrj from "./routes/project/View.svelte";
|
||||
import ViewTask from "./routes/task/View.svelte";
|
||||
import WikiIndex from "./routes/wiki/Index.svelte";
|
||||
@@ -101,6 +102,7 @@
|
||||
<Route path="/poll" component={PollList} />
|
||||
<Route path="/poll/:id/edit" component={EditPoll} />
|
||||
<Route path="/poll/:id/evaluate" component={EvalPoll} />
|
||||
<Route path="/poll/:id/view" component={ViewPoll} />
|
||||
<Route path="/project" component={ProjectList} />
|
||||
<Route path="/project/add" component={ProjectAdd} />
|
||||
<Route path="/project/:project_id/add_task" component={AddTask} />
|
||||
|
||||
@@ -40,7 +40,12 @@
|
||||
} else error(res);
|
||||
}
|
||||
|
||||
function open(poll){
|
||||
router.navigate(`/poll/${poll.id}/view`);
|
||||
}
|
||||
|
||||
function share(poll){
|
||||
|
||||
}
|
||||
|
||||
onMount(load);
|
||||
@@ -61,9 +66,9 @@
|
||||
<tbody>
|
||||
{#each polls as poll}
|
||||
<tr>
|
||||
<td>{poll.name}</td>
|
||||
<td onclick={e => open(poll)}>{poll.name}</td>
|
||||
<td>{@html poll.description.rendered}</td>
|
||||
<td>{poll.owner.name}</td>
|
||||
<td onclick={e => open(poll)}>{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>
|
||||
|
||||
103
frontend/src/routes/poll/View.svelte
Normal file
103
frontend/src/routes/poll/View.svelte
Normal file
@@ -0,0 +1,103 @@
|
||||
<script>
|
||||
import { onMount } from 'svelte';
|
||||
import { api, get, post } from '../../urls.svelte';
|
||||
import { error, yikes } from '../../warn.svelte';
|
||||
import { user } from '../../user.svelte';
|
||||
|
||||
let { id } = $props();
|
||||
import { t } from '../../translations.svelte';
|
||||
let poll = $state(null);
|
||||
let selection = $state({});
|
||||
let editor = user ? { name: user.name, user_id : user.id } : { name : '', user_id : -1 };
|
||||
|
||||
async function load(){
|
||||
let url = api('poll/'+id);
|
||||
let res = await get(url);
|
||||
if (res.ok){
|
||||
poll = await res.json();
|
||||
yikes();
|
||||
} else error(res);
|
||||
}
|
||||
|
||||
async function save(ev){
|
||||
console.log({ev,editor,selection});
|
||||
let url = api(`poll/${id}/select`);
|
||||
let res = await post(url,{editor,selection});
|
||||
if (res.ok) {
|
||||
yikes();
|
||||
} else error(res);
|
||||
}
|
||||
|
||||
function select(option,weight){
|
||||
selection[option.id] = +weight;
|
||||
}
|
||||
|
||||
onMount(load);
|
||||
</script>
|
||||
|
||||
<style>
|
||||
table td:nth-child(n+2) {
|
||||
text-align: center;
|
||||
}
|
||||
.radio {
|
||||
vertical-align: middle;
|
||||
}
|
||||
</style>
|
||||
|
||||
<fieldset>
|
||||
<legend>{t('User')}</legend>
|
||||
{#if user}
|
||||
<div>{t('logged in as: {user}',{user:user.name})}</div>
|
||||
{:else}
|
||||
<label>
|
||||
<input type="text" bind:value={editor.name} />
|
||||
{t('Your name')}
|
||||
</label>
|
||||
{/if}
|
||||
</fieldset>
|
||||
{#if poll}
|
||||
<fieldset>
|
||||
<legend>{t('poll')}: {poll.name}</legend>
|
||||
<div class="description">
|
||||
{@html poll.description.rendered}
|
||||
</div>
|
||||
<table class="poll">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>{t('option')}</td>
|
||||
{#each Object.entries(poll.weights) as [weight,name]}
|
||||
<td class="weight">
|
||||
{weight}
|
||||
<span class="description">
|
||||
{name}
|
||||
</span>
|
||||
</td>
|
||||
{/each}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{#each poll.options as option}
|
||||
<tr>
|
||||
<td class="option">
|
||||
{option.name}
|
||||
<span class="description">
|
||||
{@html option.description.rendered}
|
||||
</span>
|
||||
</td>
|
||||
{#each Object.entries(poll.weights) as [weight,name]}
|
||||
<td class="radio" onclick={e => select(option,weight)} title={t('click to select')} >
|
||||
{#if selection[option.id] == weight}
|
||||
X
|
||||
{/if}
|
||||
</td>
|
||||
{/each}
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
{#if Object.keys(selection).length}
|
||||
<button onclick={save}>{t('save')}</button>
|
||||
{/if}
|
||||
</fieldset>
|
||||
<div class="warn">TODO: add notes</div>
|
||||
{/if}
|
||||
Reference in New Issue
Block a user