From 72de1c47254ca70d7be04a96b5b11dfed8f79df6 Mon Sep 17 00:00:00 2001 From: Michel Etienne Date: Tue, 9 Oct 2012 16:03:11 +0200 Subject: add group_of_line managment --- app/assets/javascripts/group_of_line.js.coffee | 15 ++++ app/assets/stylesheets/group_of_lines.css.scss | 101 ++++++++++++++++++++++++ app/controllers/group_of_lines_controller.rb | 47 +++++++++++ app/controllers/lines_controller.rb | 17 ++++ app/maps/group_of_line_map.rb | 34 ++++++++ app/models/referential.rb | 4 + app/views/group_of_lines/_form.erb | 27 +++++++ app/views/group_of_lines/_group_of_line.erb | 9 +++ app/views/group_of_lines/_lines_detail.html.erb | 10 +++ app/views/group_of_lines/edit.html.erb | 3 + app/views/group_of_lines/index.html.erb | 26 ++++++ app/views/group_of_lines/new.html.erb | 3 + app/views/group_of_lines/show.html.erb | 48 +++++++++++ app/views/group_of_lines/show.js.erb | 4 + app/views/group_of_lines/show.kml.erb | 13 +++ app/views/layouts/application.html.erb | 1 + app/views/vehicle_journeys/_form.html.erb | 1 + 17 files changed, 363 insertions(+) create mode 100644 app/assets/javascripts/group_of_line.js.coffee create mode 100644 app/assets/stylesheets/group_of_lines.css.scss create mode 100644 app/controllers/group_of_lines_controller.rb create mode 100644 app/maps/group_of_line_map.rb create mode 100644 app/views/group_of_lines/_form.erb create mode 100644 app/views/group_of_lines/_group_of_line.erb create mode 100644 app/views/group_of_lines/_lines_detail.html.erb create mode 100644 app/views/group_of_lines/edit.html.erb create mode 100644 app/views/group_of_lines/index.html.erb create mode 100644 app/views/group_of_lines/new.html.erb create mode 100644 app/views/group_of_lines/show.html.erb create mode 100644 app/views/group_of_lines/show.js.erb create mode 100644 app/views/group_of_lines/show.kml.erb (limited to 'app') diff --git a/app/assets/javascripts/group_of_line.js.coffee b/app/assets/javascripts/group_of_line.js.coffee new file mode 100644 index 000000000..c49b0d54a --- /dev/null +++ b/app/assets/javascripts/group_of_line.js.coffee @@ -0,0 +1,15 @@ +jQuery -> + + switch_lines = (event) -> + event.preventDefault() + $('.group_of_lines.show .lines_detail').toggle('slow') + $('a.lines .switcher').toggle() + + $('.group_of_lines.show a.lines').click(switch_lines) + + + make_ajax_pagination = () -> + $.get(this.href, null, null, 'script') + false + + $('.group_of_lines.show .lines_detail .pagination a').live("click", make_ajax_pagination) diff --git a/app/assets/stylesheets/group_of_lines.css.scss b/app/assets/stylesheets/group_of_lines.css.scss new file mode 100644 index 000000000..24fbdce12 --- /dev/null +++ b/app/assets/stylesheets/group_of_lines.css.scss @@ -0,0 +1,101 @@ +// Place all the styles related to the lines controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ +@import "common"; + +#workspace.group_of_lines.index +{ + .group_of_line:after { + @include after_div_for_object; + } + + .group_of_lines { + margin-top: 20px; + } + + .group_of_lines:after { + @include content_to_clear; + } + + .group_of_line { + @include div_for_object; + + /* to create multi-column index */ + width: 350px; + float: left; + padding-right: 10px; + + } +} + +#workspace.group_of_lines.show +{ + .summary p label { + font-weight: bold; + } + .lines_detail div.page_info { + margin-top: 0px; + } + + .line:after { + @include after_div_for_object; + } + + .lines { + margin-top: 10px; + } + + .lines:after { + @include content_to_clear; + } + .group_of_line_lines { + clear: both; + margin: 0px; + padding: 0px; + a { + cursor: pointer; + } + } + + .line { + @include div_for_object; + /* to create multi-column index */ + width: 250px; + float: left; + padding-right: 10px; + + .position { + width: 25px; + height: 20px; + float: left; + background-color: #61970B; + font-weight: bold; + color: white; + margin-right: 10px; + padding-left: 4px; + } + .color { + background-color: white; + width: 64px; + height: 64px; + float: left; + margin-right: 10px; + border: 1px solid #999; + + a { + text-decoration: none; + } + } + + .number { + font-size: 16px; + text-align: center; + font-weight: bold; + padding-top: 21px; + } + .name a { + display: inline; + } + } +} + diff --git a/app/controllers/group_of_lines_controller.rb b/app/controllers/group_of_lines_controller.rb new file mode 100644 index 000000000..c758ad16d --- /dev/null +++ b/app/controllers/group_of_lines_controller.rb @@ -0,0 +1,47 @@ +class GroupOfLinesController < ChouetteController + defaults :resource_class => Chouette::GroupOfLine + respond_to :html + respond_to :xml + respond_to :json + respond_to :kml, :only => :show + + belongs_to :referential + + def show + @map = GroupOfLineMap.new(resource).with_helpers(self) + @lines = resource.lines.order(:name).paginate(:page => params[:page]) + show! + end + + def name_filter + respond_to do |format| + format.json { render :json => filtered_group_of_lines_maps} + end + + end + + protected + + def filtered_group_of_lines_maps + filtered_group_of_lines.collect do |group_of_line| + { :id => group_of_line.id, :name => group_of_line.name } + end + end + + def filtered_group_of_lines + referential.group_of_lines.select{ |t| t.name =~ /#{params[:q]}/i } + end + + def collection + @q = referential.group_of_lines.search(params[:q]) + @group_of_lines ||= @q.result(:distinct => true).order(:name).paginate(:page => params[:page]) + end + + def resource_url(group_of_line = nil) + referential_group_of_line_path(referential, group_of_line || resource) + end + + def collection_url + referential_group_of_lines_path(referential) + end +end diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index e85c29fc9..0699b0047 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -20,8 +20,25 @@ class LinesController < ChouetteController 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 } + end + end + + def filtered_lines + referential.lines.select{ |t| t.published_name =~ /#{params[:q]}/i } + end + def collection @q = referential.lines.search(params[:q]) @lines ||= @q.result(:distinct => true).order(:number).paginate(:page => params[:page]).includes([:network, :company]) diff --git a/app/maps/group_of_line_map.rb b/app/maps/group_of_line_map.rb new file mode 100644 index 000000000..fdd8cac1d --- /dev/null +++ b/app/maps/group_of_line_map.rb @@ -0,0 +1,34 @@ +class GroupOfLineMap < ApplicationMap + + attr_reader :group_of_line, :group_of_line_style + + def initialize(group_of_line, group_of_line_style = nil) + @group_of_line = group_of_line + @group_of_line_style = group_of_line_style + end + + def map + @map ||= MapLayers::Map.new(id, :projection => projection("EPSG:900913"), :controls => controls) do |map, page| + page << map.add_layer(MapLayers::OSM_MAPNIK) + page << map.add_layer(google_physical) + page << map.add_layer(google_streets) + page << map.add_layer(google_hybrid) + page << map.add_layer(google_satellite) + + page.assign "stop_areas_layer", kml_layer([group_of_line.referential, group_of_line], :styleMap => StyleMap::StopAreasStyleMap.new(helpers).style_map) + + page << map.add_layer(:stop_areas_layer) + page << map.add_control( hover_control_display_name(:stop_areas_layer) ) + page << map.zoom_to_extent(bounds.to_google.to_openlayers) if bounds + end + end + + def bounds + @bounds ||= GeoRuby::SimpleFeatures::Point.bounds(group_of_line.stop_areas.collect(&:geometry).compact) + end + + def ready? + Chouette::StopArea.bounds.present? + end + +end diff --git a/app/models/referential.rb b/app/models/referential.rb index ab4290cdd..b4601caee 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -47,6 +47,10 @@ class Referential < ActiveRecord::Base Chouette::Network.scoped end + def group_of_lines + Chouette::GroupOfLine.scoped + end + def companies Chouette::Company.scoped end diff --git a/app/views/group_of_lines/_form.erb b/app/views/group_of_lines/_form.erb new file mode 100644 index 000000000..0dcdc9379 --- /dev/null +++ b/app/views/group_of_lines/_form.erb @@ -0,0 +1,27 @@ +<%= semantic_form_for [@referential, @group_of_line] do |form| %> + <%= form.inputs do %> + <%= form.input :name %> + <%= form.input :comment %> + <%= form.input :objectid, :required => !@group_of_line.new_record?, :input_html => { :disabled => !@group_of_line.new_record? } %> + <% end %> + + <%= form.inputs do %> + <%= form.input :line_tokens, :label => t('.lines'), :as => :text, :input_html => { :"data-pre" => ( @group_of_line.lines.map { |line| { :id => line.id, :name => line.published_name } } ).to_json } %> + <% end %> + + <%= form.actions do %> + <%= form.action :submit, :as => :button %> + <%= form.action :cancel, :as => :link %> + <% end %> +<% end %> + + diff --git a/app/views/group_of_lines/_group_of_line.erb b/app/views/group_of_lines/_group_of_line.erb new file mode 100644 index 000000000..b3a9099d8 --- /dev/null +++ b/app/views/group_of_lines/_group_of_line.erb @@ -0,0 +1,9 @@ +<%= div_for(group_of_line) do %> + <%= link_to group_of_line.name, [@referential, group_of_line] %> +
+
+ <%= link_to t("actions.edit"), edit_referential_group_of_line_path(@referential, group_of_line), :class => "edit" %> | + <%= link_to t("actions.destroy"), referential_group_of_line_path(@referential, group_of_line), :method => :delete, :confirm => t('group_of_lines.actions.destroy_confirm'), :class => "remove" %> +
+
+<% end %> diff --git a/app/views/group_of_lines/_lines_detail.html.erb b/app/views/group_of_lines/_lines_detail.html.erb new file mode 100644 index 000000000..4d4058540 --- /dev/null +++ b/app/views/group_of_lines/_lines_detail.html.erb @@ -0,0 +1,10 @@ +
+ <%= t("will_paginate.page_entries_info.list") %> <%= page_entries_info @lines %> +
+
+ <%= render :partial => "lines/line", :collection => @lines %> +
+ + diff --git a/app/views/group_of_lines/edit.html.erb b/app/views/group_of_lines/edit.html.erb new file mode 100644 index 000000000..541e708ca --- /dev/null +++ b/app/views/group_of_lines/edit.html.erb @@ -0,0 +1,3 @@ +<%= title_tag t('group_of_lines.edit.title', :group_of_line => @group_of_line.name) %> + +<%= render "form" %> diff --git a/app/views/group_of_lines/index.html.erb b/app/views/group_of_lines/index.html.erb new file mode 100644 index 000000000..6f01455b8 --- /dev/null +++ b/app/views/group_of_lines/index.html.erb @@ -0,0 +1,26 @@ +<%= title_tag t('group_of_lines.index.title') %> + +<%= search_form_for @q, :url => referential_group_of_lines_path(@referential), :html => {:method => :get} do |f| %> + <%= f.label :name_cont, "#{t('.name')} :" %> + <%= f.text_field :name_cont %> + + <%= f.submit t('actions.search') %> <%= t("or") %> + <%= link_to t("cancel"), referential_group_of_lines_path(@referential) %> +<% end %> + +
+ <%= t("will_paginate.page_entries_info.search") %> <%= page_entries_info @group_of_lines %> +
+
+ <%= render :partial => "group_of_line", :collection => @group_of_lines %> +
+ + +<% content_for :sidebar do %> + +<% end %> diff --git a/app/views/group_of_lines/new.html.erb b/app/views/group_of_lines/new.html.erb new file mode 100644 index 000000000..a2da652af --- /dev/null +++ b/app/views/group_of_lines/new.html.erb @@ -0,0 +1,3 @@ +<%= title_tag t('group_of_lines.new.title') %> + +<%= render "form" %> diff --git a/app/views/group_of_lines/show.html.erb b/app/views/group_of_lines/show.html.erb new file mode 100644 index 000000000..01084fb74 --- /dev/null +++ b/app/views/group_of_lines/show.html.erb @@ -0,0 +1,48 @@ +<%= title_tag t('group_of_lines.show.title', :group_of_line => @group_of_line.name )%> + +
+ <%= @map.to_html %> +
+

+ + <%= @group_of_line.name %> +

+

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

+

+ + <%= @group_of_line.objectid %> +

+

+ + <%= l @group_of_line.creation_time %> +

+

+ + <%= @group_of_line.creator_id %> +

+
+ +

+

+ <%= t('.lines') %> + <%= image_tag("icons/plus.png" , :class => "switcher") %> + <%= image_tag("icons/minus.png" , :class => "switcher" , :style => "display: none;") %> + +

+ + + +
+ +<% content_for :sidebar do %> + +<% end %> diff --git a/app/views/group_of_lines/show.js.erb b/app/views/group_of_lines/show.js.erb new file mode 100644 index 000000000..bd8ac5a7f --- /dev/null +++ b/app/views/group_of_lines/show.js.erb @@ -0,0 +1,4 @@ +$(function (){ + $(".lines_detail").html("<%= escape_javascript(render(:partial => "lines_detail")) %>"); +}); + diff --git a/app/views/group_of_lines/show.kml.erb b/app/views/group_of_lines/show.kml.erb new file mode 100644 index 000000000..6b1a34688 --- /dev/null +++ b/app/views/group_of_lines/show.kml.erb @@ -0,0 +1,13 @@ + + + + <% @group_of_line.commercial_stop_areas.each do |stop_area| %> + + <%= stop_area.name %> + <%= stop_area.area_type.underscore %> + <%= (stop_area.position or stop_area.default_position).kml_representation.html_safe %> + + <% end %> + + + diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 5df5f6b41..77873a855 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -47,6 +47,7 @@
  • <%= link_to t("layouts.tabs.dashboard").capitalize, referential_path(@referential), :class => ("current" if current_page?(referential_path(@referential))) %>
  • <%= tab_link_to Chouette::Network, referential_networks_path(@referential) %>
  • <%= tab_link_to Chouette::Company, referential_companies_path(@referential) %>
  • +
  • <%= tab_link_to Chouette::GroupOfLine, referential_group_of_lines_path(@referential) %>
  • <%= tab_link_to Chouette::Line, referential_lines_path(@referential) %>
  • <%= tab_link_to Chouette::StopArea, referential_stop_areas_path(@referential) %>
  • <%= tab_link_to Chouette::ConnectionLink, referential_connection_links_path(@referential) %>
  • diff --git a/app/views/vehicle_journeys/_form.html.erb b/app/views/vehicle_journeys/_form.html.erb index 0c0ccaecc..dd1a0dbaf 100644 --- a/app/views/vehicle_journeys/_form.html.erb +++ b/app/views/vehicle_journeys/_form.html.erb @@ -62,6 +62,7 @@ crossDomain: false, prePopulate: $('#time_table_tokens').data('pre'), minChars: 3, + preventDuplicates: true, }); }); -- cgit v1.2.3