diff --git a/src/features/default/src/Components/Datasets_New/DataSetsView.js b/src/features/default/src/Components/Datasets_New/DataSetsView.js
index ac912918..0d68dc83 100644
--- a/src/features/default/src/Components/Datasets_New/DataSetsView.js
+++ b/src/features/default/src/Components/Datasets_New/DataSetsView.js
@@ -285,6 +285,7 @@ const DataSetsView = (props) => {
)}
datasetId={response?.data?.id}
id={tempFile.id}
+ getDataset={getDataset}
usagePolicy={tempFile.usage_policy}
fileType={tempFile.accessibility}
userType={userType === "guest" ? "guest" : ""}
diff --git a/src/features/default/src/Components/Table/DataTableForDatasetView.jsx b/src/features/default/src/Components/Table/DataTableForDatasetView.jsx
index 5670bf83..a4c65756 100644
--- a/src/features/default/src/Components/Table/DataTableForDatasetView.jsx
+++ b/src/features/default/src/Components/Table/DataTableForDatasetView.jsx
@@ -1,6 +1,12 @@
import React, { useContext, useEffect, useMemo, useState } from "react";
-import { Box, Button, CircularProgress } from "@mui/material";
-import { useHistory } from "react-router-dom";
+import {
+ Box,
+ Button,
+ CircularProgress,
+ useMediaQuery,
+ useTheme,
+} from "@mui/material";
+import { useHistory, useLocation } from "react-router-dom";
import EmptyFile from "../Datasets_New/TabComponents/EmptyFile";
import { Table } from "antd";
import DownloadIcon from "@mui/icons-material/Download";
@@ -12,6 +18,12 @@ import HTTPService from "../../Services/HTTPService";
import global_style from "./../../Assets/CSS/global.module.css";
import ArrowForwardIosIcon from "@mui/icons-material/ArrowForwardIos";
import ArrowBackIosNewIcon from "@mui/icons-material/ArrowBackIosNew";
+import {
+ getUserMapId,
+ isLoggedInUserAdmin,
+ isLoggedInUserCoSteward,
+} from "common/utils/utils";
+import { FarmStackContext } from "common/components/context/DefaultContext/FarmstackProvider";
const DataTableForDatasetView = ({
datasetId,
@@ -22,9 +34,14 @@ const DataTableForDatasetView = ({
fileType,
userType,
isOther,
+ getDataset,
}) => {
const antIcon = ;
+ const { callLoader, callToast } = useContext(FarmStackContext);
const history = useHistory();
+ const location = useLocation();
+ const theme = useTheme();
+ const mobile = useMediaQuery(theme.breakpoints.down("sm"));
const [data, setData] = useState();
const [pages, setPages] = useState({
current: 1,
@@ -157,6 +174,104 @@ const DataTableForDatasetView = ({
}
};
+ const askToDownload = () => {
+ let accessToken = getTokenLocal() ?? false;
+ let url = UrlConstant.base_url + UrlConstant.ask_for_permission;
+ let body = {
+ dataset_file: id,
+ user_organization_map: getUserMapId(),
+ };
+ callLoader(true);
+ HTTPService("POST", url, body, false, true, accessToken)
+ .then((res) => {
+ callLoader(false);
+ getDataset();
+ callToast(
+ "Successfully, sent the request for downloading the file",
+ "success",
+ true
+ );
+ })
+ .catch((err) => {
+ callLoader(false);
+ callToast(
+ "Something went wrong while asking for the permission.",
+ "error",
+ true
+ );
+ });
+ };
+
+ const handleDelete = (usagePolicyid) => {
+ let accessToken = getTokenLocal() ?? false;
+ let url =
+ UrlConstant.base_url +
+ UrlConstant.ask_for_permission +
+ usagePolicyid +
+ "/";
+ callLoader(true);
+ HTTPService("DELETE", url, "", false, true, accessToken)
+ .then((res) => {
+ callLoader(false);
+ getDataset();
+ })
+ .catch((err) => {
+ callLoader(false);
+ callToast("Something went wrong while recalling.", "error", true);
+ });
+ };
+
+ const getButtonName = () => {
+ if (usagePolicy?.[0]) {
+ if (usagePolicy[0].approval_status === "requested") {
+ return "Recall";
+ } else if (usagePolicy[0].approval_status === "approved") {
+ return "Download";
+ } else if (usagePolicy[0].approval_status === "rejected") {
+ return "Ask to Download";
+ }
+ } else {
+ return "Recall";
+ }
+ };
+
+ const isLoggedInUserFromHome = () => {
+ if (
+ location.pathname === "/home/datasets/" + datasetId &&
+ getTokenLocal() &&
+ (fileType === "registered" || fileType === "private")
+ ) {
+ return true;
+ } else {
+ return false;
+ }
+ };
+ const handleButtonClick = (id, name) => {
+ if (userType !== "guest") {
+ if (fileType === "public" || fileType === "registered" || !isOther) {
+ handleDownload(id, name);
+ }
+ if (isOther && fileType === "private") {
+ if (!Object.keys(usagePolicy)?.length) {
+ askToDownload();
+ } else {
+ if (usagePolicy?.[0]?.approval_status === "requested") {
+ handleDelete(usagePolicy?.[0]?.id);
+ } else if (usagePolicy?.[0]?.approval_status === "approved") {
+ handleDownload(id, name);
+ } else if (usagePolicy?.[0]?.approval_status === "rejected") {
+ askToDownload(id, name);
+ }
+ }
+ }
+ } else {
+ if (fileType === "public") {
+ handleDownload(id, name);
+ } else {
+ history.push("/login");
+ }
+ }
+ };
useEffect(() => {
fetchData(0);
setPages({ current: 1, next: false });
@@ -195,41 +310,76 @@ const DataTableForDatasetView = ({
: " (Meta data)"}
- {usagePolicy &&
- (!isOther ||
- usagePolicy[0]?.approval_status === "approved" ||
- fileType === "public") ? (
-
- {" "}
-
- ) : (
- ""
- )}
+
+ {isLoggedInUserFromHome() ? (
+
+ ) : (
+ <>>
+ )}
)}
columns={memoCol}