apidae 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0603f295a6946a070d13d9a70813840de04bc155
4
- data.tar.gz: 9e15a59b156bad347b5d0cec0625fdb6ddca2c38
3
+ metadata.gz: 31b78ff6495e0ea74d29caaed66d76b83523d88c
4
+ data.tar.gz: 59baa0f6635975e9853087ec0a270d7aa53e25a7
5
5
  SHA512:
6
- metadata.gz: 960c0cc9dcbbca0b5a290b4d44b60ca10b81271b55050d27ac6d279680d77233221720e117f5b2d7193824856e75d8cf842880625cda9d6b7a29fc94bde2b05b
7
- data.tar.gz: 4dacb5596fad4f0824c76e1a2f4fd9f124f12399fbd753401e5ff3deea084b12ca087e83985dea9e7c5e9e3ee0725a315af69417a205ae7d8f9a186734b1e871
6
+ metadata.gz: 75220b103c72f0b97a8f4c1be7f3d7c190c20ddc6485ddc64c365a667d7ecb43b9f5021f162849a47f81cd241e78883551c480a911b3a550383276e12c248cdb
7
+ data.tar.gz: ef1e4fb867c8b0945b73914b3d0d69540b45ad87c0d8fa65fd59cf4a071afa7a98d744fb42e47629451ceef3007d329ed1e269181e6c27ef6418254c367d5bc2
@@ -13,3 +13,12 @@
13
13
  *= require_tree .
14
14
  *= require_self
15
15
  */
16
+
17
+ #apidae_imports_panel > a:first-child {
18
+ float: right;
19
+ }
20
+
21
+ #apidae_form label {
22
+ font-size: 18px;
23
+ margin-right: 1rem;
24
+ }
@@ -16,7 +16,6 @@ module Apidae
16
16
  @objects = SelectionObject.where(apidae_selection_id: selections.map {|s| s.id}.uniq).map {|so| so.apidae_object_id}.uniq.count
17
17
  @last_imports = FileImport.where(apidae_id: apidae_user.apidae_projects_ids).order(id: :desc).take(100)
18
18
  end
19
- @references = Reference.count
20
19
  end
21
20
  end
22
21
  end
@@ -37,34 +37,62 @@ module Apidae
37
37
  def run
38
38
  success = true
39
39
  Export.pending.each do |e|
40
- begin
41
- open(e.file_url) do |f|
42
- begin
43
- FileImport.import(f, e.project_id)
40
+ success &&= import_data(e)
41
+ end
42
+ success ? head(:ok) : head(:internal_server_error)
43
+ end
44
+
45
+ def new
46
+ @export = Export.new(status: Export::PENDING)
47
+ end
48
+
49
+ def create
50
+ @export = Export.new(export_params)
51
+ if @export.save && import_data(@export)
52
+ redirect_to apidae.root_url, notice: 'Le fichier a bien été importé.'
53
+ else
54
+ flash.now[:alert] = "Une erreur s'est produite lors de l'import du fichier."
55
+ render :new
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def export_params
62
+ params.require(:export).permit(:project_id, :file_url, :status)
63
+ end
64
+
65
+ def import_data(e)
66
+ success = true
67
+ begin
68
+ open(e.file_url) do |f|
69
+ begin
70
+ FileImport.import(f, e.project_id)
71
+ unless e.confirm_url.blank?
44
72
  uri = URI(e.confirm_url)
45
73
  req = Net::HTTP::Post.new(uri)
46
74
  Net::HTTP.start(uri.hostname, uri.port) do |http|
47
75
  http.request(req)
48
76
  end
49
- e.update(status: Export::COMPLETE)
50
- if Rails.application.config.respond_to?(:apidae_import_callback)
51
- Rails.application.config.apidae_import_callback.call(e)
52
- end
53
- rescue Exception => ex
54
- logger.error("Failed to import export file : #{e.file_url}")
55
- logger.error("Error is : #{ex} \n#{ex.backtrace.join("\n") unless ex.backtrace.blank?}")
56
- success = false
57
- e.update(status: Export::CANCELLED)
58
77
  end
