Skip to content

Commit

Permalink
Fix Route Coloring & Refresh Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
consindo committed Sep 19, 2017
1 parent 4a92b33 commit d651dcb
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 174 deletions.
2 changes: 1 addition & 1 deletion js/stores/settingsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class settingsStore {
this.state[attrname] = preState[attrname]
}
}
localStorage.setItem('AppVersion', '1.5.0')
localStorage.setItem('AppVersion', '1.6.0')
}
getState() {
return this.state
Expand Down
132 changes: 8 additions & 124 deletions js/stores/stationStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@ import { t } from './translationStore.js'
export class stationStore extends Events {
constructor(props) {
super(props)
this.trainStations = [
'0133','0115', // britomart, newmarket
'0277','0118','0122','0104','0119','0120','0105','0129','0123','0124','0121','0125','0126','0128','0127', // western line
'0114','0113','0112','0102','0606','0605', // onehunga line
'0140', '0111','0101','0109','0100','0108','0099','0098','0107','0106','0097','0134', // southern line
'0116','0117','0103','0130','0244','9218' // eastern line
]
// not in any order
this.ferryStations = [
'9600','9610','9623','9630','9670','9690','9730',
'9660','9650','9720','9810','9640','9770','9760',
'9790','9740','9700','9604','9620','9603','9750']

this.StationData = {}
if (localStorage.getItem('StationData')) {
Expand Down Expand Up @@ -53,122 +41,15 @@ export class stationStore extends Events {

getIcon(station) {
let icon = 'bus'
if (typeof(station) === 'number') {
if (station === 2) {
icon = 'train'
} else if (station === 4) {
icon = 'ferry'
} else if (station === 5) {
icon = 'cablecar'
}
return icon
}

if (this.trainStations.indexOf(station) != -1) {
if (station === 2) {
icon = 'train'
} else if (this.ferryStations.indexOf(station) != -1) {
} else if (station === 4) {
icon = 'ferry'
} else if (station === 5) {
icon = 'cablecar'
}
return icon
}
// deprecated
getColor(agency_id, code){
switch(agency_id){
case 'AM': // Auckland Metro
switch (code) {
case 'WEST': // West Line
//return '#006553' official
return '#4f9734'
case 'STH': // South Line
//return '#a60048' official
return '#e52f2b'
case 'EAST': // East Line
return '#f39c12'
case 'PUK': // South Line
//return '#a60048'
return '#e52f2b'
case 'ONE': // ONE Line
return '#21b4e3'
default:
return '#17232f'
}
case 'FGL': // Fullers
return '#2756a4'

case 'HE': // Howick and Eastern
return '#2196F3'

case 'NZBGW': // NZ Bus - Go West
return '#4CAF50'

case 'NZBML': // NZ Bus - metrolink
switch (code) {
case 'CTY': // City Link
return '#ef3c34'

case 'INN': // Inner Link
return '#41b649'

case 'OUT': // Outer Link
return '#f7991c'

default:
return '#0759b0'
}

case 'NZBNS': // NZ Bus - North Star
return '#f39c12'

case 'NZBWP': // NZ Bus - Waka Pacific
return '#0f91ab'

case 'UE': // Urban Express / Same as Pavolich
return '#776242'

case 'BTL': // Birkenhead Transport
return '#b2975b'

case 'RTH': // Ritchies
switch (code) {
case 'NEX': // Northern Express
//return '#0079c2' official
return '#0056a9'

default:
return '#ff6f2c'
}

case 'WBC': // Waiheke Bus Company
return '#2196F3'

case 'EXPNZ': // Explore Waiheke - supposed to be closed?
return '#ffe81c'

case 'BFL': // Belaire Ferries
return '#ffd503'

case 'ATAPT': // AT Airporter
return '#f7931d'

case 'SLPH': // Pine Harbour / Sealink
return '#d92732'

case 'GBT': // Go Bus
return '#58aa17'

case '360D': // 360 Discovery
return '#2756a4'

case 'ABEXP': //Skybus
return '#F44336'

case 'PC': // Pavolich
return '#776242'

default: //MSB, PBC, BAYES - Schools
return '#17232f'
}
}
getHeadsign(prefix, longname, direction) {
if (prefix === 'nz-wlg') {
let rawname = longname.split('(')
Expand Down Expand Up @@ -239,7 +120,7 @@ export class stationStore extends Events {
dataCollection.forEach((data, key) => {
let no = stopNumber.split('+')[key]
let description = t('savedStations.stop', {number: `${no} / ${data.stop_name}`})
let icon = this.getIcon(no)
let icon = this.getIcon(data.route_type)

let zName = stopName
if (stopNumber.split('+').length > 1) {
Expand Down Expand Up @@ -324,6 +205,9 @@ export class stationStore extends Events {
trips = trips.concat(data.trips)
realtime = Object.assign(realtime, data.realtime)
})
trips.sort((a,b) => {
return a.departure_time_seconds - b.departure_time_seconds
})
this.timesFor = [stations, new Date()]
this.tripData = trips
this.realtimeData = realtime
Expand Down
53 changes: 19 additions & 34 deletions js/views/station.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ const iconMap = {
bus: <BusIcon />
}

// hack
let liveRefresh, realtimeRefresh

const normalStyle = UiStore.getAnimation()
const fancyStyle = UiStore.getAnimation('fancy')

Expand All @@ -33,6 +30,8 @@ class Station extends React.Component {
match: PropTypes.object,
history: PropTypes.object,
}
liveRefresh
realtimeRefresh
state = {
name: '',
description: '',
Expand Down Expand Up @@ -86,10 +85,21 @@ class Station extends React.Component {
description = data.description
}
document.title = name + ' - ' + t('app.name')

let route_type = data.route_type
if (data.icon === 'train') {
route_type = 2
} else if (data.icon === 'bus') {
route_type = 3
} else if (data.icon === 'ferry') {
route_type = 4
} else if (data.icon === 'cablecar') {
route_type = 5
}
this.setState({
name: name,
description: description,
route_type: data.route_type,
route_type: route_type,
stop_lat: data.stop_lat,
stop_lon: data.stop_lon || data.stop_lng // horrible api design, probs my fault, idk
})
Expand Down Expand Up @@ -362,10 +372,10 @@ class Station extends React.Component {

// times: every 3 minutes
// realtime: every 20 seconds
liveRefresh = setInterval(() => {
this.liveRefresh = setInterval(() => {
this.getData(this.props)
}, 180000)
realtimeRefresh = setInterval(() => {
this.realtimeRefresh = setInterval(() => {
StationStore.getRealtime(this.state.trips)
}, 20000)
}
Expand All @@ -378,8 +388,8 @@ class Station extends React.Component {
UiStore.unbind('expandChange', this.expandChange)
window.removeEventListener('online', this.triggerRetry)

clearInterval(liveRefresh)
clearInterval(realtimeRefresh)
clearInterval(this.liveRefresh)
clearInterval(this.realtimeRefresh)
}
expandChange = (item) => {
setTimeout(() => {
Expand Down Expand Up @@ -433,36 +443,11 @@ class Station extends React.Component {
})
this.getData(this.props)
}
componentWillReceiveProps(newProps) {
// basically don't do anything if the station doesn't change
if (this.props.match.params.station === newProps.match.params.station) {
// setTimeout(() => {
// if (this.state.fancyMode) {
// this.setState({
// fancyMode: false
// })
// }
// }, 300)
return
}

this.setState({
name: '',
description: '',
trips: [],
realtime: {},
loading: true,
saveModal: false,
currentTrips: [],
definedOrder: [],
})
this.getData(newProps)
}
render() {
const region = this.props.match.params.region
const stop = this.props.match.params.station
const regionStop = region + '|' + stop
const icon = StationStore.getIcon(this.state.route_type || stop)
const icon = StationStore.getIcon(this.state.route_type)
let iconStr = this.state.description

let topIcon = <span className="header-left" onTouchTap={this.triggerBack}><BackIcon /></span>
Expand Down
9 changes: 6 additions & 3 deletions js/views/test_lines.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ const variants = [
['248', 2],
['248X', 2],
['249', 2],
['255', 4],
['255', 2],
['255F', 2],
['258', 4],
['258', 2],
['258F', 2],
['258X', 2],
['267', 2],
Expand Down Expand Up @@ -87,11 +87,13 @@ const variants = [
['501', 2],
['500', 2],
['501', 2],
['505', 2],
['515', 2],
['525', 2],
['532', 2],
['545', 2],
['550', 2],
['550X', 2],
['551', 2],
['552', 2],
['565', 2],
Expand Down Expand Up @@ -195,6 +197,7 @@ const variants = [
['873X', 2],
['874X', 2],
['875', 2],
['877X', 2],
['879', 2],
['880', 2],
['881', 2],
Expand Down Expand Up @@ -268,7 +271,7 @@ class TestLines extends React.Component {
test() {
let test = (index) => {
let route = variants[index]
fetch('${local.endpoint}/nz-akl/line/'+route[0]).then((res) => {
fetch(`${local.endpoint}/nz-akl/line/`+route[0]).then((res) => {
res.json().then((data) => {
// return at the end
let results = this.state.results.slice()
Expand Down
8 changes: 2 additions & 6 deletions js/views/vehicle_loc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,11 @@ class vehicle_location extends React.Component {
let color = '#000000'
let geoJson = null
if (typeof(this.state.line) !== 'undefined') {
color = StationStore.getColor(this.props.tripInfo.agency_id, this.props.tripInfo.route_short_name)
//console.log(color)
color = this.props.tripInfo.route_color
geoJson = <GeoJson className='line' data={this.state.line} style={{color: color}}/>
}

let icon = StationStore.getIcon(this.props.params.station)
if (typeof(this.state.stops[0]) !== 'undefined') {
icon = StationStore.getIcon(this.state.stops[0][2])
}
let icon = StationStore.getIcon(this.props.tripInfo.route_type)
let leafletIcon = busIcon
if (icon === 'train') {
leafletIcon = trainIcon
Expand Down
5 changes: 3 additions & 2 deletions js/views/vehicle_loc_bootstrap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ class VehicleLocationBootstrap extends React.Component {
tripInfo.route_long_name = data[0].route_long_name
tripInfo.shape_id = data[0].shape_id
tripInfo.route_type = data[0].route_type
// tripInfo.route_type = data[]
tripInfo.route_color = data[0].route_color

this.setState({
lineInfo: data,
tripInfo: tripInfo
Expand Down Expand Up @@ -215,7 +216,7 @@ class VehicleLocationBootstrap extends React.Component {
<div className="header-expand">
<h1 className='line-name'>
<section className="line-pill-wrapper-header">
<span className={roundelStyle} style={{backgroundColor: StationStore.getColor(this.state.tripInfo.agency_id, this.state.tripInfo.route_short_name)}}>
<span className={roundelStyle} style={{backgroundColor: this.state.tripInfo.route_color}}>
{code}
</span>
</section>
Expand Down
5 changes: 5 additions & 0 deletions server/db/create-database.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ CREATE TABLE stops (
CONSTRAINT uc_Stops UNIQUE (prefix, version, stop_id)
)
`
const trips_index = `
CREATE NONCLUSTERED INDEX id_Stops
ON trips (prefix, version)
INCLUDE (prefix, version, stop_code)
`

const routes = `
CREATE TABLE routes (
Expand Down
1 change: 1 addition & 0 deletions server/lines/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ var line = {
route_id: route.route_id._,
route_long_name: route.route_long_name._,
route_short_name: route.route_short_name._,
route_color: line.getColor(prefix, route.route_short_name._),
shape_id: route.shape_id._,
route_type: route.route_type._
}
Expand Down
Loading

0 comments on commit d651dcb

Please sign in to comment.