|
|
|
@ -2,24 +2,61 @@ import React, {Component} from 'react'; |
|
|
|
|
import {Container, Content, Header, Tab, Tabs} from 'native-base'; |
|
|
|
|
import Stundenliste from './Stundenliste'; |
|
|
|
|
import DefaultHeader from "../components/DefaultHeader"; |
|
|
|
|
import NoResultsFound from "../pages/NoResultsFound"; |
|
|
|
|
import ReplacementLesson from "../model/ReplacementLesson"; |
|
|
|
|
|
|
|
|
|
export default class Vertretungsplan extends Component { |
|
|
|
|
constructor(props) { |
|
|
|
|
super(props); |
|
|
|
|
this.state = { |
|
|
|
|
replacementLessons: [ |
|
|
|
|
ReplacementLesson.constructFromObject({ |
|
|
|
|
id: 2, |
|
|
|
|
date: "2017-08-22", |
|
|
|
|
lesson: {teacher: {name: "Szabo"}, period: 1, subject: {name: "Informatik"}} |
|
|
|
|
}), |
|
|
|
|
ReplacementLesson.constructFromObject({ |
|
|
|
|
id: 4, |
|
|
|
|
date: "2017-08-22", |
|
|
|
|
lesson: {teacher: {name: "Szabo"}, period: 2, subject: {name: "Informatik"}} |
|
|
|
|
}), |
|
|
|
|
ReplacementLesson.constructFromObject({ |
|
|
|
|
id: 3, |
|
|
|
|
date: "2017-08-23", |
|
|
|
|
lesson: {teacher: {name: "Szabo"}, period: 2, subject: {name: "Informatik"}} |
|
|
|
|
}) |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
render() { |
|
|
|
|
return ( |
|
|
|
|
<Container> |
|
|
|
|
<DefaultHeader hasTabs title="Vertretungsplan" navigation={this.props.navigation}/> |
|
|
|
|
<Tabs initialPage={0}> |
|
|
|
|
<Tab heading="Mo, 28. Aug"> |
|
|
|
|
<Stundenliste/> |
|
|
|
|
</Tab> |
|
|
|
|
<Tab heading="Di, 29. Aug"> |
|
|
|
|
<Stundenliste/> |
|
|
|
|
</Tab> |
|
|
|
|
<Tab heading="Mi, 30. Aug"> |
|
|
|
|
<Stundenliste/> |
|
|
|
|
</Tab> |
|
|
|
|
</Tabs> |
|
|
|
|
{this.renderTabsForLessons(this.state.replacementLessons)} |
|
|
|
|
</Container> |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
* @param {ReplacementLesson[]} lessons |
|
|
|
|
*/ |
|
|
|
|
renderTabsForLessons(lessons) { |
|
|
|
|
tabsByDate = {}; |
|
|
|
|
lessons.forEach((lesson) => { |
|
|
|
|
console.log(lesson); |
|
|
|
|
if (!(lesson.date.toLocaleDateString() in tabsByDate)) { |
|
|
|
|
tabsByDate[lesson.date.toLocaleDateString()] = [] |
|
|
|
|
} |
|
|
|
|
tabsByDate[lesson.date.toLocaleDateString()].push(lesson) |
|
|
|
|
}); |
|
|
|
|
console.log(tabsByDate); |
|
|
|
|
tabs = Object.keys(tabsByDate).map(value => <Tab heading={value}><Stundenliste |
|
|
|
|
data={tabsByDate[value]}/></Tab>); |
|
|
|
|
if (tabsByDate.length == 0) { |
|
|
|
|
tabsByDate.push(<Tab heading="Keine Ergebnisse"><NoResultsFound/></Tab>) |
|
|
|
|
} |
|
|
|
|
console.log(tabs); |
|
|
|
|
return <Tabs>{tabs}</Tabs> |
|
|
|
|
} |
|
|
|
|
} |