Feature: ermögliche den Import von CSV-Daten
This commit is contained in:
@@ -5,10 +5,12 @@
|
||||
import xIcon from '@iconify-icons/oi/x'
|
||||
import EditByDay from "./Formular/EditByDay.svelte";
|
||||
import EditByWeek from "./Formular/EditByWeek.svelte";
|
||||
import ImportCsv from "./Formular/ImportCsv.svelte";
|
||||
import {TimekeepingDate} from "../../components/TimekeepingDate.svelte";
|
||||
|
||||
const DAILY_EDIT = 0
|
||||
const WEEKLY_EDIT = 1
|
||||
const CSV_IMPORT = 2
|
||||
|
||||
const Controller = {
|
||||
'saveRecord': () => {
|
||||
@@ -65,6 +67,11 @@
|
||||
})
|
||||
}
|
||||
}
|
||||
const CsvController = {
|
||||
'makeTimekeepingList': () => {
|
||||
MenuController.dailyEdit()
|
||||
}
|
||||
}
|
||||
const MenuController = {
|
||||
'dailyEdit': () => {
|
||||
period_of_edit = DAILY_EDIT
|
||||
@@ -75,6 +82,11 @@
|
||||
period_of_edit = WEEKLY_EDIT
|
||||
makeTimekeepingList = WeekController.makeTimekeepingList
|
||||
makeTimekeepingList()
|
||||
},
|
||||
'csvImport': () => {
|
||||
period_of_edit = CSV_IMPORT
|
||||
activeRecordList = []
|
||||
makeTimekeepingList = CsvController.makeTimekeepingList
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +105,7 @@
|
||||
<nav class="menu">
|
||||
<span on:click={MenuController.dailyEdit} on:keypress={() => {}} class:active={period_of_edit === DAILY_EDIT}>Täglich</span>
|
||||
<span on:click={MenuController.weeklyEdit} on:keypress={() => {}} class:active={period_of_edit === WEEKLY_EDIT}>Wöchentlich</span>
|
||||
<span on:click={MenuController.csvImport} on:keypress={() => {}} class:active={period_of_edit === CSV_IMPORT}>Import per CSV</span>
|
||||
</nav>
|
||||
{#if period_of_edit === DAILY_EDIT}
|
||||
<EditByDay bind:activeRecordList bind:activeDate bind:makeTimekeepingList/>
|
||||
@@ -100,6 +113,9 @@
|
||||
{#if period_of_edit === WEEKLY_EDIT}
|
||||
<EditByWeek bind:activeRecordList bind:activeDate bind:makeTimekeepingList/>
|
||||
{/if}
|
||||
{#if period_of_edit === CSV_IMPORT}
|
||||
<ImportCsv bind:activeRecordList bind:makeTimekeepingList/>
|
||||
{/if}
|
||||
<fieldset name="buttons">
|
||||
<button on:click={Controller.saveRecord} type="button">Übernehmen und Weiter
|
||||
<IconifyIcon icon={checkIcon} color="green"/>
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<script>
|
||||
import Papa from '../../../papaparse.min'
|
||||
export let activeRecordList = []
|
||||
let imported_data = []
|
||||
|
||||
let files = null
|
||||
|
||||
const VerarbeiteDateien = () => {
|
||||
for (const file of files) {
|
||||
VerarbeiteCsv(file)
|
||||
}
|
||||
}
|
||||
|
||||
const VerarbeiteCsv = file => {
|
||||
Papa.parse(file, {
|
||||
header: true,
|
||||
skipEmptyLines: true,
|
||||
complete: results => {
|
||||
let cash_work_days = {}
|
||||
results.data.forEach(item => {
|
||||
// noinspection JSNonASCIINames
|
||||
let activity = item['Aktivität']
|
||||
if (activity.trim() === 'Mittagspause') {
|
||||
return
|
||||
}
|
||||
let work_from = new Date(item['Von'])
|
||||
let work_to = new Date(item['Bis'])
|
||||
let actual_day = work_from.toISOString().substring(0, 10)
|
||||
let actual_work_hours = (work_to - work_from)/(1000*60*60)
|
||||
if (cash_work_days[actual_day] === undefined) {
|
||||
cash_work_days[actual_day] = actual_work_hours
|
||||
} else {
|
||||
cash_work_days[actual_day] += actual_work_hours
|
||||
}
|
||||
})
|
||||
for (let day in cash_work_days) {
|
||||
let hours = cash_work_days[day]
|
||||
let hours_digits = Math.trunc(hours)
|
||||
let minutes_digits = Math.round((hours-hours_digits)*60)
|
||||
let working_time = String(hours_digits).padStart(2, '0') + ":"
|
||||
+ String(minutes_digits).padStart(2, '0') + ':00'
|
||||
activeRecordList.push({workingTime: working_time, workingDay: day})
|
||||
}
|
||||
imported_data = activeRecordList
|
||||
},
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<fieldset>
|
||||
<legend>Download-Liste</legend>
|
||||
<div class="zelle">
|
||||
<label for="csv-file">Download der Zeiten von <i>aTimeLogger2</i></label>
|
||||
<input type="file" accept="text/csv" id="csv-file" bind:files/>
|
||||
<button type="button" on:click={VerarbeiteDateien}>Upload</button>
|
||||
</div>
|
||||
</fieldset>
|
||||
<fieldset name="record-data-for-import">
|
||||
<div>
|
||||
{#if imported_data.length < 1}
|
||||
<p>Loading...</p>
|
||||
{:else}
|
||||
<table>
|
||||
<tbody>
|
||||
{#each imported_data as item}
|
||||
<tr>
|
||||
<td>
|
||||
{item.workingDay}
|
||||
</td>
|
||||
<td>
|
||||
{item.workingTime}
|
||||
</td>
|
||||
</tr>
|
||||
{/each}
|
||||
</tbody>
|
||||
</table>
|
||||
{/if}
|
||||
</div>
|
||||
</fieldset>
|
||||
Reference in New Issue
Block a user