aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Florisson2014-09-17 13:51:28 +0200
committerMarc Florisson2014-09-17 13:51:28 +0200
commit1e3d5138f09702a0bc38296b5bed36903e7f08e8 (patch)
tree1485dd7baca86414c9dd4b04e5b865b116bc63ae
parentd489c3a664bf27e2ec3272c90002698f00689921 (diff)
parent375962d92d2b4222f955a5494b17f0031b9dbcf0 (diff)
downloadchouette-core-1e3d5138f09702a0bc38296b5bed36903e7f08e8.tar.bz2
merge vj
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock2
-rw-r--r--app/controllers/time_tables_controller.rb38
-rw-r--r--app/controllers/vehicle_journeys_controller.rb50
-rw-r--r--app/views/vehicle_journeys/_sidebar.html.erb15
-rw-r--r--app/views/vehicle_journeys/_vehicle_journeys.html.erb48
-rw-r--r--app/views/vehicle_journeys/index.html.erb136
-rw-r--r--app/views/vehicle_journeys/index.js.erb2
-rw-r--r--config/locales/vehicle_journeys.yml8
9 files changed, 180 insertions, 120 deletions
diff --git a/Gemfile b/Gemfile
index 984c9b675..94595ce95 100644
--- a/Gemfile
+++ b/Gemfile
@@ -66,7 +66,6 @@ gem 'will_paginate', '~> 3.0'
gem 'ransack'
gem 'squeel'
gem 'ninoxe', :git => 'https://github.com/afimb/ninoxe.git', :branch => :sismo
-#gem 'ninoxe',:path => '~/projects/ninoxe'
#gem 'ninoxe',:path => '~/workspace/chouette/ninoxe'
#gem 'ninoxe', '~> 1.0.3'
diff --git a/Gemfile.lock b/Gemfile.lock
index 5f2596da1..033631a1c 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/afimb/ninoxe.git
- revision: 139f461be9a23566d242495df14331ec06308ce1
+ revision: 70a316b3b7d8a3faf8d79fbd1732c4b9812cdb59
branch: sismo
specs:
ninoxe (1.1.0)
diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb
index 586713c60..78d633581 100644
--- a/app/controllers/time_tables_controller.rb
+++ b/app/controllers/time_tables_controller.rb
@@ -10,36 +10,36 @@ class TimeTablesController < ChouetteController
def show
add_breadcrumb Referential.human_attribute_name("time_tables"), referential_time_tables_path(@referential)
-
+
@year = params[:year] ? params[:year].to_i : Date.today.cwyear
- @time_table_combination = TimeTableCombination.new
+ @time_table_combination = TimeTableCombination.new
show!
end
-
+
def new
add_breadcrumb Referential.human_attribute_name("time_tables"), referential_time_tables_path(@referential)
-
+
@autocomplete_items = ActsAsTaggableOn::Tag.all
new!
end
def edit
- edit! do
+ edit! do
add_breadcrumb Referential.human_attribute_name("time_tables"), referential_time_tables_path(@referential)
add_breadcrumb @time_table.comment, referential_time_table_path(@referential, @time_table)
-
+
@autocomplete_items = ActsAsTaggableOn::Tag.all
end
end
def comment_filter
- respond_to do |format|
- format.json { render :json => filtered_time_tables_maps}
- end
-
+ respond_to do |format|
+ format.json { render :json => filtered_time_tables_maps}
+ end
+
end
- def index
+ def index
request.format.kml? ? @per_page = nil : @per_page = 12
index! do |format|
@@ -48,7 +48,7 @@ class TimeTablesController < ChouetteController
redirect_to params.merge(:page => 1)
end
}
- end
+ end
end
def duplicate
@@ -60,7 +60,7 @@ class TimeTablesController < ChouetteController
end
def tags
- @tags = ActsAsTaggableOn::Tag.where("tags.name LIKE ?", "%#{params[:tag]}%")
+ @tags = ActsAsTaggableOn::Tag.where("tags.name LIKE ?", "%#{params[:tag]}%")
respond_to do |format|
format.json { render :json => @tags.map{|t| {:id => t.id, :name => t.name }} }
end
@@ -83,11 +83,19 @@ class TimeTablesController < ChouetteController
tag_search = ransack_params["tag_search"].split(",").collect(&:strip) if ransack_params.present? && ransack_params["tag_search"].present?
ransack_params.delete("tag_search") if ransack_params.present?
- select_time_tables = tag_search ? referential.time_tables.tagged_with(tag_search) : referential.time_tables
- @q = select_time_tables.search(ransack_params)
+ selected_time_tables = tag_search ? select_time_tables.tagged_with(tag_search) : select_time_tables
+ @q = selected_time_tables.search(ransack_params)
@time_tables ||= @q.result(:distinct => true).order(:comment).paginate(:page => params[:page])
end
+ def select_time_tables
+ if params[:route_id]
+ referential.time_tables.joins( vehicle_journeys: :route).where( "routes.id IN (#{params[:route_id]})")
+ else
+ referential.time_tables
+ end
+ end
+
def resource_url(time_table = nil)
referential_time_table_path(referential, time_table || resource)
end
diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb
index 848fda507..18cd6b96c 100644
--- a/app/controllers/vehicle_journeys_controller.rb
+++ b/app/controllers/vehicle_journeys_controller.rb
@@ -1,7 +1,7 @@
class VehicleJourneysController < ChouetteController
defaults :resource_class => Chouette::VehicleJourney
- respond_to :js, :only => [:select_journey_pattern, :edit, :new]
+ respond_to :js, :only => [:select_journey_pattern, :edit, :new, :index]
belongs_to :referential do
belongs_to :line, :parent_class => Chouette::Line do
@@ -30,31 +30,49 @@ class VehicleJourneysController < ChouetteController
update!(:alert => t('activerecord.errors.models.vehicle_journey.invalid_times'))
end
- def index
- index! do |format|
- format.html {
- @matrix ||= matrix
- if collection.out_of_bounds?
- redirect_to params.merge(:page => 1)
- end
- }
- end
+ def index
+ index! do
+ @matrix ||= matrix
+ if collection.out_of_bounds?
+ redirect_to params.merge(:page => 1)
+ end
+ end
end
- # overwrite inherited resources to use delete instead of destroy
+ # overwrite inherited resources to use delete instead of destroy
# foreign keys will propagate deletion)
def destroy_resource(object)
object.delete
end
protected
-
+
alias_method :vehicle_journey, :resource
-
+
def collection
- @q = parent.sorted_vehicle_journeys.search(params[:q])
- @vehicle_journeys ||= @q.result.order( "vehicle_journey_at_stops.departure_time").paginate(:page => params[:page], :per_page => 8)
+ adapt_time_params
+ @q = select_vehicles.search(params[:q])
+ @vehicle_journeys ||= @q.result.order( "vehicle_journey_at_stops.departure_time").paginate(:page => params[:page], :per_page => 8)
+ end
+
+ def adapt_time_params
+ hour_entry = "vehicle_journey_at_stops_departure_time_gt(4i)".to_sym
+ if params[:q] && params[:q][ hour_entry]
+ params[:q].merge! hour_entry => (params[:q][ hour_entry].to_i - utc_offset)
+ end
+ end
+ def utc_offset
+ # Ransack Time eval - utc eval
+ sample = [2001,1,1,10,0]
+ Time.zone.local(*sample).utc.hour - Time.utc(*sample).hour
+ end
+ def select_vehicles
+ if params[:q] && params[:q][ :time_tables_id_eq ]
+ parent.sorted_vehicle_journeys.joins( :time_tables).where( "time_tables_vehicle_journeys.time_table_id" => params[:q][ :time_tables_id_eq ].split(','))
+ else
+ parent.sorted_vehicle_journeys
+ end
end
def matrix
@@ -62,7 +80,7 @@ class VehicleJourneysController < ChouetteController
Chouette::VehicleJourney.find( @vehicle_journeys.map { |v| v.id } ).
each do |vj|
vj.vehicle_journey_at_stops.each do |vjas|
- hash[ "#{vj.id}-#{vjas.stop_point_id}"] = vjas
+ hash[ "#{vj.id}-#{vjas.stop_point_id}"] = vjas
end
end
end
diff --git a/app/views/vehicle_journeys/_sidebar.html.erb b/app/views/vehicle_journeys/_sidebar.html.erb
new file mode 100644
index 000000000..355f90618
--- /dev/null
+++ b/app/views/vehicle_journeys/_sidebar.html.erb
@@ -0,0 +1,15 @@
+ <ul class="actions">
+ <li><%= link_to t('vehicle_journeys.actions.new'), new_referential_line_route_vehicle_journey_path(@referential, @line, @route), :class => "add" %></li>
+ <li><%= link_to t('.timeless'), timeless_referential_line_route_vehicle_journeys_path(@referential, @line, @route), :class => "link" %></li>
+ <li><%= link_to t('vehicle_journey_imports.new.title'), new_referential_line_route_vehicle_journey_import_path( @referential, @line, @route ), :class => "import" %></li>
+ </ul>
+ <div class="btn-group">
+ <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
+ <%= t('vehicle_journey_imports.new.export_vehicle_journeys') %><span class="caret"></span>
+ </button>
+ <ul class="dropdown-menu" role="menu">
+ <li><%= link_to image_tag("icons/file_csv.png") + " Csv" , referential_line_route_vehicle_journey_exports_path(@referential, @line, @route, :format => :csv) %></li>
+ <li><%= link_to image_tag("icons/file_excel.png") + " Excel", referential_line_route_vehicle_journey_exports_path(@referential, @line, @route, :format => :xls) %></li>
+ </ul>
+ </div>
+
diff --git a/app/views/vehicle_journeys/_vehicle_journeys.html.erb b/app/views/vehicle_journeys/_vehicle_journeys.html.erb
new file mode 100644
index 000000000..ed9ad67ca
--- /dev/null
+++ b/app/views/vehicle_journeys/_vehicle_journeys.html.erb
@@ -0,0 +1,48 @@
+<div class="page_info">
+ <span class="search"> <%= t("will_paginate.page_entries_info.search") %></span> <%= page_entries_info @vehicle_journeys %>
+</div>
+<div class="pagination">
+ <%= will_paginate @vehicle_journeys, :container => false, renderer: RemoteBootstrapPaginationLinkRenderer %>
+</div>
+<div class="vehicle_journeys paginated_content">
+ <table class="table table-hover table-striped">
+ <thead>
+ <tr>
+ <th class="title"><%= Chouette::JourneyPattern.model_name.human.pluralize %> :</th>
+ <% @vehicle_journeys.map(&:journey_pattern).each do |jp| %>
+ <th><%= link_to journey_name( jp), [@referential, @line, @route, jp] %></th>
+ <% end %>
+ </tr>
+ <tr>
+ <th class="title"><%= Chouette::TimeTable.model_name.human.pluralize %> :</th>
+ <% @vehicle_journeys.each do |vj| %>
+ <th title="<%= time_tables_info( vj) %>" class="calendars">
+ <%= time_tables_shortest_info( vj) %>
+ </th>
+ <% end %>
+ </tr>
+ <tr>
+ <th class="title"><%= Chouette::VehicleJourney.model_name.human.pluralize %> :</th>
+ <% @vehicle_journeys.each do |vj| %>
+ <th> <%= link_to vehicle_name(vj), [@referential, @line, @route, vj]%></th>
+ <% end %>
+ </tr>
+ </thead>
+ <tbody>
+ <% @route.stop_points.each_with_index do |sp, index| %>
+ <tr class="<%= cycle('odd', 'even') %>">
+ <td class="stop_area"><%= sp.stop_area.name %></td>
+ <% @vehicle_journeys.each do |vj| %>
+ <td class="hours <%= missing_time_check(@matrix["#{vj.id}-#{sp.id}"]) %>">
+ <%= (@matrix["#{vj.id}-#{sp.id}"] && @matrix["#{vj.id}-#{sp.id}"].departure_time) ? l( @matrix["#{vj.id}-#{sp.id}"].departure_time, :format => :hour) : "" %>
+ </td>
+ <% end %>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+</div>
+<div class="pagination">
+ <%= will_paginate @vehicle_journeys, :container => false, renderer: RemoteBootstrapPaginationLinkRenderer %>
+</div>
+
diff --git a/app/views/vehicle_journeys/index.html.erb b/app/views/vehicle_journeys/index.html.erb
index 212c06bbf..b50f25027 100644
--- a/app/views/vehicle_journeys/index.html.erb
+++ b/app/views/vehicle_journeys/index.html.erb
@@ -4,92 +4,58 @@
</ol>
<%= title_tag t('vehicle_journeys.index.title', :route => @route.name ) %>
-<div class="page_info">
- <span class="search"> <%= t("will_paginate.page_entries_info.search") %></span> <%= page_entries_info @vehicle_journeys %>
-</div>
-<div class="pagination">
- <%= will_paginate @vehicle_journeys, :container => false, renderer: BootstrapPagination::Rails %>
-</div>
-<div class="vehicle_journeys paginated_content">
- <table class="table table-hover table-striped">
- <thead>
- <tr>
- <th class="title"><%= Chouette::JourneyPattern.model_name.human.pluralize %> :</th>
- <% @vehicle_journeys.map(&:journey_pattern).each do |jp| %>
- <th><%= link_to journey_name( jp), [@referential, @line, @route, jp] %></th>
- <% end %>
- </tr>
- <tr>
- <th class="title"><%= Chouette::TimeTable.model_name.human.pluralize %> :</th>
- <% @vehicle_journeys.each do |vj| %>
- <th title="<%= time_tables_info( vj) %>" class="calendars">
- <%= time_tables_shortest_info( vj) %>
- </th>
- <% end %>
- </tr>
- <tr>
- <th class="title"><%= Chouette::VehicleJourney.model_name.human.pluralize %> :</th>
- <% @vehicle_journeys.each do |vj| %>
- <th> <%= link_to vehicle_name(vj), [@referential, @line, @route, vj]%></th>
- <% end %>
- </tr>
- </thead>
- <tbody>
- <% @route.stop_points.each_with_index do |sp, index| %>
- <tr class="<%= cycle('odd', 'even') %>">
- <td class="stop_area"><%= sp.stop_area.name %></td>
- <% @vehicle_journeys.each do |vj| %>
- <td class="hours <%= missing_time_check(@matrix["#{vj.id}-#{sp.id}"]) %>">
- <%= (@matrix["#{vj.id}-#{sp.id}"] && @matrix["#{vj.id}-#{sp.id}"].departure_time) ? l( @matrix["#{vj.id}-#{sp.id}"].departure_time, :format => :hour) : "" %>
- </td>
- <% end %>
- </tr>
- <% end %>
- </tbody>
- </table>
-</div>
-<div class="pagination">
- <%= will_paginate @vehicle_journeys, :container => false, renderer: BootstrapPagination::Rails %>
-</div>
-<% content_for :sidebar do %>
- <ul class="actions">
- <li><%= link_to t('vehicle_journeys.actions.new'), new_referential_line_route_vehicle_journey_path(@referential, @line, @route), :class => "add" %></li>
- <li><%= link_to t('.timeless'), timeless_referential_line_route_vehicle_journeys_path(@referential, @line, @route), :class => "link" %></li>
- <li><%= link_to t('vehicle_journey_imports.new.title'), new_referential_line_route_vehicle_journey_import_path( @referential, @line, @route ), :class => "import" %></li>
- <li><%= link_to image_tag("icons/file_csv.png") + t('vehicle_journey_exports.new.title'), referential_line_route_vehicle_journey_exports_path(@referential, @line, @route, :format => :zip), :class => "with_fa" %></li>
- </ul>
- <!--
- <div class="btn-group">
- <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
- <%= t('vehicle_journey_exports.new.title') %><span class="caret"></span>
- </button>
- <ul class="dropdown-menu" role="menu">
- <li><%= link_to image_tag("icons/file_csv.png") + " Csv" , referential_line_route_vehicle_journey_exports_path(@referential, @line, @route, :format => :csv) %></li>
- <li><%= link_to image_tag("icons/file_excel.png") + " Excel", referential_line_route_vehicle_journey_exports_path(@referential, @line, @route, :format => :xls) %></li>
- </ul>
- </div>
- -->
- <h4><%= t(".selection") %></h4>
-
- <h5><%= Chouette::JourneyPattern.model_name.human.pluralize %></h5>
- <ul class="selection">
- <% @route.journey_patterns.each do |journey_pattern| %>
- <li><%= link_with_search journey_name(journey_pattern), "journey_pattern_id_eq" => journey_pattern.id %></li>
- <% end %>
- <li><%= link_with_search t(".selection_all"), {"journey_pattern_id_eq" => nil}, :class => "all" %></li>
- </ul>
-
- <h5><%= Chouette::TimeTable.model_name.human.pluralize %></h5>
-
- <ul class="selection">
- <% @route.time_tables.each do |time_table| %>
- <li><%= link_with_search time_table.comment, "time_tables_comment_eq" => time_table.comment %></li>
- <% end %>
- <li><%= link_with_search t(".selection_all"), {"time_tables_comment_eq" => nil}, :class => "all" %></li>
- </ul>
+<%= search_form_for @q, :url => referential_line_route_vehicle_journeys_path(@referential,@line,@route), remote: true, :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f| %>
+<div class="panel panel-default">
+ <div class="panel-heading">
+ <div class="input-group col-md-9">
+ <%= f.collection_select :journey_pattern_id_eq, @route.journey_patterns.map{|j| j.name = journey_name(j); j}, :id, :name, :include_blank => "All" %>
+ <%= f.label :time_tables_id_eq, "TM" %>
+ <%= f.text_field :time_tables_id_eq, :input_html => { :"data-pre" => [].to_json} %>
+ <input name=<%= "q[vehicle_journey_at_stops_departure_time_gt(3i)]" %> type="hidden" value="1">
+ <input name=<%= "q[vehicle_journey_at_stops_departure_time_gt(2i)]" %> type="hidden" value="1">
+ <input name=<%= "q[vehicle_journey_at_stops_departure_time_gt(1i)]" %> type="hidden" value="2000">
+ <%= f.label :vehicle_journey_at_stops_departure_time_gt, t('.time_range') %>
+ <%= select_hour(@q.send( "vehicle_journey_at_stops_departure_time_gt") ? @q.send( "vehicle_journey_at_stops_departure_time_gt").hour : 0,
+ :prefix => "q", :field_name => "vehicle_journey_at_stops_departure_time_gt(4i)") %>
+ <%= select_minute(@q.send( "vehicle_journey_at_stops_departure_time_gt") ? @q.send( "vehicle_journey_at_stops_departure_time_gt").min : 0,
+ :prefix => "q", :field_name => "vehicle_journey_at_stops_departure_time_gt(5i)") %>
+ <div class="input-group-btn">
+ <button class="btn btn-default" type="submit"><i class="fa fa-search"></i></button>
+ </div>
+ </div><!-- /input-group -->
+ <a data-toggle="collapse" data-parent="#search" href="#advanced_search">
+ <i class="fa fa-plus"></i> <%= "#{t('.advanced_search')}" %>
+ </a>
+ </div>
- <h4><%= t('.time_range') %></h4>
- <%= render :partial => "time_filter", :locals => { :time_field => "departure_time"} %>
+ <div id="advanced_search" class="panel-collapse collapse">
+ <div class="panel-body">
+ <p>other fields</p>
+ </div>
+ </div>
+</div>
<% end %>
+<div id="vehicle_journeys" ><%= render "vehicle_journeys" %></div>
+<% content_for :sidebar do %>
+ <%= render "sidebar" %>
+<% end %>
+<script>
+ $(function() {
+ var time_tables_url = function(){
+ return '<%= referential_time_tables_path(@referential, :format => :json) %>?route_id=<%= @route.id %>';
+ };
+ $( "#q_time_tables_id_eq" ).tokenInput( time_tables_url, {
+ crossDomain: false,
+ prePopulate: $('#q_time_tables_id_eq').data('pre'),
+ minChars: 3,
+ queryParam: 'q[comment_cont]',
+ propertyToSearch: 'comment',
+ hintText: '<%= t('search_hint') %>',
+ noResultsText: '<%= t('no_result_text') %>',
+ searchingText: '<%= t('searching_term') %>',
+ resultsFormatter: function(item){ return '<li><div class=\"name\">' + item.comment + '</div><div class=\"info\">' + item.start_date + ' ' + item.end_date + '</div></li>' },
+ });
+ });
+</script>
diff --git a/app/views/vehicle_journeys/index.js.erb b/app/views/vehicle_journeys/index.js.erb
new file mode 100644
index 000000000..72b57c8fb
--- /dev/null
+++ b/app/views/vehicle_journeys/index.js.erb
@@ -0,0 +1,2 @@
+$('#vehicle_journeys').html('<%= escape_javascript(render("vehicle_journeys")) %>');
+
diff --git a/config/locales/vehicle_journeys.yml b/config/locales/vehicle_journeys.yml
index ae5946963..2c7f93fe6 100644
--- a/config/locales/vehicle_journeys.yml
+++ b/config/locales/vehicle_journeys.yml
@@ -43,10 +43,12 @@ en:
index:
title: "Vehicle journeys on route %{route}"
vehicle_journeys: "Departure's times"
- title: "Timeless vehicle journeys"
selection: "Filter on"
selection_all: "All"
time_range: "Departure time threshold"
+ advanced_search: "Advanced Search"
+ sidebar:
+ timeless: "Timeless vehicle journeys"
time_filter:
time_range_filter: "Filter"
activerecord:
@@ -138,13 +140,15 @@ fr:
translation_form: "Cloner la course"
index:
title: "Courses de la séquence d'arrêts %{route}"
- timeless: "Courses sans horaire"
vehicle_journeys: "Horaires de départ aux arrêts"
selection: "Filtrer sur"
selection_all: "Tous"
time_range: "Seuil horaire au départ"
+ advanced_search: "Recherche avancée"
time_filter:
time_range_filter: "Filtrer"
+ sidebar:
+ timeless: "Courses sans horaire"
activerecord:
models:
vehicle_journey: