From affbacfcd955230f66badb261dcc462cca9cd0b9 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Sun, 15 May 2016 09:22:06 +0200 Subject: Associate LineReferential to Referential. Create ReferentialLines to manage lines in Referential. Refs #826 --- app/controllers/referential_lines_controller.rb | 89 +++++++++++++++ app/models/referential.rb | 8 +- app/views/referential_lines/_form.erb | 54 ++++++++++ app/views/referential_lines/_line.erb | 51 +++++++++ app/views/referential_lines/_lines.html.erb | 9 ++ app/views/referential_lines/edit.html.erb | 3 + app/views/referential_lines/index.html.erb | 51 +++++++++ app/views/referential_lines/index.js.erb | 1 + app/views/referential_lines/new.html.erb | 3 + app/views/referential_lines/show.html.erb | 137 ++++++++++++++++++++++++ app/views/referential_lines/show.kml.erb | 14 +++ 11 files changed, 416 insertions(+), 4 deletions(-) create mode 100644 app/controllers/referential_lines_controller.rb create mode 100644 app/views/referential_lines/_form.erb create mode 100644 app/views/referential_lines/_line.erb create mode 100644 app/views/referential_lines/_lines.html.erb create mode 100644 app/views/referential_lines/edit.html.erb create mode 100644 app/views/referential_lines/index.html.erb create mode 100644 app/views/referential_lines/index.js.erb create mode 100644 app/views/referential_lines/new.html.erb create mode 100644 app/views/referential_lines/show.html.erb create mode 100644 app/views/referential_lines/show.kml.erb (limited to 'app') diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb new file mode 100644 index 000000000..7112cf452 --- /dev/null +++ b/app/controllers/referential_lines_controller.rb @@ -0,0 +1,89 @@ +class ReferentialLinesController < ChouetteController + + defaults :resource_class => Chouette::Line, :collection_name => 'lines', :instance_name => 'line' + respond_to :html + respond_to :xml + respond_to :json + respond_to :kml, :only => :show + respond_to :js, :only => :index + + belongs_to :referential + + def index + index! do |format| + format.html { + if collection.out_of_bounds? + redirect_to params.merge(:page => 1) + end + build_breadcrumb :index + } + end + end + + def show + @map = LineMap.new(resource).with_helpers(self) + @routes = @line.routes + @group_of_lines = @line.group_of_lines + show! do + build_breadcrumb :show + end + end + + # overwrite inherited resources to use delete instead of destroy + # foreign keys will propagate deletion) + def destroy_resource(object) + object.delete + end + + def delete_all + objects = + get_collection_ivar || set_collection_ivar(end_of_association_chain.where(:id => params[:ids])) + objects.each { |object| object.delete } + respond_with(objects, :location => smart_collection_url) + end + + def name_filter + respond_to do |format| + format.json { render :json => filtered_lines_maps} + end + end + + protected + + def filtered_lines_maps + filtered_lines.collect do |line| + { :id => line.id, :name => (line.published_name ? line.published_name : line.name) } + end + end + + def filtered_lines + referential.lines.select{ |t| [t.name, t.published_name].find { |e| /#{params[:q]}/i =~ e } } + end + + def collection + if params[:q] && params[:q]["network_id_eq"] == "-1" + params[:q]["network_id_eq"] = "" + params[:q]["network_id_blank"] = "1" + end + + if params[:q] && params[:q]["company_id_eq"] == "-1" + params[:q]["company_id_eq"] = "" + params[:q]["company_id_blank"] = "1" + end + + if params[:q] && params[:q]["group_of_lines_id_eq"] == "-1" + params[:q]["group_of_lines_id_eq"] = "" + params[:q]["group_of_lines_id_blank"] = "1" + end + + @q = referential.lines.search(params[:q]) + @lines ||= @q.result(:distinct => true).order(:number).paginate(:page => params[:page]).includes([:network, :company]) + end + + private + + def line_params + params.require(:line).permit( :transport_mode, :network_id, :company_id, :objectid, :object_version, :creation_time, :creator_id, :name, :number, :published_name, :transport_mode_name, :registration_number, :comment, :mobility_restricted_suitability, :int_user_needs, :flexible_service, :group_of_lines, :group_of_line_ids, :group_of_line_tokens, :url, :color, :text_color, :stable_id, { footnotes_attributes: [ :code, :label, :_destroy, :id ] } ) + end + +end diff --git a/app/models/referential.rb b/app/models/referential.rb index 1f0c5bcfd..55e7eff79 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -25,6 +25,10 @@ class Referential < ActiveRecord::Base belongs_to :organisation validates_presence_of :organisation + belongs_to :line_referential + # validates_presence_of :line_referential + has_many :lines, through: :line_referential + def slug_excluded_values if ! slug.nil? if slug.start_with? "pg_" @@ -47,10 +51,6 @@ class Referential < ActiveRecord::Base self.class.human_attribute_name(*args) end - def lines - Chouette::Line.all - end - def networks Chouette::Network.all end diff --git a/app/views/referential_lines/_form.erb b/app/views/referential_lines/_form.erb new file mode 100644 index 000000000..442434d3b --- /dev/null +++ b/app/views/referential_lines/_form.erb @@ -0,0 +1,54 @@ +<%= semantic_form_for [@referential, @line] do |form| %> + <%= form.inputs do %> + <%= form.input :network, :as => :select, :collection => Chouette::Network.all, :include_blank => false %> + <%= form.input :company, :as => :select, :collection => Chouette::Company.all, :include_blank => false%> + <%= form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.line.name") } %> + <%= form.input :published_name %> + <%= form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.line.registration_number")} %> + <%= form.input :number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.line.number") } %> + <%= form.input :transport_mode, :as => :select, :collection => Chouette::Line.transport_modes, :include_blank => false, :member_label => Proc.new { |mode| t("transport_modes.label.#{mode}") } %> + <%= form.input :color, :as => :string %> + <%= form.input :text_color %> + <%= form.input :stable_id %> + <%= form.input :url %> + <%= form.input :mobility_restricted_suitability, :as => :select, :collection => [[@line.human_attribute_name("accessible"), true], [@line.human_attribute_name("not_accessible"), false]], :include_blank => true %> + <%= form.input :flexible_service, :as => :select, :collection => [[@line.human_attribute_name("on_demaond_fs"), true], [@line.human_attribute_name("regular_fs"), false]], :include_blank => true %> + <%= form.input :comment %> + <%= form.input :objectid, :required => !@line.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.line.objectid")} %> + <%= form.input :group_of_line_tokens, :label => t('.group_of_lines'), :as => :text, :input_html => { :"data-pre" => ( @line.group_of_lines.map { |group_of_line| { :id => group_of_line.id, :name => group_of_line.name } } ).to_json } %> + +
+

