Skip to content

Commit 1d9f34f

Browse files
committed
The Report.js analyzeReport now also finds all references to files in contentItems. Still needs module searching.
1 parent da869ee commit 1d9f34f

File tree

5 files changed

+66
-17
lines changed

5 files changed

+66
-17
lines changed

assets/js/Components/App.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export default function App(initialData) {
134134
const processNewReport = (rawReport) => {
135135
const tempReport = analyzeReport(rawReport, ISSUE_STATE)
136136
setReport(tempReport)
137+
console.log(tempReport)
137138

138139
let api = new Api(settings)
139140
api.setReportData(tempReport.id, {'scanCounts': tempReport.scanCounts, 'scanRules': tempReport.scanRules})

assets/js/Components/Widgets/FileReviewPreview.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import DownloadIcon from '../Icons/DownloadIcon'
33
import ExternalLinkIcon from '../Icons/ExternalLinkIcon'
44
import * as Text from '../../Services/Text'
55
import './FixIssuesContentPreview.css'
6+
import SeverityIcon from '../Icons/SeverityIcon'
67

78

89
export default function FixIssuesContentPreview({
@@ -62,6 +63,28 @@ export default function FixIssuesContentPreview({
6263
<div className="flex-column flex-center allow-word-break">{Text.getReadableDateTime(activeIssue.fileData.updated)}</div>
6364
</div>
6465
</div>
66+
{ activeIssue.fileData.references.length === 0 ? (
67+
<div className="mt-3 callout-container">
68+
<div className="flex-row">
69+
<div className="flex-column justify-content-start mr-2">
70+
<SeverityIcon severity="potential" className="icon-md potential-color" alt="" />
71+
</div>
72+
<div className="flex-column justify-content-start">
73+
{t('fix.message.no_references_found')}
74+
</div>
75+
</div>
76+
</div>
77+
) : (
78+
<div className="mt-3">
79+
<h3>{t('fix.label.references')}</h3>
80+
{ activeIssue.fileData.references.map((reference) => (
81+
<p>
82+
<a href={reference.contentItemUrl} target="_blank" rel="noreferrer">{reference.contentItemTitle}</a>
83+
</p>
84+
)) }
85+
</div>
86+
)}
87+
6588
<div className="mt-3 flex-row justify-content-center gap-3">
6689
{ activeIssue.fileData.downloadUrl && (
6790
<button className="btn btn-secondary btn-icon-left" onClick={() => window.open(activeIssue.fileData.downloadUrl, 'download')}>

assets/js/Services/Report.js

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,39 @@ export function analyzeReport(report, ISSUE_STATE) {
8585
let millisecondsInADay = 86400000 // 1000 * 60 * 60 * 24
8686

8787
const parser = new DOMParser()
88+
const fileReferences = {}
89+
90+
// Parse every document only once. Not every content item will have issues, but we need to parse each one anyway
91+
// so we can scan them for references to course files.
92+
Object.values(report.contentItems).forEach((contentItem) => {
93+
if(contentItem.body) {
94+
let tempBody = parser.parseFromString(contentItem.body, 'text/html')
95+
96+
// Get all of the links to files in the content item.
97+
let links = tempBody.getElementsByTagName('a')
98+
const fileUrlPattern = /\/files\/(\d+)/
99+
for(let i = 0; i < links.length; i++) {
100+
let link = links[i]
101+
let href = link.getAttribute('href')
102+
if(href) {
103+
let match = href.match(fileUrlPattern)
104+
if(match && match[1]) {
105+
let fileId = match[1]
106+
if(!fileReferences[fileId]) {
107+
fileReferences[fileId] = []
108+
}
109+
fileReferences[fileId].push({
110+
contentItemTitle: contentItem.title,
111+
contentItemUrl: contentItem.url,
112+
contentType: contentItem.contentType,
113+
})
114+
}
115+
}
116+
}
117+
118+
parsedDocuments[contentItem.id] = tempBody
119+
}
120+
})
88121

89122
report.issues.forEach((issue) => {
90123

@@ -98,21 +131,9 @@ export function analyzeReport(report, ISSUE_STATE) {
98131
// Get the relevant content item
99132
let contentItemId = issue.contentItemId
100133

101-
// We're quickly caching all of the parsed documents so we don't have to parse them for each issue.
102-
let parsedDocument = null
103134
if(parsedDocuments[contentItemId]) {
104-
parsedDocument = parsedDocuments[contentItemId]
105-
}
106-
else {
107-
if(report?.contentItems[contentItemId]?.body) {
108-
parsedDocuments[contentItemId] = parser.parseFromString(report.contentItems[contentItemId].body, 'text/html')
109-
parsedDocument = parsedDocuments[contentItemId]
110-
}
111-
}
112-
113-
if(parsedDocument) {
114135
// In the initial scan, whatever comes back is saved to both the issue.xpath and issue.sourceHtml variables.
115-
let element = Html.findElementWithIssue(parsedDocument, issue)
136+
let element = Html.findElementWithIssue(parsedDocuments[contentItemId], issue)
116137
if(element) {
117138
issue.sourceHtml = Html.toString(element)
118139
let elementClasses = element.getAttribute('class')
@@ -169,6 +190,10 @@ export function analyzeReport(report, ISSUE_STATE) {
169190
}
170191
})
171192

193+
report.files.forEach((file) => {
194+
file.references = fileReferences[parseInt(file.lmsFileId)] || []
195+
})
196+
172197
let tempFilesReviewed = 0
173198
Object.values(report.files).forEach((file) => {
174199
if(file.reviewed) {
@@ -182,6 +207,7 @@ export function analyzeReport(report, ISSUE_STATE) {
182207
tempReport.issues = activeIssues
183208
tempReport.scanCounts = scanCounts
184209
tempReport.scanRules = scanRules
210+
tempReport.files = {...report.files}
185211
tempReport.contentItems = usedContentItems
186212
tempReport.sessionIssues = sessionIssues
187213
tempReport.filesReviewed = tempFilesReviewed

src/Entity/Course.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,7 @@ public function getFileItems($activeOnly = true): array
299299
$files = [];
300300

301301
foreach ($this->fileItems as $file) {
302-
// if ($activeOnly && !$file->isActive()) {
303-
// continue;
304-
// }
305-
$files[$file->getId()] = $file;
302+
$files[] = $file;
306303
}
307304

308305
return $files;

translations/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
"fix.label.file_type": "File Type",
203203
"fix.label.file_size": "File Size",
204204
"fix.label.file_updated": "Last Updated",
205+
"fix.label.references": "References in Course",
205206
"fix.label.screen_reader": "Screen Reader Text",
206207
"fix.label.no_error_preview": "Accessibility Barrier Not Found",
207208
"fix.label.no_saving": "Editing and Saving Unavailable",
@@ -236,6 +237,7 @@
236237
"fix.button.next_file": "Next File",
237238
"fix.button.scroll_to_issue": "Scroll to Issue",
238239
"fix.button.show_no_error_preview": "Show Content Preview",
240+
"fix.message.no_references_found": "This file is not referenced anywhere in the course. If it is not needed, consider deleting it to reduce clutter.",
239241
"fix.msg.select_issue": "Select an issue from the list to view its details and either fix it or mark it as reviewed.",
240242
"fix.msg.resolved": "If you have reviewed this issue and determined that it is not an accessibility barrier, you can mark it as reviewed.",
241243
"fix.msg.unresolved": "This issue has been marked as reviewed. If additional changes need to be made, you can mark it as unreviewed.",

0 commit comments

Comments
 (0)