apidae 1.0.2 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 825f592628dd0818de54c1fce82fa36b7b97140b
4
- data.tar.gz: f857a1e30e89a720ab025d2171915e203638fa36
3
+ metadata.gz: b537e9e99b7f05f62b0c694b52382e7ca9c56c89
4
+ data.tar.gz: 7943e22b985c52739837a9db2c748b8891e634b1
5
5
  SHA512:
6
- metadata.gz: c242aa6b115d15716e01db251b30ccb8d76dcdd1a1c118691a090ed3a151742d3ea02d43d39f1bef71855a300e3ee0f736d2fa3bd4cc9aa1d77da9cf7511b13b
7
- data.tar.gz: e34650ebe27509274682fa4e968f7d12d1f3f3577cdc5183e0c464595dc65c86ace66f323b21a774a4045a177ac4ac3ca21d225ae6a85bb9941641f442a1a0da
6
+ metadata.gz: c43827fbbacb7331fe032903e5ab2a5ac0f3e08e482811928d5a610d728c5734eaebd7c07bec35100c91fef71e688e56188ef68d422214336b0d924da8315f45
7
+ data.tar.gz: be1a882acd0d0714cf655a60bdd71ac329530ba6a125db12940beee9d746cc0d3dd7d62e120bef1909777df51f337fab7402ac7fe24c6da9a9f6e5106ee893c1
@@ -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
@@ -6,6 +6,7 @@ module Apidae
6
6
  class ImportController < ApplicationController
7
7
  skip_before_action :verify_authenticity_token
8
8
  skip_before_action Rails.application.config.apidae_auth
9
+ skip_before_action :check_user_data!
9
10
 
10
11
  # Callback endpoint for Apidae exports
11
12
  #
@@ -36,34 +37,62 @@ module Apidae
36
37
  def run
37
38
  success = true
38
39
  Export.pending.each do |e|
39
- begin
40
- open(e.file_url) do |f|
41
- begin
42
- 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?
43
72
  uri = URI(e.confirm_url)
44
73
  req = Net::HTTP::Post.new(uri)
45
74
  Net::HTTP.start(uri.hostname, uri.port) do |http|
46
75
  http.request(req)
47
76
  end
48
- e.update(status: Export::COMPLETE)
49
- if Rails.application.config.respond_to?(:apidae_import_callback)
50
- Rails.application.config.apidae_import_callback.call(e)
51
- end
52
- rescue Exception => ex
53
- logger.error("Failed to import export file : #{e.file_url}")
54
- logger.error("Error is : #{ex} \n#{ex.backtrace.join("\n") unless ex.backtrace.blank?}")
55
- success = false
56
- e.update(status: Export::CANCELLED)
57
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)
58
87
  end
59
- rescue OpenURI::HTTPError => err
60
- logger.error("Failed to download export file : #{e.file_url}")
61
- logger.error("Error is : #{err}")
62
- success = false
63
- e.update(status: Export::CANCELLED)
64
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)
65
94
  end
66
- success ? head(:ok) : head(:internal_server_error)
95
+ success
67
96
  end
68
97
  end
69
98
  end
@@ -3,6 +3,7 @@ require_dependency "apidae/application_controller"
3
3
  module Apidae
4
4
  class ProjectsController < ApplicationController
5
5
  before_action :set_project, only: [:edit, :update, :destroy]
6
+ skip_before_action :check_user_data!, only: [:create]
6
7
 
7
8
  def index
8
9
  if user_is_admin?
@@ -24,7 +25,7 @@ module Apidae
24
25
  else
25
26
  @project = Project.new(project_params)
26
27
  if @project.save
27
- referrer = (session.delete(:referrer) || projects_url)
28
+ referrer = params[:redirect_to] || session.delete(:referrer) || projects_url
28
29
  redirect_to (referrer + "?apidae_project_id=#{@project.id}"), notice: 'Le projet a bien été créé'
29
30
  else
30
31
  flash.now[:alert] = "Une erreur s'est produite lors la création du projet"
@@ -54,7 +55,7 @@ module Apidae
54
55
 
55
56
  def update_project
56
57
  if @project.update(project_params)
57
- referrer = session.delete(:referrer)
58
+ referrer = params[:redirect_to] || session.delete(:referrer)
58
59
  redirect_to (referrer + "?apidae_project_id=#{@project.id}"), notice: 'Le projet a bien été mis à jour'
59
60
  else
60
61
  flash.now[:alert] = "Une erreur s'est produite lors la mise à jour du projet"
@@ -10,6 +10,17 @@ module Apidae
10
10
  YELP = 4007
11
11
  TRIP_ADVISOR = 4000
12
12
 
13
+ CONTACTS_MAP = {
14
+ 'telephone' => PHONE,
15
+ 'email' => EMAIL,
16
+ 'website' => WEBSITE,
17
+ 'facebook' => FACEBOOK,
18
+ 'google' => GOOGLE,
19
+ 'trip_advisor' => TRIP_ADVISOR,
20
+ 'twitter' => TWITTER,
21
+ 'yelp' => YELP
22
+ }
23
+
13
24
  MODE_AUTO = 'auto'
14
25
  MODE_MANUAL = 'manual'
15
26
 
@@ -114,7 +125,7 @@ module Apidae
114
125
  url: pic[:traductionFichiers][0][:url].gsub('http:', 'https:'),
115
126
  description: localized_value(pic, :legende, locale),
116
127
  credits: localized_value(pic, :copyright, locale),
117
- expiration_date: pic[:dateLimiteDePublication]
128
+ expiration_date: pic[:dateLimiteDePublication] || ''
118
129
  }
119
130
  end
120
131
  end
@@ -149,29 +160,29 @@ module Apidae
149
160
  contact_entries.each do |c|
150
161
  case c[:type][:id]
151
162
  when PHONE, ALT_PHONE
152
- contact_details[:telephone] ||= []
153
- contact_details[:telephone] << c[:coordonnees][:fr]
163
+ contact_details[:telephone] ||= {}
164
+ contact_details[:telephone][c[:identifiant]] = c[:coordonnees][:fr]
154
165
  when EMAIL
155
- contact_details[:email] ||= []
156
- contact_details[:email] << c[:coordonnees][:fr]
166
+ contact_details[:email] ||= {}
167
+ contact_details[:email][c[:identifiant]] = c[:coordonnees][:fr]
157
168
  when WEBSITE
158
- contact_details[:website] ||= []
159
- contact_details[:website] << c[:coordonnees][:fr]
169
+ contact_details[:website] ||= {}
170
+ contact_details[:website][c[:identifiant]] = c[:coordonnees][:fr]
160
171
  when GOOGLE
161
- contact_details[:google] ||= []
162
- contact_details[:google] << c[:coordonnees][:fr]
172
+ contact_details[:google] ||= {}
173
+ contact_details[:google][c[:identifiant]] = c[:coordonnees][:fr]
163
174
  when FACEBOOK
164
- contact_details[:facebook] ||= []
165
- contact_details[:facebook] << c[:coordonnees][:fr]
175
+ contact_details[:facebook] ||= {}
176
+ contact_details[:facebook][c[:identifiant]] = c[:coordonnees][:fr]
166
177
  when TWITTER
167
- contact_details[:twitter] ||= []
168
- contact_details[:twitter] << c[:coordonnees][:fr]
178
+ contact_details[:twitter] ||= {}
179
+ contact_details[:twitter][c[:identifiant]] = c[:coordonnees][:fr]
169
180
  when YELP
170
- contact_details[:yelp] ||= []
171
- contact_details[:yelp] << c[:coordonnees][:fr]
181
+ contact_details[:yelp] ||= {}
182
+ contact_details[:yelp][c[:identifiant]] = c[:coordonnees][:fr]
172
183
  when TRIP_ADVISOR
173
- contact_details[:trip_advisor] ||= []
174
- contact_details[:trip_advisor] << c[:coordonnees][:fr]
184
+ contact_details[:trip_advisor] ||= {}
185
+ contact_details[:trip_advisor][c[:identifiant]] = c[:coordonnees][:fr]
175
186
  else
176
187
  end
177
188
  end
@@ -210,7 +221,8 @@ module Apidae
210
221
  openings_desc: node_value(openings_hash, :periodeEnClair, *locales),
211
222
  openings_desc_mode: openings_hash[:periodeEnClairGenerationMode] == 'AUTOMATIQUE' ? MODE_AUTO : MODE_MANUAL,
212
223
  openings: build_openings(openings_hash, *locales),
213
- time_periods: lists_ids(openings_hash[:indicationsPeriode])
224
+ time_periods: lists_ids(openings_hash[:indicationsPeriode]),
225
+ openings_extra: lists_ids(openings_hash[:ouverturesComplementaires])
214
226
  }
215
227
  end
216
228
  end
@@ -338,6 +350,7 @@ module Apidae
338
350
  external_id: o[:identifiantTechnique],
339
351
  start_date: o[:dateDebut],
340
352
  end_date: o[:dateFin],
353
+ each_year: o[:tousLesAns],
341
354
  closing_days: closing_days.blank? ? [] : closing_days.map {|d| d[:dateSpeciale]},
342
355
  details: node_value(o, :complementHoraire, *locales),
343
356
  time_periods: [
@@ -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)
@@ -18,7 +18,7 @@ module Apidae
18
18
  store_accessor :entity_data, :entity_id, :entity_name, :service_provider_id
19
19
  store_accessor :contact_data, :telephone, :email, :website, :google, :facebook, :twitter, :yelp, :trip_advisor, :contacts
20
20
  store_accessor :location_data, :address, :place, :latitude, :longitude, :access, :territories, :environments
21
- store_accessor :openings_data, :openings_desc, :openings_desc_mode, :openings, :time_periods
21
+ store_accessor :openings_data, :openings_desc, :openings_desc_mode, :openings, :time_periods, :openings_extra
22
22
  store_accessor :rates_data, :rates_desc, :rates_desc_mode, :rates, :payment_methods, :includes, :excludes
23
23
  store_accessor :service_data, :services, :equipments, :comfort, :activities, :challenged, :languages
24
24
  store_accessor :booking_data, :booking_desc, :booking_entities
@@ -5,6 +5,10 @@ module Apidae
5
5
 
6
6
  store_accessor :meta_data, :category, :parent
7
7
 
8
+ def self.default_scope
9
+ where(is_active: true)
10
+ end
11
+
8
12
  def self.import(refs_json)
9
13
  locales = Rails.application.config.respond_to?(:apidae_locales) ? Rails.application.config.apidae_locales : [DEFAULT_LOCALE]
10
14
  locales_map = Hash[locales.map {|loc| ["libelle#{loc.camelize.gsub('-', '')}".to_sym, loc]}]
@@ -15,6 +19,7 @@ module Apidae
15
19
  ref.label_data = ref_data.slice(*locales_map.keys).transform_keys {|k| locales_map[k]}
16
20
  ref.parent = ref_data[:parent][:id] if ref_data[:parent]
17
21
  ref.category = ref_data[:familleCritere] ? ref_data[:familleCritere][:id] : (ref_data[:typeLabel] ? ref_data[:typeLabel][:id] : nil)
22
+ ref.is_active = ref_data[:actif]
18
23
  ref.save!
19
24
  end
20
25
  end
@@ -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
@@ -0,0 +1,6 @@
1
+ class AddIsActiveToApidaeReferences < ActiveRecord::Migration[5.2]
2
+ def change
3
+ add_column :apidae_references, :is_active, :boolean
4
+ add_index :apidae_references, :is_active, unique: false
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module Apidae
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.1"
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.2
4
+ version: 1.1.1
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-25 00:00:00.000000000 Z
11
+ date: 2020-06-03 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
@@ -178,6 +180,7 @@ files:
178
180
  - db/migrate/20200312150008_add_version_data_to_apidae_objs.rb
179
181
  - db/migrate/20200312150904_add_version_index_on_apidae_objs.rb
180
182
  - db/migrate/20200522124205_rename_objs_contact_to_contact_data.rb
183
+ - db/migrate/20200528101957_add_is_active_to_apidae_references.rb
181
184
  - lib/apidae.rb
182
185
  - lib/apidae/engine.rb
183
186
  - lib/apidae/version.rb