Add: Update user disruption status when user is not selected

This commit is contained in:
williameriksson126 2020-12-10 13:19:07 +01:00
parent cd2a61947f
commit 078393335a
3 changed files with 106 additions and 20 deletions

View File

@ -5,11 +5,12 @@ import Stop from './classes/Stop.js'
import Departure from './classes/Departure.js';
let globalData = {
users : [],
user: new User(
"test",
"123",
new Coordinates(),
"9022014014020001"
"123"
),
disruption: new Disruption(
),

View File

@ -2,6 +2,21 @@ import addNotification from "react-push-notification";
import globData from '../GlobalData.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'
@ -14,7 +29,11 @@ import moment from "moment";
class DisruptionButton extends Button {
state = {
jsonLocation: this.props.path,
disruption: ""
disruption: "",
u1 : user1,
u2 : user2,
u3 : user3,
u4 : user4,
}
updatePage = () => {
@ -26,25 +45,65 @@ class DisruptionButton extends Button {
return(time.format("HH:mm"))
}
genUsers = () => {
if(globData.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;
globData.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 globData.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 === globData.user.stoppointgid){
this.state.disruption = ex1;
var old1t = moment(globData.stop.departures[0].time,"HH:mm");
old1t.add(ex1.time, "HH:mm");
globData.stop.departures[0].newTime = this.showMomentTime(old1t);
var old2t = moment(globData.stop.departures[0].time,"HH:mm");
old2t.add(ex1.time, "HH:mm");
globData.stop.departures[0].newTime = this.showMomentTime(old2t);
globData.stop.departures[0].trafficInfo = ex1.title;
}
}
} else if (this.state.jsonLocation === "ex2"){
for (let stopPoint of ex2.affectedStopPoints) {
for (let user of globData.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 === globData.user.stoppointgid){
this.state.disruption = ex2;
var old2t = moment(globData.stop.departures[0].time,"HH:mm");
old2t.add(ex2.time, "HH:mm");
globData.stop.departures[0].newTime = this.showMomentTime(old2t);
var old4t = moment(globData.stop.departures[0].time,"HH:mm");
old4t.add(ex2.time, "HH:mm");
globData.stop.departures[0].newTime = this.showMomentTime(old4t);
globData.stop.departures[0].trafficInfo = ex2.title;
}
}

View File

@ -21,23 +21,49 @@ import disruptIcon from '../img/flash.svg';
import globalData from '../GlobalData.js';
class SelectUserButton extends Button {
state = {
first : false,
u1 : user1,
u2 : user2,
u3 : user3,
u4 : user4,
}
genUsers = () => {
if(globData.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;
globData.users = [
this.state.u1,
this.state.u2,
this.state.u3,
this.state.u4
]
}
}
selectUser = () => {
this.genUsers()
if(this.props.path === "user1"){
globData.user = user1
globData.stop = locationuser1.LocationList.StopLocation[0]
globData.stop.departures = departureuser1.DepartureBoard.Departures
globData.user = globData.users[0]
globData.stop = globData.users[0].stop
}else if (this.props.path === "user2"){
globData.user = user2
globData.stop = locationuser2.LocationList.StopLocation[0]
globData.stop.departures = departureuser2.DepartureBoard.Departures
globData.user = globData.users[1]
globData.stop = globData.users[1].stop
}else if (this.props.path === "user3"){
globData.user = user3
globData.stop = locationuser3.LocationList.StopLocation[0]
globData.stop.departures = departureuser3.DepartureBoard.Departures
globData.user = globData.users[2]
globData.stop = globData.users[2].stop
}else if (this.props.path === "user4"){
globData.user = user4
globData.stop = locationuser4.LocationList.StopLocation[0]
globData.stop.departures = departureuser4.DepartureBoard.Departures
globData.user = globData.users[3]
globData.stop = globData.users[3].stop
}
}