Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 46 additions & 20 deletions assets/js/Components/FixIssuesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export default function FixIssuesPage({
})
{



// Define the kinds of filters that will be available to the user
const FILTER = {
TYPE: {
Expand Down Expand Up @@ -623,7 +625,6 @@ export default function FixIssuesPage({
if(state === null) {
state = settings.ISSUE_STATE.UNCHANGED
}

// This updates the counter for the daily progress
updateSessionIssue(issueId, state, contentItemId)

Expand Down Expand Up @@ -655,20 +656,26 @@ export default function FixIssuesPage({
}
}

const updateFile = (tempFile) => {
const updateFile = (tempFile, oldFile) => {
const tempReport = Object.assign({}, report)
if(activeIssue?.fileData?.id === oldFile.id){ // Check if we are still on the same issue
const formattedFile = formatFileData(tempFile);
setActiveIssue(formattedFile); // Make it the new issue
}
tempReport.files[tempFile.id] = tempFile;
delete tempReport.files[oldFile.id]; // Delete the old file

// Occasionally, the report will send back a list of files in an object instead of an array.
// It would be nice to use tempReport.files.map, but that doesn't work with objects.
for (const [key, value] of Object.entries(tempReport.files)) {
if (key.toString() === tempFile.id.toString()) {
if(activeIssue?.fileData?.id === tempFile.id) {
const formattedFile = formatFileData(tempFile)
setActiveIssue(formattedFile)
}
tempReport.files[key] = tempFile
}
}
// for (const [key, value] of Object.entries(tempReport.files)) {
// if (key.toString() === tempFile.id.toString()) {
// if(activeIssue?.fileData?.id === tempFile.id) {
// const formattedFile = formatFileData(tempFile)
// setActiveIssue(formattedFile)
// }
// tempReport.files[key] = tempFile
// }
// }
processNewReport(tempReport)
}

Expand Down Expand Up @@ -801,25 +808,43 @@ export default function FixIssuesPage({
* handleFileUpload is called when a new file has already been selected by the user
* and is ready to be uploaded to the server and verified.
*/
const handleFileUpload = (newFileData) => {
const handleFileUpload = (newFileData, references) => {

const tempFile = Object.assign({}, activeIssue.fileData)
const tempFile = Object.assign({}, activeIssue.fileData) // Copy over the current file

updateActiveSessionIssue("file-" + tempFile.id, settings.ISSUE_STATE.SAVING)
console.log("References from fixPageIssues: " + references);

try {
let api = new Api(settings)
api.postFile(tempFile, newFileData)
let api = new Api(settings) // API Call
api.postFile(tempFile, newFileData, references)
.then((responsStr) => responsStr.json())
.then((response) => {
const updatedFileData = { ...tempFile, ...response.data.file }

// let updatedFileData = Object.assign({}, tempFile) // New copy of the file to add updated fields
// // Iterate over every key value pair from response and update them in response, very short O(1) as we are going over the same number of key value pairs everytime

// for(const [key, value] of Object.entries(response.data.data.content)){
// if(key.toString() === 'id'){
// updatedFileData.lmsFileId = value;
// updatedFileData.lmsUrl = updatedFileData.lmsUrl.replace(/preview=\d+/, `preview=${value}`)
// }
// if(key.toString() === 'filename'){
// updatedFileData.fileName = value;
// }
// if(key.toString() === 'size'){
// updatedFileData.fileSize = value;
// }
// if(key.toString() === 'url'){
// updatedFileData.downloadUrl = value;
// }
// }
const newFile = response.data; // Get the new file data from the response
// Set messages
response.messages.forEach((msg) => addMessage(msg))

// Update the local report and activeIssue
updateActiveSessionIssue("file-" + tempFile.id, settings.ISSUE_STATE.SAVED)
updateFile(updatedFileData)
updateFile(newFile, tempFile)
updateActiveSessionIssue("file-" + newFile.id, settings.ISSUE_STATE.RESOLVED)

})
} catch (error) {
console.error(error)
Expand Down Expand Up @@ -1010,6 +1035,7 @@ export default function FixIssuesPage({
return keywords.join(' ')
}


return (
<>
{ widgetState === WIDGET_STATE.LOADING ? (
Expand Down
23 changes: 22 additions & 1 deletion assets/js/Components/Forms/FileForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default function FileForm ({

const [acceptType, setAcceptType] = useState([])
const [uploadedFile, setUploadedFile] = useState(null)
const [changeReferences, setChangeReferences] = useState(false)

const getAcceptType = (file) => {
let accept = []
Expand Down Expand Up @@ -56,6 +57,8 @@ export default function FileForm ({
if(activeFile) {
setAcceptType(getAcceptType(activeFile.fileData))
}
console.log(activeFile)
console.log(changeReferences);
}, [activeFile])

// Drag and Drop code is adapted from:
Expand Down Expand Up @@ -92,6 +95,11 @@ export default function FileForm ({
event.preventDefault()
}

// Set checkReferences to true or false depending on event on checkbox
const handleReferences = (e) => {
setChangeReferences(e.target.checked);
}

// In order to trigger the file input dialog, we need an input element,
// and we don't want it to show on the page. So we create a temporary one.
const handleFileSelect = () => {
Expand All @@ -107,9 +115,14 @@ export default function FileForm ({
if (!uploadedFile) {
return
}
handleFileUpload(uploadedFile)
console.log("Change References from fileForm: " + changeReferences);
handleFileUpload(uploadedFile, changeReferences)
}

useEffect(() => {
console.log(changeReferences);
}, [changeReferences])

return (
<>
{/* <h3 >{t('form.file.label.replace')}</h3> */}
Expand Down Expand Up @@ -144,6 +157,14 @@ export default function FileForm ({
<div className="mt-3 flex-row">
<button className="btn btn-primary" onClick={handleSubmit}>{t('form.submit')}</button>
</div>
<div className=''>
<input
type='checkbox'
checked={changeReferences}
onChange={handleReferences}
/>
<span>Change Links to files in all content items</span>
</div>
</>
)}
</>
Expand Down
Loading