Merge gmpl main2 #55

Merged
SinusFox merged 9 commits from merge_gmpl_main2 into main 2024-10-11 21:25:56 +00:00
2 changed files with 53 additions and 62 deletions
Showing only changes of commit e72c75e6e4 - Show all commits
+50 -59
View File
@@ -16,16 +16,6 @@ const GlpPage = () => {
const tr_hTitle = text(language, 'header_title'); const tr_hTitle = text(language, 'header_title');
const tr_hSubtitle = text(language, 'header_subtitle'); const tr_hSubtitle = text(language, 'header_subtitle');
// const tr_boxObjTitle = text(language, 'boxObjTitle');
// const tr_boxObjDesc = text(language, "boxObjDesc");
// const tr_boxSubjTitle = text(language, 'boxSubjTitle');
// const tr_boxSubjDesc = text(language, "boxSubjDesc");
// const tr_boxBoundsTitle = text(language, 'boxBoundsTitle');
// const tr_boxBoundsDesc = text(language, "boxBoundsDesc");
// const tr_boxVarsTitle = text(language, 'boxVarsTitle');
// const tr_boxVarsDesc = text(language, "boxVarsDesc");
// const tr_boxOut = text(language, "boxOut");
const tr_boxExportLP = text(language, "boxExportLP");
const tr_calcButton = text(language, "buttonCalc"); const tr_calcButton = text(language, "buttonCalc");
const tr_GmplTitle = text(language, 'GmplHeader'); const tr_GmplTitle = text(language, 'GmplHeader');
const tr_GenProblems = text(language, 'GenProblem'); const tr_GenProblems = text(language, 'GenProblem');
@@ -43,11 +33,11 @@ const GlpPage = () => {
const [solverTime, setSolverTime] = useState<string>(''); const [solverTime, setSolverTime] = useState<string>('');
const [showPopup, setShowPopup] = useState(false); const [showPopup, setShowPopup] = useState(false);
const [resultContent, setResultContent] = useState<string>(''); const [resultContent, setResultContent] = useState<string>('');
const [syntaxErrors, setSyntaxErrors] = useState<string[]>([]); //const [syntaxErrors, setSyntaxErrors] = useState<string[]>([]);
const [showErrorPopup, setShowErrorPopup] = useState(false); const [showErrorPopup, setShowErrorPopup] = useState(false);
const solverTimeoutRef = useRef<NodeJS.Timeout | null>(null); const solverTimeoutRef = useRef<NodeJS.Timeout | null>(null);
const solverAbortController = useRef<AbortController | null>(null); const solverAbortController = useRef<AbortController | null>(null);
const [highlightedContent, setHighlightedContent] = useState<string>(''); //const [highlightedContent, setHighlightedContent] = useState<string>('');
const [fileName, setFileName] = useState<string>(""); const [fileName, setFileName] = useState<string>("");
@@ -64,11 +54,11 @@ const GlpPage = () => {
} }
}; };
useEffect(() => { //useEffect(() => {
if (syntaxErrors.length > 0) { // if (syntaxErrors.length > 0) {
setShowErrorPopup(true); // setShowErrorPopup(true);
} // }
}, [syntaxErrors]); //}, [syntaxErrors]);
const addMessage = (message: string) => { const addMessage = (message: string) => {
const msgZone = document.getElementById("msgZone"); const msgZone = document.getElementById("msgZone");
@@ -77,10 +67,10 @@ const GlpPage = () => {
} }
}; };
const updateHighlightedContent = (content: string) => { // const updateHighlightedContent = (content: string) => {
const highlighted = highlightErrors(content); // const highlighted = highlightErrors(content);
setHighlightedContent(highlighted); // setHighlightedContent(highlighted);
}; // };
const handleFileUpload = (event: React.ChangeEvent<HTMLInputElement>) => { const handleFileUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
@@ -94,50 +84,50 @@ const GlpPage = () => {
reader.onload = (e) => { reader.onload = (e) => {
const content = e.target?.result as string; const content = e.target?.result as string;
setFileContent(content); setFileContent(content);
updateHighlightedContent(content); // updateHighlightedContent(content);
addMessage("File successfully uploaded and read."); addMessage("File successfully uploaded and read.");
setIsFileUploaded(true); setIsFileUploaded(true);
// Perform syntax check // Perform syntax check
const errors = checkSyntax(content); //const errors = checkSyntax(content);
setSyntaxErrors(errors); //setSyntaxErrors(errors);
updateHighlightedContent(content); // updateHighlightedContent(content);
}; };
reader.readAsText(file); reader.readAsText(file);
}; };
const checkSyntax = (content: string): string[] => { //const checkSyntax = (content: string): string[] => {
const errors: string[] = []; // const errors: string[] = [];
const lines = content.split("\n"); // const lines = content.split("\n");
//
const ignorePattern = /^(#|\/\/|printf|\/\*|\*).*$/; // const ignorePattern = /^(#|\/\/|printf|\/\*|\*).*$/;
//
lines.forEach((line, index) => { // lines.forEach((line, index) => {
if (ignorePattern.test(line) || line.trim() === "") { // if (ignorePattern.test(line) || line.trim() === "") {
return; // Ignore this line // return; // Ignore this line
} // }
//
const validGmplLinePattern = /^(var|param|set|maximize|minimize|s\.t\.|subject to|for|in|if|then|else|end|:=|<=|>=|=|\+|\-|\*|\/|[a-zA-Z_][a-zA-Z0-9_]*\s*[=<>+\-*/]*\s*[0-9a-zA-Z_]+.*;)/; // const validGmplLinePattern = /^(var|param|set|maximize|minimize|s\.t\.|subject to|for|in|if|then|else|end|:=|<=|>=|=|\+|\-|\*|\/|[a-zA-Z_][a-zA-Z0-9_]*\s*[=<>+\-*/]*\s*[0-9a-zA-Z_]+.*;)/;
//
if (!validGmplLinePattern.test(line)) { // if (!validGmplLinePattern.test(line)) {
errors.push(`Syntax error on line ${index + 1}: ${line}`); // errors.push(`Syntax error on line ${index + 1}: ${line}`);
} // }
}); // });
//
return errors; // return errors;
}; //};
// Highlight syntax errors in the file content // Highlight syntax errors in the file content
const highlightErrors = (content: string) => { //const highlightErrors = (content: string) => {
const lines = content.split("\n"); // const lines = content.split("\n");
return lines.map((line, index) => { // return lines.map((line, index) => {
const error = syntaxErrors.find((error) => error.includes(`line ${index + 1}`)); // const error = syntaxErrors.find((error) => error.includes(`line ${index + 1}`));
if (error) { // if (error) {
return `<span style="background-color: yellow; color: black;" title="${error}">${line}</span>`; // return `<span style="background-color: yellow; color: black;" title="${error}">${line}</span>`;
} // }
return line; // return line;
}).join("\n"); // }).join("\n");
}; //};
// Function to dynamically set the height of the textarea // Function to dynamically set the height of the textarea
const getTextAreaHeight = (value: any) => { const getTextAreaHeight = (value: any) => {
@@ -231,7 +221,6 @@ const GlpPage = () => {
} }
}; };
// Function to download the modified file
const downloadFile = () => { const downloadFile = () => {
const element = document.createElement("a"); const element = document.createElement("a");
const file = new Blob([fileContent], { type: 'text/plain' }); const file = new Blob([fileContent], { type: 'text/plain' });
@@ -306,7 +295,7 @@ const GlpPage = () => {
value={fileContent} value={fileContent}
onChange={(e) => { onChange={(e) => {
setFileContent(e.target.value); setFileContent(e.target.value);
updateHighlightedContent(e.target.value); //updateHighlightedContent(e.target.value);
}} }}
rows={getTextAreaHeight(fileContent)} rows={getTextAreaHeight(fileContent)}
/> />
@@ -326,7 +315,7 @@ const GlpPage = () => {
<div id="msgZone" className="msgZone"></div> <div id="msgZone" className="msgZone"></div>
<div>{solverTime}</div> {/* Display Solver Time */} <div>{solverTime}</div> {/* Display Solver Time */}
{/* Syntax Errors */} {/* Syntax Errors
{syntaxErrors.length > 0 && ( {syntaxErrors.length > 0 && (
<div className="syntaxErrorBox"> <div className="syntaxErrorBox">
<h3>Syntax Errors</h3> <h3>Syntax Errors</h3>
@@ -337,13 +326,15 @@ const GlpPage = () => {
</ul> </ul>
</div> </div>
)} )}
*/}
{/* Syntax Error Popup */} {/* Syntax Error Popup
{showErrorPopup && ( {showErrorPopup && (
<div className="errorPopup"> <div className="errorPopup">
<p>There are syntax errors in the file.</p> <p>There are syntax errors in the file.</p>
</div> </div>
)} )}
*/}
{/* Result Popup */} {/* Result Popup */}
{showPopup && ( {showPopup && (
+3 -3
View File
@@ -1,7 +1,7 @@
import type { Metadata } from "next"; import type { Metadata } from "next";
import Image from "next/image"; import Image from "next/image";
import localFont from "next/font/local"; import localFont from "next/font/local";
import { LanguageProvider } from './context/LanguageContext'; // Importiere den Provider import { LanguageProvider } from './context/LanguageContext';
import "./globals.css"; import "./globals.css";
const geistSans = localFont({ const geistSans = localFont({
@@ -33,8 +33,6 @@ export default function RootLayout({
className={`${geistSans.variable} ${geistMono.variable} antialiased`} className={`${geistSans.variable} ${geistMono.variable} antialiased`}
> >
<LanguageProvider> <LanguageProvider>
{children} {}
</LanguageProvider>
{children} {children}
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]"> <div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
<footer className=" flex gap-6 flex-wrap items-center justify-center"> <footer className=" flex gap-6 flex-wrap items-center justify-center">
@@ -85,6 +83,8 @@ export default function RootLayout({
</a> </a>
</footer> </footer>
</div> </div>
</LanguageProvider>
</body> </body>
</html> </html>
); );