diff options
| author | Marc Florisson | 2015-01-26 10:00:13 +0100 |
|---|---|---|
| committer | Marc Florisson | 2015-01-26 10:00:13 +0100 |
| commit | 657966f57ab15234effcc56d58ff49dace885576 (patch) | |
| tree | eb03fb97d9138b9f7feb2a81e7768238410d793b | |
| parent | c6f7d75a1c41db2406510b9c33c86506ab190bc9 (diff) | |
| download | chouette-core-657966f57ab15234effcc56d58ff49dace885576.tar.bz2 | |
add restrictions specific to Hub
| -rw-r--r-- | app/controllers/routes_controller.rb | 11 | ||||
| -rw-r--r-- | app/models/referential.rb | 13 | ||||
| -rw-r--r-- | app/views/organisations/edit.html.erb | 5 | ||||
| -rw-r--r-- | app/views/organisations/show.html.erb | 2 | ||||
| -rw-r--r-- | db/migrate/20150121144108_add_hub_restrictions_to_organisation.rb | 7 | ||||
| -rw-r--r-- | db/schema.rb | 7 | ||||
| -rw-r--r-- | lib/ninoxe_extension/hub/route_restrictions.rb | 25 |
7 files changed, 60 insertions, 10 deletions
diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 6454ce068..afef75830 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -9,7 +9,7 @@ class RoutesController < ChouetteController belongs_to :line, :parent_class => Chouette::Line, :optional => true, :polymorphic => true end - def index + def index index! do |format| format.html { redirect_to referential_line_path(@referential,@line) } end @@ -22,14 +22,14 @@ class RoutesController < ChouetteController def save_boarding_alighting @route = route - + if @route.update_attributes(params[:route]) redirect_to referential_line_route_path(@referential, @line, @route) else render "edit_boarding_alighting" end end - + def show @map = RouteMap.new(route).with_helpers(self) @stop_points = route.stop_points.paginate(:page => params[:page]) @@ -38,7 +38,7 @@ class RoutesController < ChouetteController 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 @@ -53,6 +53,7 @@ class RoutesController < ChouetteController def create create! do |success, failure| success.html { redirect_to referential_line_path(@referential,@line) } + failure.html { flash[:alert] = route.errors[:flash]; render :action => :new } end end @@ -67,7 +68,7 @@ class RoutesController < ChouetteController def collection @q = parent.routes.search(params[:q]) - @routes ||= + @routes ||= begin routes = @q.result(:distinct => true).order(:name) routes = routes.paginate(:page => params[:page]) if @per_page.present? diff --git a/app/models/referential.rb b/app/models/referential.rb index 063e7436c..1cd0a16a8 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -207,6 +207,10 @@ Rails.application.config.after_initialize do @referential ||= Referential.where(:slug => Apartment::Database.current_database).first! end + def hub_restricted? + referential.organisation.hub_restrictions + end + # override prefix for good prefix in objectid generation def prefix self.referential.prefix @@ -214,6 +218,15 @@ Rails.application.config.after_initialize do end + Chouette::Route + + class Chouette::Route + include NinoxeExtension::Hub::RouteRestrictions + + #validates_numericality_of :number + #validates_numericality_of :wayback_code + end + Chouette::TimeTable class Chouette::TimeTable diff --git a/app/views/organisations/edit.html.erb b/app/views/organisations/edit.html.erb index ef3cc1530..f37c2e7df 100644 --- a/app/views/organisations/edit.html.erb +++ b/app/views/organisations/edit.html.erb @@ -1,8 +1,9 @@ <%= title_tag t(".title") %> <%= semantic_form_for @organisation, :url => organisation_path do |form| %> - <%= form.inputs do %> - <%= form.input :name %> + <%= form.inputs do %> + <%= form.input :name %> + <%= form.input :hub_restrictions %> <% end %> <%= form.actions do %> diff --git a/app/views/organisations/show.html.erb b/app/views/organisations/show.html.erb index c67eeb271..27b1eccb2 100644 --- a/app/views/organisations/show.html.erb +++ b/app/views/organisations/show.html.erb @@ -2,6 +2,8 @@ <div class="summary"> <p> +<label><%= Organisation.human_attribute_name("hub_restrictions") %>: </label> +<%= @organisation.hub_restrictions %> </p> </div> diff --git a/db/migrate/20150121144108_add_hub_restrictions_to_organisation.rb b/db/migrate/20150121144108_add_hub_restrictions_to_organisation.rb new file mode 100644 index 000000000..7417105e9 --- /dev/null +++ b/db/migrate/20150121144108_add_hub_restrictions_to_organisation.rb @@ -0,0 +1,7 @@ +class AddHubRestrictionsToOrganisation < ActiveRecord::Migration + def change + change_table :organisations do |t| + t.boolean :hub_restrictions + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 40f04d44f..fdcc40582 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150120183020) do +ActiveRecord::Schema.define(:version => 20150121144108) do create_table "access_links", :force => true do |t| t.integer "access_point_id", :limit => 8 @@ -326,8 +326,9 @@ ActiveRecord::Schema.define(:version => 20150120183020) do create_table "organisations", :force => true do |t| t.string "name" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.boolean "hub_restrictions" end create_table "pt_links", :force => true do |t| diff --git a/lib/ninoxe_extension/hub/route_restrictions.rb b/lib/ninoxe_extension/hub/route_restrictions.rb new file mode 100644 index 000000000..c6c403796 --- /dev/null +++ b/lib/ninoxe_extension/hub/route_restrictions.rb @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +module NinoxeExtension::Hub::RouteRestrictions + extend ActiveSupport::Concern + + included do + validate :max_instance_limitation, :wayback_code_limitation + + def wayback_code_limitation + return unless hub_restricted? + errors.add( :wayback_code, "déjà pris!") if line.routes.reject {|r| r.id==id}.map(&:wayback_code).include?( wayback_code) + end + + def max_instance_limitation + return unless hub_restricted? + errors.add( :flash, "2 routes max") + end + + with_options if: :hub_restricted? do |route| + route.validates_format_of :objectid, :with => %r{^\w+:\w+:[\w]{1,8}$} + #admin.validates :password, length: { minimum: 10 } + #admin.validates :email, presence: true + end + end +end + |
