Merged PR 205: Add new AddingBehavior ReplaceParent + Allow AddingBehavior override by response + fix double key in context menu + Rename node-http.js to http.js
This commit is contained in:
parent
34c00d267c
commit
38a6919192
7 changed files with 151 additions and 379 deletions
|
@ -1,62 +1,69 @@
|
|||
// http.js
|
||||
import { serve } from 'bun';
|
||||
import http from 'http';
|
||||
const host = 'localhost';
|
||||
const port = 5000;
|
||||
|
||||
serve({
|
||||
port: 5000,
|
||||
async fetch(request) {
|
||||
console.log(`${request.method}: ${request.url}`);
|
||||
if (request.method === 'POST') {
|
||||
const url = new URL(request.url);
|
||||
let json;
|
||||
if (url.pathname === '/GetSVGLayoutConfiguration') {
|
||||
json = GetSVGLayoutConfiguration();
|
||||
} else if (url.pathname === '/SetContainerList') {
|
||||
const bodyParsed = await request.json();
|
||||
console.log(bodyParsed);
|
||||
switch (bodyParsed.Action) {
|
||||
case 'FillHoleWithChassis':
|
||||
json = FillHoleWithChassis(bodyParsed);
|
||||
break;
|
||||
case 'SplitRemplissage':
|
||||
json = SplitRemplissage(bodyParsed);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (url.pathname === '/GetFeedback') {
|
||||
const bodyParsed = await request.json();
|
||||
console.log(bodyParsed);
|
||||
json = {
|
||||
messages: [
|
||||
{
|
||||
text: `${new Date()}`,
|
||||
type: 3
|
||||
}
|
||||
]
|
||||
}
|
||||
} else {
|
||||
// TODO: Return 404 rather than this
|
||||
json = GetSVGLayoutConfiguration();
|
||||
const requestListener = async (request, response) => {
|
||||
response.setHeader('Access-Control-Allow-Origin', '*');
|
||||
response.setHeader('Access-Control-Allow-Headers', '*');
|
||||
response.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
||||
if (request.method === 'POST') {
|
||||
response.setHeader('Content-Type', 'application/json');
|
||||
const url = request.url;
|
||||
let json;
|
||||
if (url === '/SetContainerList') {
|
||||
const buffers = [];
|
||||
for await (const chunk of request) {
|
||||
buffers.push(chunk);
|
||||
}
|
||||
return new Response(JSON.stringify(json), {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Headers': '*'
|
||||
}
|
||||
});
|
||||
const data = Buffer.concat(buffers).toString();
|
||||
const bodyParsed = JSON.parse(data);
|
||||
console.log(bodyParsed);
|
||||
switch (bodyParsed.Action.Action) {
|
||||
case 'FillHoleWithChassis':
|
||||
json = FillHoleWithChassis(bodyParsed);
|
||||
break;
|
||||
case 'SplitRemplissage':
|
||||
json = SplitRemplissage(bodyParsed);
|
||||
break;
|
||||
case 'SplitRemplissageParent':
|
||||
json = SplitRemplissage(bodyParsed);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else if (url === '/GetFeedback') {
|
||||
const buffers = [];
|
||||
for await (const chunk of request) {
|
||||
buffers.push(chunk);
|
||||
}
|
||||
const data = Buffer.concat(buffers).toString();
|
||||
const bodyParsed = JSON.parse(data);
|
||||
console.log(bodyParsed);
|
||||
json = {
|
||||
messages: [
|
||||
{
|
||||
text: `${new Date()}`,
|
||||
type: 3
|
||||
}
|
||||
]
|
||||
}
|
||||
} else {
|
||||
json = GetSVGLayoutConfiguration();
|
||||
}
|
||||
|
||||
return new Response('Welcome to Bun!', {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'text/plain',
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
'Access-Control-Allow-Headers': '*'
|
||||
}
|
||||
});
|
||||
response.writeHead(200);
|
||||
return response.end(JSON.stringify(json));
|
||||
} else if (request.method === 'OPTIONS') {
|
||||
response.writeHead(200);
|
||||
return response.end();
|
||||
}
|
||||
|
||||
response.setHeader('Content-Type', 'text/plain');
|
||||
response.writeHead(200);
|
||||
return response.end('Hello world');
|
||||
};
|
||||
|
||||
const server = http.createServer(requestListener);
|
||||
server.listen(port, host, () => {
|
||||
console.log(`Server is running on http://${host}:${port}`);
|
||||
});
|
||||
|
||||
const GetSVGLayoutConfiguration = () => {
|
||||
|
@ -64,11 +71,8 @@ const GetSVGLayoutConfiguration = () => {
|
|||
AvailableContainers: [
|
||||
{
|
||||
Type: 'Chassis',
|
||||
DisplayedText: 'Chassis?',
|
||||
Whitelist: ["Trou"],
|
||||
MaxWidth: 500,
|
||||
MinWidth: 200,
|
||||
Width: 200,
|
||||
DisplayedText: 'Chassis horizontal',
|
||||
MaxHeight: 200,
|
||||
DefaultChildType: 'Trou',
|
||||
Style: {
|
||||
fillOpacity: 1,
|
||||
|
@ -76,8 +80,24 @@ const GetSVGLayoutConfiguration = () => {
|
|||
stroke: 'red',
|
||||
fill: '#d3c9b7',
|
||||
},
|
||||
ShowSelfDimensions: true,
|
||||
IsDimensionBorrower: true,
|
||||
ShowSelfDimensions: [0, 2],
|
||||
ShowDimensionWithMarks: [1, 3],
|
||||
Category: "Stuff"
|
||||
},
|
||||
{
|
||||
Type: 'ChassisVertical',
|
||||
Orientation: 1,
|
||||
DisplayedText: 'Chassis vertical',
|
||||
MaxWidth: 200,
|
||||
DefaultChildType: 'Trou',
|
||||
Style: {
|
||||
fillOpacity: 1,
|
||||
strokeWidth: 2,
|
||||
stroke: 'red',
|
||||
fill: '#d3c9b7',
|
||||
},
|
||||
ShowSelfDimensions: [0, 2],
|
||||
ShowDimensionWithMarks: [1, 3],
|
||||
Category: "Stuff"
|
||||
},
|
||||
{
|
||||
|
@ -121,6 +141,19 @@ const GetSVGLayoutConfiguration = () => {
|
|||
Url: ""
|
||||
},
|
||||
AddingBehavior: 2
|
||||
},
|
||||
{
|
||||
Id: "SplitRemplissageParent",
|
||||
Action: "SplitRemplissageParent",
|
||||
Label: "Diviser le parent",
|
||||
Description: "Diviser le remplissage en insérant un montant",
|
||||
CustomLogo: {
|
||||
Base64Image: null,
|
||||
Name: 'Image1',
|
||||
Svg: null,
|
||||
Url: ""
|
||||
},
|
||||
AddingBehavior: 3
|
||||
}
|
||||
],
|
||||
Style: {
|
||||
|
@ -138,8 +171,8 @@ const GetSVGLayoutConfiguration = () => {
|
|||
{
|
||||
Type: 'Montant',
|
||||
Width: 10,
|
||||
PositionReference: 1,
|
||||
MarkPositionToDimensionBorrower: true,
|
||||
PositionReference: 4,
|
||||
MarkPositionToDimensionBorrower: [0],
|
||||
Style: {
|
||||
fillOpacity: 0,
|
||||
strokeWidth: 2,
|
||||
|
@ -147,11 +180,24 @@ const GetSVGLayoutConfiguration = () => {
|
|||
fill: '#713f12',
|
||||
}
|
||||
},
|
||||
{
|
||||
Type: 'Traverse',
|
||||
Height: 10,
|
||||
PositionReference: 4,
|
||||
Orientation: 1,
|
||||
MarkPositionToDimensionBorrower: [1],
|
||||
Style: {
|
||||
fillOpacity: 0,
|
||||
strokeWidth: 2,
|
||||
stroke: '#6517fa',
|
||||
fill: '#6517fa',
|
||||
}
|
||||
},
|
||||
{
|
||||
Type: 'Dilatation',
|
||||
Width: 4,
|
||||
PositionReference: 1,
|
||||
MarkPositionToDimensionBorrower: true,
|
||||
MarkPositionToDimensionBorrower: [0],
|
||||
Style: {
|
||||
fillOpacity: 0,
|
||||
strokeWidth: 2,
|
||||
|
@ -222,7 +268,13 @@ const GetSVGLayoutConfiguration = () => {
|
|||
MainContainer: {
|
||||
Type: 'main',
|
||||
Width: 800,
|
||||
Height: 200
|
||||
Height: 800,
|
||||
Orientation: 1,
|
||||
Style: {
|
||||
stroke: 'black',
|
||||
strokeWidth: 2,
|
||||
fillOpacity: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -265,3 +317,5 @@ const SplitRemplissage = (request) => {
|
|||
Containers: lstModels
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue