import React, { Component } from 'react' import PropTypes from 'prop-types' import actions from '../actions' import EditVehicleJourney from '../containers/tools/EditVehicleJourney' import VehicleJourneyInfoButton from '../containers/tools/VehicleJourneyInfoButton' export default class VehicleJourney extends Component { constructor(props) { super(props) this.previousCity = undefined } journey_length() { return this.props.value.journey_pattern.journey_length + "km" } cityNameChecker(sp) { return this.props.vehicleJourneys.showHeader(sp.stop_point_objectid) } hasFeature(key) { return this.props.filters.features[key] } timeTableURL(tt) { let refURL = window.location.pathname.split('/', 3).join('/') let ttURL = refURL + '/time_tables/' + tt.id return ( ) } purchaseWindowURL(tt) { let refURL = window.location.pathname.split('/', 3).join('/') let ttURL = refURL + '/purchase_windows/' + tt.id return ( ) } columnHasDelta() { let a = [] this.props.value.vehicle_journey_at_stops.map((vj, i) => { a.push(vj.delta) }) let b = a.reduce((p, c) => p+c, 0) if(b > 0) { return true } } displayDelta(delta) { if(delta > 99){ return "+" } return delta } hasTimeTable(time_tables, tt) { let found = false time_tables.map((t, index) => { if(t.id == tt.id){ found = true return } }) return found } hasPurchaseWindow(purchase_windows, window) { return this.hasTimeTable(purchase_windows, window) } isDisabled(bool1, bool2) { return (bool1 || bool2) } extraHeaderValue(header) { if(header.type == "custom_field"){ let field = this.props.value.custom_fields[header["name"]] if(field.field_type == "list"){ return field.options.list_values[field.value] } else{ return field.value } } else{ return this.props.value[header["name"]] } } render() { this.previousCity = undefined let detailed_calendars = this.hasFeature('detailed_calendars') && !this.disabled let detailed_calendars_shown = $('.detailed-timetables-bt').hasClass('active') let detailed_purchase_windows = this.hasFeature('detailed_purchase_windows') && !this.disabled let detailed_purchase_windows_shown = $('.detailed-purchase-windows-bt').hasClass('active') let {time_tables, purchase_windows} = this.props.value return (
!this.props.disabled && ($(e.target).parents("a").length == 0) && this.props.onSelectVehicleJourney(this.props.index) } >
{this.props.value.short_id || '-'}
{ if(this.props.disabled){ return } e.stopPropagation(true) e.preventDefault() this.props.onOpenInfoModal(this.props.value) $('#EditVehicleJourneyModal').modal('show') false } } > {this.props.value.published_journey_name && this.props.value.published_journey_name != I18n.t('undefined') ? this.props.value.published_journey_name : '-'}
{this.props.value.journey_pattern.short_id || '-'}
{this.props.value.company ? this.props.value.company.name : '-'}
{ this.props.extraHeaders.map((header, i) =>
{this.extraHeaderValue(header)}
) } { this.hasFeature('journey_length_in_vehicle_journeys') &&
{this.journey_length()}
} { this.hasFeature('purchase_windows') &&
{purchase_windows.slice(0,3).map((tt, i)=> {this.purchaseWindowURL(tt)} )} {purchase_windows.length > 3 && + {purchase_windows.length - 3}}
} { detailed_purchase_windows &&
{this.props.allPurchaseWindows.map((w, i) =>
)}
}
{time_tables.slice(0,3).map((tt, i)=> {this.timeTableURL(tt)} )} {time_tables.length > 3 && + {time_tables.length - 3}}
{!this.props.disabled &&
this.props.onSelectVehicleJourney(this.props.index)} type='checkbox' disabled={this.props.value.deletable} checked={this.props.value.selected} >
} {this.props.disabled && } { detailed_calendars &&
{this.props.allTimeTables.map((tt, i) =>
)}
}
{this.props.value.vehicle_journey_at_stops.map((vj, i) =>
{this.props.filters.toggleArrivals &&
{this.props.onUpdateTime(e, i, this.props.index, 'hour', false, false)}} onBlur={(e) => {this.props.onUpdateTime(e, i, this.props.index, 'hour', false, false, true)}} value={vj.arrival_time['hour']} /> : {this.props.onUpdateTime(e, i, this.props.index, 'minute', false, false)}} onBlur={(e) => {this.props.onUpdateTime(e, i, this.props.index, 'minute', false, false, true)}} value={vj.arrival_time['minute']} />
}
{(vj.delta != 0) && }
{this.props.onUpdateTime(e, i, this.props.index, 'hour', true, this.props.filters.toggleArrivals)}} onBlur={(e) => {this.props.onUpdateTime(e, i, this.props.index, 'hour', true, this.props.filters.toggleArrivals, true)}} value={vj.departure_time['hour']} /> : {this.props.onUpdateTime(e, i, this.props.index, "minute", true, this.props.filters.toggleArrivals)}} onBlur={(e) => {this.props.onUpdateTime(e, i, this.props.index, "minute", true, this.props.filters.toggleArrivals, true)}} value={vj.departure_time['minute']} />
)}
) } } VehicleJourney.propTypes = { value: PropTypes.object.isRequired, filters: PropTypes.object.isRequired, index: PropTypes.number.isRequired, onUpdateTime: PropTypes.func.isRequired, onSelectVehicleJourney: PropTypes.func.isRequired, vehicleJourneys: PropTypes.object.isRequired, allTimeTables: PropTypes.array.isRequired, allPurchaseWindows: PropTypes.array.isRequired, extraHeaders: PropTypes.array.isRequired, }