aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2015-02-25 12:02:00 +0100
committerLuc Donnet2015-02-25 12:02:00 +0100
commit0adee77238b5c70bcf518e939e16136f3a481493 (patch)
tree3c11a8b5b43abd851e7fe014575355839990892b
parent6fdfb5e292994215a663349d17e349ce5ed1db29 (diff)
downloadchouette-core-0adee77238b5c70bcf518e939e16136f3a481493.tar.bz2
Initialize import index access from IEV server
-rw-r--r--Gemfile5
-rw-r--r--Gemfile.lock20
-rw-r--r--app/controllers/imports_controller.rb20
-rw-r--r--app/helpers/imports_helper.rb19
-rw-r--r--app/models/import.rb55
-rw-r--r--app/views/imports/_import.erb26
-rw-r--r--app/views/imports/_imports.html.erb9
-rw-r--r--app/views/imports/index.html.erb12
-rw-r--r--app/views/imports/index.js.erb1
-rw-r--r--app/views/shared/_header.erb2
-rw-r--r--config/locales/imports.yml208
-rw-r--r--config/routes.rb6
-rw-r--r--lib/iev_api/client.rb12
13 files changed, 365 insertions, 30 deletions
diff --git a/Gemfile b/Gemfile
index 849c167f0..a2f81cf28 100644
--- a/Gemfile
+++ b/Gemfile
@@ -88,7 +88,7 @@ gem 'raphael-rails'
# Use twitter bootstrap resources
gem 'rails-assets-bootstrap-sass-official', '~> 3.3.0'
gem 'font-awesome-sass', '~> 4.2.0'
-gem 'will_paginate-bootstrap'
+gem 'will_paginate-bootstrap', '~> 1.0.1'
gem 'simple_form', '~> 3.1.0'
gem 'rails-assets-tagmanager', '~> 3.0.1.0'
gem 'rails-assets-typeahead.js', '~> 0.10.5'
@@ -108,9 +108,10 @@ gem 'inherited_resources'
gem 'google-analytics-rails'
# Model
-gem 'will_paginate', '~> 3.0', :git => "https://github.com/mislav/will_paginate.git"
+gem 'will_paginate', '~> 3.0.7'
gem 'ransack'
gem 'squeel'
+gem 'enumerize', '~> 0.10.0'
gem 'ninoxe', :git => 'https://github.com/afimb/ninoxe.git', :branch => "rails4"
#gem 'ninoxe', :git => 'https://github.com/afimb/ninoxe.git'
diff --git a/Gemfile.lock b/Gemfile.lock
index fd52a11bb..13bbe6635 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/afimb/ninoxe.git
- revision: e0fa5fccbaf2b9d45d37e61fe2d41a65c51064b2
+ revision: 05544f2d54436a7acb2985089790d071798f4de5
branch: rails4
specs:
ninoxe (1.1.3)
@@ -9,16 +9,10 @@ GIT
acts_as_list (>= 0.1.6)
acts_as_tree (>= 1.1.0)
deep_cloneable (~> 2.0.0)
- enumerize (~> 0.8.0)
+ enumerize (~> 0.10.0)
foreigner (= 1.6.0)
georuby-ext (= 0.0.5)
-GIT
- remote: https://github.com/mislav/will_paginate.git
- revision: 74a6cd0197072903cd8b83744133744ff4b4c046
- specs:
- will_paginate (3.0.4)
-
GEM
remote: http://rubygems.org/
remote: https://rails-assets.org/
@@ -132,7 +126,7 @@ GEM
diff-lcs (1.2.5)
dr-ffi-proj4 (0.0.3)
ffi (>= 1.0.0)
- enumerize (0.8.0)
+ enumerize (0.10.0)
activesupport (>= 3.2)
erubis (2.7.0)
execjs (2.2.2)
@@ -441,7 +435,8 @@ GEM
websocket-driver (0.5.1-java)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.1)
- will_paginate-bootstrap (1.0.0)
+ will_paginate (3.0.7)
+ will_paginate-bootstrap (1.0.1)
will_paginate (>= 3.0.3)
xpath (2.0.0)
nokogiri (~> 1.3)
@@ -471,6 +466,7 @@ DEPENDENCIES
devise-encryptable
devise-i18n
devise_invitable
+ enumerize (~> 0.10.0)
factory_girl_rails (~> 4.0)
faraday (~> 0.9.1)
faraday_middleware (~> 0.9.1)
@@ -530,5 +526,5 @@ DEPENDENCIES
turbolinks
uglifier (>= 1.3.0)
warbler
- will_paginate (~> 3.0)!
- will_paginate-bootstrap
+ will_paginate (~> 3.0.7)
+ will_paginate-bootstrap (~> 1.0.1)
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb
new file mode 100644
index 000000000..14e7a9b95
--- /dev/null
+++ b/app/controllers/imports_controller.rb
@@ -0,0 +1,20 @@
+require 'will_paginate/array'
+
+class ImportsController < ChouetteController
+ respond_to :html, :xml, :json
+ respond_to :js, :only => [:show, :index]
+ belongs_to :referential
+
+ protected
+
+ def test
+ test = IevApi.jobs(@referential.slug, { :action => "importer" }).map do |import_hash|
+ Import.new(import_hash)
+ end
+ end
+
+ def collection
+ @imports ||= test.paginate(:page => params[:page])
+ end
+
+end
diff --git a/app/helpers/imports_helper.rb b/app/helpers/imports_helper.rb
index fbb9c13df..42db85b43 100644
--- a/app/helpers/imports_helper.rb
+++ b/app/helpers/imports_helper.rb
@@ -26,28 +26,23 @@ module ImportsHelper
end
end
- def import_progress_bar_tag(export)
+ def import_progress_bar_tag(import)
- if export.status == "failed"
+ if import.canceled? || import.aborted?
div_class = "progress-bar progress-bar-danger"
- percentage_progress = "100"
- elsif export.status == "pending"
+ elsif import.scheduled?
div_class = "progress-bar progress-bar-info"
- percentage_progress = "10"
- elsif export.status == "processing"
+ elsif import.created?
div_class = "progress-bar progress-bar-info"
- percentage_progress = "50"
- elsif export.status == "completed"
+ elsif import.terminated?
div_class = "progress-bar progress-bar-success"
- percentage_progress = "100"
else
div_class = ""
- percentage_progress = ""
end
content_tag :div, :class => "progress" do
- content_tag :div, :class => div_class, role: "progressbar", :'aria-valuenow' => percentage_progress, :'aria-valuemin' => "0", :'aria-valuemax' => "100", :style => "width: #{percentage_progress}%;" do
- percentage_progress + "% " + I18n.t("exports.statuses.#{export.status}")
+ content_tag :div, :class => div_class, role: "progressbar", :'aria-valuenow' => "#{import.percentage_progress}", :'aria-valuemin' => "0", :'aria-valuemax' => "100", :style => "width: #{import.percentage_progress}%;" do
+ "#{import.percentage_progress}% " + I18n.t("import_tasks.statuses.#{import.import_status}")
end
end
diff --git a/app/models/import.rb b/app/models/import.rb
new file mode 100644
index 000000000..526d77783
--- /dev/null
+++ b/app/models/import.rb
@@ -0,0 +1,55 @@
+class Import
+ extend Enumerize
+ extend ActiveModel::Naming
+ include ActiveModel::Model
+
+ enumerize :import_status, in: %w{created scheduled terminated canceled aborted}, default: "created", predicates: true
+ enumerize :import_format, in: %w{neptune netex gtfs}, default: "neptune", predicates: true
+
+ attr_reader :datas
+
+ def initialize(options=Hashie::Mash.new)
+ @datas = options
+ @import_status = @datas.status.downcase if @datas.status
+ @import_format = @datas.type.downcase
+ end
+
+ def percentage_progress
+ if %w{created}.include? import_status
+ 0
+ elsif %w{ terminated canceled aborted }.include? import_status
+ 100
+ else
+ 20
+ end
+ end
+
+ def links
+ @datas.links
+ end
+
+ def name
+ @datas.parameters.name
+ end
+
+ def user_name
+ @datas.parameters.user_name
+ end
+
+ def no_save
+ @datas.parameters.no_save
+ end
+
+ def filename
+ @datas.filename
+ end
+
+ def created_at
+ Time.at(@datas.created.to_i / 1000)
+ end
+
+ def updated_at
+ Time.at(@datas.updated.to_i / 1000)
+ end
+
+end
diff --git a/app/views/imports/_import.erb b/app/views/imports/_import.erb
new file mode 100644
index 000000000..8b6889aa4
--- /dev/null
+++ b/app/views/imports/_import.erb
@@ -0,0 +1,26 @@
+<div id="index_item" class="panel panel-default">
+ <div class="panel-heading">
+ <div class="panel-title clearfix">
+ <span class="pull-right">
+ <%= link_to "#{Rails.application.config.iev_url}#{import.datas.links[4].href}", :method => :delete, :data => {:confirm => t('import_tasks.actions.destroy_confirm')}, :class => "btn btn-danger btn-sm" do %>
+ <span class="fa fa-trash-o"></span>
+ <% end %>
+ </span>
+ <h5>
+ <%= link_to( "#{Rails.application.config.iev_url}#{import.datas.links[3].href}", :class => "preview", :title => "#{ImportTask.model_name.human.capitalize} #{import.name}") do %>
+ <span class="name">
+ <% if !import.no_save %><i class="fa fa-save"></i><% end %> <%= truncate(import.name, :length => 20) %>
+ </span>
+ <% end %>
+ </h5>
+ </div>
+ </div>
+ <div class="panel-body">
+ </div>
+ <div class="panel-footer">
+ <%= import_progress_bar_tag(import) %>
+ <div class="history">
+ <%= l import.created_at, :format => "%d/%m/%Y %H:%M" %> | <%= import.user_name %>
+ </div>
+ </div>
+</div>
diff --git a/app/views/imports/_imports.html.erb b/app/views/imports/_imports.html.erb
new file mode 100644
index 000000000..51d1c02b2
--- /dev/null
+++ b/app/views/imports/_imports.html.erb
@@ -0,0 +1,9 @@
+<div class="page_info">
+ <span class="search"> <%= t("will_paginate.page_entries_info.search") %></span> <%= page_entries_info @imports %>
+</div>
+<div class="imports paginated_content">
+ <%= paginated_content @imports %>
+</div>
+<div class="pagination">
+ <%= will_paginate @imports, :container => false, renderer: RemoteBootstrapPaginationLinkRenderer %>
+</div>
diff --git a/app/views/imports/index.html.erb b/app/views/imports/index.html.erb
new file mode 100644
index 000000000..32bb6fe27
--- /dev/null
+++ b/app/views/imports/index.html.erb
@@ -0,0 +1,12 @@
+<%= title_tag t('.title') %>
+<div class="warning"><%= t('.warning') %> </div>
+
+<div id="imports"><%= render 'imports' %></div>
+
+
+<% content_for :sidebar do %>
+<ul class="actions">
+ <li><%= link_to t('imports.actions.new'), new_referential_import_path(@referential), :class => "add" %></li>
+ <li><%= link_to t('rule_parameter_sets.actions.index'), referential_rule_parameter_sets_path(@referential), :class => "link" %></li>
+</ul>
+<% end %>
diff --git a/app/views/imports/index.js.erb b/app/views/imports/index.js.erb
new file mode 100644
index 000000000..1207b18ce
--- /dev/null
+++ b/app/views/imports/index.js.erb
@@ -0,0 +1 @@
+$('#imports').html('<%= escape_javascript(render("imports")) %>'); \ No newline at end of file
diff --git a/app/views/shared/_header.erb b/app/views/shared/_header.erb
index e0d4e9c92..d90117859 100644
--- a/app/views/shared/_header.erb
+++ b/app/views/shared/_header.erb
@@ -67,7 +67,7 @@
</li>
</ul>
</li>
- <li><%= link_to Referential.human_attribute_name("import_tasks"), referential_import_tasks_path(@referential) %></li>
+ <li><%= link_to Referential.human_attribute_name("imports"), referential_imports_path(@referential) %></li>
<li><%= link_to Referential.human_attribute_name("export_tasks"), referential_exports_path(@referential) %></li>
<li><%= link_to Referential.human_attribute_name("compliance_check_tasks"), referential_compliance_check_tasks_path(@referential) %></li>
<% end %>
diff --git a/config/locales/imports.yml b/config/locales/imports.yml
new file mode 100644
index 000000000..e49263520
--- /dev/null
+++ b/config/locales/imports.yml
@@ -0,0 +1,208 @@
+en:
+ imports:
+ actions:
+ new: "New import"
+ destroy: "Destroy"
+ destroy_confirm: "Are you sure you want destroy this import?"
+ new:
+ title: "New import"
+ all: "All"
+ flash: "Import task on queue, refresh page to see progression"
+ fields_gtfs_import:
+ warning: "Filter on stop areas import only GTFS stops and transfers files, these may contain extra attributes"
+ index:
+ title: "Imports"
+ warning: ""
+ show:
+ report: "Report"
+ not_yet_started: "On queue"
+ imported_file: "Imported file"
+ completed: "[ Completed ]"
+ failed: "[ Failed ]"
+ pending: "[ In the treatment queue ]"
+ processing: "[ In progress... ]"
+ graph:
+ files:
+ title_zip: "Import results for files in zip"
+ title_default: "Import result for %{extension} file"
+ error: "Errors"
+ ignored: "Ignored"
+ ok: "Success"
+ lines:
+ title: "Imported objects"
+ objects_label: "Objects count"
+ lines_stats: "Lines"
+ routes_stats: "Routes"
+ connection_links_stats: "Connection Links"
+ time_tables_stats: "Timetables"
+ stop_areas_stats: "Stop Areas"
+ access_points_stats: "Access Points"
+ vehicle_journeys_stats: "Vehicle Journeys"
+ journey_patterns_stats: "Journey Patterns"
+ statuses:
+ created: "Pending ..."
+ scheduled: "Processing ..."
+ terminated: "Completed"
+ canceled: "Canceled"
+ aborted: "Failed"
+ compliance_check_task: "Validate Report"
+ severities:
+ info: "Information"
+ uncheck: "Unchecked"
+ ok: "Ok"
+ warning: "Warning"
+ error: "Error"
+ fatal: "Fatal"
+ activerecord:
+ models:
+ import:
+ zero: "import"
+ one: "import"
+ other: "imports"
+ neptune_import:
+ zero: "import"
+ one: "Neptune import"
+ other: "imports"
+ csv_import:
+ zero: "import"
+ one: "CSV import"
+ other: "imports"
+ gtfs_import:
+ zero: "import"
+ one: "GTFS import"
+ other: "imports"
+ netex_import:
+ zero: "import"
+ one: "NeTEx import"
+ other: "imports"
+ attributes:
+ import:
+ resources: "File to import"
+ created_at: "Created on"
+ status: "Status"
+ references_type: "subset"
+ no_save: "No save"
+ rule_parameter_set_id: "Rule parameter set for compliance check"
+ object_id_prefix: "Neptune Id prefix"
+ max_distance_for_commercial: "Max distance for commercial stop"
+ max_distance_for_connection_link: "Max distance for connection link"
+ ignore_last_word: "ignore last word"
+ ignore_end_chars: "ignore last chars"
+ formtastic:
+ titles:
+ import:
+ max_distance_for_commercial: "Maximal distance to merge homonymous stops in commercial stop in meter"
+ max_distance_for_connection_link: "Maximal distance to link stops by connection link stop in meter"
+ ignore_last_word: "ignore last word on stop name in homonymous detection (inappliable when just one word occurs)"
+ ignore_end_chars: "ignore some chars at the end of stop names in homonymous detection"
+fr:
+ imports:
+ actions:
+ new: "Nouvel import"
+ destroy: "Supprimer cet import"
+ destroy_confirm: "Etes vous sûr de supprimer cet import ?"
+ new:
+ title: "Nouvel import"
+ all: "Tout"
+ flash: "La demande d'import est mise en file d'attente, veuillez rafraichir régulièrement la page pour en suivre la progression"
+ fields_gtfs_import:
+ warning: "Le filtre sur arrêts importe uniquement les fichiers GTFS stops et transfers gtfs, ceux-ci pouvant contenir des attributs supplémentaires"
+ index:
+ title: "Imports"
+ warning: ""
+ show:
+ report: "Rapport"
+ not_yet_started: "En file d'attente"
+ imported_file: "Fichier importé"
+ completed: "[ Terminé ]"
+ failed: "[ Echoué ]"
+ pending: "[ En file d'attente ]"
+ processing: "[ En progression... ]"
+ graph:
+ files:
+ title_zip: "Résultat d'import des fichiers du zip"
+ title_default: "Résultat d'import du fichier %{extension}"
+ error: "Erreurs"
+ ignored: "Ignorés"
+ ok: "Succès"
+ lines:
+ title: "Volume de données lues par type de donnée"
+ objects_label: "Quantité lue"
+ lines_stats: "Lignes"
+ routes_stats: "Séquences d'arrêts"
+ connection_links_stats: "Correspondances"
+ time_tables_stats: "Calendriers"
+ stop_areas_stats: "Zones d'arrèt"
+ access_points_stats: "Accès"
+ vehicle_journeys_stats: "Courses"
+ journey_patterns_stats: "Missions"
+ table:
+ line:
+ name: "Nom"
+ save: "Sauvegarde"
+ routes: "Séquences d'arrêts"
+ connection_links: "Correspondances"
+ time_tables: "Calendriers"
+ stop_areas: "Zones d'arrèt"
+ access_points: "Accès"
+ vehicle_journeys: "Courses"
+ journey_patterns: "Missions"
+ not_saved: "Non Sauvé"
+ saved: "Sauvé"
+ save_error: "Sauvegarde en erreur"
+ statuses:
+ created: "En attente ..."
+ scheduled: "En cours ..."
+ terminated: "Achevé"
+ canceled: "Annulé"
+ aborted: "Echoué"
+ compliance_check_task: "Validation"
+ severities:
+ info: "Information"
+ uncheck: "Non testé"
+ ok: "Ok"
+ warning: "Alerte"
+ error: "Erreur"
+ fatal: "Fatal"
+ activerecord:
+ models:
+ import:
+ zero: "import"
+ one: "import"
+ other: "imports"
+ neptune_import:
+ zero: "import"
+ one: "import Neptune"
+ other: "imports"
+ csv_import:
+ zero: "import"
+ one: "import CSV"
+ other: "imports"
+ gtfs_import:
+ zero: "import"
+ one: "import GTFS"
+ other: "imports"
+ netex_import:
+ zero: "import"
+ one: "import NeTEx"
+ other: "imports"
+ attributes:
+ import:
+ resources: "Fichier à importer"
+ created_at: "Créé le"
+ status: "Status"
+ no_save: "Pas de sauvegarde"
+ references_type: "Sous ensemble"
+ rule_parameter_set_id: "Jeu de paramètres pour validation"
+ object_id_prefix: "Préfixe d'identifiants"
+ max_distance_for_commercial: "Distance max pour créer les zones"
+ max_distance_for_connection_link: "Distance max pour créer les correspondances"
+ ignore_last_word: "ignorer le dernier mot"
+ ignore_end_chars: "ignorer les n derniers caractères"
+ formtastic:
+ titles:
+ import:
+ max_distance_for_commercial: "Distance maximale entre deux arrêts homonymes pour créer les zones d'arrêt (en mètre)"
+ max_distance_for_connection_link: "Distance maximale entre deux arrêts pour créer les correspondances (en mètre)"
+ ignore_last_word: "Ignorer le dernier mot pour détecter l'homonymie des noms d'arrêt (inapplicable quand le nom ne comporte qu'un mot)"
+ ignore_end_chars: "Ignorer les n derniers caractères du nom de l'arrêt pour détecter l'homonymie"
diff --git a/config/routes.rb b/config/routes.rb
index b7680e1d2..93b1b2303 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -86,6 +86,12 @@ ChouetteIhm::Application.routes.draw do
end
end
+ resources :imports do
+ member do
+ get 'file_to_import'
+ end
+ end
+
resources :exports do
collection do
get 'references'
diff --git a/lib/iev_api/client.rb b/lib/iev_api/client.rb
index 11a39dd10..9fb9c94c3 100644
--- a/lib/iev_api/client.rb
+++ b/lib/iev_api/client.rb
@@ -3,6 +3,9 @@ module IevApi
PER_PAGE = 12
PARALLEL_WORKERS = 10
+ ACTIONS = %w{ importer exporter validator }
+ IMPORT_FORMAT = %w{ neptune netex gtfs }
+ EXPORT_FORMAT = %w{ neptune netex gtfs hub kml }
attr_accessor *IevApi::Configuration::VALID_OPTIONS_KEYS
@@ -61,13 +64,16 @@ module IevApi
# Perform an HTTP request
def request(method, path, params = {}, options = {})
-
+
+ action_and_format = (params[:action].present? && params[:format].present?) ? "/#{params[:action]}/#{params[:format]}" : ""
+ build_path = connection.path_prefix + path + action_and_format
+ puts build_path.inspect
response = connection(options).run_request(method, nil, nil, nil) do |request|
case method
when :delete, :get
- request.url(connection.path_prefix + path, params)
+ request.url(build_path, params)
when :post, :put
- request.url(connection.path_prefix + path)
+ request.url(build_path)
request.body = params unless params.empty?
end
end