Skip to content

Commit

Permalink
report history table implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
NadunSanjeevana committed Sep 11, 2023
1 parent c95254c commit 271b846
Showing 1 changed file with 73 additions and 193 deletions.
266 changes: 73 additions & 193 deletions src/layouts/reports/data/reportsdata.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
/* eslint-disable react/prop-types */
/* eslint-disable react/function-component-definition */
/**
=========================================================
* Material Dashboard 2 React - v2.2.0
=========================================================
* Product Page: https://www.creative-tim.com/product/material-dashboard-react
* Copyright 2023 Creative Tim (https://www.creative-tim.com)
Coded by www.creative-tim.com
=========================================================
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/
* =========================================================
* Material Dashboard 2 React - v2.2.0
* =========================================================
*
* Product Page: https://www.creative-tim.com/product/material-dashboard-react
* Copyright 2023 Creative Tim (https://www.creative-tim.com)
*
* Coded by www.creative-tim.com
*
* =========================================================
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/

// Material Dashboard 2 React components
import MDBox from "components/MDBox";
import MDTypography from "components/MDTypography";
import MDBadge from "components/MDBadge";
// import { useEffect } from "react";
// import { getReportList } from "api/report/reportsdata";
// import { useState } from "react";
import { useEffect, useState } from "react";
import { getReportList } from "api/report/reportsdata";

export default function data() {
export default function Data() {
const Job = ({ title, description }) => (
<MDBox lineHeight={1} textAlign="left">
<MDTypography display="block" variant="caption" color="text" fontWeight="medium">
Expand All @@ -33,19 +32,34 @@ export default function data() {
</MDBox>
);

// const [reportDetails, setReportsDetails] = useState([]);
const [reportDetails, setReportsDetails] = useState([]);

useEffect(() => {
// Fetch average price data from the Flask API endpoint
getReportList()
.then((data) => {
setReportsDetails(data);
console.log(data); // Use 'data' instead of 'reportDetails'
})
.catch((error) => {
console.error("Error fetching data:", error);
});
}, []);

// useEffect(() => {
// // Fetch average price data from the Flask API endpoint
// getReportList()
// .then((data) => {
// setReportsDetails(data);
// //console.log(adDistribution);
// })
// .catch((error) => {
// console.error("Error fetching data:", error);
// });
// }, []);
const handleDownload = (pdf_Url) => {
if (pdf_Url) {
// Create an anchor element to trigger the download
const anchor = document.createElement("a");
anchor.href = pdf_Url;
anchor.target = "_blank"; // Open the link in a new tab
anchor.download = "your_file_name.ext"; // Replace with the desired file name

// Trigger the download
anchor.click();
} else {
console.error("Download URL is not available.");
}
};

return {
rawData: [
Expand Down Expand Up @@ -87,169 +101,35 @@ export default function data() {
{ Header: "Date", accessor: "employed", align: "center" },
{ Header: "Download", accessor: "action", align: "center" },
],

// rows: getReportList.map((report, index) => ({
// author: (
// <MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
// DemographicAnalysis
// </MDTypography>
// ),
// function: <Job title="Manager" description="Organization" />,
// status: (
// <MDBox ml={-1}>
// <MDBadge badgeContent="pdf" color="error" variant="gradient" size="sm" />
// </MDBox>
// ),
// employed: (
// <MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
// 23/04/18
// </MDTypography>
// ),
// action: (
// <MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
// Download
// </MDTypography>
// ),
// })),
rows: [
{
author: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
DemographicAnalysis
</MDTypography>
),
function: <Job title="Manager" description="Organization" />,
status: (
<MDBox ml={-1}>
<MDBadge badgeContent="pdf" color="error" variant="gradient" size="sm" />
</MDBox>
),
employed: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
23/04/18
</MDTypography>
),
action: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
Download
</MDTypography>
),
},
{
author: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
MyReport
</MDTypography>
),
function: <Job title="Programator" description="Developer" />,
status: (
<MDBox ml={-1}>
<MDBadge badgeContent="csv" color="success" variant="gradient" size="sm" />
</MDBox>
),
employed: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
11/01/19
</MDTypography>
),
action: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
Download
</MDTypography>
),
},
{
author: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
Test
</MDTypography>
),
function: <Job title="Executive" description="Projects" />,
status: (
<MDBox ml={-1}>
<MDBadge badgeContent="excel" color="warning" variant="gradient" size="sm" />
</MDBox>
),
employed: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
19/09/17
</MDTypography>
),
action: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
Download
</MDTypography>
),
},
{
author: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
WTH
</MDTypography>
),
function: <Job title="Programator" description="Developer" />,
status: (
<MDBox ml={-1}>
<MDBadge badgeContent="csv" color="success" variant="gradient" size="sm" />
</MDBox>
),
employed: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
24/12/08
</MDTypography>
),
action: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
Download
</MDTypography>
),
},
{
author: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
WHOAMI
</MDTypography>
),
function: <Job title="Manager" description="Executive" />,
status: (
<MDBox ml={-1}>
<MDBadge badgeContent="txt" color="dark" variant="gradient" size="sm" />
</MDBox>
),
employed: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
04/10/21
</MDTypography>
),
action: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
Download
</MDTypography>
),
},
{
author: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
Helloworld
</MDTypography>
),
function: <Job title="Programator" description="Developer" />,
status: (
<MDBox ml={-1}>
<MDBadge badgeContent="pdf" color="error" variant="gradient" size="sm" />
</MDBox>
),
employed: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
14/09/20
</MDTypography>
),
action: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
Download
</MDTypography>
),
},
],
rows: reportDetails.map((report) => ({
author: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
{report.Title}
</MDTypography>
),
function: <Job title={report.UserID} description="Organization" />,
status: (
<MDBox ml={-1}>
<MDBadge badgeContent="pdf" color="error" variant="gradient" size="sm" />
</MDBox>
),
employed: (
<MDTypography component="a" href="#" variant="caption" color="text" fontWeight="medium">
{report.timestamp}
</MDTypography>
),
action: (
<MDTypography
component="a"
href="#"
variant="caption"
color="text"
fontWeight="medium"
onClick={() => handleDownload(report.PDF_URL)} // Use an arrow function
>
Download
</MDTypography>
),
})),
};
}

0 comments on commit 271b846

Please sign in to comment.