1 | import React, { useState, useEffect } from "react";
|
---|
2 | import { useParams, Outlet } from "react-router-dom";
|
---|
3 | import JSOG from "jsog";
|
---|
4 | import {
|
---|
5 | ProfessorCard,
|
---|
6 | ProfessorCardName,
|
---|
7 | ProfessorCardSeparator,
|
---|
8 | ProfessorCardDetails,
|
---|
9 | } from "../Components/Styled/ProfessorCard.style";
|
---|
10 | import {
|
---|
11 | EntityUl,
|
---|
12 | EntityLi,
|
---|
13 | EntityParam,
|
---|
14 | EntityTypeSelector,
|
---|
15 | } from "../Components/Styled/EntityList.style";
|
---|
16 | import SubjectsAccordion from "../Components/SubjectsAccordion";
|
---|
17 | import { CurrentPageNav } from "../Components/Styled/Main.style";
|
---|
18 | import LoadingSpinner from "../Components/Styled/LoadingSpinner.style";
|
---|
19 |
|
---|
20 | const Faculty = () => {
|
---|
21 | let params = useParams();
|
---|
22 |
|
---|
23 | const [professors, setProfessors] = useState(null);
|
---|
24 | const [studyProgrammes, setStudyProgrammes] = useState(null);
|
---|
25 | const [professorOpinionCount, setProfessorOpinionCount] = useState(null);
|
---|
26 | const [loadedProfessors, setLoadedProfessors] = useState(false);
|
---|
27 | const [loadedStudyProgrammes, setLoadedStudyProgrammes] = useState(false);
|
---|
28 | const [loadedProfessorOpinionCount, setLoadedProfessorOpinionCount] = useState(false);
|
---|
29 |
|
---|
30 | const [fetchError, setFetchError] = useState(false);
|
---|
31 | const [entityType, setEntityType] = useState(0);
|
---|
32 |
|
---|
33 | useEffect(() => {
|
---|
34 | const fetchProfessors = async () => {
|
---|
35 | try {
|
---|
36 | const response = await fetch(`http://192.168.1.108:8080/public/professors?facultyId=${params.facultyId}`);
|
---|
37 | let cyclicGraph = await response.json();
|
---|
38 | let jsogStructure = JSOG.encode(cyclicGraph);
|
---|
39 | cyclicGraph = JSOG.decode(jsogStructure);
|
---|
40 | setProfessors(cyclicGraph);
|
---|
41 | setLoadedProfessors(true);
|
---|
42 | } catch (error) {
|
---|
43 | setFetchError(true);
|
---|
44 | }
|
---|
45 | };
|
---|
46 |
|
---|
47 | const fetchStudyProgrammes = async () => {
|
---|
48 | try {
|
---|
49 | const response2 = await fetch(`http://192.168.1.108:8080/public/study_programmes?facultyId=${params.facultyId}`);
|
---|
50 | let cyclicGraph2 = await response2.json();
|
---|
51 | let jsogStructure2 = JSOG.encode(cyclicGraph2);
|
---|
52 | cyclicGraph2 = JSOG.decode(jsogStructure2);
|
---|
53 | setStudyProgrammes(cyclicGraph2);
|
---|
54 | setLoadedStudyProgrammes(true);
|
---|
55 | } catch (error) {
|
---|
56 | setFetchError(true);
|
---|
57 | }
|
---|
58 | };
|
---|
59 |
|
---|
60 | const fetchProfessorOpinionCount = async () => {
|
---|
61 | try {
|
---|
62 | const response3 = await fetch(`http://192.168.1.108:8080/public/faculty/${params.facultyId}/opinionCountForEachProfessor`);
|
---|
63 | let cyclicGraph3 = await response3.json();
|
---|
64 | let jsogStructure3 = JSOG.encode(cyclicGraph3);
|
---|
65 | cyclicGraph3 = JSOG.decode(jsogStructure3);
|
---|
66 | setProfessorOpinionCount(cyclicGraph3);
|
---|
67 | setLoadedProfessorOpinionCount(true);
|
---|
68 | } catch (error) {
|
---|
69 | setFetchError(true);
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | fetchProfessors();
|
---|
74 | fetchStudyProgrammes();
|
---|
75 | fetchProfessorOpinionCount();
|
---|
76 | }, [params.facultyId]);
|
---|
77 |
|
---|
78 | return loadedProfessors && professors.length !== 0 ? (
|
---|
79 | entityType === 0 ? (
|
---|
80 | <>
|
---|
81 | <CurrentPageNav>
|
---|
82 | »{" "}
|
---|
83 | <a
|
---|
84 | href={
|
---|
85 | "/university/" + professors[0].faculty.university.universityId
|
---|
86 | }
|
---|
87 | >
|
---|
88 | {professors[0].faculty.university.universityName}
|
---|
89 | </a>{" "}
|
---|
90 | » <a href="#">{professors[0].faculty.facultyName}</a>
|
---|
91 | </CurrentPageNav>
|
---|
92 | <ProfessorCard>
|
---|
93 | <ProfessorCardName>
|
---|
94 | {professors[0].faculty.facultyName}
|
---|
95 | </ProfessorCardName>
|
---|
96 | <ProfessorCardSeparator />
|
---|
97 | <ProfessorCardDetails fontSize="20px">
|
---|
98 | {professors[0].faculty.university.universityName}
|
---|
99 | </ProfessorCardDetails>
|
---|
100 | </ProfessorCard>
|
---|
101 | <div style={{ display: "flex" }}>
|
---|
102 | <EntityTypeSelector
|
---|
103 | backgroundcolor="rgba(0, 102, 204, 1)"
|
---|
104 | color="white"
|
---|
105 | boxshadow="none"
|
---|
106 | boxshadowhover="none"
|
---|
107 | opacityhover="0.6"
|
---|
108 | cursor="auto"
|
---|
109 | >
|
---|
110 | Прикажи професори
|
---|
111 | </EntityTypeSelector>
|
---|
112 | <EntityTypeSelector
|
---|
113 | boxshadow="2px 2px 5px #aaaaaa"
|
---|
114 | cursor="pointer"
|
---|
115 | boxshadowhover="2px 2px 10px #aaaaaa"
|
---|
116 | opacityhover="1"
|
---|
117 | onClick={() => setEntityType(1)}
|
---|
118 | >
|
---|
119 | Прикажи предмети
|
---|
120 | </EntityTypeSelector>
|
---|
121 | </div>
|
---|
122 | <div key={params.facultyId}>
|
---|
123 | {professors.map((professor, idx) => {
|
---|
124 | let totalPosts = loadedProfessorOpinionCount ? parseInt(professorOpinionCount[idx].split(",")[1]) : 0;
|
---|
125 | return (
|
---|
126 | <EntityUl key={professor.professorId}>
|
---|
127 | <EntityLi bgcolor="cornsilk">
|
---|
128 | <a href={"/professor/" + professor.professorId}>
|
---|
129 | {professor.professorName}
|
---|
130 | </a>
|
---|
131 | <EntityParam right="30px">
|
---|
132 | {totalPosts !== 1 ? (
|
---|
133 | totalPosts !== 0 ? (
|
---|
134 | <span
|
---|
135 | style={{
|
---|
136 | fontWeight: "normal",
|
---|
137 | opacity: totalPosts === 0 ? "0.5" : "1",
|
---|
138 | }}
|
---|
139 | >
|
---|
140 | <span
|
---|
141 | style={{
|
---|
142 | fontWeight: "bold",
|
---|
143 | opacity: totalPosts === 0 ? "0.5" : "1",
|
---|
144 | }}
|
---|
145 | >
|
---|
146 | {totalPosts}
|
---|
147 | </span>{" "}
|
---|
148 | мислења
|
---|
149 | </span>
|
---|
150 | ) : (
|
---|
151 | <span
|
---|
152 | style={{
|
---|
153 | fontWeight: "normal",
|
---|
154 | opacity: totalPosts === 0 ? "0.5" : "1",
|
---|
155 | }}
|
---|
156 | >
|
---|
157 | <span
|
---|
158 | style={{
|
---|
159 | fontWeight: "bold",
|
---|
160 | opacity: totalPosts === 0 ? "0.5" : "1",
|
---|
161 | }}
|
---|
162 | >
|
---|
163 | {totalPosts}
|
---|
164 | </span>{" "}
|
---|
165 | мислења
|
---|
166 | </span>
|
---|
167 | )
|
---|
168 | ) : (
|
---|
169 | <span style={{ fontWeight: "normal" }}>
|
---|
170 | <span style={{ fontWeight: "bold" }}>{totalPosts}</span>{" "}
|
---|
171 | мислење
|
---|
172 | </span>
|
---|
173 | )}
|
---|
174 | </EntityParam>
|
---|
175 | </EntityLi>
|
---|
176 | </EntityUl>
|
---|
177 | );
|
---|
178 | })}
|
---|
179 | </div>
|
---|
180 | </>
|
---|
181 | ) : (
|
---|
182 | loadedStudyProgrammes && (
|
---|
183 | <>
|
---|
184 | <CurrentPageNav>
|
---|
185 | »{" "}
|
---|
186 | <a
|
---|
187 | href={
|
---|
188 | "/university/" + professors[0].faculty.university.universityId
|
---|
189 | }
|
---|
190 | >
|
---|
191 | {professors[0].faculty.university.universityName}
|
---|
192 | </a>{" "}
|
---|
193 | » <a href="#">{professors[0].faculty.facultyName}</a>
|
---|
194 | </CurrentPageNav>
|
---|
195 | <ProfessorCard>
|
---|
196 | <ProfessorCardName>
|
---|
197 | {professors[0].faculty.facultyName}
|
---|
198 | </ProfessorCardName>
|
---|
199 | <ProfessorCardSeparator />
|
---|
200 | <ProfessorCardDetails fontSize="20px">
|
---|
201 | {professors[0].faculty.university.universityName}
|
---|
202 | </ProfessorCardDetails>
|
---|
203 | </ProfessorCard>
|
---|
204 | <div style={{ display: "flex" }}>
|
---|
205 | <EntityTypeSelector
|
---|
206 | boxshadow="2px 2px 5px #aaaaaa"
|
---|
207 | cursor="pointer"
|
---|
208 | boxshadowhover="2px 2px 10px #aaaaaa"
|
---|
209 | opacityhover="1"
|
---|
210 | onClick={() => setEntityType(0)}
|
---|
211 | >
|
---|
212 | Прикажи професори
|
---|
213 | </EntityTypeSelector>
|
---|
214 | <EntityTypeSelector
|
---|
215 | backgroundcolor="rgba(0, 102, 204, 1)"
|
---|
216 | color="white"
|
---|
217 | boxshadow="none"
|
---|
218 | boxshadowhover="none"
|
---|
219 | opacityhover="0.6"
|
---|
220 | cursor="auto"
|
---|
221 | >
|
---|
222 | Прикажи предмети
|
---|
223 | </EntityTypeSelector>
|
---|
224 | </div>
|
---|
225 | <div key={params.facultyId}>
|
---|
226 | {studyProgrammes.map((studyProgramme) => {
|
---|
227 | return (
|
---|
228 | <SubjectsAccordion
|
---|
229 | key={studyProgramme.studyProgrammeId}
|
---|
230 | title={studyProgramme}
|
---|
231 | ></SubjectsAccordion>
|
---|
232 | );
|
---|
233 | })}
|
---|
234 | </div>
|
---|
235 | </>
|
---|
236 | )
|
---|
237 | )
|
---|
238 | ) : !fetchError && !loadedProfessors ? (
|
---|
239 | <div>
|
---|
240 | <LoadingSpinner style={{ marginTop: "140px" }}/>
|
---|
241 | <Outlet />
|
---|
242 | </div>
|
---|
243 | ) : (
|
---|
244 | <div style={{ marginTop: "140px" }}>
|
---|
245 | <h1 style={{ textAlign: "center" }}>Страницата не е пронајдена.</h1>
|
---|
246 | </div>
|
---|
247 | );
|
---|
248 | };
|
---|
249 |
|
---|
250 | export default Faculty;
|
---|