From a3201af69f292535c15aa1b18d49df917e73a30f Mon Sep 17 00:00:00 2001 From: Kevin Charles Date: Sun, 26 Mar 2023 03:51:55 +0000 Subject: [PATCH] Update card size to 180 - fix editor cap image bug --- src/Api/getPortfolioActivityData.php | 3 +- src/Api/upload.php | 176 +++++++++--------- .../MenuPanelCaps/PortfilioEditorInfoCap.jsx | 40 +++- src/Tools/_framework/Paths/Portfolio.jsx | 18 +- .../Paths/PortfolioActivitySettings.jsx | 50 +++-- .../_framework/Paths/PublicPortfolio.jsx | 142 +++++++------- src/Tools/singlepage/index.jsx | 4 +- 7 files changed, 226 insertions(+), 207 deletions(-) diff --git a/src/Api/getPortfolioActivityData.php b/src/Api/getPortfolioActivityData.php index e56904929c..adf55ba90f 100644 --- a/src/Api/getPortfolioActivityData.php +++ b/src/Api/getPortfolioActivityData.php @@ -53,6 +53,7 @@ FROM course_content WHERE doenetId = '$doenetId' "; + $temp = $sql; $result = $conn->query($sql); if ($result->num_rows > 0) { @@ -76,7 +77,6 @@ $message = 'You need permission to edita a portfolio activity.'; } } - //Assume we are updating the activity and need the current settings if ($success) { $sql = " @@ -112,6 +112,7 @@ 'success' => $success, 'message' => $message, 'activityData' => $activityData, + 'temp' => $temp, ]; http_response_code(200); diff --git a/src/Api/upload.php b/src/Api/upload.php index f32770090b..db9a24074d 100644 --- a/src/Api/upload.php +++ b/src/Api/upload.php @@ -1,27 +1,23 @@ query($sql); $row = $result->fetch_assoc(); -if ($row['canUpload'] == '1'){$canUpload = TRUE;} - -if (!$canUpload){ - $success = false; - $msg = "You don't have permission to upload files."; +if ($row['canUpload'] == '1') { + $canUpload = true; } -//Test if user has space to upload files -if ($success){ - list($userQuotaBytesAvailable,$quotaBytes) = getBytesAvailable($conn,$userId); - - if ($userQuotaBytesAvailable - $size <= 0){ +if (!$canUpload) { $success = false; - $msg = "You don't have enough space in your quota to upload files."; - } + $msg = "You don't have permission to upload files."; } -if ($success){ - if ($size > 1000000){ - $success = false; - $msg = "File is larger than 1MB limit."; - } +//Test if user has space to upload files +if ($success) { + list($userQuotaBytesAvailable, $quotaBytes) = getBytesAvailable( + $conn, + $userId + ); + + if ($userQuotaBytesAvailable - $size <= 0) { + $success = false; + $msg = "You don't have enough space in your quota to upload files."; + } } +if ($success) { + if ($size > 1000000) { + $success = false; + $msg = 'File is larger than 1MB limit.'; + } +} $already_have_file = false; -if ($success){ - move_uploaded_file($tmp_name, $tmp_dest); - $SHA = hash_file("sha256",$tmp_dest); - $cid = cidFromSHA($SHA); - - $newFileName = getFileName($cid,$type); - $destination = $uploads_dir . $newFileName; +if ($success) { + move_uploaded_file($tmp_name, $tmp_dest); + $SHA = hash_file('sha256', $tmp_dest); + $cid = cidFromSHA($SHA); + + $newFileName = getFileName($cid, $type); + $destination = $uploads_dir . $newFileName; - rename($tmp_dest,$destination); + rename($tmp_dest, $destination); - $mime_type = mime_content_type($destination); + $mime_type = mime_content_type($destination); - $width = 0; - $height = 0; - if ($mime_type == 'image/jpeg' || $mime_type == 'image/png'){ - list($width,$height) = getimagesize($destination); - } + $width = 0; + $height = 0; + if ($mime_type == 'image/jpeg' || $mime_type == 'image/png') { + list($width, $height) = getimagesize($destination); + } - //Test if user already has this file in this activity - $sql = " + //Test if user already has this file in this activity + $sql = " SELECT cid FROM support_files WHERE userId = '$userId' AND cid = '$cid' AND doenetId = '$doenetId' "; - $result = $conn->query($sql); + $result = $conn->query($sql); - if ($result->num_rows > 0){ + if ($result->num_rows > 0) { $already_have_file = true; - $success = false; - $msg = "Already have the file '$original_file_name' in this activity. Not used against your quota."; - } + $success = true; + $msg = "Already have the file '$original_file_name' in this activity. Not used against your quota."; + } } - -if ($success){ - //Test if user has file in another activity - $sql = " +if ($success) { + //Test if user has file in another activity + $sql = " SELECT cid FROM support_files WHERE userId = '$userId' AND cid = '$cid' AND doenetId != '$doenetId' "; - $result = $conn->query($sql); + $result = $conn->query($sql); - if ($result->num_rows > 0){ - $already_have_file = true; - $msg = "Found the file in another activity. Not used against your quota."; - } + if ($result->num_rows > 0) { + $already_have_file = true; + $msg = + 'Found the file in another activity. Not used against your quota.'; + } } - $escapedType = str_replace('\/', '/', $type); -if ($success && !$already_have_file){ - //track upload for IPFS upload nanny to upload later - $sql = " +if ($success && !$already_have_file) { + //track upload for IPFS upload nanny to upload later + $sql = " INSERT INTO ipfs_to_upload (cid,fileType,sizeInBytes,timestamp) VALUES ('$cid','$escapedType','$size',CONVERT_TZ(NOW(), @@session.time_zone, '+00:00')) "; - $result = $conn->query($sql); + $result = $conn->query($sql); } -if ($success){ - $sql = " +if ($success) { + $sql = " INSERT INTO support_files (userId,cid,doenetId,fileType,description,asFileName,sizeInBytes,widthPixels,heightPixels,timestamp) VALUES ('$userId','$cid','$doenetId','$escapedType','$description','$original_file_name','$size','$width','$height',CONVERT_TZ(NOW(), @@session.time_zone, '+00:00')) "; - $result = $conn->query($sql); + $result = $conn->query($sql); } -if ($success){ -// //TODO: test at the top as well for over quota - list($userQuotaBytesAvailable,$quotaBytes) = getBytesAvailable($conn,$userId); +if ($success) { + // //TODO: test at the top as well for over quota + list($userQuotaBytesAvailable, $quotaBytes) = getBytesAvailable( + $conn, + $userId + ); } // set response code - 200 OK http_response_code(200); -$response_arr = array("success" => $success, - "cid" => $cid, - "fileName" => $newFileName, - "description" => $description, - "asFileName" => $original_file_name, - "width" => $width, - "height" => $height, - "msg" => $msg, - "userQuotaBytesAvailable" => $userQuotaBytesAvailable); +$response_arr = [ + 'success' => $success, + 'cid' => $cid, + 'fileName' => $newFileName, + 'description' => $description, + 'asFileName' => $original_file_name, + 'width' => $width, + 'height' => $height, + 'msg' => $msg, + 'userQuotaBytesAvailable' => $userQuotaBytesAvailable, +]; // make it json format echo json_encode($response_arr); $conn->close(); -?> \ No newline at end of file +?> diff --git a/src/Tools/_framework/MenuPanelCaps/PortfilioEditorInfoCap.jsx b/src/Tools/_framework/MenuPanelCaps/PortfilioEditorInfoCap.jsx index 0da57f29cc..0f852ee7b8 100644 --- a/src/Tools/_framework/MenuPanelCaps/PortfilioEditorInfoCap.jsx +++ b/src/Tools/_framework/MenuPanelCaps/PortfilioEditorInfoCap.jsx @@ -1,13 +1,22 @@ +import { Box, Image } from '@chakra-ui/react'; import React from 'react'; import { useLoaderData } from 'react-router'; export async function loader(){ // export async function loader({params}){ - let params = new URL(document.location).searchParams; - let doenetId = params.get("doenetId"); // is the string "Jonathan Smith". - const response = await fetch(`/api/getPortfolioActivityData.php?doenetId=${doenetId}`); - const data = await response.json(); - + // let params = new URL(document.location).searchParams; + // let search = new URL(document.location).search; + // console.log("search",search) + // let doenetId = params.get("doenetId"); + let afterDoenetId = document.location.href?.split('&doenetId=')[1]; + let doenetId = afterDoenetId?.split('&pageId=')[0]; + //Somehow it still has the url which got us here + if (doenetId == undefined){ + doenetId = document.location.href?.split('/')[4]; + } + const response = await fetch(`/api/getPortfolioActivityData.php?doenetId=${doenetId}`); + const data = await response.json(); + return data.activityData; } @@ -15,9 +24,24 @@ export default function PortfilioEditorInfoCap(){ let data = useLoaderData(); return <> -
- Activity Thumbnail -
+ + Activity Image +
Portfolio Activity Editor
{/*
{data.label}
*/} diff --git a/src/Tools/_framework/Paths/Portfolio.jsx b/src/Tools/_framework/Paths/Portfolio.jsx index 53c13c1ab9..a4ce536488 100644 --- a/src/Tools/_framework/Paths/Portfolio.jsx +++ b/src/Tools/_framework/Paths/Portfolio.jsx @@ -9,7 +9,6 @@ import { GoKebabVertical } from 'react-icons/go'; export async function action({request}) { const formData = await request.formData(); let formObj = Object.fromEntries(formData); - console.log("formObj",formObj) if (formObj?._action == "Add Activity"){ //Create a portfilio activity and redirect to the editor for it @@ -132,8 +131,8 @@ function Card({ doenetId, imagePath, label, pageDoenetId, fullName, isPublic }) + height="130px"> Activity Card @@ -186,10 +185,9 @@ function Card({ doenetId, imagePath, label, pageDoenetId, fullName, isPublic }) - {/* */} - + {fullName} diff --git a/src/Tools/_framework/Paths/PortfolioActivitySettings.jsx b/src/Tools/_framework/Paths/PortfolioActivitySettings.jsx index a1ddc545bb..d6416bec5d 100644 --- a/src/Tools/_framework/Paths/PortfolioActivitySettings.jsx +++ b/src/Tools/_framework/Paths/PortfolioActivitySettings.jsx @@ -7,15 +7,17 @@ import Button from '../../../_reactComponents/PanelHeaderComponents/Button'; import { useDropzone } from 'react-dropzone'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faFileImage } from '@fortawesome/free-solid-svg-icons'; +import { Box, Image } from '@chakra-ui/react'; export async function action({ request, params }) { const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); const referrer = urlParams.get('referrer'); - + const formData = await request.formData(); let updates = Object.fromEntries(formData); + console.log("update settings updates",updates) let response = await axios.post("/api/updatePortfolioActivitySettings.php",{ ...updates, doenetId:params.doenetId }) @@ -106,26 +108,6 @@ const Td = styled.td` padding:10px; ` - const Image = styled.img` - max-width: 238px; - max-height: 122px; - ` - const CardTop = styled.div` - height: 124px; - width: 240px; - background: black; - overflow: hidden; - margin: 10px; - border: 2px solid #949494; - border-radius: 6px; - ` - -function ImagePreview({defaultValue}){ - return - preview - -} - const DropPad = styled.div` border: 2px dashed #949494; height: 144px; @@ -179,8 +161,8 @@ export function PortfolioActivitySettings(){ file, { quality: 0.9, - maxWidth: 238, - maxHeight: 122, + maxWidth: 176, + maxHeight: 127, debug: true } ); @@ -217,7 +199,6 @@ export function PortfolioActivitySettings(){ //uploads are finished clear it out numberOfFilesUploading.current = 0; let {success, cid} = data; - if (success){ setImagePath(`/media/${cid}.jpg`) } @@ -257,8 +238,25 @@ export function PortfolioActivitySettings(){ : (<>Image