From 5b4136b2907ffc918210495d8f9a29c1e7d681fb Mon Sep 17 00:00:00 2001 From: Bruno Perles Date: Wed, 28 Oct 2015 11:35:08 +0100 Subject: Merge Timeband feature and revert Gemfile --- Gemfile | 7 +-- Gemfile.lock | 7 +-- app/assets/javascripts/timebands.js.coffee | 3 ++ app/assets/stylesheets/application.css.scss.erb | 1 + app/assets/stylesheets/main/timebands.css.scss | 0 app/assets/stylesheets/partials/base.scss | 23 ++++++++ app/controllers/timebands_controller.rb | 20 +++++++ app/controllers/vehicle_journeys_controller.rb | 2 +- app/helpers/application_helper.rb | 2 + app/helpers/breadcrumb_helper.rb | 8 +++ app/helpers/timebands_helper.rb | 2 + app/models/referential.rb | 4 ++ app/views/help/timebands.textile | 0 app/views/shared/_header.erb | 4 ++ app/views/timebands/_form.html.erb | 12 +++++ app/views/timebands/_sidebar.html.erb | 11 ++++ app/views/timebands/edit.html.erb | 3 ++ app/views/timebands/index.html.erb | 29 ++++++++++ app/views/timebands/new.html.erb | 3 ++ app/views/timebands/show.html.erb | 12 +++++ config/locales/referentials.yml | 2 + config/locales/timebands.en.yml | 26 +++++++++ config/locales/timebands.fr.yml | 26 +++++++++ config/routes.rb | 2 + ...0151023101306_create_timebands.ninoxe_engine.rb | 16 ++++++ db/schema.rb | 14 ++++- spec/features/timebands_spec.rb | 62 ++++++++++++++++++++++ spec/views/timebands/edit.html.erb_spec.rb | 23 ++++++++ spec/views/timebands/index.html.erb_spec.rb | 20 +++++++ spec/views/timebands/new.html.erb_spec.rb | 21 ++++++++ spec/views/timebands/show.html.erb_spec.rb | 24 +++++++++ 31 files changed, 381 insertions(+), 8 deletions(-) create mode 100644 app/assets/javascripts/timebands.js.coffee create mode 100644 app/assets/stylesheets/main/timebands.css.scss create mode 100644 app/assets/stylesheets/partials/base.scss create mode 100644 app/controllers/timebands_controller.rb create mode 100644 app/helpers/timebands_helper.rb create mode 100644 app/views/help/timebands.textile create mode 100644 app/views/timebands/_form.html.erb create mode 100644 app/views/timebands/_sidebar.html.erb create mode 100644 app/views/timebands/edit.html.erb create mode 100644 app/views/timebands/index.html.erb create mode 100644 app/views/timebands/new.html.erb create mode 100644 app/views/timebands/show.html.erb create mode 100644 config/locales/timebands.en.yml create mode 100644 config/locales/timebands.fr.yml create mode 100644 db/migrate/20151023101306_create_timebands.ninoxe_engine.rb create mode 100644 spec/features/timebands_spec.rb create mode 100644 spec/views/timebands/edit.html.erb_spec.rb create mode 100644 spec/views/timebands/index.html.erb_spec.rb create mode 100644 spec/views/timebands/new.html.erb_spec.rb create mode 100644 spec/views/timebands/show.html.erb_spec.rb diff --git a/Gemfile b/Gemfile index d6dbcb136..cac64c5db 100644 --- a/Gemfile +++ b/Gemfile @@ -115,9 +115,9 @@ gem 'squeel' gem 'enumerize', '~> 0.10.0' -# gem 'ninoxe', :git => 'https://github.com/afimb/ninoxe.git' +gem 'ninoxe', :git => 'https://github.com/afimb/ninoxe.git' #gem 'ninoxe', '1.2.2' -gem 'ninoxe', path: '../ninoxe' +#gem 'ninoxe', path: '../ninoxe' gem 'acts_as_list', '~> 0.6.0' gem "acts_as_tree", '~> 2.1.0', :require => "acts_as_tree" @@ -128,6 +128,8 @@ gem 'delayed_job_active_record' gem 'devise-async' gem 'apartment', "~> 1.0.0" +gem 'newrelic_rpm' + group :development do gem 'capistrano', '2.13.5' gem 'capistrano-ext' @@ -161,7 +163,6 @@ group :test, :development do end group :production do - gem 'newrelic_rpm' gem "SyslogLogger", :require => "syslog/logger" gem "daemons" end diff --git a/Gemfile.lock b/Gemfile.lock index d676c0724..c4a21fdeb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,5 +1,6 @@ -PATH - remote: ../ninoxe +GIT + remote: https://github.com/afimb/ninoxe.git + revision: 766d2293bde741d34a5b9f23da21e5dc8d66bb2f specs: ninoxe (1.2.1) activerecord (~> 4.1.1) @@ -256,7 +257,7 @@ GEM net-ssh (2.9.2) net-ssh-gateway (1.2.0) net-ssh (>= 2.6.5) - newrelic_rpm (3.9.6.257) + newrelic_rpm (3.11.2.286) nokogiri (1.6.6.2) mini_portile (~> 0.6.0) nokogiri (1.6.6.2-java) diff --git a/app/assets/javascripts/timebands.js.coffee b/app/assets/javascripts/timebands.js.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/app/assets/javascripts/timebands.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/application.css.scss.erb b/app/assets/stylesheets/application.css.scss.erb index 52405c14c..770e3c82b 100644 --- a/app/assets/stylesheets/application.css.scss.erb +++ b/app/assets/stylesheets/application.css.scss.erb @@ -17,6 +17,7 @@ $body-bg: #eee; @import "modules/progress_bars"; // Partials +@import "partials/base"; @import "partials/header"; @import "partials/footer"; diff --git a/app/assets/stylesheets/main/timebands.css.scss b/app/assets/stylesheets/main/timebands.css.scss new file mode 100644 index 000000000..e69de29bb diff --git a/app/assets/stylesheets/partials/base.scss b/app/assets/stylesheets/partials/base.scss new file mode 100644 index 000000000..e4258c277 --- /dev/null +++ b/app/assets/stylesheets/partials/base.scss @@ -0,0 +1,23 @@ +.formtastic.timeband { + .time_select { + .fragments { + .fragments-group { + padding-left: 0; + } + legend.label { + position: relative; + width: auto; + display: block; + width: 25%; + float: left; + border: none; + label { + position: relative; + width: auto; + font-size: 125%; + padding: .2em .6em .3em; + } + } + } + } +} diff --git a/app/controllers/timebands_controller.rb b/app/controllers/timebands_controller.rb new file mode 100644 index 000000000..446255cac --- /dev/null +++ b/app/controllers/timebands_controller.rb @@ -0,0 +1,20 @@ +class TimebandsController < ChouetteController + + defaults :resource_class => Chouette::Timeband + + respond_to :html + + belongs_to :referential + + def new + new! do + build_breadcrumb :new + end + end + + private + + def timeband_params + params.require(:timeband).permit( :name, :start_time, :end_time ) + end +end diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb index bac4166a5..2c2a533aa 100644 --- a/app/controllers/vehicle_journeys_controller.rb +++ b/app/controllers/vehicle_journeys_controller.rb @@ -97,7 +97,7 @@ class VehicleJourneysController < ChouetteController :stop_point_id, :departure_time, :is_frequency] }, - { frequencies_attributes: [ :scheduled_headway_interval, :first_departure_time, + { journey_frequencies_attributes: [ :scheduled_headway_interval, :first_departure_time, :last_departure_time, :exact_time ] } ) end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 058e30732..37b9d7a63 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -69,6 +69,8 @@ module ApplicationHelper "connection_links" when path.include?("/time_tables") "time_tables" + when path.include?("/timebands") + "timebands" when path.include?("/rule_parameter_set") "parametersets" when path.include?("/import_tasks") diff --git a/app/helpers/breadcrumb_helper.rb b/app/helpers/breadcrumb_helper.rb index fc5721452..cb259baf7 100644 --- a/app/helpers/breadcrumb_helper.rb +++ b/app/helpers/breadcrumb_helper.rb @@ -30,6 +30,8 @@ module BreadcrumbHelper connection_link_breadcrumb action when "Chouette::TimeTable" time_table_breadcrumb action + when "Chouette::Timeband" + timeband_breadcrumb action when "StopAreaCopy" stop_area_copy_breadcrumb action when "Import" @@ -104,6 +106,12 @@ module BreadcrumbHelper add_breadcrumb breadcrumb_label(@time_table), referential_time_table_path(@referential, @time_table),:title => breadcrumb_tooltip(@time_table) if action == :edit end + def timeband_breadcrumb(action) + referential_breadcrumb + add_breadcrumb Chouette::Timeband.model_name.human(:count => 2), referential_timebands_path(@referential) unless action == :index + add_breadcrumb breadcrumb_label(@timeband), referential_timeband_path(@referential, @timeband),:title => breadcrumb_tooltip(@timeband) if action == :edit + end + def line_breadcrumb(action) referential_breadcrumb add_breadcrumb Chouette::Line.model_name.human(:count => 2), referential_lines_path(@referential) unless action == :index diff --git a/app/helpers/timebands_helper.rb b/app/helpers/timebands_helper.rb new file mode 100644 index 000000000..51251e46f --- /dev/null +++ b/app/helpers/timebands_helper.rb @@ -0,0 +1,2 @@ +module TimebandsHelper +end diff --git a/app/models/referential.rb b/app/models/referential.rb index d50694c60..e32c956fb 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -79,6 +79,10 @@ class Referential < ActiveRecord::Base Chouette::TimeTable.all end + def timebands + Chouette::Timeband.all + end + def connection_links Chouette::ConnectionLink.all end diff --git a/app/views/help/timebands.textile b/app/views/help/timebands.textile new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/shared/_header.erb b/app/views/shared/_header.erb index d1e8dd2ce..1e8a63fba 100644 --- a/app/views/shared/_header.erb +++ b/app/views/shared/_header.erb @@ -65,6 +65,10 @@ <%= @referential.time_tables.size %><%= Referential.human_attribute_name("time_tables") %> <% end %> +
  • <%= link_to referential_timebands_path(@referential) do %> + <%= @referential.timebands.size %><%= Referential.human_attribute_name("timebands") %> + <% end %> +
  • <%= link_to Referential.human_attribute_name("imports"), referential_imports_path(@referential) %>
  • diff --git a/app/views/timebands/_form.html.erb b/app/views/timebands/_form.html.erb new file mode 100644 index 000000000..bfa32212e --- /dev/null +++ b/app/views/timebands/_form.html.erb @@ -0,0 +1,12 @@ +<%= semantic_form_for [@referential, @timeband] do |form| %> + <%= form.inputs do %> + <%= form.input :name %> + <%= form.input :start_time %> + <%= form.input :end_time %> + <% end %> + + <%= form.actions do %> + <%= form.action :submit, :as => :button %> + <%= form.action :cancel, :as => :link %> + <% end %> +<% end %> diff --git a/app/views/timebands/_sidebar.html.erb b/app/views/timebands/_sidebar.html.erb new file mode 100644 index 000000000..8ffa16dca --- /dev/null +++ b/app/views/timebands/_sidebar.html.erb @@ -0,0 +1,11 @@ +<% content_for :sidebar do %> + +<% end %> + + diff --git a/app/views/timebands/edit.html.erb b/app/views/timebands/edit.html.erb new file mode 100644 index 000000000..bc2c73ace --- /dev/null +++ b/app/views/timebands/edit.html.erb @@ -0,0 +1,3 @@ +<%= title_tag t('timebands.edit.title', timeband: @timeband.name) %> + +<%= render "form" %> diff --git a/app/views/timebands/index.html.erb b/app/views/timebands/index.html.erb new file mode 100644 index 000000000..54be52675 --- /dev/null +++ b/app/views/timebands/index.html.erb @@ -0,0 +1,29 @@ +<%= title_tag t('timebands.index.title') %> + +<% if @timebands.any? %> + + + + + + + + + + + <% @timebands.each do |timeband| %> + + + + + + + <% end %> + +
    <%= t('activerecord.attributes.timeband.name') %><%= t('activerecord.attributes.timeband.start_time') %><%= t('activerecord.attributes.timeband.end_time') %>
    <%= link_to timeband.name, referential_timeband_path(@referential, timeband) %><%= l(timeband.start_time, format: :hour) %><%= l(timeband.end_time, format: :hour) %> + <%= link_to '', edit_referential_timeband_path(@referential, timeband), :class => "edit" %> + <%= link_to '', referential_timeband_path(@referential, timeband), :method => :delete, :data => {:confirm => t('timebands.actions.destroy_confirm')}, :class => "remove" %> +
    +<% end %> + +<%= render 'sidebar' %> diff --git a/app/views/timebands/new.html.erb b/app/views/timebands/new.html.erb new file mode 100644 index 000000000..c016325d0 --- /dev/null +++ b/app/views/timebands/new.html.erb @@ -0,0 +1,3 @@ +<%= title_tag t('timebands.new.title') %> + +<%= render "form" %> diff --git a/app/views/timebands/show.html.erb b/app/views/timebands/show.html.erb new file mode 100644 index 000000000..1a6171712 --- /dev/null +++ b/app/views/timebands/show.html.erb @@ -0,0 +1,12 @@ +<%= title_tag t( 'timebands.show.title', timeband: @timeband.name )%> + +
    +

    + + <%= l(@timeband.start_time, format: :hour) %> + - + <%= l(@timeband.end_time, format: :hour) %> +

    +
    + +<%= render 'sidebar' %> diff --git a/config/locales/referentials.yml b/config/locales/referentials.yml index c23e748d3..c38fb8a4b 100644 --- a/config/locales/referentials.yml +++ b/config/locales/referentials.yml @@ -68,6 +68,7 @@ en: rule_parameter_sets: "Rule parameters sets" data_format_restrictions: "Data format constraint" data_format: "Favorite format for export" + timebands: "Time bands" formtastic: titles: referential: @@ -146,6 +147,7 @@ fr: rule_parameter_sets: "Jeux de paramètres" data_format_restrictions: "Appliquer les contraintes de format des données" data_format: "Format d'export privilégié" + timebands: "Plages horaires" formtastic: titles: referential: diff --git a/config/locales/timebands.en.yml b/config/locales/timebands.en.yml new file mode 100644 index 000000000..fae2f1d30 --- /dev/null +++ b/config/locales/timebands.en.yml @@ -0,0 +1,26 @@ +en: + timebands: + actions: + new: "Add a time band" + edit: "Edit a time band" + destroy: "Delete a time band" + destroy_confirm: "Thank you to confirm the deletion of these time band." + new: + title: "Add a time band" + edit: + title: "Edit this time band %{timeband}" + show: + title: "Time band %{timeband}" + index: + title: "Time bands" + activerecord: + models: + timeband: + zero: "Time band" + one: "Time band" + other: "Time bands" + attributes: + timeband: + name: "Title" + start_time: "Start time" + end_time: "End time" diff --git a/config/locales/timebands.fr.yml b/config/locales/timebands.fr.yml new file mode 100644 index 000000000..1865d0c39 --- /dev/null +++ b/config/locales/timebands.fr.yml @@ -0,0 +1,26 @@ +fr: + timebands: + actions: + new: "Ajouter une plage horaire" + edit: "Modifier cette plage horaire" + destroy: "Supprimer cette plage horaire" + destroy_confirm: "Merci de confirmer la suppression de cette plage horaire." + new: + title: "Ajouter une plage horaire" + edit: + title: "Modifier la plage horaire %{timeband}" + show: + title: Plage horaire %{timeband} + index: + title: "Plages horaires" + activerecord: + models: + timeband: + zero: "plage horaire" + one: "plage horaire" + other: "plages horaires" + attributes: + timeband: + name: "Titre" + start_time: "Heure de début" + end_time: "Heure de fin" diff --git a/config/routes.rb b/config/routes.rb index 4cb5f9439..fdcc506bf 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -133,6 +133,8 @@ ChouetteIhm::Application.routes.draw do resources :time_table_combinations end + resources :timebands + resources :access_points do resources :access_links end diff --git a/db/migrate/20151023101306_create_timebands.ninoxe_engine.rb b/db/migrate/20151023101306_create_timebands.ninoxe_engine.rb new file mode 100644 index 000000000..3758fdf09 --- /dev/null +++ b/db/migrate/20151023101306_create_timebands.ninoxe_engine.rb @@ -0,0 +1,16 @@ +# This migration comes from ninoxe_engine (originally 20151023083836) +class CreateTimebands < ActiveRecord::Migration + def change + create_table :timebands do |t| + t.string "objectid", :null => false + t.integer "object_version" + t.datetime "creation_time" + t.string "creator_id" + t.string :name + t.time :start_time, null: false + t.time :end_time, null: false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 4f7945953..988693132 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20151022150419) do +ActiveRecord::Schema.define(version: 20151023101306) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -477,6 +477,18 @@ ActiveRecord::Schema.define(version: 20151022150419) do add_index "time_tables_vehicle_journeys", ["time_table_id"], name: "index_time_tables_vehicle_journeys_on_time_table_id", using: :btree add_index "time_tables_vehicle_journeys", ["vehicle_journey_id"], name: "index_time_tables_vehicle_journeys_on_vehicle_journey_id", using: :btree + create_table "timebands", force: true do |t| + t.string "objectid", null: false + t.integer "object_version" + t.datetime "creation_time" + t.string "creator_id" + t.string "name" + t.time "start_time", null: false + t.time "end_time", null: false + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "users", force: true do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "" diff --git a/spec/features/timebands_spec.rb b/spec/features/timebands_spec.rb new file mode 100644 index 000000000..6f07fab4f --- /dev/null +++ b/spec/features/timebands_spec.rb @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +require 'spec_helper' + +describe "Timebands", :type => :feature do + login_user + + let!(:timebands) { Array.new(2) { create(:timeband) } } + subject { timebands.first } + + describe "list" do + it "display timebands" do + visit referential_timebands_path(referential) + expect(page).to have_content(timebands.first.name) + expect(page).to have_content(timebands.last.name) + end + + end + + describe "show" do + it "display timeband" do + visit referential_timebands_path(referential) + click_link "#{timebands.first.name}" + expect(page).to have_content(timebands.first.name) + end + + end + + describe "new" do + it "creates timeband and return to show" do + visit referential_timebands_path(referential) + click_link "Ajouter une plage horaire" + fill_in "Titre", :with => "Timeband 1" + + select '10', from: 'timeband_start_time_4i' + select '00', from: 'timeband_start_time_5i' + select '11', from: 'timeband_end_time_4i' + select '00', from: 'timeband_end_time_5i' + + click_button("Créer plage horaire") + expect(page).to have_content("Timeband 1") + end + end + + describe "edit and return to show" do + it "edit timeband" do + visit referential_timeband_path(referential, subject) + click_link "Modifier cette plage horaire" + fill_in "Titre", :with => "Timeband Modified" + click_button("Modifier plage horaire") + expect(page).to have_content("Timeband Modified") + end + end + + describe "delete and return to list" do + it "delete timeband" do + visit referential_timebands_path(referential) + page.all('.remove')[0].click + expect(page).to_not have_content("Timeband Modified") + end + end + +end diff --git a/spec/views/timebands/edit.html.erb_spec.rb b/spec/views/timebands/edit.html.erb_spec.rb new file mode 100644 index 000000000..26c85c229 --- /dev/null +++ b/spec/views/timebands/edit.html.erb_spec.rb @@ -0,0 +1,23 @@ +require 'spec_helper' + +describe "/timebands/edit", :type => :view do + assign_referential + let!(:timeband) { assign(:timeband, create(:timeband) ) } + + describe "test" do + it "should render h2 with the group name" do + render + expect(rendered).to have_selector("h2", text: Regexp.new(timeband.name)) + end + end + + describe "form" do + it "should render input for timeband" do + render + expect(rendered).to have_selector("form") do + with_tag "input[type=text][name='timeband[name]'][value=?]", timeband.name + end + end + + end +end diff --git a/spec/views/timebands/index.html.erb_spec.rb b/spec/views/timebands/index.html.erb_spec.rb new file mode 100644 index 000000000..0ce0c419c --- /dev/null +++ b/spec/views/timebands/index.html.erb_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe "/timebands/index", :type => :view do + + assign_referential + let!(:timebands) { assign :timebands, Array.new(2){ create(:timeband) }.paginate } + + it "should render a show link for each timeband" do + render + timebands.each do |timeband| + expect(rendered).to have_selector("a[href='#{view.referential_timeband_path(referential, timeband)}']", :text => timeband.name) + end + end + + it "should render a link to create a new timeband" do + render + expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{new_referential_timeband_path(referential)}']") + end + +end diff --git a/spec/views/timebands/new.html.erb_spec.rb b/spec/views/timebands/new.html.erb_spec.rb new file mode 100644 index 000000000..73a99cad5 --- /dev/null +++ b/spec/views/timebands/new.html.erb_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe "/timebands/new", :type => :view do + assign_referential + let!(:timeband) { assign(:timeband, build(:timeband)) } + + describe "form" do + + it "should render inputs" do + render + expect(rendered).to have_selector("form") do + with_selector "input[type=text][name=?]", timeband.name + with_selector "select[start_time(4i)=?]", timeband.start_time + with_selector "select[start_time(5i)=?]", timeband.start_time + with_selector "select[end_time(4i)=?]", timeband.end_time + with_selector "select[end_time(5i)=?]", timeband.end_time + end + end + + end +end diff --git a/spec/views/timebands/show.html.erb_spec.rb b/spec/views/timebands/show.html.erb_spec.rb new file mode 100644 index 000000000..d43ba588c --- /dev/null +++ b/spec/views/timebands/show.html.erb_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper' + +describe "/timebands/show", :type => :view do + + assign_referential + let!(:timeband) { assign(:timeband, create(:timeband)) } + + it "should render h2 with the timeband name" do + render + expect(rendered).to have_selector("h2", text: Regexp.new(timeband.name)) + end + + it "should render a link to edit the timeband" do + render + expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.edit_referential_timeband_path(referential, timeband)}']") + end + + it "should render a link to remove the timeband" do + render + expect(view.content_for(:sidebar)).to have_selector(".actions a[href='#{view.referential_timeband_path(referential, timeband)}'][class='remove']") + end + +end + -- cgit v1.2.3