<%= t("footnotes.index.title") %>

+
+ <%= form.semantic_fields_for :footnotes do |f| %> + <%= render "footnotes/footnote_fields", :f => f %> + <% end %> +
+
+ <%= link_to_add_association t("footnotes.actions.add_footnote"), form, :footnotes , + :partial => "footnotes/footnote_fields", + :"data-association-insertion-method" => "append", + :"data-association-insertion-node" => "div#footnotes", :class => "add" %> +
+
+ <% end %> + + <%= form.actions do %> + <%= form.action :submit, :as => :button %> + <%= form.action :cancel, :as => :link %> + <% end %> +<% end %> + + diff --git a/app/views/referential_lines/_line.erb b/app/views/referential_lines/_line.erb new file mode 100644 index 000000000..512f6ae7b --- /dev/null +++ b/app/views/referential_lines/_line.erb @@ -0,0 +1,51 @@ +
+
+ +
+
+

+ <% if line.network.nil? %> + <%= line.human_attribute_name('network') %> <%= t('lines.index.unset') %> + <% else %> + <%= line.human_attribute_name('network') %> <%= link_to_if line.network, line.network.name, referential_network_path(@referential, line.network), :title => "#{line.human_attribute_name('network')} #{line.network.name}" %> + <% end %> +

+

+ <% if line.company.nil? %> + <%= line.human_attribute_name('company') %> <%= t('lines.index.unset') %> + <% else %> + <%= line.human_attribute_name('company') %> <%= link_to_if( line.company, line.company.name, referential_company_path(@referential, line.company), :title => "#{line.human_attribute_name('company')} #{line.company.name}" ) %> + <% end %> +

+

+ <% if line.group_of_lines.count == 0 %> +
<%# t('lines.form.no_group_of_line') %> + <% elsif line.group_of_lines.count == 1 %> + <%= line.human_attribute_name('group_of_line') %> + <%= link_to_if( line.group_of_lines.first, line.group_of_lines.first.name, referential_group_of_line_path(@referential, line.group_of_lines.first), :title => "#{line.human_attribute_name('group_of_line')} #{line.group_of_lines.first.name}") %> + <% else %> + <%= t('lines.form.several_group_of_lines', :count => line.group_of_lines.count) %> + <% end %> +

+
+
diff --git a/app/views/referential_lines/_lines.html.erb b/app/views/referential_lines/_lines.html.erb new file mode 100644 index 000000000..a4d9a3f0b --- /dev/null +++ b/app/views/referential_lines/_lines.html.erb @@ -0,0 +1,9 @@ +
+ <%= t("will_paginate.page_entries_info.search") %> <%= page_entries_info @lines %> +
+
+ <%= paginated_content(@lines) %> +
+ diff --git a/app/views/referential_lines/edit.html.erb b/app/views/referential_lines/edit.html.erb new file mode 100644 index 000000000..d2c9880ae --- /dev/null +++ b/app/views/referential_lines/edit.html.erb @@ -0,0 +1,3 @@ +<%= title_tag t('lines.edit.title', :line => @line.name ) %> + +<%= render "form" %> diff --git a/app/views/referential_lines/index.html.erb b/app/views/referential_lines/index.html.erb new file mode 100644 index 000000000..e0c601572 --- /dev/null +++ b/app/views/referential_lines/index.html.erb @@ -0,0 +1,51 @@ +<%= title_tag t('lines.index.title') %> + +<%= search_form_for @q, :url => referential_lines_path(@referential), remote: true, :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f| %> +
+
+
+ <%= f.text_field :name_or_number_cont, :placeholder => "#{t('.name_or_number')}", :class => 'form-control' %> +
+ +
+
+ + <%= "#{t('.advanced_search')}" %> + +
+ + +
+<% end %> + +
<%= render 'lines' %>
+ +<% content_for :sidebar do %> + + +
+

<%= t(".multi_selection") %>

+
+ <%= t(".multi_selection_enable") %> +
+ + +
+ +<% end %> diff --git a/app/views/referential_lines/index.js.erb b/app/views/referential_lines/index.js.erb new file mode 100644 index 000000000..97595d5e9 --- /dev/null +++ b/app/views/referential_lines/index.js.erb @@ -0,0 +1 @@ +$('#lines').html('<%= escape_javascript(render("lines")) %>'); \ No newline at end of file diff --git a/app/views/referential_lines/new.html.erb b/app/views/referential_lines/new.html.erb new file mode 100644 index 000000000..452ec5df2 --- /dev/null +++ b/app/views/referential_lines/new.html.erb @@ -0,0 +1,3 @@ +<%= title_tag t('lines.new.title') %> + +<%= render "form" %> diff --git a/app/views/referential_lines/show.html.erb b/app/views/referential_lines/show.html.erb new file mode 100644 index 000000000..b1248c275 --- /dev/null +++ b/app/views/referential_lines/show.html.erb @@ -0,0 +1,137 @@ +<% text_color = @line.text_color.blank? ? "black" : "##{@line.text_color}" %> +<% bg_color = @line.color.blank? ? "white" : "#"+@line.color %> + +<%= title_tag t('lines.show.title', :line => @line.name ) %> + +
+ <%= @map.to_html %> + +
+ <% text_color = @line.text_color.blank? ? "black" : "##{@line.text_color}" %> + <% bg_color = @line.color.blank? ? "white" : "#"+@line.color %> + <% if colors?(@line) %> +

