diff options
| author | Marc Florisson | 2012-06-01 12:20:57 +0200 |
|---|---|---|
| committer | Marc Florisson | 2012-06-01 12:20:57 +0200 |
| commit | ee866a45955bac5cef7a8bdec58f86ffcb7cb702 (patch) | |
| tree | e66d3da0e628034afc362b524b52a1a71977f4ff /app | |
| parent | 7fd20ad1409398e06fb1167332c57b4ac4c9aadc (diff) | |
| parent | 7082d66ec221aee194d64a17ab5d21eb2955f419 (diff) | |
| download | chouette-core-ee866a45955bac5cef7a8bdec58f86ffcb7cb702.tar.bz2 | |
Merge branch 'master' of chouette.dryade.priv:/srv/git/chouette2
Diffstat (limited to 'app')
27 files changed, 168 insertions, 53 deletions
diff --git a/app/assets/images/severity-error.png b/app/assets/images/severity-error.png Binary files differnew file mode 100644 index 000000000..516a4d61a --- /dev/null +++ b/app/assets/images/severity-error.png diff --git a/app/assets/images/severity-info.png b/app/assets/images/severity-info.png Binary files differnew file mode 100644 index 000000000..740170cb7 --- /dev/null +++ b/app/assets/images/severity-info.png diff --git a/app/assets/images/severity-warning.png b/app/assets/images/severity-warning.png Binary files differnew file mode 100644 index 000000000..661327276 --- /dev/null +++ b/app/assets/images/severity-warning.png 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 = $('<form method="post" action="' + href + '"></form>') + target = link.attr('target') + metadata_input = '<input name="_method" value="' + method + '" type="hidden" />' + if csrf_param? and csrf_token? + metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />' + 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/imports.css.scss b/app/assets/stylesheets/imports.css.scss index dda468465..bdc3a65cd 100644 --- a/app/assets/stylesheets/imports.css.scss +++ b/app/assets/stylesheets/imports.css.scss @@ -23,3 +23,15 @@ padding-right: 10px; } } + +#workspace.imports.show { + table { + th { + text-align: center; + font-style: italic; + } + td.message, td.created_at, td.position { + padding: 0 20px; + } + } +}
\ No newline at end of file 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/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 = {}) - "<div id=\"#{id}\" class=\"#{default_class}\"></div> #{map.to_html(options)}" + if not respond_to?(:ready?) or ready? + "<div id=\"#{id}\" class=\"#{default_class}\"></div> #{map.to_html(options)}".html_safe + end end def kml 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/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/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/models/import.rb b/app/models/import.rb index fd3fb139d..64b5b5624 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -9,6 +9,8 @@ class Import < ActiveRecord::Base attr_accessor :resources attr_accessor :loader + has_many :log_messages, :class_name => "ImportLogMessage", :order => :position, :dependent => :destroy + def loader @loader ||= ::Chouette::Loader.new(referential.slug) end @@ -26,7 +28,7 @@ class Import < ActiveRecord::Base self.status ||= "pending" end - after_create :import + after_create :delayed_import def delayed_import save_resources delay.import @@ -49,8 +51,13 @@ class Import < ActiveRecord::Base "#{root}/#{id}.zip" end + def name + "#{Import.model_name.humanize} #{id}" + end + def import begin + log_messages.create :key => :started if resources with_original_filename do |file| # chouette-command checks the file extension (and requires .zip) :( @@ -64,6 +71,7 @@ class Import < ActiveRecord::Base Rails.logger.error "Import #{id} failed : #{e}, #{e.backtrace}" update_attribute :status, "failed" end + log_messages.create :key => status end end diff --git a/app/models/import_log_message.rb b/app/models/import_log_message.rb new file mode 100644 index 000000000..699c9603d --- /dev/null +++ b/app/models/import_log_message.rb @@ -0,0 +1,36 @@ +class ImportLogMessage < ActiveRecord::Base + belongs_to :import + acts_as_list :scope => :import + + validates_presence_of :key + validates_inclusion_of :severity, :in => %w{info warning error} + + def arguments=(arguments) + write_attribute :arguments, (arguments.to_json if arguments.present?) + end + + def arguments + @decoded_arguments ||= + begin + if (stored_arguments = raw_attributes).present? + ActiveSupport::JSON.decode stored_arguments + else + {} + end + end + end + + def raw_attributes + read_attribute(:arguments) + end + + before_validation :define_default_attributes, :on => :create + def define_default_attributes + self.severity ||= "info" + end + + def full_message + I18n.translate key, arguments.symbolize_keys.merge(:scope => "import_log_messages.messages") + end + +end 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/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 ) %> <div class="connection_link_show"> - <%= @map.to_html.html_safe %> + <%= @map.to_html %> <div class="summary"> <p> diff --git a/app/views/imports/_import.erb b/app/views/imports/_import.erb index 643b3f18b..6ccd5bb23 100644 --- a/app/views/imports/_import.erb +++ b/app/views/imports/_import.erb @@ -1,8 +1,8 @@ <%= div_for(import) do %> - <%= link_to("#", :class => "preview") do %> + <%= link_to(referential_import_path(@referential, import), :class => "preview") do %> <%= image_tag "import-#{import.status}.png" %> <% end %> - <%= Import.model_name.humanize %> <%= import.id %> + <%= link_to(import.name, referential_import_path(@referential, import)) %> <div class="info"> <%= l import.created_at %> diff --git a/app/views/imports/show.html.erb b/app/views/imports/show.html.erb new file mode 100644 index 000000000..fe2c89a39 --- /dev/null +++ b/app/views/imports/show.html.erb @@ -0,0 +1,38 @@ +<%= title_tag @import.name %> + +<div class="import_show"> + <div class="summary"> + <p> + <label><%= Import.human_attribute_name(:created_at) %>: </label> + <%= l @import.created_at %> + </p> + <p> + <label><%= Import.human_attribute_name(:status) %>: </label> + <%= t @import.status, :scope => "imports.statuses" %> + </p> + </div> + + <h3><%= t(".report") %></h3> + <table> + <tr> + <th></th> + <th><%= ImportLogMessage.human_attribute_name(:created_at) %></th> + <th><%= ImportLogMessage.human_attribute_name(:position) %></th> + <th><%= ImportLogMessage.human_attribute_name(:full_message) %></th> + </tr> + <% @import.log_messages.each do |message| %> + <tr> + <td class="severity"><%= image_tag "severity-#{message.severity}.png", :alt => t(message.severity, :scope => "import_log_messages.severities") %></td> + <td class="created_at"><%= l message.created_at, :format => :short %></td> + <td class="position"><%= message.position %></td> + <td class="message"><%= message.full_message %></td> + </tr> + <% end %> + </table> +</div> + +<% content_for :sidebar do %> +<ul class="actions"> + <li><%= link_to t('imports.actions.destroy'), referential_import_path(@referential, @import), :method => :delete, :confirm => t('imports.actions.destroy_confirm'), :class => "remove" %></li> +</ul> +<% end %> 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 %> <div class="color"> <% if line.number and line.number.length <= 3 %> - <div class="number"><%= line.number %></div> + <div class="number"><%= line.number %></div> <% end %> - <%= check_box_tag "ids[]", line.id, false, :class => "multiple_selection", :style => "display: none;" %> </div> <% 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}" %> <div class="info"> <%= 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 @@ <a class="disable" href="#"><%= t(".multi_selection_disable") %></a> <ul class="actions"> - <li><a href="#" class="remove"><%= t(".delete_selected") %></a></li> + <%= link_to t(".delete_selected"), referential_lines_path(@referential), "data-multiple-method" => "delete", :class => "remove" %> <li><a href="#" class="export"><%= t(".export_selected") %></a></li> </ul> diff --git a/app/views/lines/show.html.erb b/app/views/lines/show.html.erb index 8d6157cc7..5e210ff5e 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 ) %> <div class="line_show"> - <%= @map.to_html.html_safe %> + <%= @map.to_html %> <div class="summary"> <p> diff --git a/app/views/networks/show.html.erb b/app/views/networks/show.html.erb index b11cde17d..8c68f7a31 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 )%> <div class="network_show"> - <%= @map.to_html.html_safe %> + <%= @map.to_html %> <div class="summary"> <p> <label><%= Chouette::Network.human_attribute_name("name") %>: </label> diff --git a/app/views/routes/show.html.erb b/app/views/routes/show.html.erb index 2ecbd0ada..72524846b 100644 --- a/app/views/routes/show.html.erb +++ b/app/views/routes/show.html.erb @@ -1,7 +1,7 @@ <%= title_tag t('routes.show.title', :route => @route.name, :line => @route.line.name ) %> <div class="route_show"> - <%= @map.to_html.html_safe %> + <%= @map.to_html %> <div class="summary"> <p> diff --git a/app/views/stop_areas/edit.html.erb b/app/views/stop_areas/edit.html.erb index be09d94e0..1ec77056d 100644 --- a/app/views/stop_areas/edit.html.erb +++ b/app/views/stop_areas/edit.html.erb @@ -1,5 +1,5 @@ <%= title_tag t('stop_areas.edit.title', :stop_area => @stop_area.name ) %> -<%= @map.to_html.html_safe %> +<%= @map.to_html %> <%= render "form" %> diff --git a/app/views/stop_areas/show.html.erb b/app/views/stop_areas/show.html.erb index 992a4050b..41d7576b5 100644 --- a/app/views/stop_areas/show.html.erb +++ b/app/views/stop_areas/show.html.erb @@ -1,7 +1,7 @@ <%= title_tag t('stop_areas.show.title', :stop_area => @stop_area.name ) %> <div class="stop_area_show"> - <%= @map.to_html.html_safe %> + <%= @map.to_html %> <div class="summary"> <p> <label><%= @stop_area.human_attribute_name("name") %>: </label> |
