feat: implement initial prototype

This commit is contained in:
Raito Bezarius 2022-02-20 19:16:33 +01:00
parent 5d53c11d6b
commit a18072cc27
7 changed files with 914 additions and 24 deletions

835
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -5,18 +5,20 @@
"scripts": { "scripts": {
"build": "rollup -c", "build": "rollup -c",
"dev": "rollup -c -w", "dev": "rollup -c -w",
"start": "sirv public --no-clear" "start": "sirv public --cors --no-clear"
}, },
"devDependencies": { "devDependencies": {
"@fullcalendar/daygrid": "^5.10.1", "@fullcalendar/daygrid": "^5.10.1",
"@fullcalendar/timegrid": "^5.10.1", "@fullcalendar/timegrid": "^5.10.1",
"@rollup/plugin-commonjs": "^17.0.0", "@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.0", "@rollup/plugin-node-resolve": "^11.0.0",
"dav": "^1.8.0",
"postcss": "^8.3.11", "postcss": "^8.3.11",
"prettier": "^2.4.1", "prettier": "^2.4.1",
"prettier-plugin-svelte": "^2.5.0", "prettier-plugin-svelte": "^2.5.0",
"rollup": "^2.3.4", "rollup": "^2.3.4",
"rollup-plugin-css-only": "^3.1.0", "rollup-plugin-css-only": "^3.1.0",
"rollup-plugin-dev": "^2.0.3",
"rollup-plugin-livereload": "^2.0.0", "rollup-plugin-livereload": "^2.0.0",
"rollup-plugin-postcss": "^4.0.1", "rollup-plugin-postcss": "^4.0.1",
"rollup-plugin-svelte": "^7.0.0", "rollup-plugin-svelte": "^7.0.0",
@ -25,6 +27,8 @@
"svelte-fullcalendar": "^1.1.1" "svelte-fullcalendar": "^1.1.1"
}, },
"dependencies": { "dependencies": {
"@nextcloud/cdav-library": "^1.0.0",
"ical.js": "^1.5.0",
"sirv-cli": "^1.0.0" "sirv-cli": "^1.0.0"
} }
} }

View file

@ -5,9 +5,11 @@ import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser'; import { terser } from 'rollup-plugin-terser';
import css from 'rollup-plugin-css-only'; import css from 'rollup-plugin-css-only';
import postcss from 'rollup-plugin-postcss'; import postcss from 'rollup-plugin-postcss';
import dev from 'rollup-plugin-dev';
const production = !process.env.ROLLUP_WATCH; const production = !process.env.ROLLUP_WATCH;
/*
function serve() { function serve() {
let server; let server;
@ -27,7 +29,7 @@ function serve() {
process.on('exit', toExit); process.on('exit', toExit);
} }
}; };
} }*/
export default { export default {
input: 'src/main.js', input: 'src/main.js',
@ -64,7 +66,13 @@ export default {
// In dev mode, call `npm run start` once // In dev mode, call `npm run start` once
// the bundle has been generated // the bundle has been generated
!production && serve(), !production && dev({
dirs: ['public'],
proxy: [
{ from: '/cal', to: 'https://nuage.beta.rz.ens.wtf/remote.php/dav/public-calendars/' }
],
port: 5000
}),
// Watch the `public` directory and refresh the // Watch the `public` directory and refresh the
// browser on changes when not in production // browser on changes when not in production

View file

@ -1,5 +1,5 @@
{ pkgs ? import ./nix {} }: { pkgs ? import ./nix {} }:
pkgs.npmlock2nix.shell { pkgs.npmlock2nix.shell {
src = ./.; src = ./.;
nodejs = pkgs.nodejs-12_x; nodejs = pkgs.nodejs-14_x;
} }

View file

@ -1,16 +1,24 @@
<script> <script>
import { onMount } from 'svelte';
import FullCalendar from 'svelte-fullcalendar'; import FullCalendar from 'svelte-fullcalendar';
import timeGridPlugin from '@fullcalendar/timegrid'; import timeGridPlugin from '@fullcalendar/timegrid';
import frLocale from '@fullcalendar/core/locales/fr'; import frLocale from '@fullcalendar/core/locales/fr';
import { refreshEvents } from './calendar';
export let events;
let options = { let options = {
initialView: 'timeGridWeek', initialView: 'timeGridWeek',
plugins: [timeGridPlugin], plugins: [timeGridPlugin],
locale: frLocale, locale: frLocale,
events events: []
}; };
onMount(async () => {
const evts = await refreshEvents();
options.events = evts[0];
options = { ...options };
});
$: console.log(options);
</script> </script>
<div style="height:100vh"> <div style="height:100vh">

52
src/calendar.js Normal file
View file

@ -0,0 +1,52 @@
import ICAL from 'ical.js';
const calendarIds = [
"5WrcagPPARQ3BD87"
];
function mkCalendarUrl(id) {
return `/cal/${id}/?export&accept=jcal`;
}
function fetchCalendar(id) {
return fetch(mkCalendarUrl(id), { credentials: 'omit' }).then(resp => resp.json()).catch(err => console.error(err));
}
class Calendar {
constructor (calendar) {
this.calName = calendar[1][3][3];
this.events = calendar[2].filter(item => item[0] === 'vevent').map(item => this._parse_vevent(item[1]));
}
_parse_vevent(vevent) {
const event = {};
vevent.forEach(elt => {
event[elt[0]] = elt[3];
});
return event;
}
}
function mkEventsFromCalendar(id) {
return fetchCalendar(id).then(calendar => {
if (calendar[0] !== 'vcalendar') return;
const cal = new Calendar(calendar)
return cal.events.map(evt => ({ title: evt.summary, start: new Date(evt.dtstart), end: new Date(evt.dtend) }))
});
}
export function mkEvent(title, start, duration, ...rest) {
start = new Date(start)
const end = new Date(start)
end.setMinutes(start.getMinutes() + duration)
return {
title,
start,
end,
...rest
}
}
export function refreshEvents() {
return Promise.all(calendarIds.map(mkEventsFromCalendar))
}

View file

@ -1,24 +1,7 @@
import App from './App.svelte'; import App from './App.svelte';
function mkEvent(title, start, duration, ...rest) {
start = new Date(start)
const end = new Date(start)
end.setMinutes(start.getMinutes() + duration)
return {
title,
start,
end,
...rest
}
}
const app = new App({ const app = new App({
target: document.body, target: document.body,
props: {
events: [
mkEvent('Me donner À MANGER', '2021-11-16T12:00', 30),
]
}
}); });
export default app; export default app;