Merge branch 'master' into feature-ui/eintrag-per-woche

# Conflicts:
#	ui/src/components/Repositories.svelte
#	ui/src/routes/WorkingHours.svelte
This commit is contained in:
2022-01-10 15:56:56 +01:00
11 changed files with 712 additions and 244 deletions
+3 -23
View File
@@ -1,31 +1,11 @@
<script>
import Views from "./Views.svelte";
export let params;
import {WorkingHoursViewsRepository} from "../components/Repositories.svelte";
export let params
params = {
title: 'Monatsansicht',
records: [],
isLoading: true
promise: WorkingHoursViewsRepository.monthly()
}
const View = {
'browse': () => {
fetch(env.API_URL + '/views/working-hours/monthly')
.then(res => {
if (!res.ok) {
throw new Error('Fail!');
}
return res.json();
})
.then(data => {
params.records = data;
params.isLoading = false;
})
.catch(err => {
params.isLoading = false;
console.log(err);
});
}
};
View.browse();
</script>
<Views {params} />
+11 -3
View File
@@ -1,5 +1,7 @@
<script>
export let params;
export let params = {};
let records = []
let isLoading = true
console.log(params)
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position) {
@@ -9,6 +11,12 @@
}
$: isNegative = time => time.startsWith('-') ? 'absence-time' : '';
$: cutMinusChar = time => time.startsWith('-') ? time.substr(1) : time;
const init = async () => await params.promise.then(data => {
records = data
isLoading = false
})
init()
</script>
<svelte:head>
@@ -20,7 +28,7 @@
<h1>{params.title}</h1>
</header>
<article>
{#if params.isLoading === true}
{#if isLoading === true}
<p>Loading...</p>
{:else}
<table>
@@ -39,7 +47,7 @@
</tr>
</thead>
<tbody>
{#each params.records as record}
{#each records as record}
<tr>
<td>{record.period}</td>
<td>{record.workingDays}</td>
+3 -23
View File
@@ -1,31 +1,11 @@
<script>
import Views from "./Views.svelte";
export let params;
import {WorkingHoursViewsRepository} from "../components/Repositories.svelte";
export let params
params = {
title: 'Wochenansicht',
records: [],
isLoading: true
promise: WorkingHoursViewsRepository.weekly()
}
const View = {
'browse': () => {
fetch(env.API_URL + '/views/working-hours/weekly')
.then(res => {
if (!res.ok) {
throw new Error('Fail!');
}
return res.json();
})
.then(data => {
params.records = data;
params.isLoading = false;
})
.catch(err => {
params.isLoading = false;
console.log(err);
});
}
};
View.browse();
</script>
<Views {params} />
+24 -113
View File
@@ -1,121 +1,32 @@
<script>
export let params;
const TITLE = "Bearbeitung Einträge";
import IconifyIcon from '@iconify/svelte';
import wrenchIcon from '@iconify-icons/oi/wrench';
import checkIcon from '@iconify-icons/oi/check';
import xIcon from '@iconify-icons/oi/x';
import documentIcon from '@iconify-icons/oi/document';
import {WorkingHoursRepository} from '../components/Repositories.svelte'
import NewByDay from "./working-hours/NewByDay.svelte";
import List from "./WorkingHours/List.svelte";
import Formular from "./WorkingHours/Formular.svelte";
export let params = {};
let TITLE = "Bearbeitung Einträge"
let activeRecord = null;
params = {
title: 'Einträge',
records: [],
isLoading: true
}
const Controller = {
'listRecords': () => {
WorkingHoursRepository.browse().then(data => {
activeRecord = null;
params.records = data;
params.isLoading = false;
})
},
'newRecord': () => {
activeRecord = {workingTime: '00:00:00', workingDay: null};
},
'saveRecord': () => {
if (activeRecord.workingDay === null) {
WorkingHoursRepository.add(activeRecord).then(() => {
Controller.listRecords()
});
} else {
WorkingHoursRepository.update(activeRecord.workingDay, activeRecord).then(() => {
Controller.listRecords()
})
}
},
'selectActiveRecord': record => WorkingHoursRepository.read(record.workingDay).then(data => {
activeRecord = data;
if (activeRecord === null) {
Controller.listRecords()
}
}),
'cancelActiveRecord': () => {
activeRecord = null;
}
};
const initSite = () => {
Controller.listRecords()
};
initSite()
</script>
<svelte:head>
<title>{TITLE}</title>
</svelte:head>
<section id="list-records">
<header>
<h1>{TITLE}</h1>
</header>
{#if activeRecord === null}
<article>
{#if params.isLoading === true}
<p>Loading...</p>
{:else}
<!--suppress HtmlUnknownTarget -->
<form action="/working-hours">
<fieldset>
<button on:click={Controller.newRecord} type="button">Neuer Eintrag
<IconifyIcon icon={documentIcon}/>
</button>
</fieldset>
</form>
<table>
<colgroup>
<col />
<col />
<col />
</colgroup>
<thead>
<tr>
<th>Datum</th>
<th>Arbeitsstunden</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody>
{#each params.records as record}
<tr>
<td>{record.workingDay}</td>
<td>{record.workingTime}</td>
<td>
<button on:click={() => Controller.selectActiveRecord(record)} type="button">Bearbeiten
<IconifyIcon icon={wrenchIcon}/>
</button>
</td>
</tr>
{/each}
</tbody>
</table>
{/if}
</article>
{:else}
<article>
<!--suppress HtmlUnknownTarget -->
<form action="/working-hours" name="editRecord">
<NewByDay activeRecord="{activeRecord}"/>
<fieldset name="buttons">
<button on:click={Controller.saveRecord} type="button">Übernehmen
<IconifyIcon icon={checkIcon} color="green"/>
</button>
<button on:click={Controller.cancelActiveRecord} type="button" class="sub-button">Abbrechen
<IconifyIcon icon={xIcon}/>
</button>
</fieldset>
</form>
</article>
{/if}
</section>
{#if activeRecord === null}
<section id="list-records">
<header>
<h1>{TITLE}</h1>
</header>
<article>
<List bind:activeRecord={activeRecord}/>
</article>
</section>
{:else}
<section id="edit-record">
<header>
<h1>{TITLE}</h1>
</header>
<article>
<Formular bind:activeRecord={activeRecord}/>
</article>
</section>
{/if}
@@ -0,0 +1,47 @@
<script>
import {WorkingHoursRepository} from "../../components/Repositories.svelte"
import IconifyIcon from '@iconify/svelte'
import checkIcon from '@iconify-icons/oi/check'
import xIcon from '@iconify-icons/oi/x'
import {TimekeepingDate} from "../../components/TimekeepingDate.svelte"
export let activeRecord = null
const Controller = {
'saveRecord': () => {
WorkingHoursRepository.addOrUpdate(activeRecord.workingDay, activeRecord).then(() => {
Controller.nextDay()
});
},
'nextDay': async () => {
let actDate = new TimekeepingDate(activeRecord.workingDay)
let nextDay = actDate.getNextDay()
activeRecord = await WorkingHoursRepository.readOrNew(nextDay.getDateString())
},
'cancelActiveRecord': () => {
activeRecord = null;
}
}
</script>
<!--suppress HtmlUnknownTarget -->
<form action="/working-hours" name="editRecord">
<fieldset name="record-data">
<div>
<label for="workingDay">Arbeitstag</label>
<input bind:value={activeRecord.workingDay} type="date"
id="workingDay" required pattern="\d\{4}-[0-1]\d-[0-3]\d\">
</div>
<div>
<label for="workingTime">Arbeitszeit</label>
<input bind:value={activeRecord.workingTime} placeholder="Arbeitszeit" type="time"
id="workingTime" required pattern="[0-5]\d:[0-5]\d:[0-5]\d">
</div>
</fieldset>
<fieldset name="buttons">
<button on:click={Controller.saveRecord} type="button">Übernehmen und Weiter
<IconifyIcon icon={checkIcon} color="green"/>
</button>
<button on:click={Controller.cancelActiveRecord} type="button" class="sub-button">Abbrechen
<IconifyIcon icon={xIcon}/>
</button>
</fieldset>
</form>
+77
View File
@@ -0,0 +1,77 @@
<script>
import {WorkingHoursRepository} from "../../components/Repositories.svelte"
import {TimekeepingDate} from "../../components/TimekeepingDate.svelte"
export let activeRecord = null
let isLoading = true
let records = []
import IconifyIcon from '@iconify/svelte'
import wrenchIcon from '@iconify-icons/oi/wrench'
import documentIcon from '@iconify-icons/oi/document'
const Controller = {
'listRecords': () => {
Controller.cancelActiveRecord();
WorkingHoursRepository.browse().then(data => {
Controller.cancelActiveRecord()
records = data
isLoading = false
});
},
'newRecord': async () => {
const actDate = new TimekeepingDate()
activeRecord = await WorkingHoursRepository.readOrNew(actDate.getDateString())
},
'selectActiveRecord': record => WorkingHoursRepository.read(record.workingDay).then(data => {
if (data === null) {
Controller.listRecords()
return
}
activeRecord = data;
}),
'cancelActiveRecord': () => {
activeRecord = null;
}
}
Controller.listRecords()
</script>
<!--suppress HtmlUnknownTarget -->
<form action="/working-hours">
<fieldset>
<button on:click={Controller.newRecord} type="button">Neuer Eintrag
<IconifyIcon icon={documentIcon}/>
</button>
</fieldset>
</form>
{#if isLoading === true}
<p>Loading...</p>
{:else}
<table>
<colgroup>
<col/>
<col/>
<col/>
</colgroup>
<thead>
<tr>
<th>Datum</th>
<th>Arbeitsstunden</th>
<th>Aktionen</th>
</tr>
</thead>
<tbody>
{#each records as record}
<tr>
<td>{record.workingDay}</td>
<td>{record.workingTime}</td>
<td>
<button on:click={() => Controller.selectActiveRecord(record)} type="button">Bearbeiten
<IconifyIcon icon={wrenchIcon}/>
</button>
</td>
</tr>
{/each}
</tbody>
</table>
{/if}
+3 -23
View File
@@ -1,31 +1,11 @@
<script>
import Views from "./Views.svelte";
export let params;
import {WorkingHoursViewsRepository} from "../components/Repositories.svelte";
export let params
params = {
title: 'Jahresansicht',
records: [],
isLoading: true
promise: WorkingHoursViewsRepository.yearly()
}
const View = {
'browse': () => {
fetch(env.API_URL + '/views/working-hours/yearly')
.then(res => {
if (!res.ok) {
throw new Error('Fail!');
}
return res.json();
})
.then(data => {
params.records = data;
params.isLoading = false;
})
.catch(err => {
params.isLoading = false;
console.log(err);
});
}
};
View.browse();
</script>
<Views {params} />