diff --git a/package-lock.json b/package-lock.json index fcec47e..b896302 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10111,6 +10111,11 @@ "minimist": "^1.2.5" } }, + "moment": { + "version": "2.29.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.29.1.tgz", + "integrity": "sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==" + }, "move-concurrently": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz", diff --git a/package.json b/package.json index a5f2a3b..7bd7cef 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "@testing-library/react": "^11.1.2", "@testing-library/user-event": "^12.2.2", "axios": "^0.21.0", + "moment": "^2.29.1", "react": "^17.0.1", "react-axios": "^2.0.3", "react-dom": "^17.0.1", diff --git a/src/APIexamples/departureuser1.json b/src/APIexamples/departureuser1.json new file mode 100644 index 0000000..c1214b0 --- /dev/null +++ b/src/APIexamples/departureuser1.json @@ -0,0 +1,53 @@ +{ + "DepartureBoard": { + "noNamespaceSchemaLocation": "http://api.vasttrafik.se/v1/hafasRestDepartureBoard.xsd", + "servertime": "10:09", + "serverdate": "2020-12-10", + "Departures": [ + { + "name": "Buss MEXP", + "sname": "MEXP", + "journeyNumber": "24", + "type": "BUS", + "stopid": "9022014014754002", + "stop": "Bollestadsvägen, Kungälv", + "time": "10:09", + "date": "2020-12-10", + "journeyid": "9015014621000024", + "direction": "Marstrand", + "track": "B", + "rtTime": "10:11", + "rtDate": "2020-12-10", + "fgColor": "#006C93", + "bgColor": "#FFFFFF", + "stroke": "Solid", + "accessibility": "wheelChair", + "JourneyDetailRef": { + "ref": "https://api.vasttrafik.se/bin/rest.exe/v2/journeyDetail?ref=347217%2F124275%2F19874%2F105802%2F80%3Fdate%3D2020-12-10%26station_evaId%3D14754002%26station_type%3Ddep%26format%3Djson%26" + } + }, + { + "name": "Buss 920", + "sname": "920", + "journeyNumber": "2", + "type": "BUS", + "stopid": "9022014014754002", + "stop": "Bollestadsvägen, Kungälv", + "time": "12:26", + "date": "2020-12-10", + "journeyid": "9015014692000002", + "direction": "Bredsten", + "track": "B", + "rtTime": "12:26", + "rtDate": "2020-12-10", + "fgColor": "#006C93", + "bgColor": "#FFFFFF", + "stroke": "Solid", + "accessibility": "wheelChair", + "JourneyDetailRef": { + "ref": "https://api.vasttrafik.se/bin/rest.exe/v2/journeyDetail?ref=210630%2F70533%2F834318%2F346949%2F80%3Fdate%3D2020-12-10%26station_evaId%3D14754002%26station_type%3Ddep%26format%3Djson%26" + } + } + ] + } + } \ No newline at end of file diff --git a/src/APIexamples/departureuser2.json b/src/APIexamples/departureuser2.json new file mode 100644 index 0000000..20cb88c --- /dev/null +++ b/src/APIexamples/departureuser2.json @@ -0,0 +1,53 @@ +{ + "DepartureBoard": { + "noNamespaceSchemaLocation": "http://api.vasttrafik.se/v1/hafasRestDepartureBoard.xsd", + "servertime": "10:10", + "serverdate": "2020-12-10", + "Departures": [ + { + "name": "Buss MEXP", + "sname": "MEXP", + "journeyNumber": "24", + "type": "BUS", + "stopid": "9022014014020002", + "stop": "Ekelöv västra, Kungälv", + "time": "10:10", + "date": "2020-12-10", + "journeyid": "9015014621000024", + "direction": "Marstrand", + "track": "B", + "rtTime": "10:13", + "rtDate": "2020-12-10", + "fgColor": "#006C93", + "bgColor": "#FFFFFF", + "stroke": "Solid", + "accessibility": "wheelChair", + "JourneyDetailRef": { + "ref": "https://api.vasttrafik.se/bin/rest.exe/v2/journeyDetail?ref=740262%2F255290%2F59460%2F217024%2F80%3Fdate%3D2020-12-10%26station_evaId%3D14020002%26station_type%3Ddep%26format%3Djson%26" + } + }, + { + "name": "Buss 920", + "sname": "920", + "journeyNumber": "2", + "type": "BUS", + "stopid": "9022014014754002", + "stop": "Bollestadsvägen, Kungälv", + "time": "12:28", + "date": "2020-12-10", + "journeyid": "9015014692000002", + "direction": "Bredsten", + "track": "B", + "rtTime": "12:26", + "rtDate": "2020-12-10", + "fgColor": "#006C93", + "bgColor": "#FFFFFF", + "stroke": "Solid", + "accessibility": "wheelChair", + "JourneyDetailRef": { + "ref": "https://api.vasttrafik.se/bin/rest.exe/v2/journeyDetail?ref=210630%2F70533%2F834318%2F346949%2F80%3Fdate%3D2020-12-10%26station_evaId%3D14754002%26station_type%3Ddep%26format%3Djson%26" + } + } + ] + } +} \ No newline at end of file diff --git a/src/APIexamples/departureuser3.json b/src/APIexamples/departureuser3.json new file mode 100644 index 0000000..96194d8 --- /dev/null +++ b/src/APIexamples/departureuser3.json @@ -0,0 +1,27 @@ +{ + "DepartureBoard": { + "noNamespaceSchemaLocation": "http://api.vasttrafik.se/v1/hafasRestDepartureBoard.xsd", + "servertime": "10:10", + "serverdate": "2020-12-10", + "Departures": [{ + "name": "Buss MEXP", + "sname": "MEXP", + "journeyNumber": "24", + "type": "BUS", + "stopid": "9022014014751002", + "stop": "Guddeby, Kungälv", + "time": "10:07", + "date": "2020-12-10", + "journeyid": "9015014621000024", + "direction": "Marstrand", + "track": "B", + "fgColor": "#006C93", + "bgColor": "#FFFFFF", + "stroke": "Solid", + "accessibility": "wheelChair", + "JourneyDetailRef": { + "ref": "https://api.vasttrafik.se/bin/rest.exe/v2/journeyDetail?ref=473190%2F166266%2F666560%2F175550%2F80%3Fdate%3D2020-12-10%26station_evaId%3D14751002%26station_type%3Ddep%26format%3Djson%26" + } + }] + } + } \ No newline at end of file diff --git a/src/APIexamples/departureuser4.json b/src/APIexamples/departureuser4.json new file mode 100644 index 0000000..bb9fab3 --- /dev/null +++ b/src/APIexamples/departureuser4.json @@ -0,0 +1,30 @@ +{ + "DepartureBoard": { + "noNamespaceSchemaLocation": "http://api.vasttrafik.se/v1/hafasRestDepartureBoard.xsd", + "servertime": "10:11", + "serverdate": "2020-12-10", + "Departures": + [{ + "name": "Buss 928", + "sname": "928", + "journeyNumber": "10", + "type": "BUS", + "stopid": "9022014014225001", + "stop": "Skrämmenborg, Kungälv", + "time": "15:19", + "date": "2020-12-10", + "journeyid": "9015014692800010", + "direction": "Kärna", + "track": "A", + "rtTime": "15:19", + "rtDate": "2020-12-10", + "fgColor": "#006C93", + "bgColor": "#FFFFFF", + "stroke": "Solid", + "accessibility": "wheelChair", + "JourneyDetailRef": { + "ref": "https://api.vasttrafik.se/bin/rest.exe/v2/journeyDetail?ref=261732%2F87569%2F149176%2F12656%2F80%3Fdate%3D2020-12-10%26station_evaId%3D14225001%26station_type%3Ddep%26format%3Djson%26" + } + }] + } + } \ No newline at end of file diff --git a/src/APIexamples/disruption1.json b/src/APIexamples/disruption1.json new file mode 100644 index 0000000..0a97099 --- /dev/null +++ b/src/APIexamples/disruption1.json @@ -0,0 +1,16 @@ +{ + "situationNumber": "RT1", + "severity":"normal", + "title":"Nabbensbergsvägen närmast Edsvägen helt avstängd och trafiken hänvisas istället via Korsebergsvägen. Samtidigt tas den tillfälliga förbifarten bort på Edsvägen och trafiken kommer att ledas förbi den nya cirkulationsplatsen i de två västra körfälten tills arbetet på Nabbensbergsvägen är klart Hastighet: 50km/h", + "time":"00:01", + "affectedStopPoints":[ + { + "gid": "9022014014020001", + "name": "Ekelöv västra, Kungälv" + }, + { + "gid": "9022014014751001", + "name": "Guddeby, Kungälv" + } + ] +} \ No newline at end of file diff --git a/src/APIexamples/disruption2.json b/src/APIexamples/disruption2.json new file mode 100644 index 0000000..5cdea81 --- /dev/null +++ b/src/APIexamples/disruption2.json @@ -0,0 +1,12 @@ +{ + "situationNumber": "RT2", + "severity":"normal", + "title":"Försening", + "time":"00:02", + "affectedStopPoints":[ + { + "gid": "9021014014225000", + "name": "Skrämmenborg, Kungälv" + } + ] +} \ No newline at end of file diff --git a/src/APIexamples/locationuser1.json b/src/APIexamples/locationuser1.json new file mode 100644 index 0000000..8288ff8 --- /dev/null +++ b/src/APIexamples/locationuser1.json @@ -0,0 +1,36 @@ +{ + "LocationList": { + "noNamespaceSchemaLocation": "http://api.vasttrafik.se/v1/hafasRestLocation.xsd", + "servertime": "16:48", + "serverdate": "2020-12-09", + "StopLocation": [ + { + "name": "Bollestadsvägen, Kungälv", + "id": "9022014014754001", + "lat": "57.888940", + "lon": "11.885663", + "track": "A" + }, + { + "name": "Bollestadsvägen, Kungälv", + "id": "9021014014754000", + "lat": "57.889030", + "lon": "11.885708" + }, + { + "name": "Bollestadsvägen, Kungälv", + "id": "9022014014754002", + "lat": "57.889111", + "lon": "11.885753", + "track": "B" + }, + { + "name": "Bredsten, Kungälv", + "id": "9022014014753002", + "lat": "57.886450", + "lon": "11.889529", + "track": "B" + } + ] + } + } \ No newline at end of file diff --git a/src/APIexamples/locationuser2.json b/src/APIexamples/locationuser2.json new file mode 100644 index 0000000..decace7 --- /dev/null +++ b/src/APIexamples/locationuser2.json @@ -0,0 +1,36 @@ +{ + "LocationList": { + "noNamespaceSchemaLocation": "http://api.vasttrafik.se/v1/hafasRestLocation.xsd", + "servertime": "16:47", + "serverdate": "2020-12-09", + "StopLocation": [ + { + "name": "Ekelöv västra, Kungälv", + "id": "9022014014020001", + "lat": "57.892527", + "lon": "11.865321", + "track": "A" + }, + { + "name": "Ekelöv västra, Kungälv", + "id": "9021014014020000", + "lat": "57.892608", + "lon": "11.865312" + }, + { + "name": "Ekelöv västra, Kungälv", + "id": "9022014014020002", + "lat": "57.892689", + "lon": "11.865285", + "track": "B" + }, + { + "name": "Ekelöv östra, Kungälv", + "id": "9022014014021002", + "lat": "57.892994", + "lon": "11.873923", + "track": "B" + } + ] + } + } \ No newline at end of file diff --git a/src/APIexamples/locationuser3.json b/src/APIexamples/locationuser3.json new file mode 100644 index 0000000..450cfe7 --- /dev/null +++ b/src/APIexamples/locationuser3.json @@ -0,0 +1,36 @@ +{ + "LocationList": { + "noNamespaceSchemaLocation": "http://api.vasttrafik.se/v1/hafasRestLocation.xsd", + "servertime": "16:45", + "serverdate": "2020-12-09", + "StopLocation": [ + { + "name": "Guddeby, Kungälv", + "id": "9022014014751001", + "lat": "57.874665", + "lon": "11.903884", + "track": "A" + }, + { + "name": "Guddeby, Kungälv", + "id": "9021014014751000", + "lat": "57.874710", + "lon": "11.903929" + }, + { + "name": "Guddeby, Kungälv", + "id": "9022014014751002", + "lat": "57.874746", + "lon": "11.903965", + "track": "B" + }, + { + "name": "Stället, Kungälv", + "id": "9022014014744001", + "lat": "57.869784", + "lon": "11.904172", + "track": "A" + } + ] + } + } \ No newline at end of file diff --git a/src/APIexamples/locationuser4.json b/src/APIexamples/locationuser4.json new file mode 100644 index 0000000..d8f2fc4 --- /dev/null +++ b/src/APIexamples/locationuser4.json @@ -0,0 +1,35 @@ +{ + "LocationList": { + "noNamespaceSchemaLocation": "http://api.vasttrafik.se/v1/hafasRestLocation.xsd", + "servertime": "16:44", + "serverdate": "2020-12-09", + "StopLocation": [ + { + "name": "Skrämmenborg, Kungälv", + "id": "9021014014225000", + "lat": "57.863528", + "lon": "11.867406" + }, + { + "name": "Skrämmenborg, Kungälv", + "id": "9022014014225001", + "lat": "57.863528", + "lon": "11.867406", + "track": "A" + }, + { + "name": "Kuröd, Kungälv", + "id": "9022014014762002", + "lat": "57.856966", + "lon": "11.863774", + "track": "B" + }, + { + "name": "Kuröd, Kungälv", + "id": "9021014014762000", + "lat": "57.856831", + "lon": "11.864260" + } + ] + } + } \ No newline at end of file diff --git a/src/APIexamples/user1.json b/src/APIexamples/user1.json new file mode 100644 index 0000000..6f3b2f2 --- /dev/null +++ b/src/APIexamples/user1.json @@ -0,0 +1,5 @@ +{ + "name": "Användare 1", + "deviceId": "1", + "stoppointgid": "9022014014754001" +} \ No newline at end of file diff --git a/src/APIexamples/user2.json b/src/APIexamples/user2.json new file mode 100644 index 0000000..06eef29 --- /dev/null +++ b/src/APIexamples/user2.json @@ -0,0 +1,5 @@ +{ + "name": "Användare 2", + "deviceId": "2", + "stoppointgid": "9022014014020001" +} \ No newline at end of file diff --git a/src/APIexamples/user3.json b/src/APIexamples/user3.json new file mode 100644 index 0000000..6ee5f34 --- /dev/null +++ b/src/APIexamples/user3.json @@ -0,0 +1,5 @@ +{ + "name": "Användare 3", + "deviceId": "3", + "stoppointgid": "9022014014751001" +} \ No newline at end of file diff --git a/src/APIexamples/user4.json b/src/APIexamples/user4.json new file mode 100644 index 0000000..3a81c81 --- /dev/null +++ b/src/APIexamples/user4.json @@ -0,0 +1,5 @@ +{ + "name": "Användare 4", + "deviceId": "4", + "stoppointgid": "9021014014225000" +} \ No newline at end of file diff --git a/src/App.js b/src/App.js index 9df211d..f338a98 100644 --- a/src/App.js +++ b/src/App.js @@ -5,8 +5,9 @@ import React, { Component } from "react"; import { BrowserRouter as Router, Route } from "react-router-dom"; import BottomMenu from "./components/BottomMenu.js"; -//import AccessToken from "./components/AccessToken.js"; -import NearbyStation from "./components/NearbyStation"; +import NearbyStation from "./components/NearbyStation.js"; +import Disruption from "./components/Disruption.js"; +import StationDisruption from "./components/StationDisruption.js"; import Tickets from "./components/pages/Tickets.js"; import TicketsBuy from "./components/pages/TicketsBuy.js"; diff --git a/src/GlobalData.js b/src/GlobalData.js index 3f4e9b9..fa6caba 100644 --- a/src/GlobalData.js +++ b/src/GlobalData.js @@ -1,11 +1,19 @@ import User from './classes/User.js'; -import Coordinates from "./classes/Coordinates.js"; +import Disruption from './classes/Disruption.js' +import Coordinates from './classes/Coordinates.js'; +import Stop from './classes/Stop.js' let globalData = { + users : [], user: new User( - "test", + "Exempelanvändare", "123", - new Coordinates() + new Coordinates(), + "123" + ), + disruption: new Disruption( + ), + stop: new Stop( ) }; diff --git a/src/classes/AccessToken.js b/src/classes/AccessToken.js index 0537ec3..300800a 100644 --- a/src/classes/AccessToken.js +++ b/src/classes/AccessToken.js @@ -12,7 +12,6 @@ class AccessToken { axios.post('https://api.vasttrafik.se/token','grant_type=client_credentials&scope=device_'+this.device, {headers} ) .then(response => { - console.log(response); this.token = response.data.access_token }); } diff --git a/src/classes/Coordinates.js b/src/classes/Coordinates.js index 53d48bf..b326afe 100644 --- a/src/classes/Coordinates.js +++ b/src/classes/Coordinates.js @@ -12,4 +12,4 @@ class Coordinates { } } -export default Coordinates; \ No newline at end of file +export default Coordinates; diff --git a/src/classes/Departure.js b/src/classes/Departure.js index ba0eafc..960f0e6 100644 --- a/src/classes/Departure.js +++ b/src/classes/Departure.js @@ -3,15 +3,20 @@ lineName : String (Linjenamnet) finalStop : Stop (Ändhållplats) - time : String (Avgångstid) + originalTime : String (Ursprunglig Avgångstid) + newTime : String (Ny Avgångstid) trafficInfo : String (Trafikinformation) */ class Departure { - constructor(lineName, finalStop, time, trafficInfo) { - this.lineName = lineName; - this.finalStop = finalStop; - this.time = time; + constructor(lineName, finalStop, originalTime) { + this.sname = lineName; + this.direction = finalStop; + this.time = originalTime; + } + + timeUpdate(time, trafficInfo) { + this.newTime = time; this.trafficInfo = trafficInfo; } } diff --git a/src/classes/Disruption.js b/src/classes/Disruption.js new file mode 100644 index 0000000..583db9a --- /dev/null +++ b/src/classes/Disruption.js @@ -0,0 +1,11 @@ + +class Disruption { + constructor(situationNumber, severity, title, affectedStopPoints) { + this.situationNumber = situationNumber; + this.severity = severity; + this.title = title; + this.affectedStopPoints = affectedStopPoints; + } +} + +export default Disruption; \ No newline at end of file diff --git a/src/classes/Stop.js b/src/classes/Stop.js index 51a6169..f64b86c 100644 --- a/src/classes/Stop.js +++ b/src/classes/Stop.js @@ -7,11 +7,25 @@ */ class Stop { - constructor(name, locations, departures) { + constructor(name, id, lat, lon, locations, departures) { this.name = name; + this.id = id; + this.lat = lat; + this.lon = lon; this.locations = locations; this.departures = departures; } } +/* +Från västtrafiks api ett element i listan av hållplatser ser ut som följande + "id": "string", + "lon": "string", + "idx": "string", + "weight": "string", + "name": "string", + "track": "string", + "lat": "string" +*/ + export default Stop; \ No newline at end of file diff --git a/src/classes/User.js b/src/classes/User.js index 0aef9aa..22db7ec 100644 --- a/src/classes/User.js +++ b/src/classes/User.js @@ -4,13 +4,16 @@ name : String (Användarnamn) deviceId : Int (Enhetens ID) location : Coordinates (Användarens koordinater) + track : String (Nuvarande hållplatsläge) */ class User { - constructor(name, deviceId, location) { + constructor(name, deviceId, location, stoppointgid, track) { this.name = name; this.deviceId = deviceId; this.location = location; + this.stoppointgid = stoppointgid; + this.track = track; } } diff --git a/src/components/Button.js b/src/components/Button.js index 873dc00..da798fc 100644 --- a/src/components/Button.js +++ b/src/components/Button.js @@ -13,7 +13,7 @@ class Button extends Component { func(); }); } else { - console.log("Error when parsing Button onClick functions."); + console.log("Error when parsing Button onClick functions. Make sure the functions are passed as an array."); } } } diff --git a/src/components/Disruption.js b/src/components/Disruption.js new file mode 100644 index 0000000..7fd34b7 --- /dev/null +++ b/src/components/Disruption.js @@ -0,0 +1,57 @@ +import React from 'react'; +import axios from 'axios'; +import AccessToken from '../classes/AccessToken' + +class Diruption extends React.Component { + state = { + gid: '9022014005700002', + disruptions: [], + token: undefined, + tokenClass: new AccessToken() + } + + handleChangeGid = event => { + this.setState({ lat: event.target.value}); + } + + handleSubmit = event => { + event.preventDefault(); + + const headers = { + 'Authorization': 'Bearer ' + this.state.tokenClass.token + }; + + axios.get('https://api.vasttrafik.se/ts/v1/traffic-situations/stoppoint/'+this.state.gid, { headers }) + //axios.get('https://api.vasttrafik.se/ts/v1/traffic-situations/stoppoint/9022014005700002', { headers }) + .then(response => { + this.setState({ + disruptions: response.data + }) + }) + } + + render() { + return ( +
+
+ + +
+

