feat: DetailModal um Min/Max/Durchschnitt ergänzt
- Chart zeigt jetzt zusätzlich zu Messwert auch Minimal-, Maximal- und Durchschnittswerte an - Datenstruktur an Redux angepasst (i, a, g) - Darstellung entspricht jetzt LoopMeasurementChart
This commit is contained in:
@@ -8,26 +8,14 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const mode = process.env.NEXT_PUBLIC_CPL_MODE;
|
||||
|
||||
try {
|
||||
/* if (mode === "json") {
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mocks/api/SERVICE/analogInputsMockData.json"
|
||||
);
|
||||
const content = fs.readFileSync(filePath, "utf-8");
|
||||
const data = JSON.parse(content);
|
||||
return res.status(200).json(data);
|
||||
} */
|
||||
|
||||
if (mode === "json") {
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mocks/device-cgi-simulator/SERVICE/analogInputsMockData.json"
|
||||
);
|
||||
const jsonContent = fs.readFileSync(filePath, "utf-8");
|
||||
const data = JSON.parse(jsonContent);
|
||||
res.status(200).json(data);
|
||||
return;
|
||||
}
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mocks/device-cgi-simulator/SERVICE/analogInputsMockData.json"
|
||||
);
|
||||
const jsonContent = fs.readFileSync(filePath, "utf-8");
|
||||
const data = JSON.parse(jsonContent);
|
||||
res.status(200).json(data);
|
||||
return;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ error: "Internal Server Error" });
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
@@ -11,25 +10,12 @@ export default async function handler(
|
||||
) {
|
||||
const mode = process.env.NEXT_PUBLIC_CPL_MODE ?? "json";
|
||||
|
||||
if (mode === "json") {
|
||||
// Lese JSON-Datei z.B. digitalOutputsMockData.json
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mocks/api/SERVICE/digitalOutputsMockData.json"
|
||||
);
|
||||
const content = await fs.readFile(filePath, "utf-8");
|
||||
const data = JSON.parse(content);
|
||||
return res.status(200).json(data);
|
||||
}
|
||||
|
||||
if (mode === "jsSimulatedProd") {
|
||||
const digitalOutputsScript = readFileSync(
|
||||
"mocks/device-cgi-simulator/SERVICE/digitalOutputsMockData.js"
|
||||
);
|
||||
res.setHeader("Content-Type", "application/javascript");
|
||||
res.status(200).send(digitalOutputsScript);
|
||||
return;
|
||||
}
|
||||
|
||||
return res.status(400).json({ error: "Unsupported mode" });
|
||||
// Lese JSON-Datei z.B. digitalOutputsMockData.json
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mocks/device-cgi-simulator/SERVICE/digitalOutputsMockData.json"
|
||||
);
|
||||
const content = await fs.readFile(filePath, "utf-8");
|
||||
const data = JSON.parse(content);
|
||||
return res.status(200).json(data);
|
||||
}
|
||||
|
||||
@@ -15,51 +15,20 @@ export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
return res.status(400).json({ error: "Missing or invalid updates array" });
|
||||
}
|
||||
|
||||
if (mode === "json") {
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mocks/api/SERVICE/analogInputsMockData.json"
|
||||
);
|
||||
const content = fs.readFileSync(filePath, "utf-8");
|
||||
const data = JSON.parse(content);
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mocks/device-cgi-simulator/SERVICE/analogInputsMockData.json"
|
||||
);
|
||||
const content = fs.readFileSync(filePath, "utf-8");
|
||||
const data = JSON.parse(content);
|
||||
|
||||
for (const update of updates) {
|
||||
const { key, index, value } = update;
|
||||
if (Array.isArray(data[key]) && index < data[key].length) {
|
||||
data[key][index] = value;
|
||||
}
|
||||
for (const update of updates) {
|
||||
const { key, index, value } = update;
|
||||
if (Array.isArray(data[key]) && index < data[key].length) {
|
||||
data[key][index] = value;
|
||||
}
|
||||
|
||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), "utf-8");
|
||||
return res.status(200).json({ success: true });
|
||||
}
|
||||
|
||||
if (mode === "jsSimulatedProd") {
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mocks/device-cgi-simulator/SERVICE/analogInputsMockData.js"
|
||||
);
|
||||
let content = fs.readFileSync(filePath, "utf-8");
|
||||
|
||||
for (const update of updates) {
|
||||
const { key, index, value } = update;
|
||||
const regex = new RegExp(`var\\s+${key}\\s*=\\s*\\[([\\s\\S]*?)\\];`);
|
||||
const match = content.match(regex);
|
||||
if (!match) continue;
|
||||
|
||||
const items = match[1].split(",").map((s) => s.trim());
|
||||
if (index >= items.length) continue;
|
||||
|
||||
const isString = typeof value === "string";
|
||||
items[index] = isString ? `"${value}"` : `${value}`;
|
||||
|
||||
const updatedLine = `var ${key} = [${items.join(", ")}];`;
|
||||
content = content.replace(regex, updatedLine);
|
||||
}
|
||||
|
||||
fs.writeFileSync(filePath, content, "utf-8");
|
||||
return res.status(200).json({ success: true });
|
||||
}
|
||||
|
||||
return res.status(400).json({ error: "Unsupported mode" });
|
||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2), "utf-8");
|
||||
return res.status(200).json({ success: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user