diff --git a/actions/azurestorage.js b/actions/azurestorage.js index 245762fd..e1d33ea6 100644 --- a/actions/azurestorage.js +++ b/actions/azurestorage.js @@ -41,7 +41,7 @@ export const createContainerSas = async (containerName) => { ); // Need only list permission to list blobs - const containerPermissions = "rcwltd"; + const containerPermissions = "rcwltdf"; // Best practice: SAS options are time-limited const sasOptions = { @@ -472,6 +472,50 @@ export const downloadAllProgressFiles = async ( ); }; +export const downloadAllRepsFiles = async (containerName, repsBlobObj) => { + console.log( + "/////////////////////////\n downloading files: " + + JSON.stringify(repsBlobObj) + + "\n/////////////////////////\n" + ); + + const containerToken = await createContainerSas(containerName); + const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`; + const containerClient = new ContainerClient(sasUrl); + + let blobClient = {}; + let downloadedBlob = {}; + let repArr = []; + let downloaded = ""; + let caseBlob = {}; + let caseDownloaded = ""; + let blobCount = 0; + + for (const prop in repsBlobObj) { + console.log(`Progress - ${prop}: ${repsBlobObj[prop].name}`); + blobClient = containerClient.getBlobClient(repsBlobObj[prop].name); + downloadedBlob = await blobClient.download(0); + let repBlobObj = await streamToBuffer( + downloadedBlob.readableStreamBody + ); + + repBlobObj = JSON.parse(repBlobObj); + + repBlobObj["casereference"] = repsBlobObj[prop].name.split("/")[0]; + + repBlobObj = JSON.stringify(repBlobObj); + + downloaded = downloaded + repBlobObj + ","; + blobCount++; + } + + downloaded = downloaded.substring(0, downloaded.length - 1); + + return JSON.parse( + '{ "@odata.count": ' + blobCount + ',"value": [' + downloaded + "]}" + ); +}; + const streamToBuffer = async (readableStream) => { return new Promise((resolve, reject) => { const chunks = []; @@ -605,3 +649,39 @@ export const getAllProgressBlobs = async (containerName) => { return blobObj; }; + +export const getRepslobs = async (containerName, caseReference) => { + const containerToken = await createContainerSas(containerName); + + const sasUrl = `${STORAGE_PATH}/${containerName}?${containerToken}`; + + const containerClient = new ContainerClient(sasUrl); + + let blobCount = 0; + for await (const blob of containerClient.findBlobsByTags( + "blobType='Representation'" + )) { + blobCount++; + } + + console.log("this is the caasefolder:", caseReference, blobCount); + + let blobObj = []; + for await (const blob of containerClient.findBlobsByTags( + "blobType='Representation'" + )) { + console.log("in here"); + console.log(blob); + blobObj.push(blob); + } + + // blobObj = _.sortBy(blobObj, [ + // function (o) { + // return o.lastModified; + // }, + // ]).reverse()[0]; + + console.log("blobObjwwwww:", blobObj); + + return blobObj; +}; diff --git a/actions/index.js b/actions/index.js index 70f06342..660bf3bf 100644 --- a/actions/index.js +++ b/actions/index.js @@ -793,6 +793,27 @@ export const getAwaitingSubmissionFromBlob = (containerName) => { }); }; +export const getRepsFromBlob = (containerName) => { + console.log( + "///////////////////////getRepsFromBlob: " + + containerName + + "\n///////////////////////\n" + ); + return axios + .get( + BASE_URL + + "/api/file/getrepsblob?container=" + + containerName + + hashAPIPath("/api/file/getrepsblob?container=" + containerName) + ) + .then((res) => { + return res.data; + }) + .catch((error) => { + //console.log("API call error", error); + }); +}; + export const getAwaitingSubmissionFromBlobProxy = (containerName) => { return axios .get( diff --git a/components/case/summary.js b/components/case/summary.js index 8c486941..2ef51df1 100644 --- a/components/case/summary.js +++ b/components/case/summary.js @@ -288,7 +288,6 @@ const CaseSummary = (props) => { - {props.currentView.showReps == true || (props.currentView.showReps == "true" && _.has(detailsObj, "pinswg_startdate") && @@ -335,26 +334,28 @@ const CaseSummary = (props) => { ))} - {props.currentView.showReps == true && - _.has(detailsObj, "pinswg_startdate") && - hasEndDate && - showRepsEnded( - detailsObj.pinswg_startdate, - detailsObj.pinswg_representation_period_end_date - ) && ( -
-
-
-
- Representation Period ended on{" "} - {formatDates( - detailsObj.pinswg_representation_period_end_date - )} + + {props.currentView.showReps == true || + (props.currentView.showReps == "true" && + _.has(detailsObj, "pinswg_startdate") && + hasEndDate && + showRepsEnded( + detailsObj.pinswg_startdate, + detailsObj.pinswg_representation_period_end_date + ) && ( +
+
+
+
+ Representation Period ended on{" "} + {formatDates( + detailsObj.pinswg_representation_period_end_date + )} +
-
- )} + ))} {/* 1{" "} {_.has(detailsObj, "pinswg_startdatetimeiftheevent") && detailsObj.pinswg_startdatetimeiftheevent} diff --git a/components/myportal/myrepresentationsfromblob.js b/components/myportal/myrepresentationsfromblob.js new file mode 100644 index 00000000..04259947 --- /dev/null +++ b/components/myportal/myrepresentationsfromblob.js @@ -0,0 +1,62 @@ +import Link from "next/link"; +import { useRouter } from "next/router"; +import useTranslation from "next-translate/useTranslation"; +import TopThree from "./topthree_reps"; +import { connect } from "react-redux"; +import { setCurrentView } from "../../store/currentView/action"; + +const MyRepresentations = (props) => { + let { t } = useTranslation(); + + const router = useRouter(); + const { locale } = router; + const { setCurrentView } = props; + + return ( +
+
+

+ {t("myportal:myrepresentations-card-title")}dd +

+
+ +
+ + {props.myRepresentations.myRepresentations["@odata.count"] > + 3 && ( + + )} +
+
+ ); +}; + +const mapDispatchToProps = (dispatch) => { + return { + setCurrentView: (currentView) => { + dispatch(setCurrentView(currentView)); + }, + }; +}; + +export default connect(null, mapDispatchToProps)(MyRepresentations); diff --git a/components/myportal/topthree_reps.js b/components/myportal/topthree_reps.js index 973e32c3..93dbce5d 100644 --- a/components/myportal/topthree_reps.js +++ b/components/myportal/topthree_reps.js @@ -123,7 +123,7 @@ const TopThree = (props) => { return objArr._pinswg_watchedcase_value; break; case "myRepresentations": - return objArr.ticketnumber; + return objArr.casereference; break; case "awaitingSubmission": return objArr.ticketnumber; @@ -152,9 +152,8 @@ const TopThree = (props) => { "myRepresentations" ? showTopThreeArr[key] .ticketnumber - : showTopThreeArr[key][ - "_pinswg_case_value@OData.Community.Display.V1.FormattedValue" - ] + : showTopThreeArr[key] + .casereference : showTopThreeArr[key][ "_pinswg_watchedcase_value@OData.Community.Display.V1.FormattedValue" ], @@ -177,11 +176,7 @@ const TopThree = (props) => {
{t("myportal:case-reference")}:{" "} - { - showTopThreeArr[key][ - "_pinswg_case_value@OData.Community.Display.V1.FormattedValue" - ] - } + {showTopThreeArr[key].casereference}
diff --git a/pages/api/file/getrepsblob.js b/pages/api/file/getrepsblob.js new file mode 100644 index 00000000..008f86a9 --- /dev/null +++ b/pages/api/file/getrepsblob.js @@ -0,0 +1,49 @@ +import { + downloadAllRepsFiles, + getRepslobs, +} from "../../../actions/azurestorage"; +import _ from "lodash"; +import nextConnect from "next-connect"; +import middleware from "../middleware/middleware"; + +const ApiProxy = nextConnect(); +ApiProxy.use(middleware); + +ApiProxy.get(async (req, res) => { + var containerName = req.query.container; + var casefolderID = req.query.casefolderID; + + var checkHash = req.query.hash; + var checkquerypath = + "/api/file/getrepsblob?container=" + + containerName + + "&casefolderID=" + + casefolderID; + + console.log(checkquerypath); + // console.log(hashAPIPath(checkquerypath), checkHash); + // console.log(hashAPIPath(checkquerypath) == "&hash=" + checkHash); + + //if (hashAPIPath(checkquerypath) == "&hash=" + checkHash) { + const blobObj = await getRepslobs(containerName, casefolderID) + .then((data) => { + console.log("ertyuikjhgfg", data); + + return downloadAllRepsFiles(containerName, data); + }) + .then((data) => { + return res.status(200).json(data); + }); + + // } else { + // return res.status(400).json(); + // } +}); + +export const config = { + api: { + bodyParser: false, + }, +}; + +export default ApiProxy; diff --git a/pages/myportal/index.js b/pages/myportal/index.js index 506732fe..c36f3c4d 100644 --- a/pages/myportal/index.js +++ b/pages/myportal/index.js @@ -5,6 +5,7 @@ import Head from "next/head"; import { useRouter } from "next/router"; import { connect } from "react-redux"; import { + getRepsFromBlob, getAwaitingSubmissionFromBlob, getAwaitingSubmission, getMyCases, @@ -194,7 +195,7 @@ export const getServerSideProps = wrapper.getServerSideProps( ] = await Promise.all([ await getPersonalAccount(loggedInUser), await getMyCases(loggedInUser), - await getMyRepresentations(loggedInUser), + await getRepsFromBlob(thisSession.user.id), await getWatchedCases(loggedInUser), await getAwaitingSubmission(loggedInUser), await getAwaitingSubmissionFromBlob(thisSession.user.id), @@ -216,12 +217,10 @@ export const getServerSideProps = wrapper.getServerSideProps( } else { const [ myCasesDetails, - myRepresentationsDetails, watchedCasesDetails, awaitingSubmissionDetails, ] = await Promise.all([ await getDetails(myCases, "myCases"), - await getDetails(myRepresentations, "myRepresentations"), await getDetails(watchedCases, "myWatchedCases"), await getDetails(awaitingSubmission, "awaitingSubmission"), ]); @@ -231,9 +230,7 @@ export const getServerSideProps = wrapper.getServerSideProps( store.dispatch(setMyCases(myCases)); store.dispatch(setMyCasesDetails(myCasesDetails)); store.dispatch(setMyRepresentations(myRepresentations)); - store.dispatch( - setMyRepresentationsDetails(myRepresentationsDetails) - ); + store.dispatch(setWatchedCases(watchedCases)); store.dispatch(setWatchedCasesDetails(watchedCasesDetails)); store.dispatch(setAwaitingSubmission(awaitingSubmission));