forked from DGNum/metis
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:
parent
2a5f56ff37
commit
1559e5cdd9
3 changed files with 38 additions and 6 deletions
|
@ -6,6 +6,8 @@
|
||||||
import { createTriState, createTriStates, UNCHECKED, CHECKED, WEIRD } from './stores';
|
import { createTriState, createTriStates, UNCHECKED, CHECKED, WEIRD } from './stores';
|
||||||
import { Icon } from 'sveltestrap';
|
import { Icon } from 'sveltestrap';
|
||||||
|
|
||||||
|
import { mkSource } from './calendar.js';
|
||||||
|
|
||||||
export let item = null;
|
export let item = null;
|
||||||
export let level = 1;
|
export let level = 1;
|
||||||
export let generalToggle = undefined;
|
export let generalToggle = undefined;
|
||||||
|
@ -78,6 +80,11 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const url = (() => {
|
||||||
|
const source = mkSource(item);
|
||||||
|
return source ? source.export_url : undefined;
|
||||||
|
})();
|
||||||
|
|
||||||
$: selected =
|
$: selected =
|
||||||
$filtering === CHECKED ? [item, ...subselected.flat()] : subselected.flat();
|
$filtering === CHECKED ? [item, ...subselected.flat()] : subselected.flat();
|
||||||
$: subHidden = () => (collapsed ? 'd-none' : '');
|
$: subHidden = () => (collapsed ? 'd-none' : '');
|
||||||
|
@ -90,6 +97,7 @@
|
||||||
on:change={handleChange}
|
on:change={handleChange}
|
||||||
value={item}
|
value={item}
|
||||||
bind:collapsed
|
bind:collapsed
|
||||||
|
{url}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
export let state;
|
export let state;
|
||||||
export let value;
|
export let value;
|
||||||
export let collapsed = undefined;
|
export let collapsed = undefined;
|
||||||
|
export let url;
|
||||||
|
|
||||||
import { UNCHECKED, CHECKED, WEIRD } from './stores';
|
import { UNCHECKED, CHECKED, WEIRD } from './stores';
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
@ -28,14 +29,32 @@
|
||||||
<span class="cal w-100 d-block" on:click={handleClick}>
|
<span class="cal w-100 d-block" on:click={handleClick}>
|
||||||
<Icon name={icon} class="ms-2" />
|
<Icon name={icon} class="ms-2" />
|
||||||
<span class="ms-1">{value}</span>
|
<span class="ms-1">{value}</span>
|
||||||
{#if collapsed !== undefined}
|
<span class="float-end">
|
||||||
<span class="float-end" on:click|stopPropagation={() => (collapsed = !collapsed)}>
|
{#if url}
|
||||||
<Icon name={chevron} />
|
<a href={url} class="cal-link" download={value} on:click|stopPropagation>
|
||||||
</span>
|
<Icon name="cloud-download" />
|
||||||
{/if}
|
</a>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if collapsed !== undefined}
|
||||||
|
<span class="cal-link" on:click|stopPropagation={() => (collapsed = !collapsed)}>
|
||||||
|
<Icon name={chevron} />
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
.cal-link {
|
||||||
|
margin-right: 0.5rem;
|
||||||
|
padding: 3px;
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
.cal-link:hover {
|
||||||
|
color: #aabbfe;
|
||||||
|
text-shadow: 2px 2px 3px #62a1fe;
|
||||||
|
}
|
||||||
|
|
||||||
.cal {
|
.cal {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding: 0.2em;
|
padding: 0.2em;
|
||||||
|
|
|
@ -82,6 +82,10 @@ function mkCalendarUrl(id, { cloud }, extra = {}) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function mkExportUrl(id, { cloud }) {
|
||||||
|
return `/cal/${cloud}/${id}/?export`
|
||||||
|
}
|
||||||
|
|
||||||
function fetchCalendar(id, cal, extra = {}) {
|
function fetchCalendar(id, cal, extra = {}) {
|
||||||
return fetch(mkCalendarUrl(id, cal, extra), { credentials: 'omit' })
|
return fetch(mkCalendarUrl(id, cal, extra), { credentials: 'omit' })
|
||||||
.then(resp => resp.json())
|
.then(resp => resp.json())
|
||||||
|
@ -178,6 +182,7 @@ export function mkSource(name) {
|
||||||
start: start.valueOf() / 1000,
|
start: start.valueOf() / 1000,
|
||||||
end: end.valueOf() / 1000
|
end: end.valueOf() / 1000
|
||||||
}).then(successCallback, failureCallback)
|
}).then(successCallback, failureCallback)
|
||||||
}
|
},
|
||||||
|
export_url: mkExportUrl(calendarId, calendar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue