diff --git a/web/package-lock.json b/web/package-lock.json index 418d7e7..f8a2f6f 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -1,11 +1,11 @@ { - "name": "dot", + "name": "DOT", "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "dot", + "name": "DOT", "version": "0.1.0", "license": "ISC", "dependencies": { diff --git a/web/src/components/header.jsx b/web/src/components/header.jsx index a57852f..65f5227 100644 --- a/web/src/components/header.jsx +++ b/web/src/components/header.jsx @@ -15,11 +15,13 @@ import { help_outline, file_description, download, + file, } from "@equinor/eds-icons"; import { Link, Outlet } from "react-router-dom"; import { useProjectContext } from "./context"; import { readProject } from "../services/project_api"; import { handleExport } from "./handleExport"; +import ReportDialog from "../components/reportDialog"; function Header() { const [isOpen, setIsOpen] = useState(false); @@ -29,6 +31,19 @@ function Header() { const closePopover = () => setIsOpen(false); const [project, setProjectContext] = useProjectContext(); + const [isReportDialogOpen, setIsReportDialogOpen] = useState(false); // State to control dialog visibility + const [reportDialogArgs, setReportDialogArgs] = useState({}); // State to store dialog arguments + + const openReportDialog = (args) => { + setReportDialogArgs(args); // Store the arguments in state + setIsReportDialogOpen(true); // Open the dialog with the UUID + }; + + const closeReportDialog = () => { + setIsReportDialogOpen(false); // Close the dialog + setReportDialogArgs({}); // Clear the arguments + }; + const fetchData = async () => { if (project) { const project_read = await readProject(project); @@ -98,6 +113,22 @@ function Header() { > + + {isReportDialogOpen && ( + + )} ) : null} @@ -130,7 +161,7 @@ function Header() { variant="ghost_icon" as={Link} target="_blank" - to="https://fictional-adventure-eyq51g5.pages.github.io/" + to="https://equinor.github.io/dot/" > diff --git a/web/src/components/reportDialog.jsx b/web/src/components/reportDialog.jsx new file mode 100644 index 0000000..71178ce --- /dev/null +++ b/web/src/components/reportDialog.jsx @@ -0,0 +1,119 @@ +import React, { useState, useEffect } from "react"; +import { + Button, + TextField, + Dialog, + Typography, + NativeSelect, +} from "@equinor/eds-core-react"; +import { readProject, reportProject } from "../services/project_api"; + +// Dialog Component +const ReportDialog = ({ uuid, onClose }) => { + console.log("ReportDialog - uuid/onClose", uuid, onClose); + const [projectData, setProjectData] = useState(null); + const [fileFormat, setFileFormat] = useState("docx"); + const [filePath, setFilePath] = useState(""); + + useEffect(() => { + const fetchData = async () => { + console.log("ReportDialog - useEffect"); + if (!uuid) return; + try { + const project_data = await readProject(uuid); + console.log("ReportDialog - fetchData", project_data); + setProjectData(project_data); + setFilePath(project_data.name); + } catch (error) { + console.error("reportProject - Error:: ", error); + } + }; + fetchData(uuid); + }, [uuid]); + + const handleReport = () => { + console.log("handleReport - Reporting Project:"); + console.log("handleReport - Format:", fileFormat); + console.log("handleReport - Filepath:", filePath); + console.log("handleReport - Project Data:", projectData); + + try { + const project_data = reportProject(uuid); + console.log("handleReport - ReportDialog - reportProject", project_data); + } catch (error) { + console.error("handleReport - reportProject - Error:: ", error); + } + onClose(); // Close the dialog after saving + }; + + const addExtensionToFilepath = (path, ext) => { + return path + "." + ext; + }; + + return ( + <> +
+ {projectData && ( + + + Reporting of project + + + +
+
+ setFileFormat(event.target.value)} + > + + + + + +
+
+ setFilePath(event.target.value)} + > +
+
+
+
+
+ + +
+ {" "} + +
+
+
+ )} +
+ + ); +}; + +export default ReportDialog; diff --git a/web/src/pages/home.jsx b/web/src/pages/home.jsx index 536497e..e6c7e2a 100644 --- a/web/src/pages/home.jsx +++ b/web/src/pages/home.jsx @@ -7,7 +7,7 @@ import { Typography, Chip, } from "@equinor/eds-core-react"; -import { add, lock, lock_open, download } from "@equinor/eds-icons"; +import { add, lock, lock_open, download, file } from "@equinor/eds-icons"; import { Link, Outlet } from "react-router-dom"; import { allProjects, removeProject } from "../services/project_api"; import "../styles/home.css"; @@ -16,6 +16,7 @@ import { ProjectContext } from "../components/context"; import ProjectDeleteCheck from "../components/deleteCheck"; import ImportDialog from "../components/importDialog"; import { handleExport } from "../components/handleExport"; +import ReportDialog from "../components/reportDialog"; function HomeScreen() { const [projects, setProjects] = useState(null); @@ -36,6 +37,7 @@ function HomeScreen() { const handlePageChange = (event, newPage) => { setPage(newPage); }; + const itemsPerPage = 12; const startIndex = (page - 1) * itemsPerPage; const endIndex = startIndex + itemsPerPage; @@ -43,6 +45,19 @@ function HomeScreen() { ? projects.slice(startIndex, endIndex) : []; + const [isReportDialogOpen, setIsReportDialogOpen] = useState(false); // State to control dialog visibility + const [reportDialogArgs, setReportDialogArgs] = useState({}); // State to store dialog arguments + + const openReportDialog = (args) => { + setReportDialogArgs(args); // Store the arguments in state + setIsReportDialogOpen(true); // Open the dialog with the UUID + }; + + const closeReportDialog = () => { + setIsReportDialogOpen(false); // Close the dialog + setReportDialogArgs({}); // Clear the arguments + }; + return ( <>
@@ -126,6 +141,25 @@ function HomeScreen() { > + + {isReportDialogOpen && ( + + )}
{ console.error(error.response); } }; + +//report project +export const reportProject = async (projectID) => { + try { + const result = await BaseAPIServices.get("/projects/" + projectID); // BaseAPIServices.get("/projects/" + projectID + "/report"); + return result; + } catch (error) { + console.log("Failed Exporting"); + console.error(error); + } +};