aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/time_table_combinations_controller.rb24
-rw-r--r--app/controllers/time_tables_controller.rb3
-rw-r--r--app/helpers/history_helper.rb12
-rw-r--r--app/helpers/time_tables_helper.rb8
-rw-r--r--app/models/time_table_combination.rb41
-rw-r--r--app/views/time_tables/_combine.html.erb27
-rw-r--r--app/views/time_tables/_periods.html.erb35
-rw-r--r--app/views/time_tables/show.html.erb76
-rw-r--r--app/views/vehicle_journeys/_form.html.erb4
-rw-r--r--config/locales/time_table_combinations.yml27
-rw-r--r--config/locales/time_tables.yml12
-rw-r--r--config/routes.rb1
12 files changed, 206 insertions, 64 deletions
diff --git a/app/controllers/time_table_combinations_controller.rb b/app/controllers/time_table_combinations_controller.rb
new file mode 100644
index 000000000..249bb5060
--- /dev/null
+++ b/app/controllers/time_table_combinations_controller.rb
@@ -0,0 +1,24 @@
+class TimeTableCombinationsController < ChouetteController
+ respond_to :html, :only => [:create]
+
+ belongs_to :referential do
+ belongs_to :time_table, :parent_class => Chouette::TimeTable
+ end
+
+ def create
+ combination = TimeTableCombination.new( params[:time_table_combination].merge( :source_id => parent.id))
+ if combination.invalid?
+ flash[:alert] = combination.errors.full_messages.join("<br/>")
+ else
+ begin
+ combination.combine
+ flash[:notice] = t('time_table_combinations.success')
+ rescue
+ flash[:alert] = t('time_table_combinations.failure')
+ end
+ end
+ redirect_to referential_time_table_path(@referential, @time_table)
+
+ end
+
+end
diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb
index 00109aa76..b2fdf711b 100644
--- a/app/controllers/time_tables_controller.rb
+++ b/app/controllers/time_tables_controller.rb
@@ -1,4 +1,5 @@
class TimeTablesController < ChouetteController
+ include TimeTablesHelper
defaults :resource_class => Chouette::TimeTable
respond_to :html
respond_to :xml
@@ -35,7 +36,7 @@ class TimeTablesController < ChouetteController
def filtered_time_tables_maps
filtered_time_tables.collect do |time_table|
- { :id => time_table.id, :name => time_table.comment }
+ { :id => time_table.id, :name => time_table_description(time_table) }
end
end
def filtered_time_tables
diff --git a/app/helpers/history_helper.rb b/app/helpers/history_helper.rb
index 88c6b8da3..1b9d056ab 100644
--- a/app/helpers/history_helper.rb
+++ b/app/helpers/history_helper.rb
@@ -12,7 +12,17 @@ module HistoryHelper
end),
(content_tag :li do
if object.has_attribute?(:creator_id)
- object.human_attribute_name('creator_id') + ' : ' + object.creator_id if object.creator_id
+ object.human_attribute_name('creator_id') + ' : ' + object.creator_id if object.creator_id
+ end
+ end),
+ (content_tag :li do
+ if object.has_attribute?(:objectid)
+ object.human_attribute_name('objectid') + ' : ' + object.objectid if object.objectid
+ end
+ end),
+ (content_tag :li do
+ if object.has_attribute?(:object_version)
+ object.human_attribute_name('object_version') + ' : ' + object.object_version.to_s if object.object_version
end
end)].join.html_safe
end
diff --git a/app/helpers/time_tables_helper.rb b/app/helpers/time_tables_helper.rb
index b6dc3de48..100dfc656 100644
--- a/app/helpers/time_tables_helper.rb
+++ b/app/helpers/time_tables_helper.rb
@@ -42,5 +42,13 @@ module TimeTablesHelper
:periods_count => time_table.periods.count)
end
end
+
+ def time_table_description(time_table)
+ if time_table.bounding_dates.empty?
+ "#{time_table.comment} (vide)"
+ else
+ "#{time_table.comment} : #{time_table_bounding( time_table)} - #{composition_info(time_table)}"
+ end
+ end
end
diff --git a/app/models/time_table_combination.rb b/app/models/time_table_combination.rb
new file mode 100644
index 000000000..a446b47df
--- /dev/null
+++ b/app/models/time_table_combination.rb
@@ -0,0 +1,41 @@
+class TimeTableCombination
+ include ActiveModel::Validations
+ include ActiveModel::Conversion
+ extend ActiveModel::Naming
+
+ attr_accessor :source_id, :combined_id, :operation
+
+ validates_presence_of :source_id, :combined_id, :operation
+ validates_inclusion_of :operation, :in => %w( union intersection disjunction)
+
+ def self.operations
+ %w( union intersection disjunction)
+ end
+
+ def initialize(attributes = {})
+ attributes.each do |name, value|
+ send("#{name}=", value)
+ end
+ end
+
+ def persisted?
+ false
+ end
+
+ def combine
+ source = Chouette::TimeTable.find( source_id)
+ combined = Chouette::TimeTable.find( combined_id)
+ puts operation
+ if operation == "union"
+ source.merge! combined
+ elsif operation == "intersection"
+ source.intersect! combined
+ elsif operation == "disjunction"
+ source.disjoin! combined
+ else
+ raise "unknown operation"
+ end
+ source.save
+ end
+
+end
diff --git a/app/views/time_tables/_combine.html.erb b/app/views/time_tables/_combine.html.erb
new file mode 100644
index 000000000..900a8a4e8
--- /dev/null
+++ b/app/views/time_tables/_combine.html.erb
@@ -0,0 +1,27 @@
+<div id="compact_form" >
+
+<%= semantic_form_for [@referential, @time_table, TimeTableCombination.new] do |form| %>
+ <%= form.inputs do %>
+ <%= form.input :operation, :as => :radio, :collection => Hash[TimeTableCombination.operations.map {|b| [t( b, :scope => "time_table_combinations.operations"),b]}] %>
+ <%= form.input :combined_id, :as => :text %>
+ <% end %>
+
+ <%= form.actions do %>
+ <%= form.action :submit, :as => :button , :label => t('time_tables.show.combine')%>
+ <% end %>
+<% end %>
+</div>
+
+<script>
+ $(function() {
+ $( "#time_table_combination_combined_id" ).tokenInput('<%= comment_filter_referential_time_tables_path(@referential, :format => :json) %>', {
+ crossDomain: false,
+ prePopulate: $('#time_table_combination_combined_id').data('pre'),
+ tokenLimit: 1,
+ minChars: 1,
+ hintText: '<%= t('search_hint') %>',
+ noResultsText: '<%= t('no_result_text') %>',
+ searchingText: '<%= t('searching_term') %>'
+ });
+ });
+</script>
diff --git a/app/views/time_tables/_periods.html.erb b/app/views/time_tables/_periods.html.erb
index 41bf9db2d..1f0aea057 100644
--- a/app/views/time_tables/_periods.html.erb
+++ b/app/views/time_tables/_periods.html.erb
@@ -1,39 +1,4 @@
<ul class='periods'>
- <p>
- <label><%= @time_table.human_attribute_name("day_types") %>:&nbsp;&nbsp;</label>
- <% if @time_table.int_day_types & 508 == 0 %>
- <label><%= @time_table.human_attribute_name("none") %></label>
- <% else %>
- <% if @time_table.monday %>
- <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("monday") %>&nbsp;</span>
- <% end %>
-
- <% if @time_table.tuesday %>
- <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("tuesday") %>&nbsp;</span>
- <% end %>
-
- <% if @time_table.wednesday %>
- <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("wednesday") %>&nbsp;</span>
- <% end %>
-
- <% if @time_table.thursday %>
- <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("thursday") %>&nbsp;</span>
- <% end %>
-
- <% if @time_table.friday %>
- <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("friday") %>&nbsp;</span>
- <% end %>
-
- <% if @time_table.saturday %>
- <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("saturday") %>&nbsp;</span>
- <% end %>
-
- <% if @time_table.sunday %>
- <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("sunday") %>&nbsp;</span>
- <% end %>
- <% end %>
-
- </p>
<% @time_table.periods.each do |tmp| %>
<li class='period'><%= t('time_tables.show.from')%> <%= l tmp.period_start %> <%= t('time_tables.show.to')%> <%= l tmp.period_end %>
</li>
diff --git a/app/views/time_tables/show.html.erb b/app/views/time_tables/show.html.erb
index 0997c9d06..4c541a0c2 100644
--- a/app/views/time_tables/show.html.erb
+++ b/app/views/time_tables/show.html.erb
@@ -1,6 +1,14 @@
<% require 'calendar_helper' %>
+<ol class="breadcrumb">
+ <li><%= link_to Referential.human_attribute_name("time_tables"), referential_time_tables_path(@referential) %></li>
+</ol>
+
<%= title_tag t('time_tables.show.title', :time_table => @time_table.comment )%>
+<h3><%= t('.combine_form') %></h3>
+<%= render "combine" %>
+
+
<div class="time_table_show">
<div class="resume">
@@ -16,32 +24,56 @@
</div>
<div class="summary">
<p>
- <label><%= @time_table.human_attribute_name("comment") %>: </label>
- <%= @time_table.comment %>
- </p>
- <p>
<label><%= @time_table.human_attribute_name("version") %>: </label>
<%= @time_table.version %>
</p>
+ <% if @time_table.int_day_types & 1536 != 0 %>
+ <p>
+ <label><%= @time_table.human_attribute_name("peculiarities") %>:&nbsp;&nbsp;</label>
+
+ <% if @time_table.school_holliday %>
+ <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("school_holliday") %>&nbsp;</span>
+ <% end %>
+
+ <% if @time_table.public_holliday %>
+ <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("public_holliday") %>&nbsp;</span>
+ <% end %>
+
+ </p>
+ <% end %>
<p>
- <label><%= @time_table.human_attribute_name("peculiarities") %>:&nbsp;&nbsp;</label>
- <% if @time_table.int_day_types & 1536 == 0 %>
+ <label><%= @time_table.human_attribute_name("day_types") %>:&nbsp;&nbsp;</label>
+ <% if @time_table.int_day_types & 508 == 0 %>
<label><%= @time_table.human_attribute_name("none") %></label>
- <% else %>
- <% if @time_table.school_holliday %>
- <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("school_holliday") %>&nbsp;</span>
- <% end %>
-
- <% if @time_table.public_holliday %>
- <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("public_holliday") %>&nbsp;</span>
- <% end %>
-
- <% end %>
-
- </p>
- <p>
- <label><%= @time_table.human_attribute_name("objectid") %>: </label>
- <%= @time_table.objectid %>
+ <% else %>
+ <% if @time_table.monday %>
+ <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("monday") %>&nbsp;</span>
+ <% end %>
+
+ <% if @time_table.tuesday %>
+ <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("tuesday") %>&nbsp;</span>
+ <% end %>
+
+ <% if @time_table.wednesday %>
+ <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("wednesday") %>&nbsp;</span>
+ <% end %>
+
+ <% if @time_table.thursday %>
+ <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("thursday") %>&nbsp;</span>
+ <% end %>
+
+ <% if @time_table.friday %>
+ <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("friday") %>&nbsp;</span>
+ <% end %>
+
+ <% if @time_table.saturday %>
+ <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("saturday") %>&nbsp;</span>
+ <% end %>
+
+ <% if @time_table.sunday %>
+ <span class='day_type'>&nbsp;<%= @time_table.human_attribute_name("sunday") %>&nbsp;</span>
+ <% end %>
+ <% end %>
</p>
<h3 class="time_table_calendars">
@@ -116,10 +148,12 @@
<% content_for :sidebar do %>
<ul class="actions">
+ <li><%= link_to t('time_tables.actions.new'), new_referential_time_table_path(@referential), :class => "add" %></li>
<li><%= link_to t('time_tables.actions.edit'), edit_referential_time_table_path(@referential, @time_table), :class => "edit" %></li>
<li><%= link_to t('time_tables.actions.destroy'), referential_time_table_path(@referential, @time_table), :method => :delete, :data => {:confirm => t('time_tables.actions.destroy_confirm')}, :class => "remove" %></li>
<br>
</ul>
+
<%= creation_tag(@time_table) %>
<% end %>
diff --git a/app/views/vehicle_journeys/_form.html.erb b/app/views/vehicle_journeys/_form.html.erb
index 859a9027a..f512754b2 100644
--- a/app/views/vehicle_journeys/_form.html.erb
+++ b/app/views/vehicle_journeys/_form.html.erb
@@ -34,7 +34,7 @@
</tbody>
</table>
<% end %>
- <%= form.input :time_table_tokens, :label => t('.time_tables'), :as => :text, :input_html => { :"data-pre" => ( @vehicle_journey.time_tables.map { |time_table| { :id => time_table.id, :name => time_table.comment } } ).to_json } %>
+ <%= form.input :time_table_tokens, :label => t('.time_tables'), :as => :text, :input_html => { :"data-pre" => ( @vehicle_journey.time_tables.map { |time_table| { :id => time_table.id, :name => time_table_description(time_table) } } ).to_json } %>
<% end %>
@@ -55,7 +55,7 @@
$( "#vehicle_journey_time_table_tokens" ).tokenInput('<%= comment_filter_referential_time_tables_path(@referential, :format => :json) %>', {
crossDomain: false,
prePopulate: $('#time_table_tokens').data('pre'),
- minChars: 3,
+ minChars: 1,
preventDuplicates: true,
hintText: '<%= t('search_hint') %>',
noResultsText: '<%= t('no_result_text') %>',
diff --git a/config/locales/time_table_combinations.yml b/config/locales/time_table_combinations.yml
new file mode 100644
index 000000000..14d0cbe8c
--- /dev/null
+++ b/config/locales/time_table_combinations.yml
@@ -0,0 +1,27 @@
+en:
+ time_table_combinations:
+ success: "operation applied on timetable"
+ failure: "operation failed on timetable"
+ operations:
+ union: "merge"
+ intersection: "intersect"
+ disjunction: "disjoin"
+ activemodel:
+ attributes:
+ time_table_combination:
+ combined_id: "Time table to combine with"
+ operation: "operation"
+fr:
+ time_table_combinations:
+ success: "opération appliquée sur le calendrier"
+ failure: "opération échouée"
+ operations:
+ union: "fusion"
+ intersection: "intersection"
+ disjunction: "exclusion"
+ activemodel:
+ attributes:
+ time_table_combination:
+ combined_id: "Calendrier à combiner"
+ operation: "opération"
+
diff --git a/config/locales/time_tables.yml b/config/locales/time_tables.yml
index ede789bc9..3f7baa6ae 100644
--- a/config/locales/time_tables.yml
+++ b/config/locales/time_tables.yml
@@ -21,7 +21,7 @@ en:
edit:
title: "Update timetable %{time_table}"
show:
- resume: "From %{start_date} to %{end_date} (independently of any period day types)"
+ resume: "From %{start_date} to %{end_date}"
resume_empty: "Empty timetable"
title: "Timetable %{time_table}"
dates: "Application dates"
@@ -30,6 +30,8 @@ en:
to: "to"
add_period: "Add a period"
add_date: "Add a date"
+ combine_form: "Combinations"
+ combine: "Apply"
index:
title: "Timetables"
comment: "Name"
@@ -48,7 +50,7 @@ en:
peculiarities: "Peculiarities"
school_holliday: "School hollidays"
public_holliday: "Public hollidays"
- day_types: "Day types"
+ day_types: "Period day types"
none: "none"
monday: "Monday"
tuesday: "Tuesday"
@@ -97,7 +99,7 @@ fr:
edit:
title: "Modifier le calendrier %{time_table}"
show:
- resume: "Validité comprise du %{start_date} au %{end_date} (sans tenir compte des jours d'application)"
+ resume: "Validité comprise du %{start_date} au %{end_date}"
resume_empty: "Calendrier vide"
title: Calendrier %{time_table}
dates: "Dates d'application"
@@ -106,6 +108,8 @@ fr:
to: "au"
add_period: "Ajouter une période"
add_date: "Ajouter une date"
+ combine_form: "Combinatoire"
+ combine: "Appliquer"
index:
comment: "Nom"
title: "calendriers"
@@ -124,7 +128,7 @@ fr:
peculiarities: "Particularités"
school_holliday: "Vacances scolaires"
public_holliday: "Jours fériés"
- day_types: "Jours d'application"
+ day_types: "Jours d'application des périodes"
none: "aucun"
monday: "Lundi"
tuesday: "Mardi"
diff --git a/config/routes.rb b/config/routes.rb
index a167ef09c..7f4a6193a 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -129,6 +129,7 @@ ChouetteIhm::Application.routes.draw do
end
resources :time_table_dates
resources :time_table_periods
+ resources :time_table_combinations
end
resources :access_points do