http.js add missing resources
This commit is contained in:
parent
16d88f11b0
commit
6c316e8032
1 changed files with 52 additions and 4 deletions
|
@ -6,12 +6,24 @@ serve({
|
||||||
fetch(request) {
|
fetch(request) {
|
||||||
console.log(`${request.method}: ${request.url}`);
|
console.log(`${request.method}: ${request.url}`);
|
||||||
if (request.method === 'POST') {
|
if (request.method === 'POST') {
|
||||||
const json = JSON.stringify(getBody());
|
const url = new URL(request.url);
|
||||||
|
let json;
|
||||||
|
if (url.pathname === '/GetSVGLayoutConfiguration') {
|
||||||
|
json = JSON.stringify(GetSVGLayoutConfiguration());
|
||||||
|
} else if (url.pathname === 'FillHoleWithChassis') {
|
||||||
|
json = JSON.stringify(FillHoleWithChassis(request));
|
||||||
|
} else if (url.pathname === 'FillHoleWithChassis') {
|
||||||
|
json = JSON.stringify(SplitRemplissage(request));
|
||||||
|
} else {
|
||||||
|
// TODO: Return 404 rather than this
|
||||||
|
json = JSON.stringify(GetSVGLayoutConfiguration());
|
||||||
|
}
|
||||||
return new Response(json, {
|
return new Response(json, {
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'Access-Control-Allow-Origin': '*'
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
'Access-Control-Allow-Headers': '*'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -20,13 +32,14 @@ serve({
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'text/plain',
|
'Content-Type': 'text/plain',
|
||||||
'Access-Control-Allow-Origin': '*'
|
'Access-Control-Allow-Origin': '*',
|
||||||
|
'Access-Control-Allow-Headers': '*'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const getBody = () => {
|
const GetSVGLayoutConfiguration = () => {
|
||||||
return {
|
return {
|
||||||
AvailableContainers: [
|
AvailableContainers: [
|
||||||
{
|
{
|
||||||
|
@ -118,3 +131,38 @@ const getBody = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const FillHoleWithChassis = (request) => {
|
||||||
|
const maxWidthChassis = 3000;
|
||||||
|
const nbChassis = Math.ceil(request.ContainerActions.Width / maxWidthChassis);
|
||||||
|
const lstModels = [];
|
||||||
|
for (let i = 0; i <= nbChassis; i++) {
|
||||||
|
if (i === 1 && request.ContainerAction.ExistOnBefore) {
|
||||||
|
lstModels.Add({ Type: 'Dilatation' });
|
||||||
|
}
|
||||||
|
lstModels.Add({ Type: 'Chassis' });
|
||||||
|
if (i < nbChassis) {
|
||||||
|
lstModels.Add({ Type: 'Dilatation' });
|
||||||
|
}
|
||||||
|
if (i === nbChassis && request.ContainerAction.ExistOnAfter) {
|
||||||
|
lstModels.Add({ Type: 'Dilatation' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
ApplicationState: {
|
||||||
|
Containers: lstModels
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const SplitRemplissage = (request) => {
|
||||||
|
const lstModels = [
|
||||||
|
{ Type: 'Remplissage' },
|
||||||
|
{ Type: 'Montant' },
|
||||||
|
{ Type: 'Remplissage' }
|
||||||
|
];
|
||||||
|
|
||||||
|
return {
|
||||||
|
ApplicationState: { Containers: lstModels }
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue