feat(data): fetch /auth/me on load, store ZAMPP_DATA.ME with name/initials/role
This commit is contained in:
parent
854775e322
commit
eed4180b70
1 changed files with 14 additions and 1 deletions
|
|
@ -11,6 +11,7 @@ window.ZAMPP_DATA = {
|
||||||
USERS: [],
|
USERS: [],
|
||||||
BINS: [],
|
BINS: [],
|
||||||
COMMENTS: [],
|
COMMENTS: [],
|
||||||
|
ME: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
async function apiFetch(path, opts = {}) {
|
async function apiFetch(path, opts = {}) {
|
||||||
|
|
@ -111,7 +112,7 @@ function normalizeJob(j) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadData() {
|
async function loadData() {
|
||||||
const [projectsR, assetsR, recordersR, jobsR, clusterR, usersR, binsR] = await Promise.allSettled([
|
const [projectsR, assetsR, recordersR, jobsR, clusterR, usersR, binsR, meR] = await Promise.allSettled([
|
||||||
apiFetch('/projects'),
|
apiFetch('/projects'),
|
||||||
apiFetch('/assets?limit=500'),
|
apiFetch('/assets?limit=500'),
|
||||||
apiFetch('/recorders'),
|
apiFetch('/recorders'),
|
||||||
|
|
@ -119,6 +120,7 @@ async function loadData() {
|
||||||
apiFetch('/cluster'),
|
apiFetch('/cluster'),
|
||||||
apiFetch('/users'),
|
apiFetch('/users'),
|
||||||
apiFetch('/bins'),
|
apiFetch('/bins'),
|
||||||
|
apiFetch('/auth/me'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const projectMap = {};
|
const projectMap = {};
|
||||||
|
|
@ -171,6 +173,17 @@ async function loadData() {
|
||||||
icon: b.type || 'grid',
|
icon: b.type || 'grid',
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (meR.status === 'fulfilled' && meR.value) {
|
||||||
|
const me = meR.value;
|
||||||
|
window.ZAMPP_DATA.ME = {
|
||||||
|
id: me.id,
|
||||||
|
username: me.username,
|
||||||
|
name: me.display_name || me.username || 'User',
|
||||||
|
initials: (me.display_name || me.username || 'U').slice(0, 2).toUpperCase(),
|
||||||
|
role: me.role || 'viewer',
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.ZAMPP_API = { fetch: apiFetch, loadData, fmtDuration, fmtSize, fmtRelative };
|
window.ZAMPP_API = { fetch: apiFetch, loadData, fmtDuration, fmtSize, fmtRelative };
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue