Skip to content

Commit

Permalink
show teachers of the course
Browse files Browse the repository at this point in the history
  • Loading branch information
mluukkai committed Sep 13, 2024
1 parent dc8f2ee commit 3a15aee
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/client/components/Courses/Course/Stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const Stats = ({ courseId }: { courseId: string }) => {
onClick={() => setStudentListOpen(!studentListOpen)}
sx={{ mt: 1 }}
color="primary"
style={{ marginTop: 10, marginLeft: -8 }}
>
{studentListOpen
? t('admin:hideStudentList')
Expand Down
32 changes: 31 additions & 1 deletion src/client/components/Courses/Course/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import SystemMessage from '../../Chat/SystemMessage'
import Conversation from '../../Chat/Conversation'
import usePrompts from '../../../hooks/usePrompts'
import useCourse from '../../../hooks/useCourse'
import useCurrentUser from '../../../hooks/useCurrentUser'
import {
useCreatePromptMutation,
useDeletePromptMutation,
Expand Down Expand Up @@ -86,6 +87,8 @@ const Course = () => {
const [hidden, setHidden] = useState(false)
const [mandatory, setMandatory] = useState(false)

const [showTeachers, setShowTeachers] = useState(false)

const [activityPeriodFormOpen, setActivityPeriodFormOpen] = useState(false)

const { id } = useParams()
Expand All @@ -112,10 +115,12 @@ const Course = () => {

const { prompts, isLoading } = usePrompts(id as string)
const { course, isLoading: courseLoading } = useCourse(id as string)
const { user, isLoading: isUserLoading } = useCurrentUser()

const studentLink = `${window.location.origin}${PUBLIC_URL}/${course?.courseId}`

if (isLoading || courseLoading || !course) return null
if (isLoading || courseLoading || !course || isUserLoading || !user)
return null

const mandatoryPromptId = prompts.find((prompt) => prompt.mandatory)?.id

Expand Down Expand Up @@ -155,6 +160,8 @@ const Course = () => {

const courseEnabled = course.usageLimit > 0

const responsebilitues = course.responsibilities

const isCourseActive =
courseEnabled &&
Date.parse(course.activityPeriod.endDate) > Date.now() &&
Expand Down Expand Up @@ -289,6 +296,29 @@ const Course = () => {
</Tooltip>
)}
</div>

{user.isAdmin && (
<>
<Button
onClick={() => setShowTeachers(!showTeachers)}
style={{ marginTop: 10, marginLeft: -8 }}
>
{showTeachers
? t('admin:hideTeachers')
: t('admin:showTeachers')}
</Button>
{showTeachers && (
<ul>
{responsebilitues.map((responsibility) => (
<li>
{responsibility.user.last_name}{' '}
{responsibility.user.first_names}
</li>
))}
</ul>
)}
</>
)}
</Paper>
</Box>

Expand Down
2 changes: 2 additions & 0 deletions src/client/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
"noChats": "No open course chats"
},
"admin": {
"hideTeachers": "Hide teachers",
"showTeachers": "Show teachers",
"showStudentList": "Show students",
"hideStudentList": "Hide students",
"usageByUser": "Usage per student",
Expand Down
2 changes: 2 additions & 0 deletions src/client/locales/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
"invalidFileType": "Tiedostotyyppiä ei tueta"
},
"admin": {
"hideTeachers": "Piilota opettajat ja vastuuhenkilöt",
"showTeachers": "Näytä opettajat ja vastuuhenkilöt",
"showStudentList": "Näytä opiskelijat",
"hideStudentList": "Piilota opiskelijat",
"usageByUser": "Käyttö per opiskelija",
Expand Down
12 changes: 12 additions & 0 deletions src/client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,22 @@ export interface Enrolment {
student_number: string
}
}

interface Responsebility {
id: string
user: {
id: string
username: string
last_name: string
first_names: string
}
}

export interface Course extends ChatInstance {
activityPeriod: ActivityPeriod
prompts: Prompt[]
enrolments: Enrolment[]
responsibilities: Responsebility[]
}

export type ChatInstanceUsage = {
Expand Down
13 changes: 13 additions & 0 deletions src/server/routes/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
UserChatInstanceUsage,
Prompt,
User,
Responsibility,
} from '../db/models'
import { getOwnCourses } from '../chatInstances/access'

Expand Down Expand Up @@ -97,6 +98,18 @@ courseRouter.get('/:id', async (req, res) => {
const { id } = req.params

const include = [
{
model: Responsibility,
as: 'responsibilities',
attributes: ['id'],
include: [
{
model: User,
as: 'user',
attributes: ['id', 'username', 'last_name', 'first_names'],
},
],
},
{
model: Prompt,
as: 'prompts',
Expand Down

0 comments on commit 3a15aee

Please sign in to comment.