diff --git a/ui/.env.example b/ui/.env.example new file mode 100644 index 0000000..5b737f7 --- /dev/null +++ b/ui/.env.example @@ -0,0 +1,2 @@ +# Url ohne abschlißenden Slash +API_URL= http://localhost:8080 \ No newline at end of file diff --git a/ui/.gitignore b/ui/.gitignore index b21668d..76035c9 100644 --- a/ui/.gitignore +++ b/ui/.gitignore @@ -3,3 +3,4 @@ node_modules package-lock.json yarn.lock public +/.env diff --git a/ui/package.json b/ui/package.json index f794272..bdbbd6e 100644 --- a/ui/package.json +++ b/ui/package.json @@ -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", diff --git a/ui/rollup.config.js b/ui/rollup.config.js index c05a512..7b165f5 100644 --- a/ui/rollup.config.js +++ b/ui/rollup.config.js @@ -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 diff --git a/ui/src/components/App.svelte b/ui/src/components/App.svelte index 0852d11..0577043 100644 --- a/ui/src/components/App.svelte +++ b/ui/src/components/App.svelte @@ -45,52 +45,12 @@ addEventListener('pushstate', track); 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" - }; - let records = { - "title" : "Einträge", - "records" : [r, r] - }; - 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('/working-hours', () => run(import('../routes/WorkingHours.svelte'), records)) + .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'))) .listen(); onDestroy(router.unlisten); diff --git a/ui/src/routes/Home.svelte b/ui/src/routes/Home.svelte index 8041d2c..4a0fa9d 100644 --- a/ui/src/routes/Home.svelte +++ b/ui/src/routes/Home.svelte @@ -1,6 +1,5 @@ - + \ No newline at end of file diff --git a/ui/src/routes/MonthlyViews.svelte b/ui/src/routes/MonthlyViews.svelte new file mode 100644 index 0000000..fd4166e --- /dev/null +++ b/ui/src/routes/MonthlyViews.svelte @@ -0,0 +1,31 @@ + + + \ No newline at end of file diff --git a/ui/src/routes/Views.svelte b/ui/src/routes/Views.svelte index e61e5e4..8c7ee11 100644 --- a/ui/src/routes/Views.svelte +++ b/ui/src/routes/Views.svelte @@ -1,5 +1,6 @@ @@ -11,25 +12,29 @@

{params.title}

- - - - - - - - - - - {#each params.records as record} + {#if params.isLoading === true} +

Loading...

+ {:else} +
ZeitraumArbeitstageArbeitsstundenÜber- / Unterstunden
+ - - - - + + + + - {/each} - -
{record.period}{record.workingDays}{record.totalHours}{record.overtime}ZeitraumArbeitstageArbeitsstundenÜber- / Unterstunden
+ + + {#each params.records as record} + + {record.period} + {record.workingDays} + {record.totalHours} + {record.overtime} + + {/each} + + + {/if}
\ No newline at end of file diff --git a/ui/src/routes/WeeklyViews.svelte b/ui/src/routes/WeeklyViews.svelte new file mode 100644 index 0000000..34eb07b --- /dev/null +++ b/ui/src/routes/WeeklyViews.svelte @@ -0,0 +1,31 @@ + + + \ No newline at end of file diff --git a/ui/src/routes/WorkingHours.svelte b/ui/src/routes/WorkingHours.svelte index e2da199..aae1de7 100644 --- a/ui/src/routes/WorkingHours.svelte +++ b/ui/src/routes/WorkingHours.svelte @@ -3,10 +3,136 @@ 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 => { + Controller.cancelActiveRecord(); + 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) { + Controller.listRecords(); + } + }) + .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(() => { + Controller.listRecords(); + }) + .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(() => { + Controller.listRecords(); + }) + .catch(err => { + console.log(err); + }); + } + }; + const Controller = { + 'listRecords': () => { + Controller.cancelActiveRecord(); + Records.browse(); + }, + 'newRecord': () => { + activeRecord = {workingTime: '00:00:00'}; + newRecord = true; + }, + 'saveRecord': () => { + if (newRecord === true) { + Records.add(activeRecord); + } else { + Records.update(activeRecord.workingDay, activeRecord); + } + }, + 'selectActiveRecord': record => Records.read(record.workingDay), + 'cancelActiveRecord': () => { + activeRecord = null; + newRecord = false; + } + }; + const initSite = () => { + Controller.listRecords() + }; + initSite() @@ -19,27 +145,40 @@

{title}

- - - - - - - - - - {#each params.records as record} + {#if params.isLoading === true} +

Loading...

+ {:else} + + +
+ +
+ +
DatumArbeitsstundenAktionen
+ - - - + + + - {/each} - -
{record.workingDay}{record.workingTime} - - - DatumArbeitsstundenAktionen
+ + + {#each params.records as record} + + {record.workingDay} + {record.workingTime} + + + + + {/each} + + + {/if}
{:else} @@ -53,18 +192,22 @@
- - +
- - +
- - + +
diff --git a/ui/src/routes/YearlyViews.svelte b/ui/src/routes/YearlyViews.svelte new file mode 100644 index 0000000..974b2b1 --- /dev/null +++ b/ui/src/routes/YearlyViews.svelte @@ -0,0 +1,31 @@ + + + \ No newline at end of file