diff options
| author | Luc Donnet | 2014-08-19 13:55:32 +0200 |
|---|---|---|
| committer | Luc Donnet | 2014-08-19 13:55:32 +0200 |
| commit | 31e20231366bd2716d762720b83e883f46d60ba8 (patch) | |
| tree | 48296a04ed9578023c52bb116f8e9e59562d1d2f | |
| parent | 6bc916c070f8c11b979ff6a7a1e1d6721475b47e (diff) | |
| download | chouette-core-31e20231366bd2716d762720b83e883f46d60ba8.tar.bz2 | |
Initialize breadcrumbs for time table, need to be deployed everywhere
| -rw-r--r-- | Gemfile | 1 | ||||
| -rw-r--r-- | Gemfile.lock | 2 | ||||
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 16 | ||||
| -rw-r--r-- | app/views/layouts/application.html.erb | 1 | ||||
| -rw-r--r-- | app/views/layouts/without_sidebar.html.erb | 1 | ||||
| -rw-r--r-- | app/views/time_tables/show.html.erb | 3 | ||||
| -rw-r--r-- | config/application.rb | 2 | ||||
| -rw-r--r-- | lib/bootstrap_breadcrumbs_builder.rb | 31 |
8 files changed, 49 insertions, 8 deletions
@@ -51,6 +51,7 @@ gem 'simple_form' gem 'tagmanager-rails', '~> 3.0.1.0' #gem 'typeahead-rails', '~> 0.10.1' gem "twitter-typeahead-rails", :git => "https://github.com/ldonnet/twitter-typeahead-rails" +gem "breadcrumbs_on_rails" # Format Output gem 'json' diff --git a/Gemfile.lock b/Gemfile.lock index 4d0cba2ef..22c2497fa 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -77,6 +77,7 @@ GEM bootswatch-rails (3.1.1.1) railties (>= 3.1) bouncy-castle-java (1.5.0146.1) + breadcrumbs_on_rails (2.3.0) builder (3.0.4) calendar_helper (0.2.5) open4 @@ -385,6 +386,7 @@ DEPENDENCIES acts_as_tree-1.8 (= 1.1.0) bootstrap-sass (~> 3.1.1) bootswatch-rails + breadcrumbs_on_rails calendar_helper (= 0.2.5) capistrano capistrano-ext diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 14cc7aa10..a18603ed9 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -8,19 +8,27 @@ class TimeTablesController < ChouetteController belongs_to :referential 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 show! end - def new + def new + add_breadcrumb Referential.human_attribute_name("time_tables"), referential_time_tables_path(@referential) + @autocomplete_items = ActsAsTaggableOn::Tag.all new! end - def edit - @autocomplete_items = ActsAsTaggableOn::Tag.all - edit! + def edit + 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 diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5ff860a54..418b90e72 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -25,6 +25,7 @@ <div class="col-md-9"> <div id="workspace" class="<%= controller_name %> <%= action_name %>"> <%= render partial: "shared/flash_messages", flash: flash %> + <%= render partial: "shared/breadcrumb" %> <%= yield %> </div> </div> diff --git a/app/views/layouts/without_sidebar.html.erb b/app/views/layouts/without_sidebar.html.erb index d07139c2f..c61dc6b25 100644 --- a/app/views/layouts/without_sidebar.html.erb +++ b/app/views/layouts/without_sidebar.html.erb @@ -25,6 +25,7 @@ <div class="col-md-12"> <div id="workspace" class="<%= controller_name %> <%= action_name %>"> <%= render partial: "shared/flash_messages", flash: flash %> + <%= render partial: "shared/breadcrumb" %> <%= yield %> </div> </div> diff --git a/app/views/time_tables/show.html.erb b/app/views/time_tables/show.html.erb index b5c5c9dfe..e02d96a58 100644 --- a/app/views/time_tables/show.html.erb +++ b/app/views/time_tables/show.html.erb @@ -1,7 +1,4 @@ <% 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 )%> diff --git a/config/application.rb b/config/application.rb index 7ce9e9d0a..d86b254f3 100644 --- a/config/application.rb +++ b/config/application.rb @@ -23,7 +23,7 @@ module ChouetteIhm # -- all .rb files in that directory are automatically loaded. # Custom directories with classes and modules you want to be autoloadable. - # config.autoload_paths += %W(#{config.root}/extras) + config.autoload_paths += %W(#{config.root}/lib) # Only load the plugins named here, in the order given (default is alphabetical). # :all can be used as a placeholder for all plugins not explicitly named. diff --git a/lib/bootstrap_breadcrumbs_builder.rb b/lib/bootstrap_breadcrumbs_builder.rb new file mode 100644 index 000000000..daa154bdf --- /dev/null +++ b/lib/bootstrap_breadcrumbs_builder.rb @@ -0,0 +1,31 @@ +# bootstrap builder for breadcrumbs_on_rails gem +class BootstrapBreadcrumbsBuilder < BreadcrumbsOnRails::Breadcrumbs::Builder + def render + @context.content_tag(:ul, class: 'breadcrumb') do + @elements.collect do |element| + render_element(element) + end.join.html_safe + end + end + + def render_element(element) + active = element.path.nil? || @context.current_page?(compute_path(element)) + # Bootstrap use '/' divider by default but you can customize it: + # divider = @context.content_tag(:span, '/'.html_safe, class: 'divider') unless active + + @context.content_tag(:li, :class => ('active' if active)) do + content = if element.path.nil? + compute_name(element) + else + @context.link_to_unless_current(compute_name(element), compute_path(element), element.options) + end + + # content + (divider || '') + content + end + end +end + + +# Usage: +# = render_breadcrumbs(builder: BootstrapBreadcrumbsBuilder)
\ No newline at end of file |
