Compare commits
4
Commits
9d5af9a0fb
..
0.7.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c711e0ae24 | ||
|
|
74fd96cf25 | ||
|
|
9686a8505e | ||
|
|
bc83fc8dd1 |
@@ -3,10 +3,112 @@
|
|||||||
let title = "Bearbeitung Einträge"
|
let title = "Bearbeitung Einträge"
|
||||||
import IconifyIcon from '@iconify/svelte';
|
import IconifyIcon from '@iconify/svelte';
|
||||||
import wrenchIcon from '@iconify-icons/oi/wrench';
|
import wrenchIcon from '@iconify-icons/oi/wrench';
|
||||||
import trashIcon from '@iconify-icons/oi/trash';
|
|
||||||
import checkIcon from '@iconify-icons/oi/check';
|
import checkIcon from '@iconify-icons/oi/check';
|
||||||
import xIcon from '@iconify-icons/oi/x';
|
import xIcon from '@iconify-icons/oi/x';
|
||||||
|
import documentIcon from '@iconify-icons/oi/document';
|
||||||
let activeRecord = null;
|
let activeRecord = null;
|
||||||
|
let newRecord = false;
|
||||||
|
params = {
|
||||||
|
title: 'Einträge',
|
||||||
|
records: [],
|
||||||
|
isLoading: true
|
||||||
|
}
|
||||||
|
const Records = {
|
||||||
|
'browse': () => {
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
|
fetch(env.API_URL + '/working-hours')
|
||||||
|
.then(res => {
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error('Fail!');
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
activeRecord = null;
|
||||||
|
params.records = data;
|
||||||
|
params.isLoading = false;
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
params.isLoading = false;
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
'read': date => {
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
|
fetch(env.API_URL + '/working-hours/' + date)
|
||||||
|
.then(res => {
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error('Fail!');
|
||||||
|
}
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
activeRecord = data;
|
||||||
|
if (date === null) {
|
||||||
|
Records.browse();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
'add': record => {
|
||||||
|
console.log(record);
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
|
fetch(env.API_URL + '/working-hours', {
|
||||||
|
method: 'POST',
|
||||||
|
mode: 'no-cors',
|
||||||
|
cache: 'no-cache',
|
||||||
|
credentials: 'same-origin',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
redirect: 'follow',
|
||||||
|
referrerPolicy: 'no-referrer',
|
||||||
|
body: JSON.stringify(record)
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error('Fail!');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
newRecord = false;
|
||||||
|
Records.browse();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
'update': (date, record) => {
|
||||||
|
console.log(record);
|
||||||
|
// noinspection JSUnresolvedVariable
|
||||||
|
fetch(env.API_URL + '/working-hours/' + date, {
|
||||||
|
method: 'PUT',
|
||||||
|
mode: 'no-cors',
|
||||||
|
cache: 'no-cache',
|
||||||
|
credentials: 'same-origin',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
redirect: 'follow',
|
||||||
|
referrerPolicy: 'no-referrer',
|
||||||
|
body: JSON.stringify(record)
|
||||||
|
})
|
||||||
|
.then(res => {
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error('Fail!');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
Records.browse();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Records.browse();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -19,6 +121,17 @@
|
|||||||
<h1>{title}</h1>
|
<h1>{title}</h1>
|
||||||
</header>
|
</header>
|
||||||
<article>
|
<article>
|
||||||
|
{#if params.isLoading === true}
|
||||||
|
<p>Loading...</p>
|
||||||
|
{:else}
|
||||||
|
<!--suppress HtmlUnknownTarget -->
|
||||||
|
<form action="/working-hours">
|
||||||
|
<fieldset>
|
||||||
|
<button on:click={() => {activeRecord = {}; newRecord = true}}>Neuer Eintrag
|
||||||
|
<IconifyIcon icon={documentIcon}/>
|
||||||
|
</button>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@@ -33,13 +146,15 @@
|
|||||||
<td>{record.workingDay}</td>
|
<td>{record.workingDay}</td>
|
||||||
<td>{record.workingTime}</td>
|
<td>{record.workingTime}</td>
|
||||||
<td>
|
<td>
|
||||||
<button>Bearbeiten <IconifyIcon icon={wrenchIcon} /></button>
|
<button on:click={() => Records.read(record.workingDay)}>Bearbeiten
|
||||||
<button>Löschen <IconifyIcon icon={trashIcon} color="red" /></button>
|
<IconifyIcon icon={wrenchIcon}/>
|
||||||
|
</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
{/if}
|
||||||
</article>
|
</article>
|
||||||
</section>
|
</section>
|
||||||
{:else}
|
{:else}
|
||||||
@@ -53,18 +168,28 @@
|
|||||||
<fieldset name="record-data">
|
<fieldset name="record-data">
|
||||||
<div>
|
<div>
|
||||||
<label for="workingDay">Arbeitstag</label>
|
<label for="workingDay">Arbeitstag</label>
|
||||||
<!--suppress JSUnresolvedVariable -->
|
<input bind:value={activeRecord.workingDay} placeholder="Arbeitstag" type="date"
|
||||||
<input bind:value={activeRecord.workingDay} placeholder="Arbeitstag" type="date" id="workingDay">
|
id="workingDay">
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="workingTime">Arbeitszeit</label>
|
<label for="workingTime">Arbeitszeit</label>
|
||||||
<!--suppress JSUnresolvedVariable -->
|
<input bind:value={activeRecord.workingTime} placeholder="Arbeitszeit" type="time"
|
||||||
<input bind:value={activeRecord.workingTime} placeholder="Arbeitszeit" type="time" id="workingTime">
|
id="workingTime">
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset name="buttons">
|
<fieldset name="buttons">
|
||||||
<button>Übernehmen <IconifyIcon icon={checkIcon} color="green" /></button>
|
{#if newRecord === true}
|
||||||
<button>Abbrechen <IconifyIcon icon={xIcon} /></button>
|
<button on:click={() => Records.add(activeRecord)}>Übernehmen
|
||||||
|
<IconifyIcon icon={checkIcon} color="green"/>
|
||||||
|
</button>
|
||||||
|
{:else}
|
||||||
|
<button on:click={() => Records.update(activeRecord.workingDay, activeRecord)}>Übernehmen
|
||||||
|
<IconifyIcon icon={checkIcon} color="green"/>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
<button on:click={() => Records.read(null)}>Abbrechen
|
||||||
|
<IconifyIcon icon={xIcon}/>
|
||||||
|
</button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
</article>
|
</article>
|
||||||
|
|||||||
Reference in New Issue
Block a user