diff --git a/src/client/components/Courses/Course/Stats.tsx b/src/client/components/Courses/Course/Stats.tsx index 7a257ae..37a0ce3 100644 --- a/src/client/components/Courses/Course/Stats.tsx +++ b/src/client/components/Courses/Course/Stats.tsx @@ -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') diff --git a/src/client/components/Courses/Course/index.tsx b/src/client/components/Courses/Course/index.tsx index bea507c..f920eac 100644 --- a/src/client/components/Courses/Course/index.tsx +++ b/src/client/components/Courses/Course/index.tsx @@ -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, @@ -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() @@ -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 @@ -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() && @@ -289,6 +296,29 @@ const Course = () => { )} + + {user.isAdmin && ( + <> + + {showTeachers && ( + + )} + + )} diff --git a/src/client/locales/en.json b/src/client/locales/en.json index 7aca32e..75d8081 100644 --- a/src/client/locales/en.json +++ b/src/client/locales/en.json @@ -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", diff --git a/src/client/locales/fi.json b/src/client/locales/fi.json index 35c96c8..10cc63c 100644 --- a/src/client/locales/fi.json +++ b/src/client/locales/fi.json @@ -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", diff --git a/src/client/types.ts b/src/client/types.ts index 6503f8e..26714fd 100644 --- a/src/client/types.ts +++ b/src/client/types.ts @@ -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 = { diff --git a/src/server/routes/course.ts b/src/server/routes/course.ts index dc25a16..e764922 100644 --- a/src/server/routes/course.ts +++ b/src/server/routes/course.ts @@ -8,6 +8,7 @@ import { UserChatInstanceUsage, Prompt, User, + Responsibility, } from '../db/models' import { getOwnCourses } from '../chatInstances/access' @@ -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',