Merge pull request 'Raccourcit les liens de partage' (#47) from thubrecht/reduce-share into master
Reviewed-on: https://git.rz.ens.wtf/Klub-RZ/metis/pulls/47
This commit is contained in:
commit
0ee44ac32a
2 changed files with 26 additions and 1 deletions
|
@ -9,6 +9,8 @@
|
||||||
Toast
|
Toast
|
||||||
} from 'sveltestrap';
|
} from 'sveltestrap';
|
||||||
|
|
||||||
|
import { ancestors } from './calendar';
|
||||||
|
|
||||||
export let calendar = null;
|
export let calendar = null;
|
||||||
export let selectedCalendars = [];
|
export let selectedCalendars = [];
|
||||||
|
|
||||||
|
@ -33,6 +35,16 @@
|
||||||
.finally((isToastOpen = true));
|
.finally((isToastOpen = true));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const filter = calendars => {
|
||||||
|
let reduced = [];
|
||||||
|
calendars.forEach(c => {
|
||||||
|
if (!ancestors[c].some(p => calendars.includes(p))) {
|
||||||
|
reduced.push(c);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return reduced;
|
||||||
|
};
|
||||||
|
|
||||||
const updateShareLink = () => {
|
const updateShareLink = () => {
|
||||||
const loc = document.location;
|
const loc = document.location;
|
||||||
const search = new URLSearchParams();
|
const search = new URLSearchParams();
|
||||||
|
@ -41,7 +53,7 @@
|
||||||
if (calendar !== null) {
|
if (calendar !== null) {
|
||||||
search.append('v', api.view.type);
|
search.append('v', api.view.type);
|
||||||
|
|
||||||
selectedCalendars.forEach(c => search.append('c', c));
|
filter(selectedCalendars).forEach(c => search.append('c', c));
|
||||||
|
|
||||||
search.append('d', api.getDate().toISOString());
|
search.append('d', api.getDate().toISOString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,6 +176,19 @@ export const calendarTree = {
|
||||||
Divers: {}
|
Divers: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dfs = (p, t, l) => {
|
||||||
|
for (const [c, s] of Object.entries(t)) {
|
||||||
|
l[c] = p === null ? [] : [p, ...l[p]]
|
||||||
|
dfs(c, s, l)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ancestors = (() => {
|
||||||
|
let l = []
|
||||||
|
dfs(null, calendarTree, l)
|
||||||
|
return l
|
||||||
|
})()
|
||||||
|
|
||||||
export function getSubCalendars(name, tree = calendarTree) {
|
export function getSubCalendars(name, tree = calendarTree) {
|
||||||
let ret
|
let ret
|
||||||
for (const [cal, subTree] of Object.entries(tree)) {
|
for (const [cal, subTree] of Object.entries(tree)) {
|
||||||
|
|
Loading…
Reference in a new issue