Merge pull request 'statistics' (#59) from statistics into master

Reviewed-on: http://git.plannaplan.pl/y0rune/frontend/pulls/59
Reviewed-by: Maciej <glowackimaciej97@gmail.com>
This commit is contained in:
Maciej 2021-01-23 19:05:41 +01:00
commit a5d3beddb5
6 changed files with 71 additions and 22 deletions

View File

@ -1,9 +1,12 @@
import React, { useLayoutEffect, useRef } from 'react';
import React, { useContext, useLayoutEffect, useRef } from 'react';
import { useState } from 'react';
import { SchedulerEvents } from './SchedulerEvents';
import { days, hours } from '../constants/index';
import styled from 'styled-components/macro';
import { SchedulerEvent } from '../types';
import { coursesContext } from '../contexts/CoursesProvider';
import Button from '@material-ui/core/Button';
import Tooltip, { TooltipProps } from '@material-ui/core/Tooltip';
const SchedulerWrapper = styled.div`
border-collapse: collapse;
@ -17,6 +20,7 @@ const SchedulerWrapper = styled.div`
justify-content: center;
align-items: center;
box-shadow: 3px 3px 3px -2px rgba(0, 0, 0, 0.59);
position:relative;
`;
const TableBody = styled.div`
@ -62,6 +66,27 @@ const TableCell = styled.div<TableCellProps>`
font-weight: bold;
`;
const TourWrapper = styled.div`
display: flex;
justify-content:center;
align-items:center;
position:absolute;
top:8px;
right:8px;
min-width: 10px;
padding: 3px 7px;
font-size: 12px;
font-weight: 700;
color: black;
line-height: 1;
vertical-align: middle;
white-space: nowrap;
text-align: center;
background-color: #FFDC61;
border-radius: 10px;
font-size:18px;
`;
interface SchedulerProps {
schedulerEvents: Array<SchedulerEvent>;
}
@ -70,7 +95,8 @@ export const Scheduler = ({ schedulerEvents }: SchedulerProps) => {
const cellRef = useRef<HTMLDivElement>(null);
const [cellWidth, setCellWidth] = useState(0);
const [cellHeight, setCellHeight] = useState(0);
const { tour } = useContext(coursesContext)!;
useLayoutEffect(() => {
const handleResize = () => {
if (cellRef.current) {
@ -130,6 +156,19 @@ export const Scheduler = ({ schedulerEvents }: SchedulerProps) => {
))}
<SchedulerEvents cellWidth={cellWidth} cellHeight={cellHeight} schedulerEvents={schedulerEvents} />
</TableBody>
<TourWrapper>
<Tooltip title="Pierwsza Tura Zapisów">
<div style={{cursor: 'help'}}>{tour === 'FIRST_TOUR' && '1'}</div>
</Tooltip>
<Tooltip title="Druga Tura Zapisów">
<div style={{cursor: 'help'}}>{tour === 'SECOND_TOUR' && '2'}</div>
</Tooltip>
<Tooltip title="Zapisywanie wyłączone">
<div style={{cursor: 'help'}}>{tour === 'NO_TOUR' && 'X'}</div>
</Tooltip>
</TourWrapper>
</SchedulerWrapper>
);
};

View File

@ -239,10 +239,10 @@ export const SchedulerRow = ({ groups, indexRow, rowTop, cellWidth, cellHeight }
<PopoverSpan>Sala zajęć</PopoverSpan>: {groups[index].room}
</p>
<p style={{ margin: '2px 0 2px 0' }}>
<PopoverSpan>Kod przedmiotu: </PopoverSpan>ACB129
<PopoverSpan>Kod przedmiotu: </PopoverSpan> {groups[index].symbol}
</p>
<p style={{ margin: '2px 0 2px 0' }}>
<PopoverSpan>Kod grupy: </PopoverSpan>FVJ753
<PopoverSpan>Numer grupy: </PopoverSpan> {groups[index].grNr}
</p>
<p style={{ margin: '2px 0 2px 0', color:"green"}}>
<b>{groups[index].isAccepted===true && "Przedmiot został zaakceptowany"}</b>

View File

@ -10,6 +10,7 @@ import { SelectMenu } from './SelectMenu';
import { studentsContext } from '../contexts/StudentsProvider';
import { CASContext } from '../contexts/CASProvider';
import { render } from 'react-dom';
import { coursesContext } from '../contexts/CoursesProvider';
const Topbar = styled.div`
background-color: #e3e5ed;
@ -112,6 +113,8 @@ const IconWrapper = styled.div`
margin-right: 10px;
`;
const Icon = styled.img`
width: 40px;
margin-left: 40px;
@ -215,9 +218,8 @@ export default function ({ handleTransfer }: TopbarProps) {
</FlexboxColumn>
<IconWrapper>
<SelectedStudent>{selectedStudent?.email.replace(/@st.amu.edu.pl/, '')}</SelectedStudent>
{/* <Text>Maciej Głowacki</Text> */}
{userPrivilige==="STUDENT" && <Icon alt="transfer" src={TransferIcon} onClick={handleTransfer} />}
{userPrivilige === 'STUDENT' && <Icon alt="transfer" src={TransferIcon} onClick={handleTransfer} />}
{/* <Icon alt="change_language" src={isPolish ? EnglishIcon : PolishIcon} onClick={onLangChange} /> */}
<Icon alt="logout" src={LogoutIcon} onClick={logout} />
{/* <Profile anchorEl={anchorEl} handleClose={handleCloseProfile} /> */}

View File

@ -180,7 +180,7 @@ const ExchangeParagraph = styled.p`
`;
export const Transfer = ({ handleClose, isTransferOpen }: TransferProps) => {
const { basket, selectBasketCourses } = useContext(coursesContext)!;
const { basket, tour, selectBasketCourses } = useContext(coursesContext)!;
// const basketCourseGroups = useMemo(() => selectBasketCourseGroups(course.name), []);
const basketCourses = selectBasketCourses();
@ -195,7 +195,6 @@ export const Transfer = ({ handleClose, isTransferOpen }: TransferProps) => {
const [groups, setGroups] = useState<any>([]);
const [exchanges, setExchanges] = useState<any>(null);
const [save, setSave] = useState(false);
const [tour, setTour] = useState<any>(null);
// const allGroups
const handleSelectedAssignmentsGroupChange = (event: React.ChangeEvent<{ value: unknown }>) => {
setSelectedAssignmentsClasses(event.target.value as any);
@ -243,7 +242,6 @@ export const Transfer = ({ handleClose, isTransferOpen }: TransferProps) => {
}
};
getExchanges();
getCurrentTour();
getAssignmentsGroups();
}, [isTransferOpen, save]);
@ -261,15 +259,6 @@ export const Transfer = ({ handleClose, isTransferOpen }: TransferProps) => {
setSave(!save);
};
const getCurrentTour = async () => {
try {
const { data } = await axiosInstance.get(`${process.env.REACT_APP_API_URL}/api/v1/configurator/config/tour`);
setTour(data.currentTour);
} catch (e) {
console.log(e);
}
};
const deleteExchange = async (id: number) => {
try {
const response = await axiosInstance.delete(`${process.env.REACT_APP_API_URL}/api/v1/exchanges/exchange/${id}`);

View File

@ -21,6 +21,8 @@ interface CourseContext {
userID: string;
isDataLoading: boolean;
historyBasket: Array<Basket>;
tour: string;
getCurrentTour: () => void;
addCourseToBasket: (courses: Course) => void;
changeHoveredGroup: (group: Group | null) => void;
changeGroupInBasket: (group: any, courseId: number) => void;
@ -57,6 +59,7 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
const [userID, setUserID] = useState('');
const [hoveredGroup, setHoveredGroup] = useState<Group | undefined | null>(null);
const [isDataLoading, setIsDataLoading] = useState(false);
const [tour, setTour] = useState('');
const selectBasketIds = () => {
const classesIds = basket.map((course) => course?.classes?.id).filter((course) => course !== undefined);
@ -76,12 +79,12 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
const selectSchedulerEvents = () => {
return basket.reduce((res, el) => {
const { name } = el;
const { name, symbol } = el;
if (el.classes) {
res.push({ ...el.classes, name });
res.push({ ...el.classes, name, symbol});
}
if (el.lecture) {
res.push({ ...el.lecture, name });
res.push({ ...el.lecture, name, symbol });
}
return res;
}, [] as Array<SchedulerEvent>);
@ -161,7 +164,7 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
});
} catch (e) {
console.log('error: ', e);
enqueueSnackbar('Zapisywanie planu nie powiodło się', {
enqueueSnackbar('Zapisywanie niemożliwe w czasie bezturowym', {
variant: 'error',
action,
});
@ -274,9 +277,19 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
setHistoryBasket(basket);
};
const getCurrentTour = async () => {
try {
const { data } = await axiosInstance.get(`${process.env.REACT_APP_API_URL}/api/v1/configurator/config/tour`);
setTour(data.currentTour);
} catch (e) {
console.log(e);
}
};
useEffect(() => {
setIsDataLoading(true);
setTimeout(() => {
getCurrentTour();
fetchCourses();
getNewestTimetable();
setIsDataLoading(false);
@ -293,6 +306,8 @@ export const CoursesProvider = ({ children }: CoursesProviderProps) => {
timetableHistory,
isDataLoading,
historyBasket,
tour,
getCurrentTour,
addCourseToBasket,
changeHoveredGroup,
changeGroupInBasket,

View File

@ -6,6 +6,7 @@ export enum GroupType {
export interface Basket {
id: number;
name: string;
symbol?:string;
lecture?: Group;
classes?: Group;
}
@ -21,6 +22,7 @@ export interface Group {
capacity?: number;
takenPlaces: number;
isAccepted:boolean;
grNr: number;
}
export interface Course {
@ -55,6 +57,8 @@ export interface SchedulerEvent {
takenPlaces: number;
name: string;
isAccepted:boolean;
grNr?: number;
symbol?:string;
}
export interface TimetableHistory {