diff options
| author | Alban Peignier | 2012-05-16 16:55:57 +0200 |
|---|---|---|
| committer | Alban Peignier | 2012-05-16 16:55:57 +0200 |
| commit | 39a4249b8c5197cfee6b8eb4673485628408e07a (patch) | |
| tree | 61619db5ea5e722b2c7752bbfc914f5a7a859fdd | |
| parent | a2260f9d3737188d22504f705825ed5a846bb861 (diff) | |
| download | chouette-core-39a4249b8c5197cfee6b8eb4673485628408e07a.tar.bz2 | |
Create first Imports. Refs #23
26 files changed, 251 insertions, 4 deletions
diff --git a/app/assets/images/import-completed.png b/app/assets/images/import-completed.png Binary files differnew file mode 100644 index 000000000..a76d76b13 --- /dev/null +++ b/app/assets/images/import-completed.png diff --git a/app/assets/images/import-failed.png b/app/assets/images/import-failed.png Binary files differnew file mode 100644 index 000000000..f13b19234 --- /dev/null +++ b/app/assets/images/import-failed.png diff --git a/app/assets/images/import-pending.png b/app/assets/images/import-pending.png Binary files differnew file mode 100644 index 000000000..1e50e36ac --- /dev/null +++ b/app/assets/images/import-pending.png diff --git a/app/assets/images/import.png b/app/assets/images/import.png Binary files differnew file mode 100644 index 000000000..351fe4215 --- /dev/null +++ b/app/assets/images/import.png diff --git a/app/assets/javascripts/imports.js.coffee b/app/assets/javascripts/imports.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/imports.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/imports.css.scss b/app/assets/stylesheets/imports.css.scss new file mode 100644 index 000000000..dda468465 --- /dev/null +++ b/app/assets/stylesheets/imports.css.scss @@ -0,0 +1,25 @@ +@import "common"; + +#workspace.imports.index +{ + .import:after { + @include after_div_for_object; + } + + .imports { + margin-top: 20px; + } + + .imports:after { + @include content_to_clear; + } + + .import { + @include div_for_object; + + /* to create multi-column index */ + width: 300px; + float: left; + padding-right: 10px; + } +} diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb new file mode 100644 index 000000000..7e33b8c26 --- /dev/null +++ b/app/controllers/imports_controller.rb @@ -0,0 +1,17 @@ +class ImportsController < ChouetteController + respond_to :html, :xml, :json + belongs_to :referential + + def create + create! do |success, failure| + success.html { redirect_to referential_imports_path(@referential) } + end + end + + protected + + def collection + @imports ||= end_of_association_chain.paginate(:page => params[:page]) + end + +end diff --git a/app/helpers/imports_helper.rb b/app/helpers/imports_helper.rb new file mode 100644 index 000000000..2811dcbec --- /dev/null +++ b/app/helpers/imports_helper.rb @@ -0,0 +1,2 @@ +module ImportsHelper +end diff --git a/app/models/import.rb b/app/models/import.rb new file mode 100644 index 000000000..a2a7e9afa --- /dev/null +++ b/app/models/import.rb @@ -0,0 +1,44 @@ +class Import < ActiveRecord::Base + belongs_to :referential + + validates_presence_of :referential_id + validates_presence_of :resources + + validates_inclusion_of :status, :in => %w{ pending completed failed } + + attr_accessor :resources + attr_accessor :loader + + def loader + @loader ||= ::Chouette::Loader.new(referential.slug) + 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 + + before_validation :define_default_attributes, :on => :create + def define_default_attributes + self.status ||= "pending" + end + + after_create :import + def import + begin + with_original_filename do |file| + # chouette-command checks the file extension (and requires .zip) :( + loader.import file + end + update_attribute :status, "completed" + rescue + update_attribute :status, "failed" + end + end + + + +end diff --git a/app/models/referential.rb b/app/models/referential.rb index 8faeea170..84640e43c 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -2,6 +2,8 @@ class Referential < ActiveRecord::Base validates_presence_of :name validates_presence_of :slug + has_many :imports, :dependent => :destroy + def lines Chouette::Line.scoped end diff --git a/app/views/imports/_import.erb b/app/views/imports/_import.erb new file mode 100644 index 000000000..643b3f18b --- /dev/null +++ b/app/views/imports/_import.erb @@ -0,0 +1,13 @@ +<%= div_for(import) do %> + <%= link_to("#", :class => "preview") do %> + <%= image_tag "import-#{import.status}.png" %> + <% end %> + <%= Import.model_name.humanize %> <%= import.id %> + <div class="info"> + <%= l import.created_at %> + + <div class="actions"> + <%= link_to t("actions.destroy"), referential_import_path(@referential, import), :method => :delete, :confirm => t('imports.actions.destroy_confirm'), :class => "remove" %> + </div> + </div> +<% end %> diff --git a/app/views/imports/index.html.erb b/app/views/imports/index.html.erb new file mode 100644 index 000000000..9bda3ffb5 --- /dev/null +++ b/app/views/imports/index.html.erb @@ -0,0 +1,20 @@ +<%= title_tag t('.title') %> + +<div class="pagination"> + <div class="page_info"> + <%= page_entries_info @imports %> + </div> + <%= will_paginate @imports, :container => false %> +</div> +<div class="imports paginated_content"> + <%= render @imports %> +</div> +<div class="pagination"> + <%= will_paginate @imports, :container => false %> +</div> + +<% content_for :sidebar do %> +<ul class="actions"> + <li><%= link_to t('imports.actions.new'), new_referential_import_path(@referential), :class => "add" %></li> +</ul> +<% end %> diff --git a/app/views/imports/new.html.erb b/app/views/imports/new.html.erb new file mode 100644 index 000000000..0d1c54202 --- /dev/null +++ b/app/views/imports/new.html.erb @@ -0,0 +1,13 @@ +<%= title_tag t(".title") %> + +<%= semantic_form_for [@referential, @import] do |form| %> + <%= form.inputs do %> + <%= form.input :resources, :as => :file %> + <% end %> + + <%= form.buttons do %> + <%= form.commit_button true %> + <li><%= t('or') %></li> + <li><%= link_to t('back'), :back %></li> + <% end %> +<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index d757c92d4..110594cb5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -43,6 +43,8 @@ <li><%= tab_link_to Chouette::StopArea, referential_stop_areas_path(@referential) %></li> <li><%= tab_link_to Chouette::ConnectionLink, referential_connection_links_path(@referential) %></li> <li><%= tab_link_to Chouette::TimeTable, referential_time_tables_path(@referential) %></li> + + <li><%= tab_link_to Import, referential_imports_path(@referential) %></li> <% end %> </ul> </div> diff --git a/app/views/lines/index.html.erb b/app/views/lines/index.html.erb index 26b97e0b3..af9ab9ad9 100644 --- a/app/views/lines/index.html.erb +++ b/app/views/lines/index.html.erb @@ -23,7 +23,6 @@ </p> <% end %> - <div class="pagination"> <div class="page_info"> <%= page_entries_info @lines %> @@ -42,6 +41,10 @@ <li><%= link_to t('lines.actions.new'), new_referential_line_path(@referential), :class => "add" %></li> </ul> +<ul class="actions"> + <li><%= link_to t('lines.actions.import'), new_referential_import_path(@referential), :class => "import" %></li> +</ul> + <h3><%= t(".selection") %></h3> <h4><%= Chouette::Company.model_name.human.pluralize %></h4> diff --git a/config/environments/development.rb b/config/environments/development.rb index 5608f1b7b..b6fd603a1 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -31,8 +31,12 @@ ChouetteIhm::Application.configure do config.action_mailer.default_url_options = { :host => 'localhost:3000' } config.to_prepare do - Chouette::Loader.chouette_command = "true" - Chouette::Loader.chouette_command = "/var/lib/chouette/chouette.sh" + chouette_command_script = "tmp/chouette-command/chouette" + if File.exists? chouette_command_script + Chouette::Loader.chouette_command = "tmp/chouette-command/chouette" + else + Chouette::Loader.chouette_command = "true" + end end end diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index 542d7a956..eaecaeac5 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -1,6 +1,6 @@ Apartment.configure do |config| # set your options (described below) here - config.excluded_models = ["Referential", "User"] # these models will not be multi-tenanted, but remain in the global (public) namespace + config.excluded_models = ["Referential", "User", "Import"] # these models will not be multi-tenanted, but remain in the global (public) namespace # Dynamically get database names to migrate config.database_names = lambda{ Referential.select(:slug).map(&:slug) } diff --git a/config/locales/imports.yml b/config/locales/imports.yml new file mode 100644 index 000000000..2c30e30d6 --- /dev/null +++ b/config/locales/imports.yml @@ -0,0 +1,28 @@ +en: + imports: + actions: + new: New import + destroy: Destroy + destroy_confirm: Are you sure you want destroy this import? + new: + title: New import + index: + title: Imports + activerecord: + attributes: + import: + resources: File to import +fr: + imports: + actions: + new: Nouvel import + destroy: Supprimer + destroy_confirm: Etes vous sûr de détruire cet import ? + new: + title: Nouvel import + index: + title: Imports + activerecord: + attributes: + import: + resources: Fichier à importer diff --git a/config/locales/lines.yml b/config/locales/lines.yml index 7e565f24b..3d7cf583b 100644 --- a/config/locales/lines.yml +++ b/config/locales/lines.yml @@ -5,6 +5,7 @@ en: edit: Edit this line destroy: Remove this line destroy_confirm: Are you sure you want destroy this line? + import: Import lines new: title: Add a new line edit: @@ -47,6 +48,7 @@ fr: edit: Modifier cette ligne destroy: Supprimer cette ligne destroy_confirm: Etes vous sûr de détruire cette ligne ? + import: Importer des lignes new: title: Ajouter une ligne edit: diff --git a/config/routes.rb b/config/routes.rb index 491d16b43..399bae472 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,8 @@ ChouetteIhm::Application.routes.draw do + get "imports/new" + + get "imports/index" + devise_for :users # The priority is based upon order of creation: @@ -27,6 +31,8 @@ ChouetteIhm::Application.routes.draw do resources :routes end + resources :imports + resources :companies, :stop_areas resources :time_tables do diff --git a/db/migrate/20120515134710_create_imports.rb b/db/migrate/20120515134710_create_imports.rb new file mode 100644 index 000000000..5da398fc9 --- /dev/null +++ b/db/migrate/20120515134710_create_imports.rb @@ -0,0 +1,11 @@ +class CreateImports < ActiveRecord::Migration + def change + create_table :imports do |t| + t.belongs_to :referential + t.string :status + + t.timestamps + end + add_index :imports, :referential_id + end +end diff --git a/spec/controllers/imports_controller_spec.rb b/spec/controllers/imports_controller_spec.rb new file mode 100644 index 000000000..93640684a --- /dev/null +++ b/spec/controllers/imports_controller_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe ImportsController do + login_user + + describe "GET 'new'" do + it "returns http success" do + get 'new' + response.should be_success + end + end + + describe "GET 'index'" do + it "returns http success" do + get 'index' + response.should be_success + end + end + +end diff --git a/spec/helpers/imports_helper_spec.rb b/spec/helpers/imports_helper_spec.rb new file mode 100644 index 000000000..8e5ec0c86 --- /dev/null +++ b/spec/helpers/imports_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the ImportsHelper. For example: +# +# describe ImportsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe ImportsHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/import_spec.rb b/spec/models/import_spec.rb new file mode 100644 index 000000000..734445b8b --- /dev/null +++ b/spec/models/import_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe Import do + + + +end diff --git a/spec/views/imports/index.html.erb_spec.rb b/spec/views/imports/index.html.erb_spec.rb new file mode 100644 index 000000000..c0f2d3462 --- /dev/null +++ b/spec/views/imports/index.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "imports/index.html.erb" do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/imports/new.html.erb_spec.rb b/spec/views/imports/new.html.erb_spec.rb new file mode 100644 index 000000000..a31539279 --- /dev/null +++ b/spec/views/imports/new.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "imports/new.html.erb" do + pending "add some examples to (or delete) #{__FILE__}" +end |
