Skip to content

Commit 6ed6583

Browse files
committed
Add global lock for course scans; add logic for teacher name
1 parent 64e3869 commit 6ed6583

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

assets/js/Components/Admin/CoursesPage.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default function CoursePage({
1616
}) {
1717

1818
const [filteredCourses, setFilteredCourses] = useState([])
19+
const [isAnyScanning, setIsAnyScanning] = useState(false)
1920
const [tableSettings, setTableSettings] = useState({
2021
sortBy: 'errors',
2122
ascending: false,
@@ -81,20 +82,20 @@ export default function CoursePage({
8182
filesReviewed: hasReport && course.report ? course.report.filesReviewed : '---',
8283
action: <div className="flex-row gap-1">
8384
<button key={`reportButton${course.id}`}
84-
onClick={() => { !course.loading && hasReport && handleReportClick(course) }}
85+
onClick={() => { !course.loading && !isAnyScanning && hasReport && handleReportClick(course) }}
8586
textAlign="center"
86-
className={`btn btn-text btn-icon-only ${(course.loading || !hasReport) ? 'btn-disabled' : ''}`}
87-
disabled={course.loading || !hasReport}
87+
className={`btn btn-text btn-icon-only ${((course.loading || isAnyScanning) || !hasReport) ? 'btn-disabled' : ''}`}
88+
disabled={(course.loading || isAnyScanning) || !hasReport}
8889
title={hasReport ? t('report.button.view_report') : t('report.button.no_report')}
8990
aria-label={hasReport ? t('report.button.view_report') : t('report.button.no_report')}
9091
>
9192
<ReportIcon className="icon-md" />
9293
</button>
9394
<button key={`scanButton${course.id}`}
94-
onClick={() => { !course.loading && handleScanClick(course) }}
95+
onClick={() => { !course.loading && !isAnyScanning && handleScanClick(course) }}
9596
textAlign="center"
96-
className={`btn btn-text btn-icon-only ${course.loading ? 'btn-disabled' : ''}`}
97-
disabled={course.loading}
97+
className={`btn btn-text btn-icon-only ${(course.loading || isAnyScanning) ? 'btn-disabled' : ''}`}
98+
disabled={course.loading || isAnyScanning}
9899
title={t('report.button.scan')}
99100
aria-label={t('report.button.scan')}
100101
>
@@ -158,6 +159,7 @@ export default function CoursePage({
158159

159160
const handleScanClick = (course) => {
160161
let api = new Api(settings)
162+
setIsAnyScanning(true)
161163

162164
// For unscanned courses, course.id will be the LMS course ID (string/number)
163165
// and hasReport will be false. We need to create the course in UDOIT first.
@@ -227,6 +229,7 @@ export default function CoursePage({
227229
})
228230
course.loading = false
229231
handleCourseUpdate(course)
232+
setIsAnyScanning(false)
230233
})
231234
} else {
232235
// For already scanned courses, use the UDOIT database ID
@@ -259,6 +262,7 @@ export default function CoursePage({
259262
})
260263
course.loading = false
261264
handleCourseUpdate(course)
265+
setIsAnyScanning(false)
262266
})
263267
}
264268

@@ -305,6 +309,7 @@ export default function CoursePage({
305309
}
306310

307311
handleCourseUpdate(updatedCourse)
312+
setIsAnyScanning(false)
308313
}
309314
})
310315
}, newReportInterval)

src/Controller/AdminController.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,18 @@ public function getCoursesData(
128128
$instructorNames = [];
129129
if (!empty($cc['teachers']) && is_array($cc['teachers'])) {
130130
foreach ($cc['teachers'] as $teacher) {
131-
if (!empty($teacher['display_name'])) {
132-
$instructorNames[] = $teacher['display_name'];
131+
$name = null;
132+
if (!empty($teacher['name'])) {
133+
$name = $teacher['name'];
134+
} elseif (!empty($teacher['display_name'])) {
135+
$name = $teacher['display_name'];
136+
} elseif (!empty($teacher['short_name'])) {
137+
$name = $teacher['short_name'];
138+
} elseif (!empty($teacher['sortable_name'])) {
139+
$name = $teacher['sortable_name'];
140+
}
141+
if (!empty($name)) {
142+
$instructorNames[] = $name;
133143
}
134144
}
135145
}

0 commit comments

Comments
 (0)