Commit 591d93a5 authored by Jiawen Lyu's avatar Jiawen Lyu

not success in adding two students in sche

parent b8e351e7
......@@ -18,7 +18,7 @@ class App extends Component {
messages: [],
error: null,
isLoaded: false,
logins: ["lyujiawe"],
logins: ["lyujiawe", "jbarthel"],
uvs: []
};
addMessage(message) {
......
......@@ -7,45 +7,33 @@ export default WrappedComponent => {
this.state = {
error: null,
isLoaded: false,
data: []
};
}
componentDidMount() {
// this.props.logins.map(login => {
// fetch(`https://cors-anywhere.herokuapp.com/https://webapplis.utc.fr/Edt_ent_rest/myedt/result/?login=${login}`)
// .then(res => res.json())
// .then(
// (result) => {
// this.setState({
// isLoaded: true,
// data: result,
// login: login
// });
// },
// (error) => {
// this.setState({
// isLoaded: true,
// error
// });
// }
// )
// })
fetch(`https://cors-anywhere.herokuapp.com/https://webapplis.utc.fr/Edt_ent_rest/myedt/result/?login=${this.props.logins[0]}`)
.then(res => res.json())
.then(
(result) => {
this.setState({
isLoaded: true,
data: result,
login: this.props.logins[0]
});
},
(error) => {
this.setState({
isLoaded: true,
error
});
}
)
this.props.logins.map(login => {
// alert(login)
fetch(`https://cors-anywhere.herokuapp.com/https://webapplis.utc.fr/Edt_ent_rest/myedt/result/?login=${login}`)
.then(res => res.json())
.then(
(result) => {
this.setState({
isLoaded: true,
data: this.state.data.concat(result.map(elem => ({
login: login,
...elem
}))),
});
},
(error) => {
this.setState({
isLoaded: true,
error
});
}
)
})
}
render() {
......@@ -57,6 +45,7 @@ export default WrappedComponent => {
return <div>Chargement</div>;
} else {
return (
<WrappedComponent data={data} login={login} {...this.props} />
);
}
......
import React from 'react'
const data = [
const demoData = [
{
start_date: "2020-06-10 6:00",
end_date: "2020-06-10 8:00",
......@@ -31,6 +31,11 @@ const data = [
},
];
const demoLogins = [
"jiawen",
"linh"
]
const toDays = dayString => (
{
"LUNDI": 1,
......@@ -74,7 +79,7 @@ const getAllDays = (term, day) => {
return days
}
const extractUvDateInfo = (uvs, login) => {
const extractUvDateInfo = (uvs) => {
let uvInAllTerm = []
uvs.map(uv => {
const daysInTerm = getAllDays(semestreP20, toDays(uv.day))
......@@ -85,7 +90,7 @@ const extractUvDateInfo = (uvs, login) => {
end_date: day + " " + uv.end,
text: uv.uv,
id: uvInAllTerm.length + 1,
login: login
login: uv.login
}
]
})
......@@ -95,13 +100,12 @@ const extractUvDateInfo = (uvs, login) => {
const getCurrentStudents = data => Array.from(new Set(data.map(elem => elem.login)))
const withUVs = WrappedComponent => props => {
const { data, login } = props;
const uvs = extractUvDateInfo(data, login)
const currentStudents = getCurrentStudents(uvs)
return <WrappedComponent events={uvs} currentStudents={currentStudents} {...props} />;
const { data, logins } = props;
const uvs = extractUvDateInfo(data)
console.log("uvs: ", uvs)
return <WrappedComponent events={demoData} logins={demoLogins} {...props} />;
}
......
......@@ -14,8 +14,8 @@ const toColorName = index => (
4: "grey"
}[index]
)
const changeColorForEachStudent = (events, currentStudents) => events.map(event => {
event.color = toColorName(currentStudents.indexOf(event.login))
const changeColorForEachStudent = (events, logins) => events.map(event => {
event.color = toColorName(logins.indexOf(event.login))
event.text = event.text + "\n" + event.login
scheduler.updateEvent(event.id)
......@@ -66,11 +66,11 @@ export default class Scheduler extends Component {
this.initSchedulerEvents();
const { events, currentStudents } = this.props;
const { events, logins } = this.props;
scheduler.init(this.schedulerContainer, new Date(2020, 5, 10));
scheduler.clearAll();
scheduler.parse(events);
changeColorForEachStudent(events, currentStudents)
changeColorForEachStudent(events, logins)
}
shouldComponentUpdate(nextProps) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment