diff options
| author | Zog | 2018-05-31 14:02:22 +0200 |
|---|---|---|
| committer | Zog | 2018-05-31 14:02:22 +0200 |
| commit | bd865f2ef88ccb6def1364149b742a49394187bb (patch) | |
| tree | 66643eb3b84455158c1174cb2ec3e58929f82234 | |
| parent | 868222a77361068a84eb31a2878b77d275f45df8 (diff) | |
| download | chouette-core-bd865f2ef88ccb6def1364149b742a49394187bb.tar.bz2 | |
| -rw-r--r-- | app/controllers/referential_companies_controller.rb | 101 | ||||
| -rw-r--r-- | app/controllers/referential_networks_controller.rb | 91 | ||||
| -rw-r--r-- | app/controllers/referential_stop_areas_controller.rb | 136 | ||||
| -rw-r--r-- | app/views/stop_points/_stop_point.html.slim | 2 | ||||
| -rw-r--r-- | config/routes.rb | 32 | ||||
| -rw-r--r-- | spec/features/referential_companies_spec.rb | 41 | ||||
| -rw-r--r-- | spec/features/referential_group_of_lines_spec.rb | 34 | ||||
| -rw-r--r-- | spec/features/referential_networks_spec.rb | 41 |
8 files changed, 1 insertions, 477 deletions
diff --git a/app/controllers/referential_companies_controller.rb b/app/controllers/referential_companies_controller.rb deleted file mode 100644 index 4f73c4268..000000000 --- a/app/controllers/referential_companies_controller.rb +++ /dev/null @@ -1,101 +0,0 @@ -class ReferentialCompaniesController < ChouetteController - include ReferentialSupport - defaults :resource_class => Chouette::Company, :collection_name => 'companies', :instance_name => 'company' - respond_to :html - respond_to :xml - respond_to :json - respond_to :js, :only => :index - - belongs_to :referential, :parent_class => Referential - - def index - index! do |format| - format.html { - if collection.out_of_bounds? - redirect_to params.merge(:page => 1) - end - - @companies = decorate_companies(@companies) - } - - format.json { - render json: companies_maps - } - - format.js { - @companies = decorate_companies(@companies) - } - end - end - - protected - - def build_resource - super.tap do |company| - company.line_referential = referential.line_referential - end - end - - def collection - scope = referential.line_referential.companies - if params[:line_id] - line_scope = referential.line_referential.lines.find(params[:line_id]).companies - scope = line_scope if line_scope.exists? - end - - @q = scope.search(params[:q]) - ids = @q.result(:distinct => true).pluck(:id) - scope = scope.where(id: ids) - if sort_column && sort_direction - @companies ||= scope.order(sort_column + ' ' + sort_direction).paginate(:page => params[:page]) - else - @companies ||= scope.order(:name).paginate(:page => params[:page]) - end - end - - def resource_url(company = nil) - referential_company_path(referential, company || resource) - end - - def collection_url - referential_companies_path(referential) - end - - def company_params - fields = [:objectid, :object_version, :name, :short_name, :organizational_unit, :operating_department_name, :code, :phone, :fax, :email, :registration_number, :url, :time_zone] - fields += permitted_custom_fields_params(Chouette::Company.custom_fields(@referential.workgroup)) - params.require(:company).permit( fields ) - end - - private - - def sort_column - referential.workbench.companies.column_names.include?(params[:sort]) ? params[:sort] : 'name' - end - def sort_direction - %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' - end - - def collection_name - "companies" - end - - def decorate_companies(companies) - CompanyDecorator.decorate( - companies, - context: { - referential: referential - } - ) - end - - def companies_maps - @companies.collect do |company| - { :id => company.id.to_s, - :objectid => company.raw_objectid, - :name => company.name, - } - end - end - -end diff --git a/app/controllers/referential_networks_controller.rb b/app/controllers/referential_networks_controller.rb deleted file mode 100644 index 3b76deba1..000000000 --- a/app/controllers/referential_networks_controller.rb +++ /dev/null @@ -1,91 +0,0 @@ -class ReferentialNetworksController < ChouetteController - include ReferentialSupport - defaults :resource_class => Chouette::Network, :collection_name => 'networks', :instance_name => 'network' - respond_to :html - respond_to :xml - respond_to :json - respond_to :kml, :only => :show - respond_to :js, :only => :index - - belongs_to :referential, :parent_class => Referential - - def show - show! do - @network = ReferentialNetworkDecorator.decorate( - @network, - context: { - referential: referential - } - ) - end - end - - def index - index! do |format| - format.html { - if collection.out_of_bounds? - redirect_to params.merge(:page => 1) - end - - @networks = decorate_networks(@networks) - } - - format.js { - @networks = decorate_networks(@networks) - } - end - end - - protected - - def build_resource - super.tap do |network| - network.line_referential = referential.line_referential - end - end - - def collection - @q = referential.workbench.networks.search(params[:q]) - - if sort_column && sort_direction - @networks ||= @q.result(:distinct => true).order(sort_column + ' ' + sort_direction).paginate(:page => params[:page]) - else - @networks ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page]) - end - end - - def collection_name - 'networks' - end - - def resource_url(network = nil) - referential_network_path(referential, network || resource) - end - - def collection_url - referential_networks_path(referential) - end - - def network_params - params.require(:network).permit(:objectid, :object_version, :version_date, :description, :name, :registration_number, :source_name, :source_type_name, :source_identifier, :comment ) - end - - private - - def sort_column - referential.workbench.networks.column_names.include?(params[:sort]) ? params[:sort] : 'name' - end - def sort_direction - %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' - end - - def decorate_networks(networks) - ReferentialNetworkDecorator.decorate( - networks, - context: { - referential: referential - } - ) - end - -end diff --git a/app/controllers/referential_stop_areas_controller.rb b/app/controllers/referential_stop_areas_controller.rb deleted file mode 100644 index a5fd15fcb..000000000 --- a/app/controllers/referential_stop_areas_controller.rb +++ /dev/null @@ -1,136 +0,0 @@ -# -*- coding: utf-8 -*- -class ReferentialStopAreasController < ChouetteController - include ReferentialSupport - defaults :resource_class => Chouette::StopArea, :collection_name => 'stop_areas', :instance_name => 'stop_area' - - belongs_to :referential do - belongs_to :line, :parent_class => Chouette::Line, :optional => true, :polymorphic => true - belongs_to :network, :parent_class => Chouette::Network, :optional => true, :polymorphic => true - end - - respond_to :html, :kml, :xml, :json - respond_to :js, :only => :index - - def select_parent - @stop_area = stop_area - @parent = stop_area.parent - end - - def add_children - @stop_area = stop_area - @children = stop_area.children - end - - def add_routing_lines - @stop_area = stop_area - @lines = stop_area.routing_lines - end - - def add_routing_stops - @stop_area = stop_area - end - - def access_links - @stop_area = stop_area - @generic_access_links = stop_area.generic_access_link_matrix - @detail_access_links = stop_area.detail_access_link_matrix - end - - def index - request.format.kml? ? @per_page = nil : @per_page = 12 - @zip_codes = referential.stop_areas.where("zip_code is NOT null").distinct.pluck(:zip_code) - index! do |format| - format.html { - if collection.out_of_bounds? - redirect_to params.merge(:page => 1) - end - } - end - end - - def new - new! - end - - def create - create! - end - - def show - show! do |format| - unless stop_area.position or params[:default] or params[:routing] - format.kml { - render :nothing => true, :status => :not_found - } - end - - @stop_area = @stop_area.decorate - end - end - - def edit - edit! do - stop_area.position ||= stop_area.default_position - end - end - - def update - stop_area.position ||= stop_area.default_position - - update! - end - - def default_geometry - count = referential.stop_areas.without_geometry.default_geometry! - flash[:notice] = I18n.translate("stop_areas.default_geometry_success", :count => count) - redirect_to stop_area_referential_stop_areas_path(@stop_area_referential) - end - - def zip_codes - respond_to do |format| - format.json { render :json => referential.stop_areas.collect(&:zip_code).compact.uniq.to_json } - end - end - - protected - - alias_method :stop_area, :resource - - def collection - @q = parent.present? ? parent.stop_areas.search(params[:q]) : referential.stop_areas.search(params[:q]) - - if sort_column && sort_direction - @stop_areas ||= - begin - stop_areas = @q.result(:distinct => true).order(sort_column + ' ' + sort_direction) - stop_areas = stop_areas.paginate(:page => params[:page], :per_page => @per_page) if @per_page.present? - stop_areas - end - else - @stop_areas ||= - begin - stop_areas = @q.result(:distinct => true).order(:name) - stop_areas = stop_areas.paginate(:page => params[:page], :per_page => @per_page) if @per_page.present? - stop_areas - end - end - end - - private - - def sort_column - if parent.present? - parent.stop_areas.include?(params[:sort]) ? params[:sort] : 'name' - else - referential.stop_areas.include?(params[:sort]) ? params[:sort] : 'name' - end - end - def sort_direction - %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' - end - - def stop_area_params - params.require(:stop_area).permit( :routing_stop_ids, :routing_line_ids, :children_ids, :stop_area_type, :parent_id, :objectid, :object_version, :name, :comment, :area_type, :registration_number, :nearest_topic_name, :fare_code, :longitude, :latitude, :long_lat_type, :country_code, :street_name, :zip_code, :city_name, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs, :coordinates, :url, :time_zone ) - end - -end diff --git a/app/views/stop_points/_stop_point.html.slim b/app/views/stop_points/_stop_point.html.slim index e54158cef..5e87a776e 100644 --- a/app/views/stop_points/_stop_point.html.slim +++ b/app/views/stop_points/_stop_point.html.slim @@ -2,7 +2,7 @@ .panel-heading .panel-title.clearfix h5 - = link_to [@referential, stop_point.stop_area], class: "preview", title: "#{Chouette::StopArea.model_name.human.capitalize} #{stop_point.stop_area.name}" do + = link_to [stop_point.stop_area.referential, stop_point.stop_area], class: "preview", title: "#{Chouette::StopArea.model_name.human.capitalize} #{stop_point.stop_area.name}" do span.name span.label.label-primary = stop_point.position + 1 = image_tag "map/" + stop_point.stop_area.area_type + ".png" diff --git a/config/routes.rb b/config/routes.rb index dc9a17482..f2063a89a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -50,11 +50,6 @@ ChouetteIhm::Application.routes.draw do end resources :autocomplete_purchase_windows, only: [:index] resources :autocomplete_time_tables, only: [:index] - resources :group_of_lines, controller: "referential_group_of_lines" do - collection do - get 'name_filter' - end - end resources :networks, controller: "referential_networks" @@ -100,8 +95,6 @@ ChouetteIhm::Application.routes.draw do end end - resources :companies, controller: "referential_companies" - resources :purchase_windows resources :time_tables do @@ -117,31 +110,6 @@ ChouetteIhm::Application.routes.draw do resources :time_table_periods resources :time_table_combinations end - - resources :access_points do - resources :access_links - end - - resources :stop_areas, controller: "referential_stop_areas" do - resources :stop_area_routing_lines - member do - get 'add_children' - get 'select_parent' - get 'add_routing_lines' - get 'add_routing_stops' - get 'access_links' - end - collection do - put 'default_geometry' - end - end - - resources :connection_links do - resources :stop_areas - member do - get 'select_areas' - end - end resources :clean_ups end diff --git a/spec/features/referential_companies_spec.rb b/spec/features/referential_companies_spec.rb deleted file mode 100644 index 82f86b192..000000000 --- a/spec/features/referential_companies_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding: utf-8 -*- -require 'spec_helper' - -describe 'ReferentialCompanies', type: :feature do - login_user - - let(:referential) { Referential.first } - let!(:companies) { Array.new(2) { create :company, line_referential: referential.line_referential } } - - describe 'index' do - before(:each) { visit referential_companies_path(referential) } - - it 'displays referential companies' do - expect(page).to have_content(companies.first.name) - expect(page).to have_content(companies.last.name) - end - - context 'filtering' do - it 'supports filtering by name' do - fill_in 'q[name_or_objectid_cont]', with: companies.first.name - click_button 'search-btn' - expect(page).to have_content(companies.first.name) - expect(page).not_to have_content(companies.last.name) - end - - it 'supports filtering by objectid' do - fill_in 'q[name_or_objectid_cont]', with: companies.first.objectid - click_button 'search-btn' - expect(page).to have_content(companies.first.name) - expect(page).not_to have_content(companies.last.name) - end - end - end - - describe 'show' do - it 'displays referential company' do - visit referential_company_path(referential, companies.first) - expect(page).to have_content(companies.first.name) - end - end -end diff --git a/spec/features/referential_group_of_lines_spec.rb b/spec/features/referential_group_of_lines_spec.rb deleted file mode 100644 index e5970545b..000000000 --- a/spec/features/referential_group_of_lines_spec.rb +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- -require 'spec_helper' - -describe 'ReferentialLines', type: :feature do - login_user - - let(:referential) { Referential.first } - let!(:group_of_lines) { Array.new(2) { create(:group_of_line, line_referential: referential.line_referential) } } - - describe 'index' do - before(:each) { visit referential_group_of_lines_path(referential) } - - it 'displays referential groups of lines' do - expect(page).to have_content(group_of_lines.first.name) - expect(page).to have_content(group_of_lines.last.name) - end - - context 'filtering' do - it 'supports filtering by name' do - fill_in 'q[name_cont]', with: group_of_lines.first.name - click_button 'search-btn' - expect(page).to have_content(group_of_lines.first.name) - expect(page).not_to have_content(group_of_lines.last.name) - end - end - end - - describe 'show' do - it 'displays referential group of lines' do - visit referential_group_of_line_path(referential, group_of_lines.first) - expect(page).to have_content(group_of_lines.first.name) - end - end -end diff --git a/spec/features/referential_networks_spec.rb b/spec/features/referential_networks_spec.rb deleted file mode 100644 index d0a9db5f4..000000000 --- a/spec/features/referential_networks_spec.rb +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding: utf-8 -*- -require 'spec_helper' - -describe 'ReferentialNetworks', type: :feature do - login_user - - let(:referential) { Referential.first } - let!(:networks) { Array.new(2) { create :network, line_referential: referential.line_referential } } - - describe 'index' do - before(:each) { visit referential_networks_path(referential) } - - it 'displays referential networks' do - expect(page).to have_content(networks.first.name) - expect(page).to have_content(networks.last.name) - end - - context 'filtering' do - it 'supports filtering by name' do - fill_in 'q[name_or_objectid_cont]', with: networks.first.name - click_button 'search_btn' - expect(page).to have_content(networks.first.name) - expect(page).not_to have_content(networks.last.name) - end - - it 'supports filtering by objectid' do - fill_in 'q[name_or_objectid_cont]', with: networks.first.objectid - click_button 'search_btn' - expect(page).to have_content(networks.first.name) - expect(page).not_to have_content(networks.last.name) - end - end - end - - describe 'show' do - it 'displays referential network' do - visit referential_network_path(referential, networks.first) - expect(page).to have_content(networks.first.name) - end - end -end |