78
+ e.update(status: Export::COMPLETE)
79
+ if Rails.application.config.respond_to?(:apidae_import_callback)
80
+ Rails.application.config.apidae_import_callback.call(e)
81
+ end
82
+ rescue Exception => ex
83
+ logger.error("Failed to import export file : #{e.file_url}")
84
+ logger.error("Error is : #{ex} \n#{ex.backtrace.join("\n") unless ex.backtrace.blank?}")
85
+ success = false
86
+ e.update(status: Export::CANCELLED)
59
87
  end
60
- rescue OpenURI::HTTPError => err
61
- logger.error("Failed to download export file : #{e.file_url}")
62
- logger.error("Error is : #{err}")
63
- success = false
64
- e.update(status: Export::CANCELLED)
65
88
  end
89
+ rescue OpenURI::HTTPError => err
90
+ logger.error("Failed to download export file : #{e.file_url}")
91
+ logger.error("Error is : #{err}")
92
+ success = false
93
+ e.update(status: Export::CANCELLED)
66
94
  end
67
- success ? head(:ok) : head(:internal_server_error)
95
+ success
68
96
  end
69
97
  end
70
98
  end
@@ -5,6 +5,8 @@ module Apidae
5
5
  COMPLETE = 'complete'
6
6
  CANCELLED = 'cancelled'
7
7
 
8
+ validates_presence_of :file_url, :project_id
9
+
8
10
  # Note : handle reset case
9
11
  def self.pending
10
12
  where(remote_status: 'SUCCESS', status: PENDING).order(:id)
@@ -3,13 +3,20 @@
3
3
  <%= link_to pluralize(@projects, 'projet', 'projets'), apidae.projects_path, class: styles[:projects] %>
4
4
  <%= link_to pluralize(@selections, 'sélection', 'sélections'), apidae.selections_path, class: styles[:selections] %>
5
5
  <%= link_to pluralize(@objects, 'objet touristique', 'objets touristiques'), apidae.objects_path, class: styles[:objects] %>
6
- <%= link_to (pluralize(@references, 'élément', 'éléments') + ' de référence'), apidae.references_path, class: styles[:references] %>
7
6
  <%= link_to 'Retour', :back, class: styles[:back] %>
8
7
  <h1 class="<%= styles[:h1] %>">Apidae</h1>
9
8
  </div>
10
9
  <div id="apidae_dashboard" class="<%= styles[:wrapper] %>">
11
10
  <div id="apidae_imports_panel" class="<%= styles[:body] %>">
11
+ <%= link_to 'Importer un fichier', apidae.import_new_path, class: styles[:projects] %>
12
12
  <h2 class="<%= styles[:h2] %>">Derniers imports</h2>
13
+ <p>
14
+ Les imports provenant de vos projets Apidae apparaîtront ci-dessous. Pour que les données soient importées correctement,
15
+ vos projets doivent être configurés pour exporter les données au format <strong>JSON V2</strong>, en
16
+ <strong>groupant les objets exportés</strong>.<br/>
17
+ Si vous souhaitez que chaque export soit récupéré automatiquement, veillez à renseigner le paramètre
18
+ <strong>Url de notification</strong> avec la valeur <strong><%= apidae.import_callback_url %></strong>.
19
+ </p>
13
20
  <table id="apidae_imports" class="<%= styles[:table] %>">
14
21
  <thead class="<%= styles[:table_head] %>">
15
22
  <tr>
