From 913d6935727ace3ac94c08adb4e1ec378741fb19 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 3 Jan 2018 16:31:33 +0100 Subject: Refs #5455 @6h; Add time and distance between stops in Journey Patterns - Adds a `JSON` attribute in the model - Adds the fields in the editor --- app/assets/stylesheets/base/_config.sass | 2 +- app/assets/stylesheets/components/_forms.sass | 1 + app/assets/stylesheets/modules/_jp_collection.sass | 111 +++++++++++++++++++++ .../journey_patterns_collections_controller.rb | 62 +++++++----- app/javascript/journey_patterns/actions/index.js | 14 +++ .../journey_patterns/components/JourneyPattern.js | 73 ++++++++++++-- .../journey_patterns/components/JourneyPatterns.js | 3 +- .../containers/JourneyPatternList.js | 5 +- .../journey_patterns/reducers/journeyPatterns.js | 16 ++- app/javascript/packs/journey_patterns/index.js | 1 + app/models/chouette/journey_pattern.rb | 8 +- app/views/api/v1/journey_patterns/show.rabl | 4 + 12 files changed, 262 insertions(+), 38 deletions(-) (limited to 'app') diff --git a/app/assets/stylesheets/base/_config.sass b/app/assets/stylesheets/base/_config.sass index ec1c43e7f..2c226357f 100644 --- a/app/assets/stylesheets/base/_config.sass +++ b/app/assets/stylesheets/base/_config.sass @@ -16,7 +16,7 @@ $blue: #007fbb $darkgrey: #4b4b4b $grey: #a4a4a4 -$lightgrey: rgba($grey, 0.15) +$lightgrey: lighten($grey, 25) $green: #70b12b $red: #da2f36 diff --git a/app/assets/stylesheets/components/_forms.sass b/app/assets/stylesheets/components/_forms.sass index 47faf19b1..5143d2ba4 100644 --- a/app/assets/stylesheets/components/_forms.sass +++ b/app/assets/stylesheets/components/_forms.sass @@ -284,6 +284,7 @@ table, .table height: $cbx-size width: $cbx-size margin: 0 auto + transition: transform 0.2s, background-color 0.2s > input[type='checkbox'] &:not(:checked), &:checked diff --git a/app/assets/stylesheets/modules/_jp_collection.sass b/app/assets/stylesheets/modules/_jp_collection.sass index f579cf87b..22edb9599 100644 --- a/app/assets/stylesheets/modules/_jp_collection.sass +++ b/app/assets/stylesheets/modules/_jp_collection.sass @@ -103,6 +103,7 @@ .table-2entries .t2e-item-list .t2e-item position: relative + overflow: hidden .th .vj_tt display: inline-block @@ -111,6 +112,116 @@ + .vj_tt margin-left: 5px + &.with-costs + + & > div + position: relative + + .has_radio + margin-right: 150px + + .costs + background: $lightgrey + padding: 5px + color: white + position: absolute + left: 80px + top: -1px + transform: translateY(-50%) + font-size: 0.75em + transition: background 0.1s + border: 1px solid white + + &:hover + background: $blue + &:after + background: $blue + &:after + content: "" + height: 2px + position: absolute + left: -30px + background: $lightgrey + right: 100% + top: 50% + transition: background 0.1s + + p + display: block + border: none + margin-bottom: 0 + i + margin-right: 3px + width: 12px + & + p + position: relative + z-index: 2 + padding-right: 0 + margin: 0 + border-right: none + + input + display: inline-block + width: 40px + border: none + margin-right: 5px + color: black + + .edit-mode .costs + p + margin-bottom: 5px + & + p + margin-bottom: 0 + + background: $blue + &:after + background: $blue + + + .with-headline + .costs + top: 25% + + .deactivated .costs + display: none + + $link-size: 10px + .link + position: absolute + left: 40px + width: 10px + top: -7px + bottom: -7px + background: $blue + z-index: 3 + &:after + content: "" + width: $link-size + height: $link-size + position: absolute + top: 50% + bottom: 50% + margin-top: -$link-size/2 - 3px + border-top: $link-size/2 solid transparent + border-left: $link-size/2 solid transparent + border-right: $link-size/2 solid $blue + border-bottom: $link-size/2 solid $blue + transform: rotate(135deg) + left: 0% + opacity: 0 + transition: left 0.2s, opacity 0.2s + + .activated .link + &:after + left: -50% + opacity: 1 + + .headlined + .link + top: 0 + &:after + top: 75% + margin-top: -$link-size/2 - 1px + &.has-error &:before content: '' diff --git a/app/controllers/journey_patterns_collections_controller.rb b/app/controllers/journey_patterns_collections_controller.rb index 5fe78766c..6b661da0c 100644 --- a/app/controllers/journey_patterns_collections_controller.rb +++ b/app/controllers/journey_patterns_collections_controller.rb @@ -17,35 +17,45 @@ class JourneyPatternsCollectionsController < ChouetteController alias_method :vehicle_journey, :resource def show - @q = route.journey_patterns.search(params[:q]).result(distinct: true).includes(:stop_points) + @q = route.journey_patterns + if params[:q].present? + ids = @q.search(params[:q]).result(distinct: true).pluck(:id) + @q = @q.where(id: ids) + end + @q = @q.includes(:stop_points) + # @q = route.journey_patterns.search(params[:q]).result().includes(:stop_points) @ppage = 10 @journey_patterns ||= @q.paginate(page: params[:page], per_page: @ppage).order(:name) - - @stop_points_list = [] - route.stop_points.each do |sp| - @stop_points_list << { - :id => sp.stop_area.id, - :route_id => sp.try(:route_id), - :object_id => sp.try(:objectid), - :position => sp.try(:position), - :for_boarding => sp.try(:for_boarding), - :for_alighting => sp.try(:for_alighting), - :name => sp.stop_area.try(:name), - :zip_code => sp.stop_area.try(:zip_code), - :city_name => sp.stop_area.try(:city_name), - :comment => sp.stop_area.try(:comment), - :area_type => sp.stop_area.try(:area_type), - :registration_number => sp.stop_area.try(:registration_number), - :nearest_topic_name => sp.stop_area.try(:nearest_topic_name), - :fare_code => sp.stop_area.try(:fare_code), - :longitude => sp.stop_area.try(:longitude), - :latitude => sp.stop_area.try(:latitude), - :long_lat_type => sp.stop_area.try(:long_lat_type), - :country_code => sp.stop_area.try(:country_code), - :street_name => sp.stop_area.try(:street_name) - } + respond_to do |format| + format.json + format.html do + @stop_points_list = [] + route.stop_points.each do |sp| + @stop_points_list << { + :id => sp.stop_area.id, + :route_id => sp.try(:route_id), + :object_id => sp.try(:objectid), + :position => sp.try(:position), + :for_boarding => sp.try(:for_boarding), + :for_alighting => sp.try(:for_alighting), + :name => sp.stop_area.try(:name), + :zip_code => sp.stop_area.try(:zip_code), + :city_name => sp.stop_area.try(:city_name), + :comment => sp.stop_area.try(:comment), + :area_type => sp.stop_area.try(:area_type), + :registration_number => sp.stop_area.try(:registration_number), + :nearest_topic_name => sp.stop_area.try(:nearest_topic_name), + :fare_code => sp.stop_area.try(:fare_code), + :longitude => sp.stop_area.try(:longitude), + :latitude => sp.stop_area.try(:latitude), + :long_lat_type => sp.stop_area.try(:long_lat_type), + :country_code => sp.stop_area.try(:country_code), + :street_name => sp.stop_area.try(:street_name) + } + end + @stop_points_list = @stop_points_list.sort_by {|a| a[:position] } + end end - @stop_points_list = @stop_points_list.sort_by {|a| a[:position] } end def user_permissions diff --git a/app/javascript/journey_patterns/actions/index.js b/app/javascript/journey_patterns/actions/index.js index 1c2eb68b2..09e2001c1 100644 --- a/app/javascript/journey_patterns/actions/index.js +++ b/app/javascript/journey_patterns/actions/index.js @@ -64,6 +64,11 @@ const actions = { type : 'DELETE_JOURNEYPATTERN', index, }), + updateJourneyPatternCosts : (index, costs) => ({ + type : 'UPDATE_JOURNEYPATTERN_COSTS', + index, + costs + }), closeModal : () => ({ type : 'CLOSE_MODAL' }), @@ -194,6 +199,7 @@ const actions = { } }) } +<<<<<<< HEAD journeyPatterns.push({ name: val.name, object_id: val.object_id, @@ -204,6 +210,14 @@ const actions = { stop_points: val.route_short_description.stop_points, deletable: false }) +======= + journeyPatterns.push( + _.assign({}, val, { + stop_points: val.route_short_description.stop_points, + deletable: false + }) + ) +>>>>>>> Refs #5455 @6h; Add time and distance between stops in Journey Patterns } } window.currentItemsLength = journeyPatterns.length diff --git a/app/javascript/journey_patterns/components/JourneyPattern.js b/app/javascript/journey_patterns/components/JourneyPattern.js index d4c9816ec..40a6899e2 100644 --- a/app/javascript/journey_patterns/components/JourneyPattern.js +++ b/app/javascript/journey_patterns/components/JourneyPattern.js @@ -5,6 +5,17 @@ export default class JourneyPattern extends Component{ constructor(props){ super(props) this.previousCity = undefined + this.previousSpId = undefined + this.updateCosts = this.updateCosts.bind(this) + } + + updateCosts(e) { + let costs = { + [e.target.dataset.costsKey]: { + [e.target.name]: parseInt(e.target.value) + } + } + this.props.onUpdateJourneyPatternCosts(costs) } vehicleJourneyURL(jpOid) { @@ -16,16 +27,26 @@ export default class JourneyPattern extends Component{ ) } + hasFeature(key) { + return this.props.status.features[key] + } + cityNameChecker(sp) { let bool = false + if(sp.city_name != this.previousCity){ bool = true this.previousCity = sp.city_name } + return bool + } + + spNode(sp, headlined){ return (
+ + km +
++ + min +
+{(costs['distance'] || 0) + " km"}
+{time_in_words}
+- + km
diff --git a/app/javascript/journey_patterns/components/JourneyPatterns.js b/app/javascript/journey_patterns/components/JourneyPatterns.js index 69024050f..1e391b0c2 100644 --- a/app/javascript/journey_patterns/components/JourneyPatterns.js +++ b/app/javascript/journey_patterns/components/JourneyPatterns.js @@ -54,6 +54,10 @@ export default class JourneyPatterns extends Component { } } + hasFeature(key) { + return this.props.status.features[key] + } + cityNameChecker(sp) { let bool = false if(sp.city_name != this.previousCity){ @@ -115,7 +119,7 @@ export default class JourneyPatterns extends Component {