From 410457e1c1cad57ed2109fe8de9d1dc1eecf353f Mon Sep 17 00:00:00 2001
From: Zog
Date: Mon, 12 Mar 2018 10:42:01 +0100
Subject: Refs #6143; Configurable extra headers on VJs editor
---
app/assets/stylesheets/components/_tables.sass | 3 +++
.../vehicle_journeys/components/VehicleJourney.js | 21 +++++++++++++++++++++
.../vehicle_journeys/components/VehicleJourneys.js | 17 +++++++++++++++++
.../containers/VehicleJourneysList.js | 4 +++-
app/views/vehicle_journeys/index.html.slim | 1 +
config/application.rb | 1 +
6 files changed, 46 insertions(+), 1 deletion(-)
diff --git a/app/assets/stylesheets/components/_tables.sass b/app/assets/stylesheets/components/_tables.sass
index ef19bd538..ba51f7de7 100644
--- a/app/assets/stylesheets/components/_tables.sass
+++ b/app/assets/stylesheets/components/_tables.sass
@@ -376,6 +376,9 @@
border-top-color: transparent
> div:not(.btn-group)
min-height: 20px
+ white-space: nowrap
+ overflow: hidden
+ text-overflow: ellipsis
.td > .headlined
&:before
diff --git a/app/javascript/vehicle_journeys/components/VehicleJourney.js b/app/javascript/vehicle_journeys/components/VehicleJourney.js
index a667bf8aa..73d99d120 100644
--- a/app/javascript/vehicle_journeys/components/VehicleJourney.js
+++ b/app/javascript/vehicle_journeys/components/VehicleJourney.js
@@ -75,6 +75,21 @@ export default class VehicleJourney extends Component {
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
@@ -95,6 +110,11 @@ export default class VehicleJourney extends Component {
{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('purchase_windows') &&
{purchase_windows.slice(0,3).map((tt, i)=>
@@ -222,4 +242,5 @@ VehicleJourney.propTypes = {
vehicleJourneys: PropTypes.object.isRequired,
allTimeTables: PropTypes.array.isRequired,
allPurchaseWindows: PropTypes.array.isRequired,
+ extraHeaders: PropTypes.array.isRequired,
}
diff --git a/app/javascript/vehicle_journeys/components/VehicleJourneys.js b/app/javascript/vehicle_journeys/components/VehicleJourneys.js
index ae38a21af..4b2d8c7a6 100644
--- a/app/javascript/vehicle_journeys/components/VehicleJourneys.js
+++ b/app/javascript/vehicle_journeys/components/VehicleJourneys.js
@@ -163,6 +163,15 @@ export default class VehicleJourneys extends Component {
)
}
+ extraHeaderLabel(header) {
+ if(header["type"] == "custom_field"){
+ return this.props.customFields[header["name"]]["name"]
+ }
+ else{
+ return I18n.attribute_name("vehicle_journey", header)
+ }
+ }
+
render() {
this.previousBreakpoint = undefined
this._allTimeTables = null
@@ -231,6 +240,11 @@ export default class VehicleJourneys extends Component {
)}
}
+ {
+ this.props.extraHeaders.map((header, i) =>
+ {this.extraHeaderLabel(header)}
+ )
+ }
@@ -293,6 +308,8 @@ export default class VehicleJourneys extends Component {
VehicleJourneys.propTypes = {
status: PropTypes.object.isRequired,
filters: PropTypes.object.isRequired,
+ extraHeaders: PropTypes.array.isRequired,
+ customFields: PropTypes.object.isRequired,
stopPointsList: PropTypes.array.isRequired,
onLoadFirstPage: PropTypes.func.isRequired,
onUpdateTime: PropTypes.func.isRequired,
diff --git a/app/javascript/vehicle_journeys/containers/VehicleJourneysList.js b/app/javascript/vehicle_journeys/containers/VehicleJourneysList.js
index 81d603fd4..f21e2c87e 100644
--- a/app/javascript/vehicle_journeys/containers/VehicleJourneysList.js
+++ b/app/javascript/vehicle_journeys/containers/VehicleJourneysList.js
@@ -10,7 +10,9 @@ const mapStateToProps = (state) => {
status: state.status,
filters: state.filters,
stopPointsList: state.stopPointsList,
- returnStopPointsList: state.returnStopPointsList
+ returnStopPointsList: state.returnStopPointsList,
+ extraHeaders: window.extra_headers,
+ customFields: window.custom_fields,
}
}
diff --git a/app/views/vehicle_journeys/index.html.slim b/app/views/vehicle_journeys/index.html.slim
index d53d8b50c..5606bc055 100644
--- a/app/views/vehicle_journeys/index.html.slim
+++ b/app/views/vehicle_journeys/index.html.slim
@@ -29,6 +29,7 @@
| window.features = #{raw @features};
| window.all_missions = #{(@all_missions.to_json).html_safe};
| window.custom_fields = #{(@custom_fields.to_json).html_safe};
+ | window.extra_headers = #{Rails.application.config.vehicle_journeys_extra_headers.to_json.html_safe};
// | window.I18n = #{(I18n.backend.send(:translations).to_json).html_safe};
- if has_feature?(:vehicle_journeys_return_route)
diff --git a/config/application.rb b/config/application.rb
index 8da6a7428..fabea41de 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -40,6 +40,7 @@ module ChouetteIhm
)
config.development_toolbar = false
+ config.vehicle_journeys_extra_headers = []
unless Rails.env.production?
# Work around sprockets+teaspoon mismatch:
--
cgit v1.2.3