diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/time_table_combinations_controller.rb | 24 | ||||
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 3 | ||||
| -rw-r--r-- | app/helpers/history_helper.rb | 12 | ||||
| -rw-r--r-- | app/helpers/time_tables_helper.rb | 8 | ||||
| -rw-r--r-- | app/models/time_table_combination.rb | 41 | ||||
| -rw-r--r-- | app/views/time_tables/_combine.html.erb | 27 | ||||
| -rw-r--r-- | app/views/time_tables/_periods.html.erb | 35 | ||||
| -rw-r--r-- | app/views/time_tables/show.html.erb | 76 | ||||
| -rw-r--r-- | app/views/vehicle_journeys/_form.html.erb | 4 |
9 files changed, 170 insertions, 60 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") %>: </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'> <%= @time_table.human_attribute_name("monday") %> </span> - <% end %> - - <% if @time_table.tuesday %> - <span class='day_type'> <%= @time_table.human_attribute_name("tuesday") %> </span> - <% end %> - - <% if @time_table.wednesday %> - <span class='day_type'> <%= @time_table.human_attribute_name("wednesday") %> </span> - <% end %> - - <% if @time_table.thursday %> - <span class='day_type'> <%= @time_table.human_attribute_name("thursday") %> </span> - <% end %> - - <% if @time_table.friday %> - <span class='day_type'> <%= @time_table.human_attribute_name("friday") %> </span> - <% end %> - - <% if @time_table.saturday %> - <span class='day_type'> <%= @time_table.human_attribute_name("saturday") %> </span> - <% end %> - - <% if @time_table.sunday %> - <span class='day_type'> <%= @time_table.human_attribute_name("sunday") %> </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") %>: </label> + + <% if @time_table.school_holliday %> + <span class='day_type'> <%= @time_table.human_attribute_name("school_holliday") %> </span> + <% end %> + + <% if @time_table.public_holliday %> + <span class='day_type'> <%= @time_table.human_attribute_name("public_holliday") %> </span> + <% end %> + + </p> + <% end %> <p> - <label><%= @time_table.human_attribute_name("peculiarities") %>: </label> - <% if @time_table.int_day_types & 1536 == 0 %> + <label><%= @time_table.human_attribute_name("day_types") %>: </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'> <%= @time_table.human_attribute_name("school_holliday") %> </span> - <% end %> - - <% if @time_table.public_holliday %> - <span class='day_type'> <%= @time_table.human_attribute_name("public_holliday") %> </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'> <%= @time_table.human_attribute_name("monday") %> </span> + <% end %> + + <% if @time_table.tuesday %> + <span class='day_type'> <%= @time_table.human_attribute_name("tuesday") %> </span> + <% end %> + + <% if @time_table.wednesday %> + <span class='day_type'> <%= @time_table.human_attribute_name("wednesday") %> </span> + <% end %> + + <% if @time_table.thursday %> + <span class='day_type'> <%= @time_table.human_attribute_name("thursday") %> </span> + <% end %> + + <% if @time_table.friday %> + <span class='day_type'> <%= @time_table.human_attribute_name("friday") %> </span> + <% end %> + + <% if @time_table.saturday %> + <span class='day_type'> <%= @time_table.human_attribute_name("saturday") %> </span> + <% end %> + + <% if @time_table.sunday %> + <span class='day_type'> <%= @time_table.human_attribute_name("sunday") %> </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') %>', |
