Sanitize lib paths

This commit is contained in:
nemunaire 2022-10-15 11:12:51 +02:00
commit e9a906fbfb
43 changed files with 68 additions and 66 deletions

View file

@ -0,0 +1,51 @@
import { derived, writable } from 'svelte/store';
import { getActions } from '$lib/action'
function createActionsStore() {
const { subscribe, set, update } = writable({list: null, fileIdx: null});
return {
subscribe,
set: (v) => {
update((m) => Object.assign(m, v));
},
refresh: async () => {
const list = await getActions();
const fileIdx = {};
list.forEach(function(action, k) {
fileIdx[action.path] = action;
});
update((m) => (Object.assign(m, {list, fileIdx})));
return list;
},
update: (res_actions, cb=null) => {
if (res_actions.status === 200) {
res_actions.json().then((list) => {
const fileIdx = {};
list.forEach(function(action, k) {
fileIdx[action.path] = action;
})
update((m) => (Object.assign(m, {list, fileIdx})));
if (cb) {
cb(list);
}
});
}
},
};
}
export const actions = createActionsStore();
export const actions_idx = derived(
actions,
($actions) => ($actions.fileIdx),
);

View file

@ -0,0 +1,41 @@
import { derived, writable } from 'svelte/store';
import { getAlarmsException } from '$lib/alarmexception'
function createAlarmsExceptionStore() {
const { subscribe, set, update } = writable({list: null});
return {
subscribe,
set: (v) => {
update((m) => Object.assign(m, v));
},
clear: () => {
update((m) => m = {list: null});
},
refresh: async () => {
const list = await getAlarmsException();
update((m) => (Object.assign(m, {list})));
return list;
},
update: (res_AlarmsException, cb=null) => {
if (res_AlarmsException.status === 200) {
res_AlarmsException.json().then((list) => {
update((m) => (Object.assign(m, {list})));
if (cb) {
cb(list);
}
});
}
},
};
}
export const alarmsExceptions = createAlarmsExceptionStore();

View file

@ -0,0 +1,41 @@
import { derived, writable } from 'svelte/store';
import { getAlarmsRepeated } from '$lib/alarmrepeated'
function createAlarmsRepeatedStore() {
const { subscribe, set, update } = writable({list: null});
return {
subscribe,
set: (v) => {
update((m) => Object.assign(m, v));
},
clear: () => {
update((m) => m = {list: null});
},
refresh: async () => {
const list = await getAlarmsRepeated();
update((m) => (Object.assign(m, {list})));
return list;
},
update: (res_AlarmsRepeated, cb=null) => {
if (res_AlarmsRepeated.status === 200) {
res_AlarmsRepeated.json().then((list) => {
update((m) => (Object.assign(m, {list})));
if (cb) {
cb(list);
}
});
}
},
};
}
export const alarmsRepeated = createAlarmsRepeatedStore();

View file

@ -0,0 +1,41 @@
import { derived, writable } from 'svelte/store';
import { getAlarmsSingle } from '$lib/alarmsingle'
function createAlarmsSingleStore() {
const { subscribe, set, update } = writable({list: null});
return {
subscribe,
set: (v) => {
update((m) => Object.assign(m, v));
},
clear: () => {
update((m) => m = {list: null});
},
refresh: async () => {
const list = await getAlarmsSingle();
update((m) => (Object.assign(m, {list})));
return list;
},
update: (res_AlarmsSingle, cb=null) => {
if (res_AlarmsSingle.status === 200) {
res_AlarmsSingle.json().then((list) => {
update((m) => (Object.assign(m, {list})));
if (cb) {
cb(list);
}
});
}
},
};
}
export const alarmsSingle = createAlarmsSingleStore();

View file

@ -0,0 +1,36 @@
import { writable } from 'svelte/store';
import { getGongs } from '$lib/gong'
function createGongsStore() {
const { subscribe, set, update } = writable({list: null});
return {
subscribe,
set: (v) => {
update((m) => Object.assign(m, v));
},
refresh: async () => {
const list = await getGongs();
update((m) => Object.assign(m, {list}));
return list;
},
update: (res_gongs, cb=null) => {
if (res_gongs.status === 200) {
res_gongs.json().then((list) => {
update((m) => (Object.assign(m, {list})));
if (cb) {
cb(list);
}
});
}
},
};
}
export const gongs = createGongsStore();

View file

@ -0,0 +1,43 @@
import { writable } from 'svelte/store';
function createQuotesStore() {
const { subscribe, set, update } = writable({quotes: [], quoteOfTheDay: null});
return {
subscribe,
set: (quotes) => {
update((m) => Object.assign(m, {quotes}));
},
setQOTD: (quoteOfTheDay) => {
update((m) => Object.assign(m, {quoteOfTheDay}));
},
refreshQOTD: async () => {
const res = await fetch(`api/quoteoftheday`, {headers: {'Accept': 'application/json'}})
if (res.status == 200) {
const quoteOfTheDay = await res.json();
update((m) => Object.assign(m, {quoteOfTheDay}));
return quoteOfTheDay;
} else {
throw new Error((await res.json()).errmsg);
}
},
update: (res_quotes, cb=null) => {
if (res_quotes.status === 200) {
res_quotes.json().then((quotes) => {
update((m) => (Object.assign(m, {quotes})));
if (cb) {
cb(quotes);
}
});
}
},
};
}
export const quotes = createQuotesStore();

View file

@ -0,0 +1,36 @@
import { writable } from 'svelte/store';
import { getRoutines } from '$lib/routine'
function createRoutinesStore() {
const { subscribe, set, update } = writable({list: null});
return {
subscribe,
set: (v) => {
update((m) => Object.assign(m, v));
},
refresh: async () => {
const list = await getRoutines();
update((m) => Object.assign(m, {list}));
return list;
},
update: (res_routines, cb=null) => {
if (res_routines.status === 200) {
res_routines.json().then((list) => {
update((m) => (Object.assign(m, {list})));
if (cb) {
cb(list);
}
});
}
},
};
}
export const routines = createRoutinesStore();

View file

@ -0,0 +1,41 @@
import { writable } from 'svelte/store';
function createToastsStore() {
const { subscribe, update } = writable({toasts: []});
const addToast = (o) => {
o.timestamp = new Date();
o.close = () => {
update((i) => {
i.toasts = i.toasts.filter((j) => {
return !(j.title === o.title && j.msg === o.msg && j.timestamp === o.timestamp)
});
return i;
});
}
update((i) => {
i.toasts.unshift(o);
return i;
});
o.cancel = setTimeout(o.close, o.dismiss?o.dismiss:5000);
};
const addErrorToast = (o) => {
if (!o.title) o.title = 'Une erreur est survenue !';
if (!o.color) o.color = 'danger';
return addToast(o);
};
return {
subscribe,
addToast,
addErrorToast,
};
}
export const ToastsStore = createToastsStore();

View file

@ -0,0 +1,36 @@
import { writable } from 'svelte/store';
import { getTracks } from '$lib/track'
function createTracksStore() {
const { subscribe, set, update } = writable({list: null});
return {
subscribe,
set: (v) => {
update((m) => Object.assign(m, v));
},
refresh: async () => {
const list = await getTracks();
update((m) => Object.assign(m, {list}));
return list;
},
update: (res_tracks, cb=null) => {
if (res_tracks.status === 200) {
res_tracks.json().then((list) => {
update((m) => (Object.assign(m, {list})));
if (cb) {
cb(list);
}
});
}
},
};
}
export const tracks = createTracksStore();