128 lines
5.0 KiB
JavaScript
128 lines
5.0 KiB
JavaScript
import moment from "moment";
|
|
|
|
import globalData from '../GlobalData.js';
|
|
import Button from './Button.js';
|
|
|
|
import user1 from '../APIexamples/user1.json'
|
|
import user2 from '../APIexamples/user2.json'
|
|
import user3 from '../APIexamples/user3.json'
|
|
import user4 from '../APIexamples/user4.json'
|
|
|
|
import locationuser1 from '../APIexamples/locationuser1.json'
|
|
import locationuser2 from '../APIexamples/locationuser2.json'
|
|
import locationuser3 from '../APIexamples/locationuser3.json'
|
|
import locationuser4 from '../APIexamples/locationuser4.json'
|
|
|
|
import departureuser1 from '../APIexamples/departureuser1.json'
|
|
import departureuser2 from '../APIexamples/departureuser2.json'
|
|
import departureuser3 from '../APIexamples/departureuser3.json'
|
|
import departureuser4 from '../APIexamples/departureuser4.json'
|
|
|
|
import ex1 from '../APIexamples/disruption1.json'
|
|
import ex2 from '../APIexamples/disruption2.json'
|
|
|
|
|
|
class DisruptionButton extends Button {
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {
|
|
jsonLocation: this.props.path,
|
|
disruption: "",
|
|
u1: user1,
|
|
u2: user2,
|
|
u3: user3,
|
|
u4: user4,
|
|
};
|
|
}
|
|
|
|
updatePage = () => {
|
|
globalData.currentPage.forceUpdate();
|
|
}
|
|
|
|
showMomentTime = (time) => {
|
|
return (time.format("HH:mm"))
|
|
}
|
|
|
|
genUsers = () => {
|
|
if (globalData.users.length < 2) {
|
|
this.state.first = true;
|
|
this.state.u1.stop = locationuser1.LocationList.StopLocation[0];
|
|
this.state.u1.stop.departures = departureuser1.DepartureBoard.Departures;
|
|
this.state.u2.stop = locationuser2.LocationList.StopLocation[0];
|
|
this.state.u2.stop.departures = departureuser2.DepartureBoard.Departures;
|
|
this.state.u3.stop = locationuser3.LocationList.StopLocation[0];
|
|
this.state.u3.stop.departures = departureuser3.DepartureBoard.Departures;
|
|
this.state.u4.stop = locationuser4.LocationList.StopLocation[0];
|
|
this.state.u4.stop.departures = departureuser4.DepartureBoard.Departures;
|
|
globalData.users = [
|
|
this.state.u1,
|
|
this.state.u2,
|
|
this.state.u3,
|
|
this.state.u4
|
|
]
|
|
}
|
|
}
|
|
|
|
genDisrupt = () => {
|
|
this.genUsers()
|
|
|
|
this.state.disruption = undefined
|
|
if (this.state.jsonLocation === "ex1") {
|
|
for (let stopPoint of ex1.affectedStopPoints) {
|
|
for (let user of globalData.users) {
|
|
if (stopPoint.gid === user.stoppointgid) {
|
|
this.state.disruption = ex1;
|
|
var old1t = moment(user.stop.departures[0].time, "HH:mm");
|
|
old1t.add(ex1.time, "HH:mm");
|
|
user.stop.departures[0].newTime = this.showMomentTime(old1t);
|
|
user.stop.departures[0].trafficInfo = ex1.title;
|
|
}
|
|
}
|
|
if (stopPoint.gid === globalData.user.stoppointgid) {
|
|
this.state.disruption = ex1;
|
|
var old2t = moment(globalData.stop.departures[0].time, "HH:mm");
|
|
old2t.add(ex1.time, "HH:mm");
|
|
globalData.stop.departures[0].newTime = this.showMomentTime(old2t);
|
|
globalData.stop.departures[0].trafficInfo = ex1.title;
|
|
globalData.snackbarVisible = true; globalData.root.forceUpdate();
|
|
}
|
|
}
|
|
} else if (this.state.jsonLocation === "ex2") {
|
|
for (let stopPoint of ex2.affectedStopPoints) {
|
|
for (let user of globalData.users) {
|
|
if (stopPoint.gid === user.stoppointgid) {
|
|
this.state.disruption = ex2;
|
|
var old3t = moment(user.stop.departures[0].time, "HH:mm");
|
|
old3t.add(ex2.time, "HH:mm");
|
|
user.stop.departures[0].newTime = this.showMomentTime(old3t);
|
|
user.stop.departures[0].trafficInfo = ex2.title;
|
|
}
|
|
}
|
|
if (stopPoint.gid === globalData.user.stoppointgid) {
|
|
this.state.disruption = ex2;
|
|
var old4t = moment(globalData.stop.departures[0].time, "HH:mm");
|
|
old4t.add(ex2.time, "HH:mm");
|
|
globalData.stop.departures[0].newTime = this.showMomentTime(old4t);
|
|
globalData.stop.departures[0].trafficInfo = ex2.title;
|
|
globalData.snackbarVisible = true; globalData.root.forceUpdate();
|
|
}
|
|
}
|
|
}
|
|
|
|
globalData.disruption = this.state.disruption
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<div>
|
|
<Button onClick={this.props.onClick.concat([this.genDisrupt, this.updatePage])} className="disruptBtn">
|
|
{this.props.children}
|
|
</Button>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
export default DisruptionButton;
|