7 Commits
11 changed files with 280 additions and 82 deletions
+2
View File
@@ -0,0 +1,2 @@
# Url ohne abschlißenden Slash
API_URL= http://localhost:8080
+1
View File
@@ -3,3 +3,4 @@ node_modules
package-lock.json
yarn.lock
public
/.env
+1
View File
@@ -19,6 +19,7 @@
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.3.0",
"dotenv": "^8.2.0",
"npm-run-all": "^4.1.3",
"rollup": "^2.30.0",
"rollup-plugin-svelte": "^6.0.0",
+3 -1
View File
@@ -3,6 +3,7 @@ import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import {config} from 'dotenv';
const production = !process.env.ROLLUP_WATCH;
@@ -35,7 +36,8 @@ export default {
commonjs(),
replace({
'process.env.NODE_ENV': JSON.stringify(production ? 'production' : 'development')
'process.env.NODE_ENV': JSON.stringify(production ? 'production' : 'development'),
'env': JSON.stringify({...config().parsed /* attached the .env config*/})
}),
// If we're building for production (npm run build
+4 -34
View File
@@ -46,36 +46,6 @@
addEventListener('popstate', track);
let w = {
"period": "2020#01",
"workingDays": 20,
"totalHours": "99:00:00",
"overtime": "10:22:00"
};
let weekly = {
"title" : "Wochenansicht",
"records" : [w, w]
};
let m = {
"period": "2020-01",
"workingDays": 20,
"totalHours": "99:00:00",
"overtime": "10:22:00"
};
let monthly = {
"title" : "Monatsansicht",
"records" : [m, m]
};
let y = {
"period": "2020",
"workingDays": 20,
"totalHours": "99:00:00",
"overtime": "10:22:00"
};
let yearly = {
"title" : "Jahresansicht",
"records" : [y, y]
};
let r = {
"workingDay": "2020-01-15",
"workingTime": "09:00:00"
@@ -86,10 +56,10 @@
};
const router = Navaid('/')
.on('/', () => run(import('../routes/Home.svelte'), weekly))
.on('/views/weekly', () => run(import('../routes/Views.svelte'), weekly))
.on('/views/monthly', () => run(import('../routes/Views.svelte'), monthly))
.on('/views/yearly', () => run(import('../routes/Views.svelte'), yearly))
.on('/', () => run(import('../routes/Home.svelte')))
.on('/views/weekly', () => run(import('../routes/WeeklyViews.svelte')))
.on('/views/monthly', () => run(import('../routes/MonthlyViews.svelte')))
.on('/views/yearly', () => run(import('../routes/YearlyViews.svelte')))
.on('/working-hours', () => run(import('../routes/WorkingHours.svelte'), records))
.listen();
+2 -3
View File
@@ -1,6 +1,5 @@
<Views {params} />
<Views />
<script>
import Views from "./Views.svelte";
export let params;
import Views from "./WeeklyViews.svelte";
</script>
+31
View File
@@ -0,0 +1,31 @@
<script>
import Views from "./Views.svelte";
export let params;
params = {
title: 'Monatsansicht',
records: [],
isLoading: true
}
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} />
+5
View File
@@ -1,5 +1,6 @@
<script>
export let params;
console.log(params)
</script>
<svelte:head>
@@ -11,6 +12,9 @@
<h1>{params.title}</h1>
</header>
<article>
{#if params.isLoading === true}
<p>Loading...</p>
{:else}
<table>
<thead>
<tr>
@@ -31,5 +35,6 @@
{/each}
</tbody>
</table>
{/if}
</article>
</section>
+31
View File
@@ -0,0 +1,31 @@
<script>
import Views from "./Views.svelte";
export let params;
params = {
title: 'Wochenansicht',
records: [],
isLoading: true
}
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} />
+134 -9
View File
@@ -3,10 +3,112 @@
let title = "Bearbeitung Einträge"
import IconifyIcon from '@iconify/svelte';
import wrenchIcon from '@iconify-icons/oi/wrench';
import trashIcon from '@iconify-icons/oi/trash';
import checkIcon from '@iconify-icons/oi/check';
import xIcon from '@iconify-icons/oi/x';
import documentIcon from '@iconify-icons/oi/document';
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>
<svelte:head>
@@ -19,6 +121,17 @@
<h1>{title}</h1>
</header>
<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>
<thead>
<tr>
@@ -33,13 +146,15 @@
<td>{record.workingDay}</td>
<td>{record.workingTime}</td>
<td>
<button>Bearbeiten <IconifyIcon icon={wrenchIcon} /></button>
<button>Löschen <IconifyIcon icon={trashIcon} color="red" /></button>
<button on:click={() => Records.read(record.workingDay)}>Bearbeiten
<IconifyIcon icon={wrenchIcon}/>
</button>
</td>
</tr>
{/each}
</tbody>
</table>
{/if}
</article>
</section>
{:else}
@@ -53,18 +168,28 @@
<fieldset name="record-data">
<div>
<label for="workingDay">Arbeitstag</label>
<!--suppress JSUnresolvedVariable -->
<input bind:value={activeRecord.workingDay} placeholder="Arbeitstag" type="date" id="workingDay">
<input bind:value={activeRecord.workingDay} placeholder="Arbeitstag" type="date"
id="workingDay">
</div>
<div>
<label for="workingTime">Arbeitszeit</label>
<!--suppress JSUnresolvedVariable -->
<input bind:value={activeRecord.workingTime} placeholder="Arbeitszeit" type="time" id="workingTime">
<input bind:value={activeRecord.workingTime} placeholder="Arbeitszeit" type="time"
id="workingTime">
</div>
</fieldset>
<fieldset name="buttons">
<button>Übernehmen <IconifyIcon icon={checkIcon} color="green" /></button>
<button>Abbrechen <IconifyIcon icon={xIcon} /></button>
{#if newRecord === true}
<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>
</form>
</article>
+31
View File
@@ -0,0 +1,31 @@
<script>
import Views from "./Views.svelte";
export let params;
params = {
title: 'Jahresansicht',
records: [],
isLoading: true
}
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} />