From 49f8ea09ff09a6bf9ab2fd5f1bb410778b0fb209 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 23 May 2012 12:07:35 +0200 Subject: Add chouette2.war and vendor/bundle in .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 4dcf29e87..d96f025d0 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ public/assets/ *.swp *.swo .DS_Store +chouette2.war +vendor/bundle -- cgit v1.2.3 From 811ff1a56c96cee9bd95dac5aa9de91117dfcc28 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 23 May 2012 12:10:37 +0200 Subject: Run migrations after initialize when CHOUETTE_RUN_MIGRATIONS is defined. Defines it in war init. Fixes #38 --- config/database.yml | 2 +- config/initializers/db_migrate_in_war.rb | 10 ++++++++++ config/war_init.rb | 1 + config/warble.rb | 6 ++++-- lib/tasks/ci.rake | 2 +- 5 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 config/initializers/db_migrate_in_war.rb create mode 100644 config/war_init.rb diff --git a/config/database.yml b/config/database.yml index a3e357d3a..b2e8ca6dc 100644 --- a/config/database.yml +++ b/config/database.yml @@ -23,7 +23,7 @@ test: production: adapter: jdbcpostgresql - database: chouette2 + database: chouette_prod encoding: utf8 host: localhost username: chouette diff --git a/config/initializers/db_migrate_in_war.rb b/config/initializers/db_migrate_in_war.rb new file mode 100644 index 000000000..ccba79773 --- /dev/null +++ b/config/initializers/db_migrate_in_war.rb @@ -0,0 +1,10 @@ +Rails.configuration.after_initialize do + Rails.logger.info "Migrating database" + ActiveRecord::Migrator.migrate("db/migrate/", nil) + + Apartment.database_names.each do |db| + Rails.logger.info "Migrating #{db} schema" + Apartment::Migrator.migrate db + end +end if ENV["CHOUETTE_RUN_MIGRATIONS"] == "true" + diff --git a/config/war_init.rb b/config/war_init.rb new file mode 100644 index 000000000..756bc5926 --- /dev/null +++ b/config/war_init.rb @@ -0,0 +1 @@ +ENV["CHOUETTE_RUN_MIGRATIONS"] = "true" diff --git a/config/warble.rb b/config/warble.rb index 70a4ca946..cdc5583f9 100644 --- a/config/warble.rb +++ b/config/warble.rb @@ -42,7 +42,7 @@ Warbler::Config.new do |config| # An array of Bundler groups to avoid including in the war file. # Defaults to ["development", "test"]. - # config.bundle_without = [] + config.bundle_without = %w{development test assets} # Other gems to be included. If you don't use Bundler or a gemspec # file, you need to tell Warbler which gems your application needs @@ -78,7 +78,7 @@ Warbler::Config.new do |config| # Name of the archive (without the extension). Defaults to the basename # of the project directory. - # config.jar_name = "mywar" + config.jar_name = "chouette2" # Name of the MANIFEST.MF template for the war file. Defaults to a simple # MANIFEST.MF that contains the version of Warbler used to create the war file. @@ -139,4 +139,6 @@ Warbler::Config.new do |config| # JNDI data source name # config.webxml.jndi = 'jdbc/rails' + + config.init_contents << "config/war_init.rb" end diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 9c541129b..cfd68a1cf 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -3,7 +3,7 @@ namespace :ci do cp "config/database.yml.ccontrol", "config/database.yml" end task :deploy do - cp "workspace.war", "/var/lib/tomcat6/webapps/chouette2.war" + cp "chouette2.war", "/var/lib/tomcat6/webapps/" end task :build => ["db:migrate", "spec", "war", "ci:deploy"] end -- cgit v1.2.3 From c203a4b6d3d07928ad4ef41116d38873b9ac5820 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 23 May 2012 18:28:43 +0200 Subject: Add jruby-rack-worker to run workers. Fixes #37 --- Gemfile | 2 +- Gemfile.lock | 10 ++++++++++ app/models/import.rb | 2 +- app/models/referential.rb | 37 ++++--------------------------------- config/environments/production.rb | 2 +- config/warble.rb | 15 +++++++++++++-- config/web.xml.erb | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 66 insertions(+), 38 deletions(-) create mode 100644 config/web.xml.erb diff --git a/Gemfile b/Gemfile index 560716172..519bf4fd6 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ gem 'jquery-rails' gem 'devise' gem "ffi-proj4", :git => 'git://github.com/dryade/ffi-proj4.git' - +gem "jruby-rack-worker" platforms :jruby do gem 'activerecord-jdbcpostgresql-adapter', :git => 'git://github.com/dryade/activerecord-jdbc-adapter.git' diff --git a/Gemfile.lock b/Gemfile.lock index 03062f915..b09c6fafc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -71,6 +71,7 @@ GEM remote: http://rubygems.org/ specs: GeoRuby (1.3.4) + RedCloth (4.2.9) RedCloth (4.2.9-java) SyslogLogger (1.4.1) actionmailer (3.1.3) @@ -107,6 +108,7 @@ GEM acts_as_list (0.1.6) addressable (2.2.8) arel (2.2.3) + bcrypt-ruby (3.0.1) bcrypt-ruby (3.0.1-java) bouncy-castle-java (1.5.0146.1) builder (3.0.0) @@ -157,6 +159,7 @@ GEM factory_girl_rails (1.7.0) factory_girl (~> 2.6.0) railties (>= 3.0.0) + ffi (1.0.11) ffi (1.0.11-java) ffi-geos (0.0.4) ffi (~> 1.0.0) @@ -185,8 +188,13 @@ GEM jruby-openssl (0.7.6.1) bouncy-castle-java (>= 1.5.0146.1) jruby-rack (1.1.5) + jruby-rack-worker (0.3-java) + jruby-rack (>= 1.0.1) + json (1.7.3) json (1.7.3-java) json_pure (1.7.3) + launchy (2.1.0) + addressable (~> 2.2.6) launchy (2.1.0-java) addressable (~> 2.2.6) ffi (~> 1.0.9) @@ -207,6 +215,7 @@ GEM net-ssh (2.3.0) net-ssh-gateway (1.1.0) net-ssh (>= 1.99.1) + nokogiri (1.5.2) nokogiri (1.5.2-java) orm_adapter (0.0.7) polyamorous (0.5.0) @@ -345,6 +354,7 @@ DEPENDENCIES inherited_resources jquery-rails jruby-openssl + jruby-rack-worker json launchy map_layers (~> 0.0.4) diff --git a/app/models/import.rb b/app/models/import.rb index fd3fb139d..ec6caa660 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -26,7 +26,7 @@ class Import < ActiveRecord::Base self.status ||= "pending" end - after_create :import + after_create :delayed_import def delayed_import save_resources delay.import diff --git a/app/models/referential.rb b/app/models/referential.rb index 84640e43c..d7c5bba7e 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -34,44 +34,15 @@ class Referential < ActiveRecord::Base self end - before_create :prepare + before_create :create_schema before_destroy :destroy_schema - attr_accessor :resources - attr_accessor :loader - - def loader - @loader ||= ::Chouette::Loader.new(slug) - end + after_create :import_resources - def prepare - if resources - import_resources - else - create_schema - end - end - - def with_original_filename - Dir.mktmpdir do |tmp_dir| - tmp_link = File.join(tmp_dir, resources.original_filename) - FileUtils.ln_s resources.path, tmp_link - yield tmp_link - end - end + attr_accessor :resources def import_resources - # Apartment::Database.create create tables - loader.create - begin - with_original_filename do |file| - # chouette-command checks the file extension (and requires .zip) :( - loader.import file - end - rescue => e - loader.drop - raise e - end + imports.create(:resources => resources) if resources end def create_schema diff --git a/config/environments/production.rb b/config/environments/production.rb index a121daab6..d79d98df7 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -36,7 +36,7 @@ ChouetteIhm::Application.configure do # Use a different logger for distributed setups require 'syslog_logger' config.logger = SyslogLogger.new("rails/chouette2").tap do |logger| - logger.level = Logger::INFO + # logger.level = Logger::INFO end # Use a different cache store in production diff --git a/config/warble.rb b/config/warble.rb index cdc5583f9..11c6bf090 100644 --- a/config/warble.rb +++ b/config/warble.rb @@ -134,8 +134,19 @@ Warbler::Config.new do |config| # Control the pool of Rails runtimes. Leaving unspecified means # the pool will grow as needed to service requests. It is recommended # that you fix these values when running a production server! - # config.webxml.jruby.min.runtimes = 2 - # config.webxml.jruby.max.runtimes = 4 + config.webxml.jruby.min.runtimes = 2 + config.webxml.jruby.max.runtimes = 4 + + config.webxml.jruby.worker.script = < false).start +rescue => e + Rails.logger.fatal(e) + raise e +end +EOF # JNDI data source name # config.webxml.jndi = 'jdbc/rails' diff --git a/config/web.xml.erb b/config/web.xml.erb new file mode 100644 index 000000000..af962f3b7 --- /dev/null +++ b/config/web.xml.erb @@ -0,0 +1,36 @@ + + +<% webxml.context_params.each do |k,v| %> + + <%= k %> + <%= v %> + +<% end %> + + + RackFilter + org.jruby.rack.RackFilter + + + RackFilter + /* + + + + <%= webxml.servlet_context_listener %> + + + + org.kares.jruby.rack.WorkerContextListener + + +<% if webxml.jndi then [webxml.jndi].flatten.each do |jndi| %> + + <%= jndi %> + javax.sql.DataSource + Container + +<% end; end %> + -- cgit v1.2.3 From ae65f9661b288b367d5f1f3e5fd8797852127110 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Wed, 23 May 2012 18:33:10 +0200 Subject: Revert changes in database.yml --- config/database.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/database.yml b/config/database.yml index b2e8ca6dc..a3e357d3a 100644 --- a/config/database.yml +++ b/config/database.yml @@ -23,7 +23,7 @@ test: production: adapter: jdbcpostgresql - database: chouette_prod + database: chouette2 encoding: utf8 host: localhost username: chouette -- cgit v1.2.3 From 244de985c6c00b6385e9af47f9dec08de1eec6c5 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Tue, 29 May 2012 08:57:01 +0200 Subject: Include html_safe an ready? in ApplicationMap#to_html --- app/maps/application_map.rb | 4 +++- app/maps/line_map.rb | 4 ++++ app/maps/network_map.rb | 4 ++++ app/views/lines/show.html.erb | 2 +- app/views/networks/show.html.erb | 2 +- spec/views/lines/show.html.erb_spec.rb | 2 +- spec/views/networks/show.html.erb_spec.rb | 3 ++- 7 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/maps/application_map.rb b/app/maps/application_map.rb index a4d8a84ab..dffb2501c 100644 --- a/app/maps/application_map.rb +++ b/app/maps/application_map.rb @@ -34,7 +34,9 @@ class ApplicationMap end def to_html(options = {}) - "
#{map.to_html(options)}" + if not respond_to?(:ready?) or ready? + "
#{map.to_html(options)}".html_safe + end end def kml diff --git a/app/maps/line_map.rb b/app/maps/line_map.rb index 128b98dd2..a7a9f892d 100644 --- a/app/maps/line_map.rb +++ b/app/maps/line_map.rb @@ -29,4 +29,8 @@ class LineMap < ApplicationMap end + def ready? + Chouette::StopArea.bounds.present? + end + end diff --git a/app/maps/network_map.rb b/app/maps/network_map.rb index cedabdf6e..35283a48f 100644 --- a/app/maps/network_map.rb +++ b/app/maps/network_map.rb @@ -28,4 +28,8 @@ class NetworkMap < ApplicationMap end + def ready? + Chouette::StopArea.bounds.present? + end + end diff --git a/app/views/lines/show.html.erb b/app/views/lines/show.html.erb index 4e7217384..c487f8616 100644 --- a/app/views/lines/show.html.erb +++ b/app/views/lines/show.html.erb @@ -1,7 +1,7 @@ <%= title_tag t('lines.show.title', :line => @line.name ) %>
- <%= @map.to_html.html_safe %> + <%= @map.to_html %>

diff --git a/app/views/networks/show.html.erb b/app/views/networks/show.html.erb index b03347ccf..112fb5769 100644 --- a/app/views/networks/show.html.erb +++ b/app/views/networks/show.html.erb @@ -1,7 +1,7 @@ <%= title_tag t('networks.show.title', :network => @network.name )%>

- <%= @map.to_html.html_safe %> + <%= @map.to_html %>

diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb index 42261005a..f77722672 100644 --- a/spec/views/lines/show.html.erb_spec.rb +++ b/spec/views/lines/show.html.erb_spec.rb @@ -5,7 +5,7 @@ describe "/lines/show" do let!(:referential) { assign :referential, create(:referential) } let!(:line) { assign :line, create(:line) } let!(:routes) { assign :routes, Array.new(2) { create(:route, :line => line) }.paginate } - let!(:map) { assign(:map, mock(:to_html => '

')) } + let!(:map) { assign(:map, mock(:to_html => '
'.html_safe)) } it "should render h2 with the line name" do render diff --git a/spec/views/networks/show.html.erb_spec.rb b/spec/views/networks/show.html.erb_spec.rb index 9c05fe4aa..9c4f34f96 100644 --- a/spec/views/networks/show.html.erb_spec.rb +++ b/spec/views/networks/show.html.erb_spec.rb @@ -4,7 +4,7 @@ describe "/networks/show" do let!(:referential) { assign(:referential, create(:referential)) } let!(:network) { assign(:network, create(:network)) } - let!(:map) { assign(:map, mock(:to_html => '
')) } + let!(:map) { assign(:map, mock(:to_html => '
'.html_safe)) } it "should render h2 with the network name" do render @@ -13,6 +13,7 @@ describe "/networks/show" do it "should display a map with class 'network'" do render + puts rendered rendered.should have_selector("#map") end -- cgit v1.2.3 From 5266239f66247c9f5a391ab6569a8fb8021279d8 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Tue, 29 May 2012 08:58:06 +0200 Subject: Manage multiple selection to destroy several lines. Refs #25 --- .../javascripts/multiple_selection.js.coffee | 22 +++++++++++++++++++--- app/assets/stylesheets/lines.css.scss | 1 + app/assets/stylesheets/multiple_selection.scss | 2 ++ app/controllers/lines_controller.rb | 7 +++++++ app/views/lines/_line.erb | 4 ++-- app/views/lines/index.html.erb | 2 +- config/routes.rb | 1 + 7 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/multiple_selection.js.coffee b/app/assets/javascripts/multiple_selection.js.coffee index 0353a2755..1ff473c4d 100644 --- a/app/assets/javascripts/multiple_selection.js.coffee +++ b/app/assets/javascripts/multiple_selection.js.coffee @@ -27,11 +27,27 @@ jQuery -> $('#multiple_selection_menu a.deselect_all').click(deselect_all) - disabled_action = (event) -> + handle_multiple_action = (event) -> event.preventDefault() - alert("Fonction activee au prochain milestone") + link = $(event.target) - $('#multiple_selection_menu .actions a').click(disabled_action) + href = link.attr("href") + method = link.data('multiple-method') + csrf_token = $('meta[name=csrf-token]').attr('content') + csrf_param = $('meta[name=csrf-param]').attr('content') + form = $('
') + target = link.attr('target') + metadata_input = '' + if csrf_param? and csrf_token? + metadata_input += '' + form.append($(input).clone()) for input in $('input[type=checkbox].multiple_selection:checked') + + form.attr('target', target) if target? + + form.hide().append(metadata_input).appendTo('body') + form.submit() + + $('#multiple_selection_menu .actions a.remove').click(handle_multiple_action) diff --git a/app/assets/stylesheets/lines.css.scss b/app/assets/stylesheets/lines.css.scss index c5370611c..07ed34e5b 100644 --- a/app/assets/stylesheets/lines.css.scss +++ b/app/assets/stylesheets/lines.css.scss @@ -24,6 +24,7 @@ width: 350px; float: left; padding-right: 10px; + position: relative; .color { width: 64px; diff --git a/app/assets/stylesheets/multiple_selection.scss b/app/assets/stylesheets/multiple_selection.scss index e7f64857f..f3792d902 100644 --- a/app/assets/stylesheets/multiple_selection.scss +++ b/app/assets/stylesheets/multiple_selection.scss @@ -1,5 +1,7 @@ input[type=checkbox].multiple_selection { margin-left: 25px; + position: absolute; + top: 50px; } #multiple_selection_menu { diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index 42a126169..e14baf211 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -12,6 +12,13 @@ class LinesController < ChouetteController show! end + def destroy_all + objects = + get_collection_ivar || set_collection_ivar(end_of_association_chain.where(:id => params[:ids])) + objects.destroy_all + respond_with(objects, :location => smart_collection_url) + end + protected def collection diff --git a/app/views/lines/_line.erb b/app/views/lines/_line.erb index 5405bcbb5..3565966fb 100644 --- a/app/views/lines/_line.erb +++ b/app/views/lines/_line.erb @@ -2,11 +2,11 @@ <%= link_to([@referential, line], :class => "preview", :title => "Ligne #{line.number}") do %>
<% if line.number and line.number.length <= 3 %> -
<%= line.number %>
+
<%= line.number %>
<% end %> - <%= check_box_tag "ids[]", line.id, false, :class => "multiple_selection", :style => "display: none;" %>
<% end %> + <%= check_box_tag "ids[]", line.id, false, :class => "multiple_selection", :style => "display: none;" %> <%= link_to truncate(line.name, :length => 30), [@referential, line], :title => "Ligne #{line.name}" %>
<%= 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}" %> - diff --git a/app/views/lines/index.html.erb b/app/views/lines/index.html.erb index c39e94cbd..8c9766866 100644 --- a/app/views/lines/index.html.erb +++ b/app/views/lines/index.html.erb @@ -75,7 +75,7 @@ <%= t(".multi_selection_disable") %> diff --git a/config/routes.rb b/config/routes.rb index 305a219ce..74b8a34d3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,6 +20,7 @@ ChouetteIhm::Application.routes.draw do # resources :products resources :referentials do resources :stop_point_areas + match 'lines' => 'lines#destroy_all', :via => :delete resources :lines, :networks do resources :stop_areas do resources :stop_area_parents -- cgit v1.2.3 From ee0f3849cb6a2278783aabb166fb5c2661cdb400 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Tue, 29 May 2012 17:08:17 +0200 Subject: Removes explicit ApplicationMap#html_safe --- app/maps/connection_link_map.rb | 4 ++++ app/maps/route_map.rb | 14 ++++++++++---- app/maps/stop_area_map.rb | 4 ++++ app/views/connection_links/show.html.erb | 2 +- app/views/routes/show.html.erb | 2 +- app/views/stop_areas/edit.html.erb | 2 +- app/views/stop_areas/show.html.erb | 2 +- spec/views/connection_links/show.html.erb_spec.rb | 2 +- spec/views/routes/show.html.erb_spec.rb | 2 +- spec/views/stop_areas/edit.html.erb_spec.rb | 2 +- spec/views/stop_areas/show.html.erb_spec.rb | 2 +- 11 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/maps/connection_link_map.rb b/app/maps/connection_link_map.rb index e915c3ae2..a6fb8517c 100644 --- a/app/maps/connection_link_map.rb +++ b/app/maps/connection_link_map.rb @@ -23,6 +23,10 @@ class ConnectionLinkMap < ApplicationMap end end + def ready? + Chouette::StopArea.bounds.present? + end + def bounds wgs84_bounds = Chouette::StopArea.bounds @bounds ||= OpenLayers::Bounds.new(wgs84_bounds.lower_corner.x, wgs84_bounds.lower_corner.y, wgs84_bounds.upper_corner.x, wgs84_bounds.upper_corner.y).transform(OpenLayers::Projection.new("EPSG:4326"), OpenLayers::Projection.new("EPSG:900913")) diff --git a/app/maps/route_map.rb b/app/maps/route_map.rb index 417b6037a..7cc525dde 100644 --- a/app/maps/route_map.rb +++ b/app/maps/route_map.rb @@ -22,12 +22,18 @@ class RouteMap < ApplicationMap end end + def ready? + route_bounds.present? + end + + def route_bounds + @route_bound ||= (route.geometry.empty? ? Chouette::StopArea.bounds : route.geometry.envelope) + end + def bounds - wgs84_bounds = ( route.geometry.empty?) ? Chouette::StopArea.bounds : route.geometry.envelope - @bounds ||= OpenLayers::Bounds.new( - wgs84_bounds.lower_corner.x, wgs84_bounds.lower_corner.y, - wgs84_bounds.upper_corner.x, wgs84_bounds.upper_corner.y). + route_bounds.lower_corner.x, route_bounds.lower_corner.y, + route_bounds.upper_corner.x, route_bounds.upper_corner.y). transform(OpenLayers::Projection.new("EPSG:4326"), OpenLayers::Projection.new("EPSG:900913")) end diff --git a/app/maps/stop_area_map.rb b/app/maps/stop_area_map.rb index 37ba77121..b7c060dce 100644 --- a/app/maps/stop_area_map.rb +++ b/app/maps/stop_area_map.rb @@ -40,6 +40,10 @@ EOF end end + def ready? + center.present? + end + def center stop_area.geometry or stop_area.default_position end diff --git a/app/views/connection_links/show.html.erb b/app/views/connection_links/show.html.erb index 273d9102e..abc2db3de 100644 --- a/app/views/connection_links/show.html.erb +++ b/app/views/connection_links/show.html.erb @@ -1,7 +1,7 @@ <%= title_tag t('connection_links.show.title', :connection_link => @connection_link.name ) %>