+ + +

+ <% end %> +

+ + <% if @line.network.nil? %> + <%= t('lines.index.unset') %> + <% else %> + <%= link_to @line.network.name, [@referential, @line.network] %> + <% end %> +

+

+ + <% if @line.company.nil? %> + <%= t('lines.index.unset') %> + <% else %> + <%= link_to @line.company.name, [@referential, @line.company] %> + <% end %> +

+

+ + <%= @line.number %> +

+

+ + <%= @line.published_name %> +

+

+ + <%= @line.registration_number %> +

+

+ + <%= t("transport_modes.label.#{@line.transport_mode}") %> +

+

+ + <%= @line.stable_id %> +

+ +

+ + <%= @line.url %> +

+ +

+ + <% if @line.mobility_restricted_suitability.nil? %> + <%= @line.human_attribute_name("unspecified_mrs") %> + <% elsif @line.mobility_restricted_suitability? %> + <%= @line.human_attribute_name("accessible") %> + <% else %> + <%= @line.human_attribute_name("not_accessible") %> + <% end %> +
  <%= @line.human_attribute_name("number_of_mrs_vj") %> : <%= @line.vehicle_journeys.where("mobility_restricted_suitability = ?", true).count %> +
  <%= @line.human_attribute_name("number_of_non_mrs_vj") %> : <%= @line.vehicle_journeys.where("mobility_restricted_suitability = ?", false).count %> +
  <%= @line.human_attribute_name("number_of_null_mrs_vj") %> : <%= @line.vehicle_journeys.count - + (@line.vehicle_journeys.where("mobility_restricted_suitability = ?", true).count + + @line.vehicle_journeys.where("mobility_restricted_suitability = ?", false).count) %> +

+

+ + <% if @line.flexible_service.nil? %> + <%= @line.human_attribute_name("unspecified_fs") %> + <% elsif @line.flexible_service? %> + <%= @line.human_attribute_name("on_demaond_fs") %> + <% else %> + <%= @line.human_attribute_name("regular_fs") %> + <% end %> +
  <%= @line.human_attribute_name("number_of_fs_vj") %> : <%= @line.vehicle_journeys.where("flexible_service = ?", true).count %> +
  <%= @line.human_attribute_name("number_of_non_fs_vj") %> : <%= @line.vehicle_journeys.where("flexible_service = ?", false).count %> +
  <%= @line.human_attribute_name("number_of_null_fs_vj") %> + <% if @line.flexible_service.nil? %> + (<%= @line.human_attribute_name("default_fs_msg") %>) + <% end %> + : <%= @line.vehicle_journeys.count - + (@line.vehicle_journeys.where("flexible_service = ?", true).count + + @line.vehicle_journeys.where("flexible_service = ?", false).count) %> +

+

+ +

+

+

+ + <%= @line.comment %> +

+
+ +
+
+
+
+
+ +

+

<%= t('.itineraries') %>

+
+ <%= paginated_content @routes, "routes/route" %> +
+ +<% if @line.group_of_lines.any? %> +

<%= t('.group_of_lines') %>

+
+ <%= paginated_content @group_of_lines, "group_of_lines/group_of_line", :delete => false %> +
+<% end %> + +<% content_for :sidebar do %> + + <%= creation_tag(@line) %> +<% end %> diff --git a/app/views/referential_lines/show.kml.erb b/app/views/referential_lines/show.kml.erb new file mode 100644 index 000000000..8e1c82eef --- /dev/null +++ b/app/views/referential_lines/show.kml.erb @@ -0,0 +1,14 @@ + + + + <% @line.commercial_stop_areas.each do |stop_area| %> + + <%= stop_area.name %> + <%= stop_area.area_type.underscore %> + <%= t("area_types.label.#{stop_area.stop_area_type}") %> + <%= (stop_area.position or stop_area.default_position).kml_representation.html_safe %> + + <% end %> + + + -- cgit v1.2.3