mirror of
https://github.com/1f349/admin.1f349.com.git
synced 2024-11-09 22:32:57 +00:00
Bring routes and redirects views closer in implementation
This commit is contained in:
parent
3e22444b4f
commit
1d7b2842c3
@ -9,9 +9,9 @@
|
|||||||
const apiViolet = import.meta.env.VITE_API_VIOLET;
|
const apiViolet = import.meta.env.VITE_API_VIOLET;
|
||||||
|
|
||||||
let tableData: {[key: string]: CSPair<Redirect>} = {};
|
let tableData: {[key: string]: CSPair<Redirect>} = {};
|
||||||
let redirectSrcs: string[] = [];
|
let tableKeys: string[] = [];
|
||||||
|
|
||||||
$: redirectSrcs = Object.entries(tableData)
|
$: tableKeys = Object.entries(tableData)
|
||||||
.filter(x => x[1].client != null || x[1].server != null)
|
.filter(x => x[1].client != null || x[1].server != null)
|
||||||
.map(x => x[0])
|
.map(x => x[0])
|
||||||
.filter(x => domainFilter(x, $domainOption))
|
.filter(x => domainFilter(x, $domainOption))
|
||||||
@ -26,19 +26,18 @@
|
|||||||
return p.endsWith(domain);
|
return p.endsWith(domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
let promiseForRedirects: Promise<void> = reloadRedirects(true);
|
let promiseForTable: Promise<void> = reloadTable(true);
|
||||||
|
|
||||||
function reloadRedirects(firstLoad: boolean = false): Promise<void> {
|
function reloadTable(firstLoad: boolean = false): Promise<void> {
|
||||||
return new Promise<void>((res, rej) => {
|
return new Promise<void>((res, rej) => {
|
||||||
fetch(apiViolet + "/redirect", {headers: {Authorization: getBearer()}})
|
fetch(apiViolet + "/redirect", {headers: {Authorization: getBearer()}})
|
||||||
.then(x => {
|
.then(x => {
|
||||||
if (x.status != 200) throw new Error("Unexpected status code: " + x.status);
|
if (x.status !== 200) throw new Error("Unexpected status code: " + x.status);
|
||||||
return x.json();
|
return x.json();
|
||||||
})
|
})
|
||||||
.then(x => {
|
.then(x => {
|
||||||
let redirects = x as Redirect[];
|
let rows = x as Redirect[];
|
||||||
let y: {[key: string]: CSPair<Redirect>} = {};
|
rows.forEach(x => {
|
||||||
redirects.forEach(x => {
|
|
||||||
tableData[x.src] = {
|
tableData[x.src] = {
|
||||||
client: firstLoad || !tableData[x.src] ? JSON.parse(JSON.stringify(x)) : tableData[x.src]?.client,
|
client: firstLoad || !tableData[x.src] ? JSON.parse(JSON.stringify(x)) : tableData[x.src]?.client,
|
||||||
server: x,
|
server: x,
|
||||||
@ -57,7 +56,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function saveChanges() {
|
function saveChanges() {
|
||||||
let redirectPromises = redirectSrcs
|
let tableProm = tableKeys
|
||||||
.map(x => tableData[x])
|
.map(x => tableData[x])
|
||||||
.filter(x => x.client != null || x.server != null)
|
.filter(x => x.client != null || x.server != null)
|
||||||
.filter(x => !redirectEqual(x.client, x.server))
|
.filter(x => !redirectEqual(x.client, x.server))
|
||||||
@ -77,8 +76,8 @@
|
|||||||
return x.v.p;
|
return x.v.p;
|
||||||
});
|
});
|
||||||
|
|
||||||
Promise.all(redirectPromises)
|
Promise.all(tableProm)
|
||||||
.then(_ => reloadRedirects())
|
.then(_ => reloadTable())
|
||||||
.catch(_ => {
|
.catch(_ => {
|
||||||
alert("Some rows failed to save changes");
|
alert("Some rows failed to save changes");
|
||||||
});
|
});
|
||||||
@ -91,7 +90,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="scrolling-area">
|
<div class="scrolling-area">
|
||||||
{#await promiseForRedirects}
|
{#await promiseForTable}
|
||||||
<div class="text-padding">
|
<div class="text-padding">
|
||||||
<div>Loading...</div>
|
<div>Loading...</div>
|
||||||
</div>
|
</div>
|
||||||
@ -111,13 +110,13 @@
|
|||||||
on:make={e => {
|
on:make={e => {
|
||||||
const x = e.detail;
|
const x = e.detail;
|
||||||
tableData[x.src] = {client: x, server: tableData[x.src]?.server, p: Promise.resolve()};
|
tableData[x.src] = {client: x, server: tableData[x.src]?.server, p: Promise.resolve()};
|
||||||
redirectSrcs.push(x.src);
|
tableKeys.push(x.src);
|
||||||
redirectSrcs = redirectSrcs;
|
tableKeys = tableKeys;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{#each redirectSrcs as src (src)}
|
{#each tableKeys as src (src)}
|
||||||
{#await tableData[src].p}
|
{#await tableData[src].p}
|
||||||
<tr><td colspan="5">Loading...</td></tr>
|
<tr><td colspan="5">Loading...</td></tr>
|
||||||
{:then _}
|
{:then _}
|
||||||
|
@ -26,9 +26,9 @@
|
|||||||
return p.endsWith(domain);
|
return p.endsWith(domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
let promiseForRoutes: Promise<void> = reloadRoutes(true);
|
let promiseForTable: Promise<void> = reloadTable(true);
|
||||||
|
|
||||||
function reloadRoutes(firstLoad: boolean = false): Promise<void> {
|
function reloadTable(firstLoad: boolean = false): Promise<void> {
|
||||||
return new Promise<void>((res, rej) => {
|
return new Promise<void>((res, rej) => {
|
||||||
fetch(apiViolet + "/route", {headers: {Authorization: getBearer()}})
|
fetch(apiViolet + "/route", {headers: {Authorization: getBearer()}})
|
||||||
.then(x => {
|
.then(x => {
|
||||||
@ -36,9 +36,8 @@
|
|||||||
return x.json();
|
return x.json();
|
||||||
})
|
})
|
||||||
.then(x => {
|
.then(x => {
|
||||||
let routes = x as Route[];
|
let rows = x as Route[];
|
||||||
let y: {[key: string]: CSPair<Route>} = {};
|
rows.forEach(x => {
|
||||||
routes.forEach(x => {
|
|
||||||
tableData[x.src] = {
|
tableData[x.src] = {
|
||||||
client: firstLoad || !tableData[x.src] ? JSON.parse(JSON.stringify(x)) : tableData[x.src]?.client,
|
client: firstLoad || !tableData[x.src] ? JSON.parse(JSON.stringify(x)) : tableData[x.src]?.client,
|
||||||
server: x,
|
server: x,
|
||||||
@ -57,7 +56,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function saveChanges() {
|
function saveChanges() {
|
||||||
let routePromises = tableKeys
|
let tableProm = tableKeys
|
||||||
.map(x => tableData[x])
|
.map(x => tableData[x])
|
||||||
.filter(x => x.client != null || x.server != null)
|
.filter(x => x.client != null || x.server != null)
|
||||||
.filter(x => !routeEqual(x.client, x.server))
|
.filter(x => !routeEqual(x.client, x.server))
|
||||||
@ -77,8 +76,8 @@
|
|||||||
return x.v.p;
|
return x.v.p;
|
||||||
});
|
});
|
||||||
|
|
||||||
Promise.all(routePromises)
|
Promise.all(tableProm)
|
||||||
.then(_ => reloadRoutes())
|
.then(_ => reloadTable())
|
||||||
.catch(_ => {
|
.catch(_ => {
|
||||||
alert("Some rows failed to save changes");
|
alert("Some rows failed to save changes");
|
||||||
});
|
});
|
||||||
@ -91,7 +90,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="scrolling-area">
|
<div class="scrolling-area">
|
||||||
{#await promiseForRoutes}
|
{#await promiseForTable}
|
||||||
<div class="text-padding">
|
<div class="text-padding">
|
||||||
<div>Loading...</div>
|
<div>Loading...</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user