Commit f9507bf5 authored by Jiawen Lyu's avatar Jiawen Lyu

change color dynamique

parent f6f31b12
......@@ -50,6 +50,8 @@ const extractUvDateInfo = uvs => uvs.map(uv => ({
id: uvs.indexOf(uv)
}))
const getCurrentStudents = data => Array.from(new Set(data.map(elem => elem.login)))
class App extends Component {
state = {
currentTimeFormatState: true,
......@@ -99,6 +101,7 @@ class App extends Component {
render() {
const { currentTimeFormatState, messages, error, isLoaded, uvs } = this.state;
// const data = extractUvDateInfo(uvs)
const currentStudents = getCurrentStudents(data)
if (error) {
return <div>Erreur : {error.message}</div>;
} else if (!isLoaded) {
......@@ -109,6 +112,7 @@ class App extends Component {
<div className="scheduler-container">
<Scheduler
events={data}
currentStudents={currentStudents}
timeFormatState={currentTimeFormatState}
onDataUpdated={this.logDataUpdate}
/>
......
......@@ -3,11 +3,19 @@ import 'dhtmlx-scheduler';
import 'dhtmlx-scheduler/codebase/dhtmlxscheduler_material.css';
const scheduler = window.scheduler;
const changeColorForEachStudent = events => events.map(event => {
if (event.login === "jiawen") {
event.color = "green"
scheduler.updateEvent(event.id)
}
const toColorName = index => (
{
0: "orange",
1: "green",
2: "red",
}[index]
)
const changeColorForEachStudent = (events, currentStudents) => events.map(event => {
event.color = toColorName(currentStudents.indexOf(event.login))
scheduler.updateEvent(event.id)
})
export default class Scheduler extends Component {
......@@ -55,11 +63,11 @@ export default class Scheduler extends Component {
this.initSchedulerEvents();
const { events } = this.props;
const { events, currentStudents } = this.props;
scheduler.init(this.schedulerContainer, new Date(2020, 5, 10));
scheduler.clearAll();
scheduler.parse(events);
changeColorForEachStudent(events)
changeColorForEachStudent(events, currentStudents)
}
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