Rajoute le téléchargement des calendriers (#17)

Co-authored-by: Tom Hubrecht <tom.hubrecht@ens.fr>
Reviewed-on: https://git.rz.ens.wtf/Klub-RZ/metis/pulls/17
Co-authored-by: tomate <tom.hubrecht@ens.fr>
Co-committed-by: tomate <tom.hubrecht@ens.fr>
This commit is contained in:
tomate 2022-03-29 20:22:05 +02:00
parent 2a5f56ff37
commit 1559e5cdd9
3 changed files with 38 additions and 6 deletions

View file

@ -6,6 +6,8 @@
import { createTriState, createTriStates, UNCHECKED, CHECKED, WEIRD } from './stores';
import { Icon } from 'sveltestrap';
import { mkSource } from './calendar.js';
export let item = null;
export let level = 1;
export let generalToggle = undefined;
@ -78,6 +80,11 @@
});
}
const url = (() => {
const source = mkSource(item);
return source ? source.export_url : undefined;
})();
$: selected =
$filtering === CHECKED ? [item, ...subselected.flat()] : subselected.flat();
$: subHidden = () => (collapsed ? 'd-none' : '');
@ -90,6 +97,7 @@
on:change={handleChange}
value={item}
bind:collapsed
{url}
/>
</div>

View file

@ -4,6 +4,7 @@
export let state;
export let value;
export let collapsed = undefined;
export let url;
import { UNCHECKED, CHECKED, WEIRD } from './stores';
import { createEventDispatcher } from 'svelte';
@ -28,14 +29,32 @@
<span class="cal w-100 d-block" on:click={handleClick}>
<Icon name={icon} class="ms-2" />
<span class="ms-1">{value}</span>
{#if collapsed !== undefined}
<span class="float-end" on:click|stopPropagation={() => (collapsed = !collapsed)}>
<Icon name={chevron} />
</span>
{/if}
<span class="float-end">
{#if url}
<a href={url} class="cal-link" download={value} on:click|stopPropagation>
<Icon name="cloud-download" />
</a>
{/if}
{#if collapsed !== undefined}
<span class="cal-link" on:click|stopPropagation={() => (collapsed = !collapsed)}>
<Icon name={chevron} />
</span>
{/if}
</span>
</span>
<style>
.cal-link {
margin-right: 0.5rem;
padding: 3px;
color: inherit;
}
.cal-link:hover {
color: #aabbfe;
text-shadow: 2px 2px 3px #62a1fe;
}
.cal {
cursor: pointer;
padding: 0.2em;

View file

@ -82,6 +82,10 @@ function mkCalendarUrl(id, { cloud }, extra = {}) {
)
}
function mkExportUrl(id, { cloud }) {
return `/cal/${cloud}/${id}/?export`
}
function fetchCalendar(id, cal, extra = {}) {
return fetch(mkCalendarUrl(id, cal, extra), { credentials: 'omit' })
.then(resp => resp.json())
@ -178,6 +182,7 @@ export function mkSource(name) {
start: start.valueOf() / 1000,
end: end.valueOf() / 1000
}).then(successCallback, failureCallback)
}
},
export_url: mkExportUrl(calendarId, calendar)
}
}