@@ -0,0 +1,29 @@
1
+ <%= form_for(@export, url: apidae.import_create_path, method: :post, html: {class: styles[:form]}) do |f| %>
2
+ <% if @export.errors.any? %>
3
+ <div id="apidae_form_errors">
4
+ <ul>
5
+ <% @export.errors.full_messages.each do |message| %>
6
+ <li><%= message %></li>
7
+ <% end %>
8
+ </ul>
9
+ </div>
10
+ <% end %>
11
+ <p>
12
+ Pour que les données soient importées correctement,
13
+ vos projets doivent être configurés pour exporter les données au format <strong>JSON V2</strong>, en
14
+ <strong>groupant les objets exportés</strong>.
15
+ </p>
16
+
17
+ <div class="<%= styles[:form_field] %>">
18
+ <div><%= f.label :project_id %></div>
19
+ <div><%= f.text_field :project_id, placeholder: "Ex: 1234" %></div>
20
+ </div>
21
+ <div class="<%= styles[:form_field] %>">
22
+ <div><%= f.label :file_url %></div>
23
+ <div><%= f.text_field :file_url, placeholder: "Ex: http://export.apidae-tourisme.com/exports/1234_20200101-5678_ABCdef.zip" %></div>
24
+ </div>
25
+ <%= f.hidden_field :status %>
26
+ <div class="<%= styles[:form_actions] %>">
27
+ <%= f.submit 'Valider' %> | <%= link_to 'Retour', :back, class: styles[:back] %>
28
+ </div>
29
+ <% end %>
@@ -0,0 +1,11 @@
1
+ <%= render layout: "/layouts/#{Rails.application.config.apidae_layout}" do |styles| %>
2
+ <div id="apidae_header" class="<%= styles[:header] %>">
3
+ <%= link_to 'Retour', :back, class: styles[:back] %>
4
+ <h1 class="<%= styles[:h1] %>">Apidae - Importer un fichier de données</h1>
5
+ </div>
6
+ <div id="apidae_import" class="<%= styles[:wrapper] %>">
7
+ <div id="apidae_form" class="<%= styles[:body] %>">
8
+ <%= render 'form', styles: styles %>
9
+ </div>
10
+ </div>
11
+ <% end %>
@@ -10,12 +10,21 @@ fr:
10
10
  apidae/obj:
11
11
  apidae_id: Identifiant Apidae
12
12
  selection_apidae_id: Sélection Apidae
13
+ apidae/export:
14
+ project_id: Identifiant du projet
15
+ file_url: URL du fichier d'export
13
16
  errors:
14
17
  models:
15
18
  apidae/project:
16
19
  attributes:
17
20
  apidae_id:
18
21
  taken: Un projet avec cet identifiant Apidae existe déjà.
22
+ apidae/export:
23
+ attributes:
24
+ file_url:
25
+ blank: est requise
26
+ project_id:
27
+ blank: est requis
19
28
  apidae:
20
29
  file_import:
21
30
  status:
@@ -15,6 +15,8 @@ Apidae::Engine.routes.draw do
15
15
 
16
16
  match 'import/callback', via: :post, to: 'import#callback'
17
17
  match 'import/run', via: :post, to: 'import#run'
18
+ match 'import/new', via: :get, to: 'import#new'
19
+ match 'import/create', via: :post, to: 'import#create'
18
20
 
19
21
  root to: 'dashboard#index'
20
22
  end
@@ -1,3 +1,3 @@
1
1
  module Apidae
2
- VERSION = "1.0.4"
2
+ VERSION = "1.0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apidae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Baptiste Vilain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-28 00:00:00.000000000 Z
11
+ date: 2020-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -106,7 +106,9 @@ files:
106
106
  - app/models/apidae/selection_object.rb
107
107
  - app/models/apidae/town.rb
108
108
  - app/views/apidae/dashboard/index.html.erb
109
+ - app/views/apidae/import/_form.html.erb
109
110
  - app/views/apidae/import/callback.html.erb
111
+ - app/views/apidae/import/new.html.erb
110
112
  - app/views/apidae/objects/_form.html.erb
111
113
  - app/views/apidae/objects/edit.html.erb
112
114
  - app/views/apidae/objects/index.html.erb