+ {this.state.gid} +

+ {this.state.disruptions.map((item) => +
+

+ {item.description} +

+
+ )} +
+ ) + } +} +export default Diruption diff --git a/src/components/DisruptionButton.js b/src/components/DisruptionButton.js index c88e5ca..08f0dc3 100644 --- a/src/components/DisruptionButton.js +++ b/src/components/DisruptionButton.js @@ -1,23 +1,118 @@ -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' import Button from './Button.js'; import disruptIcon from '../img/flash.svg'; +import globalData from '../GlobalData.js' +import moment from "moment"; class DisruptionButton extends Button { + state = { + jsonLocation: this.props.path, + disruption: "", + u1 : user1, + u2 : user2, + u3 : user3, + u4 : user4, + } + + updatePage = () => { + globalData.currentPage.forceUpdate(); + } + + showMomentTime = (time) => { + //return(time.hours().toString()+ ":"+time.minutes().toString()) + 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 = () => { - addNotification({ - title: "Warning", - subtitle: "This is a subtitle", - message: "This is a very long message", - theme: "blue", - native: true, // when using native, your OS will handle theming. - }); + 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 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 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; + } + } + } + + globData.disruption = this.state.disruption } render() { return ( - diff --git a/src/components/FindStops.js b/src/components/FindStops.js new file mode 100644 index 0000000..46a7d0d --- /dev/null +++ b/src/components/FindStops.js @@ -0,0 +1,45 @@ + +import globData from '../GlobalData.js'; + +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 StopSelectButton from './StopSelectButton.js'; +import Button from './Button.js'; +import disruptIcon from '../img/flash.svg'; + +class FindStops extends Button { + state = { + locations : [] + } + findStops = () => { + if(globData.user.deviceId === "1"){ + this.state.locations = locationuser1.LocationList.StopLocation + }else if (globData.user.deviceId === "2"){ + this.state.locations = locationuser2.LocationList.StopLocation + }else if (globData.user.deviceId === "3"){ + this.state.locations = locationuser3.LocationList.StopLocation + }else if (globData.user.deviceId === "4"){ + this.state.locations = locationuser4.LocationList.StopLocation + } + } + + render() { + return ( + <> + + {this.state.locations.map((item) => + + )} + + ); + } +} + + +export default FindStops; diff --git a/src/components/MainArea.js b/src/components/MainArea.js index 2ad5f6c..8fd526d 100644 --- a/src/components/MainArea.js +++ b/src/components/MainArea.js @@ -5,7 +5,7 @@ import './css/MainArea.css'; class MainArea extends Component { render() { return ( -
+
{this.props.children}
); diff --git a/src/components/NavigationDrawer.js b/src/components/NavigationDrawer.js index de49e86..48a40d7 100644 --- a/src/components/NavigationDrawer.js +++ b/src/components/NavigationDrawer.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import globalData from '../GlobalData.js'; import DisruptionButton from "./DisruptionButton.js"; +import SelectUserButton from "./SelectUserButton.js" import Popup from './Popup.js'; import Button from './Button.js'; @@ -43,16 +44,23 @@ class NavigationDrawer extends Component { this.popupElem.current.show(); }; + hidePopup = () => { + this.popupElem.current.hide(); + }; + + updatePage = () => { + globalData.currentPage.render(); + } + render() { + return ( <>

Välj hållplats:

    -
  • -
  • -
  • -
  • +
  • Störningsscenario 1
  • +
  • Störningsscenario 2
@@ -63,7 +71,11 @@ class NavigationDrawer extends Component { example@gmail.com
Projektgrupp 3 - Utmaning 7 diff --git a/src/components/NearbyStation.js b/src/components/NearbyStation.js index 7455c93..5e240a9 100644 --- a/src/components/NearbyStation.js +++ b/src/components/NearbyStation.js @@ -1,6 +1,8 @@ import React from 'react'; import axios from 'axios'; -import AccessToken from '../classes/AccessToken' +import AccessToken from '../classes/AccessToken'; +import StopComponent from './StopComponent'; +import Stop from '../classes/Stop'; class NearbyStation extends React.Component { state = { @@ -26,11 +28,8 @@ class NearbyStation extends React.Component { 'Authorization': 'Bearer ' + this.state.tokenClass.token }; - console.log('Attempted connection') - - axios.get('https://api.vasttrafik.se/bin/rest.exe/v2/location.nearbystops?originCoordLat='+this.state.lat+'&originCoordLong='+this.state.long+'&maxNo=20&format=json', { headers }) + axios.get('https://api.vasttrafik.se/bin/rest.exe/v2/location.nearbystops?originCoordLat='+this.state.lat+'&originCoordLong='+this.state.long+'&maxNo=5&format=json', { headers }) .then(response => { - console.log(response.data.LocationList.StopLocation) this.setState({ stops: response.data.LocationList.StopLocation, }) @@ -58,32 +57,11 @@ class NearbyStation extends React.Component { {this.state.long} {this.state.stops.map((item) => -
-

- {item.name}, - {item.id}, - {item.lat}, - {item.lon}, - {item.track} -

-
+ )} ) } } + export default NearbyStation - -//https://api.vasttrafik.se/bin/rest.exe/v2/location.nearbystops?originCoordLat=57.5987&originCoordLong=11.9454&maxNo=20&format=json - -//https://api.vasttrafik.se/bin/rest.exe/v2/location.nearbystops - - -//'https://reqres.in/api/articles' - -//'https://api.vasttrafik.se/token' - -//grant_type=client_credentials&scope= - -//BPvMjPidHckBtETZxr3dHP1rptQa -//z5MFCS_wwmqprc0s4iLZWBAUJdga \ No newline at end of file diff --git a/src/components/SelectUserButton.js b/src/components/SelectUserButton.js new file mode 100644 index 0000000..aeb5da8 --- /dev/null +++ b/src/components/SelectUserButton.js @@ -0,0 +1,92 @@ +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 Button from './Button.js'; +import userIcon from '../img/userDark.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.user.track = locationuser1.LocationList.StopLocation[0].track + globData.stop = locationuser1.LocationList.StopLocation[0] + globData.stop.departures = departureuser1.DepartureBoard.Departures + }else if (this.props.path === "user2"){ + globData.user = user2 + globData.user.track = locationuser2.LocationList.StopLocation[0].track + globData.stop = locationuser2.LocationList.StopLocation[0] + globData.stop.departures = departureuser2.DepartureBoard.Departures + }else if (this.props.path === "user3"){ + globData.user = user3 + globData.user.track = locationuser3.LocationList.StopLocation[0].track + globData.stop = locationuser3.LocationList.StopLocation[0] + globData.stop.departures = departureuser3.DepartureBoard.Departures + }else if (this.props.path === "user4"){ + globData.user = user4 + globData.user.track = locationuser4.LocationList.StopLocation[0].track + globData.stop = locationuser4.LocationList.StopLocation[0] + globData.stop.departures = departureuser4.DepartureBoard.Departures + } + } + + updatePage = () => { + globalData.currentPage.forceUpdate(); + } + + render() { + return ( + + ); + } +} + +export default SelectUserButton; diff --git a/src/components/StationDisruption.js b/src/components/StationDisruption.js new file mode 100644 index 0000000..e266d4c --- /dev/null +++ b/src/components/StationDisruption.js @@ -0,0 +1,61 @@ +import React from 'react'; +import axios from 'axios'; +import AccessToken from '../classes/AccessToken' + +class StationDisruption extends React.Component { + state = { + gid: '9022014005700002', + lat: '57.7', + long: '12.0', + disruptions: [], + token: undefined, + tokenClass: new AccessToken() + } + + handleChangeGid = event => { + this.setState({ lat: event.target.value}); + } + + handleSubmit = event => { + event.preventDefault(); + + const headers = { + 'Authorization': 'Bearer ' + this.state.tokenClass.token + }; + + axios.get('https://api.vasttrafik.se/bin/rest.exe/v2/location.nearbystops?originCoordLat='+this.state.lat+'&originCoordLong='+this.state.long+'&maxNo=5&format=json', { headers }) + .then(response => { + }) + axios.get('https://api.vasttrafik.se/ts/v1/traffic-situations/stoppoint/'+this.state.gid, { headers }) + .then(response => { + this.setState({ + disruptions: response.data + }) + }) + } + + render() { + return ( +
+
+ + +
+

+ {this.state.gid} +

+ {this.state.disruptions.map((item) => +
+

+ {item.description} +

+
+ )} +
+ ) + } +} +export default StationDisruption diff --git a/src/components/StopComponent.js b/src/components/StopComponent.js new file mode 100644 index 0000000..db5bdb2 --- /dev/null +++ b/src/components/StopComponent.js @@ -0,0 +1,19 @@ +import React, {Component} from 'react'; + +class StopComponent extends Component { + render() { + return ( +
+

+ {this.props.stop.name}, + {this.props.stop.id}, + {this.props.stop.lat}, + {this.props.stop.lon}, + {this.props.stop.track} +

+
+ ); + } +} +// TODO Add css +export default StopComponent diff --git a/src/components/StopSelectButton.js b/src/components/StopSelectButton.js new file mode 100644 index 0000000..e326874 --- /dev/null +++ b/src/components/StopSelectButton.js @@ -0,0 +1,22 @@ +import React, {Component} from 'react'; +import globalData from '../GlobalData'; +import Button from './Button.js'; + +class StopSelectButton extends Component { + + selectStop = () => { + globalData.stop = this.props.stop + } + + render() { + return ( + <> + + + ); + } +} +// TODO Add css +export default StopSelectButton diff --git a/src/components/StopSelector.js b/src/components/StopSelector.js new file mode 100644 index 0000000..e69de29 diff --git a/src/components/StopTitle.js b/src/components/StopTitle.js index d2bf05c..f8719ca 100644 --- a/src/components/StopTitle.js +++ b/src/components/StopTitle.js @@ -1,16 +1,56 @@ import React, { Component } from 'react'; +import Button from './Button.js'; +import Popup from './Popup.js'; + import './css/StopTitle.css'; + class StopTitle extends Component { + constructor(props) { + super(props); + this.popupElem = React.createRef(); + } + + showPopup = () => { + this.popupElem.current.show(); + }; + + hidePopup = () => { + this.popupElem.current.hide(); + }; + render() { return (
-

{this.props.stop.name}

-
-

{this.props.stop.locations[0]}

- -
+ +

Välj läge:

+
    + <> +
  • +
  • + +
+
+ +

{this.props.stop.name !== undefined ? + this.props.stop.name + : "Hållplats saknas" + }

+ + {this.props.stop.name !== undefined && this.props.stop.track !== undefined ? +
+

+ {"Läge " + this.props.stop.track} +

+ +
+ : + (this.props.stop.name !== undefined ? + <> + :

Vänligen aktivera platsåtkomst

+ ) + }
); } diff --git a/src/components/TrafficEntry.js b/src/components/TrafficEntry.js index c14144a..3b6e82a 100644 --- a/src/components/TrafficEntry.js +++ b/src/components/TrafficEntry.js @@ -1,4 +1,5 @@ import React, { Component } from 'react'; +import { Link } from 'react-router-dom'; import './css/TrafficInfo.css'; @@ -6,6 +7,29 @@ import busIcon from '../img/bus.svg'; import warningIcon from '../img/warning.svg'; class TrafficEntry extends Component { + state = { + expanded: false + }; + + toggle = () => { + if (this.state.expanded) + this.collapse(); + else + this.expand(); + }; + + expand = () => { + this.setState({ + expanded: true + }); + }; + + collapse = () => { + this.setState({ + expanded: false + }); + }; + render() { let trafficInfo = this.props.departure.trafficInfo; let lineInterference = trafficInfo !== "" && trafficInfo !== null && trafficInfo !== undefined; @@ -14,25 +38,40 @@ class TrafficEntry extends Component {
- {this.props.departure.time} + {!lineInterference && + {this.props.departure.time} + } {lineInterference && + <> +
+ {this.props.departure.newTime} + {this.props.departure.time} +
+ }
- {this.props.departure.lineName} + {this.props.departure.sname} - {this.props.departure.finalStop} + {"Mot " + this.props.departure.direction}
{lineInterference && -

{trafficInfo} Visa mer

+
+

{trafficInfo}

+ Visa mer +
}
{lineInterference && - + Hitta annan resväg }
); diff --git a/src/components/TrafficList.js b/src/components/TrafficList.js index c91101c..9dd9d52 100644 --- a/src/components/TrafficList.js +++ b/src/components/TrafficList.js @@ -7,21 +7,23 @@ import './css/TrafficInfo.css'; class TrafficList extends Component { render() { let entries = []; + + if (this.props.departures) { + let i = 0; // React requires elems in array to have associated unique key - let i = 0; // React requires elems in array to have associated unique key + this.props.departures.forEach(departure => { + entries.push( + + ); + }); - this.props.departures.forEach(departure => { - entries.push( - - ); - }); + // Add separator between every element + const intersperse = (arr, sep) => arr.reduce((a,v)=>[...a,v,sep],[]).slice(0,-1); + entries = intersperse(entries, (
)); - // Add separator between every element - const intersperse = (arr, sep) => arr.reduce((a,v)=>[...a,v,sep],[]).slice(0,-1); - entries = intersperse(entries, (
)); - - // Add separator after the last element - entries.push(
); + // Add separator after the last element + entries.push(
); + } return (
diff --git a/src/components/TripSelector.js b/src/components/TripSelector.js index d1394c8..d5af5e8 100644 --- a/src/components/TripSelector.js +++ b/src/components/TripSelector.js @@ -5,10 +5,10 @@ class TripSelector extends Component { return (
- +
- +
); } diff --git a/src/components/css/BottomMenu.css b/src/components/css/BottomMenu.css index 8139696..1634795 100644 --- a/src/components/css/BottomMenu.css +++ b/src/components/css/BottomMenu.css @@ -1,7 +1,7 @@ #bottomMenu { width: 100%; height: 9vh; - min-height: 60px; + min-height: 70px; background: white; display: flex; justify-content: space-evenly; diff --git a/src/components/css/Button.css b/src/components/css/Button.css index 19a47ca..4aef246 100644 --- a/src/components/css/Button.css +++ b/src/components/css/Button.css @@ -1,3 +1,7 @@ button:active { background: rgba(0, 0, 0, 0.1); +} + +a:active { + background: rgba(0, 0, 0, 0.1); } \ No newline at end of file diff --git a/src/components/css/Header.css b/src/components/css/Header.css index 4672c4c..3a39c8c 100644 --- a/src/components/css/Header.css +++ b/src/components/css/Header.css @@ -3,7 +3,7 @@ header { display: flex; flex-direction: row; align-items: center; - padding: 15px 15px 15vh 15px; + padding: 15px 15px 12vh 15px; top: 0; background: linear-gradient(90deg, var(--colorVT1), var(--colorVT2)); } diff --git a/src/components/css/MainArea.css b/src/components/css/MainArea.css index 2fd34da..31bc845 100644 --- a/src/components/css/MainArea.css +++ b/src/components/css/MainArea.css @@ -3,6 +3,6 @@ main { flex: 1 1 auto; display: flex; flex-flow: column; - justify-content: space-evenly; + justify-content: flex-start; overflow: hidden scroll; } \ No newline at end of file diff --git a/src/components/css/StopTitle.css b/src/components/css/StopTitle.css index d03dcb0..8063d66 100644 --- a/src/components/css/StopTitle.css +++ b/src/components/css/StopTitle.css @@ -8,21 +8,38 @@ justify-content: space-evenly; padding: 0 5vw; z-index: 4; + max-width: 80vw; } #stopTitle h1, #stopTitle h3 { font-weight: 100; } -#stopTitle div { - display: flex; - flex-direction: row; +#stopTitle h1 { + font-size: 9vw; } #stopTitle h3 { + font-size: 5vw; color: var(--colorDiscrete); } +@media screen and (min-width: 400px) { + #stopTitle h1 { + font-size: 35px; + } + + #stopTitle h3 { + font-size: 20px; + color: var(--colorDiscrete); + } +} + +#stopTitle div { + display: flex; + flex-direction: row; +} + #stopTitle button { width: auto; height: 100%; diff --git a/src/components/css/TrafficInfo.css b/src/components/css/TrafficInfo.css index 088bc6c..5b2333f 100644 --- a/src/components/css/TrafficInfo.css +++ b/src/components/css/TrafficInfo.css @@ -1,6 +1,7 @@ #trafficList { height: 100%; margin-top: 40px; + padding-bottom: 40px; background: white; } @@ -10,8 +11,9 @@ justify-content: space-evenly; align-items: center; width: 100vw; - padding: 6vw 0; + padding: 8vw 0; background: white; + font-size: 3.5vw; } .trafficEntry div { @@ -19,13 +21,25 @@ display: flex; flex-direction: row; justify-content: space-evenly; - margin-bottom: 8px; -} + margin-bottom: 2vh; +} + +.trafficEntry div:only-child { + margin-bottom: 0; +} + +.trafficEntry div:only-child > .timeColumn, +.trafficEntry div:only-child > .lineColumn { + margin-bottom: 0; +} + +.trafficEntry div:only-child > .timeColumn { + justify-content: center !important; +} .trafficEntry div p { text-align: left; - font-size: 3.5vw; - padding: 3vw 0; + padding: 3vh 0 0 0; } .trafficEntry div div { @@ -33,25 +47,6 @@ flex-direction: column; } -.timeColumn { - flex-basis: 15%; - justify-content: flex-start; - align-items: center; -} - -.timeColumn img { - width: 20px; -} - -.lineColumn { - flex-basis: 75%; -} - -.lineColumn img { - width: 30px; - margin-right: 10px; -} - .trafficEntry div div div { display: flex; flex-direction: row; @@ -59,6 +54,53 @@ align-items: flex-end; } +.timeColumn { + flex-basis: 15%; + justify-content: space-between !important; + align-items: center; +} + +.timeColumn div { + align-items: center !important; +} + +.timeColumn img { + width: 3.5vw; +} + +.lineColumn { + flex-basis: 75%; + max-width: 75%; +} + +.lineColumn div { + margin-bottom: 0px; +} + +.lineColumn img { + width: 7.5vw; + margin-right: 10px; +} + +.infoWrapper p { + text-overflow: ellipsis; + overflow: hidden; + flex-basis: 75%; + flex-grow: 1; + display: block; + white-space: nowrap; + max-height: 3.5vw; +} + +.infoWrapper span { + flex-basis: 25%; +} + +.expanded { + white-space: normal !important; + max-height: none !important; +} + .lineName { background: var(--colorLine); color: white; @@ -69,11 +111,10 @@ } .destination { - font-size: 100%; text-align: left; } -.trafficEntry button { +.trafficEntry a { width: 90%; font-size: 4vw; font-weight: bold; @@ -81,4 +122,5 @@ padding: 4vw 0; border-radius: var(--borderRadius); box-shadow: var(--boxShadow); + text-decoration: none; } \ No newline at end of file diff --git a/src/components/pages/Tickets.js b/src/components/pages/Tickets.js index b79a73b..d1fe324 100644 --- a/src/components/pages/Tickets.js +++ b/src/components/pages/Tickets.js @@ -2,13 +2,16 @@ import React, { Component } from 'react'; import Header from '../Header.js'; import MainArea from '../MainArea.js'; +import globalData from '../../GlobalData.js'; class Tickets extends Component { render() { + globalData.currentPage = this; + return ( <>
- +

Du har inga biljetter

diff --git a/src/components/pages/TicketsBuy.js b/src/components/pages/TicketsBuy.js index db3e092..077d1c0 100644 --- a/src/components/pages/TicketsBuy.js +++ b/src/components/pages/TicketsBuy.js @@ -9,8 +9,12 @@ import clockIcon from '../../img/clock.svg'; import calendarIcon from '../../img/calendar.svg'; import recurringIcon from '../../img/redo.svg'; +import globalData from '../../GlobalData.js'; + class TicketsBuy extends Component { render() { + globalData.currentPage = this; + return ( <>
@@ -19,7 +23,7 @@ class TicketsBuy extends Component { - +

Du har inga tidigare köp

diff --git a/src/components/pages/TrafficInfo.js b/src/components/pages/TrafficInfo.js index 0fa69c2..c59c0a3 100644 --- a/src/components/pages/TrafficInfo.js +++ b/src/components/pages/TrafficInfo.js @@ -6,34 +6,21 @@ import MainArea from "../MainArea.js"; import StopTitle from "../StopTitle.js"; import TrafficList from "../TrafficList.js"; -import Stop from "../../classes/Stop.js"; -import Departure from "../../classes/Departure.js"; +import globalData from '../../GlobalData.js'; class TrafficInfo extends Component { render() { - let testStop = new Stop( - "Lemmingsgatan", - ["Läge A", "Läge B", "Läge C"], - [ - new Departure( - "519", - "Mot Heden", - "11:59", - "Trafikolycka vid Partille Centrum." - ), - new Departure("58", "Mot Västra Eriksberg", "12:07"), - ] - ); + globalData.currentPage = this; return ( <>
- + - + ); diff --git a/src/components/pages/Travel.js b/src/components/pages/Travel.js index bf99ef9..5f582f6 100644 --- a/src/components/pages/Travel.js +++ b/src/components/pages/Travel.js @@ -7,15 +7,22 @@ import TripSelector from '../TripSelector.js'; import '../css/TripSelector.css'; +import globalData from '../../GlobalData.js'; + class Travel extends Component { render() { + globalData.currentPage = this; + return ( <>
- + - + ); diff --git a/src/img/userDark.svg b/src/img/userDark.svg new file mode 100644 index 0000000..06172f0 --- /dev/null +++ b/src/img/userDark.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + +