feat: implement filtering through calendars
This commit is contained in:
parent
da2f53d86a
commit
503eecf33e
5 changed files with 37 additions and 23 deletions
|
@ -16,7 +16,7 @@
|
||||||
const modal = writable(null);
|
const modal = writable(null);
|
||||||
let calendar;
|
let calendar;
|
||||||
|
|
||||||
let options = {
|
let options = writable({
|
||||||
initialView: 'timeGridWeek',
|
initialView: 'timeGridWeek',
|
||||||
plugins: [timeGridPlugin, dayGridPlugin, rrulePlugin, listPlugin, adaptivePlugin],
|
plugins: [timeGridPlugin, dayGridPlugin, rrulePlugin, listPlugin, adaptivePlugin],
|
||||||
locale: frLocale,
|
locale: frLocale,
|
||||||
|
@ -33,36 +33,44 @@
|
||||||
modal.set(bind(EventDetails, { event: info.event }));
|
modal.set(bind(EventDetails, { event: info.event }));
|
||||||
},
|
},
|
||||||
events: []
|
events: []
|
||||||
};
|
});
|
||||||
|
|
||||||
let selectedCalendars;
|
let selectedCalendars;
|
||||||
|
let updateTimer;
|
||||||
|
|
||||||
async function reloadEvents(selectedCalendars, options) {
|
async function reloadEvents(selectedCalendars) {
|
||||||
const evts = await refreshEvents(selectedCalendars);
|
const evts = await refreshEvents(selectedCalendars);
|
||||||
return evts.flat();
|
return evts.flat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateEvents(calendars) {
|
||||||
|
return reloadEvents(calendars).then(events => {
|
||||||
|
options.update(opts => ({
|
||||||
|
...opts,
|
||||||
|
events
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
options.events = await reloadEvents(selectedCalendars, options);
|
const events = await reloadEvents(selectedCalendars);
|
||||||
options = { ...options };
|
options.update(opts => ({
|
||||||
|
...opts,
|
||||||
|
events
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
$: {
|
$: updateEvents(selectedCalendars);
|
||||||
/*reloadEvents(selectedCalendars, options).then(events => {
|
|
||||||
options.events = events;
|
|
||||||
options = { ...options };
|
|
||||||
});*/
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<h1 class="title">Calendrier de la vie étudiante à l'ENS</h1>
|
<h1 class="title">Calendrier de la vie étudiante à l'ENS</h1>
|
||||||
<div style="height: 100%; display: flex;">
|
<div style="height: 100%; display: flex;">
|
||||||
<Modal show={$modal}>
|
<Modal show={$modal}>
|
||||||
<FilterBar {calendarTree} />
|
<FilterBar {calendarTree} bind:selected={selectedCalendars} />
|
||||||
<div style="flex: 1;">
|
<div style="flex: 1;">
|
||||||
<FullCalendar bind:this={calendar} {options} />
|
<FullCalendar bind:this={calendar} options={$options} />
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
<script>
|
<script>
|
||||||
import FilterItem from './FilterItem.svelte';
|
import FilterItem from './FilterItem.svelte';
|
||||||
export let calendarTree = [];
|
export let calendarTree = [];
|
||||||
export let selectedCalendars = null;
|
export let selected = null;
|
||||||
|
|
||||||
let subSelections = Array(Object.keys(calendarTree).length).fill([]);
|
let subSelections = Array.from({length: Object.keys(calendarTree).length}, e => []);
|
||||||
$: selectedCalendars = subSelections.flat();
|
$: selected = subSelections.flat();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{#each Object.entries(calendarTree) as [toplevel, subtrees], i}
|
{#each Object.entries(calendarTree) as [toplevel, subtrees], i}
|
||||||
<FilterItem item={toplevel} children={subtrees} />
|
<FilterItem item={toplevel} children={subtrees} bind:selected={subSelections[i]} />
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
export let selected = [];
|
export let selected = [];
|
||||||
export let filtering = createTriState(CHECKED);
|
export let filtering = createTriState(CHECKED);
|
||||||
let subfiltering = createTriStates(CHECKED, Object.entries(children).length);
|
let subfiltering = createTriStates(CHECKED, Object.entries(children).length);
|
||||||
|
let subselected = Array.from({length: Object.entries(children).length}, e => []);
|
||||||
|
|
||||||
function isVal(val) {
|
function isVal(val) {
|
||||||
return function (other) {
|
return function (other) {
|
||||||
|
@ -33,7 +34,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
subfiltering.subscribe(subvalues => {
|
subfiltering.subscribe(subvalues => {
|
||||||
console.log('new subvalues', subvalues);
|
|
||||||
if (areAllChecked(subvalues) && $filtering !== CHECKED) {
|
if (areAllChecked(subvalues) && $filtering !== CHECKED) {
|
||||||
filtering.setChecked();
|
filtering.setChecked();
|
||||||
} else if (areAllUnchecked(subvalues) && $filtering !== UNCHECKED) {
|
} else if (areAllUnchecked(subvalues) && $filtering !== UNCHECKED) {
|
||||||
|
@ -45,7 +45,6 @@
|
||||||
|
|
||||||
if (subfiltering.length > 0) {
|
if (subfiltering.length > 0) {
|
||||||
filtering.subscribe(value => {
|
filtering.subscribe(value => {
|
||||||
console.log(item, value);
|
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case CHECKED:
|
case CHECKED:
|
||||||
subfiltering.updateAll(_ => CHECKED);
|
subfiltering.updateAll(_ => CHECKED);
|
||||||
|
@ -63,6 +62,7 @@
|
||||||
dispatch('change', { value: evt.detail.value });
|
dispatch('change', { value: evt.detail.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: selected = $filtering === CHECKED ? [item, ...subselected.flat()] : subselected.flat();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if item != null}
|
{#if item != null}
|
||||||
|
@ -72,9 +72,9 @@
|
||||||
<ul>
|
<ul>
|
||||||
{#each Object.entries(children) as [toplevel, subchildren], i}
|
{#each Object.entries(children) as [toplevel, subchildren], i}
|
||||||
{#if subchildren}
|
{#if subchildren}
|
||||||
<svelte:self item={toplevel} children={subchildren} on:change={handleChildChange(i)} filtering={subfiltering.storeAt(i)} />
|
<svelte:self item={toplevel} children={subchildren} on:change={handleChildChange(i)} filtering={subfiltering.storeAt(i)} bind:selected={subselected[i]} />
|
||||||
{:else}
|
{:else}
|
||||||
<svelte:self item={toplevel} on:change={handleChildChange(i)} filtering={subfiltering.storeAt(i)} />
|
<svelte:self item={toplevel} on:change={handleChildChange(i)} filtering={subfiltering.storeAt(i)} bind:selected={subselected[i]} />
|
||||||
{/if}
|
{/if}
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
if (node) {
|
if (node) {
|
||||||
if (state === CHECKED) {
|
if (state === CHECKED) {
|
||||||
checkedValue = true;
|
checkedValue = true;
|
||||||
} else if (state === UNCHECKED) {
|
} else {
|
||||||
checkedValue = false;
|
checkedValue = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,13 @@ export const calendarTree = {
|
||||||
"Club réseau": {},
|
"Club réseau": {},
|
||||||
"hackENS": {},
|
"hackENS": {},
|
||||||
},
|
},
|
||||||
"COF": {},
|
"COF": {
|
||||||
|
"BDA": {
|
||||||
|
"Philharmonie": {},
|
||||||
|
},
|
||||||
|
"AG": {},
|
||||||
|
},
|
||||||
|
"BDS": {},
|
||||||
"Délégation Générale": {},
|
"Délégation Générale": {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue