|
|
|
@ -4,34 +4,36 @@ import Stundenliste from './Stundenliste'; |
|
|
|
|
import DefaultHeader from "../components/DefaultHeader"; |
|
|
|
|
import NoResultsFound from "../pages/NoResultsFound"; |
|
|
|
|
import ReplacementLesson from "../model/ReplacementLesson"; |
|
|
|
|
import ReplacementLessonsApi from "../api/ReplacementLessonsApi"; |
|
|
|
|
import ApiClient from "../ApiClient"; |
|
|
|
|
|
|
|
|
|
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"}} |
|
|
|
|
}) |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
replacementLessons: [] |
|
|
|
|
}; |
|
|
|
|
api = new ApiClient(); |
|
|
|
|
api.authentications.passwordAuth.username = "de" |
|
|
|
|
api.authentications.passwordAuth.password = "de" |
|
|
|
|
this.rla = new ReplacementLessonsApi(api); |
|
|
|
|
vplan = this |
|
|
|
|
this.rla.findReplacementLessons((s, lessons, pure) =>{ |
|
|
|
|
console.log(lessons, "lessons"); |
|
|
|
|
console.log(s, "s"); |
|
|
|
|
console.log(pure, "pure") |
|
|
|
|
vplan.setState({replacementLessons: lessons}) |
|
|
|
|
} ) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
refreshData() { |
|
|
|
|
alert("HEY!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
|
return ( |
|
|
|
|
<Container> |
|
|
|
|
<DefaultHeader hasTabs title="Vertretungsplan" navigation={this.props.navigation}/> |
|
|
|
|
<DefaultHeader hasTabs title="Vertretungsplan" navigation={this.props.navigation} refresh={this.refreshData()}/> |
|
|
|
|
{this.renderTabsForLessons(this.state.replacementLessons)} |
|
|
|
|
</Container> |
|
|
|
|
); |
|
|
|
@ -42,15 +44,22 @@ export default class Vertretungsplan extends Component { |
|
|
|
|
* @param {ReplacementLesson[]} lessons |
|
|
|
|
*/ |
|
|
|
|
renderTabsForLessons(lessons) { |
|
|
|
|
//Grouping by date and course
|
|
|
|
|
rawTabs = this._groupByDateAndCourse(lessons); |
|
|
|
|
|
|
|
|
|
//Bringing grouped things into machine-readable format
|
|
|
|
|
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); |
|
|
|
|
for(date in rawTabs) { |
|
|
|
|
tabItems = []; |
|
|
|
|
content = rawTabs[date]; |
|
|
|
|
content.forEach(function (value, course) { |
|
|
|
|
console.log(course, "c"); |
|
|
|
|
console.log(value, "con"); |
|
|
|
|
tabItems.push({title: course, data: value}) |
|
|
|
|
}); |
|
|
|
|
tabsByDate[new Date(date).toLocaleDateString()] = tabItems; |
|
|
|
|
} |
|
|
|
|
console.log(tabsByDate, "tabs"); |
|
|
|
|
tabs = Object.keys(tabsByDate).map(value => <Tab heading={value}><Stundenliste |
|
|
|
|
data={tabsByDate[value]}/></Tab>); |
|
|
|
|
if (tabsByDate.length == 0) { |
|
|
|
@ -59,4 +68,26 @@ export default class Vertretungsplan extends Component { |
|
|
|
|
console.log(tabs); |
|
|
|
|
return <Tabs>{tabs}</Tabs> |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_groupByDateAndCourse(lessons) { |
|
|
|
|
groupedByDate = _.mapValues(_.groupBy(lessons, 'date'), |
|
|
|
|
clist => clist.map(car => _.omit(car, 'date'))); |
|
|
|
|
function groupBy(list, keyGetter) { |
|
|
|
|
const map = new Map(); |
|
|
|
|
list.forEach((item) => { |
|
|
|
|
const key = keyGetter(item); |
|
|
|
|
const collection = map.get(key); |
|
|
|
|
if (!collection) { |
|
|
|
|
map.set(key, [item]); |
|
|
|
|
} else { |
|
|
|
|
collection.push(item); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
Object.keys(groupedByDate).map(function (key, index) { |
|
|
|
|
groupedByDate[key] = groupBy(groupedByDate[key], replacementLesson => replacementLesson.lesson.course) |
|
|
|
|
}); |
|
|
|
|
return groupedByDate |
|
|
|
|
} |
|
|
|
|
} |