apidae 0.9.15 → 0.9.16
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/apidae/import_controller.rb +1 -1
- data/app/controllers/apidae/objects_controller.rb +22 -11
- data/app/controllers/apidae/projects_controller.rb +1 -1
- data/app/models/apidae/selection.rb +71 -0
- data/app/views/apidae/objects/edit.html.erb +1 -1
- data/app/views/apidae/objects/index.html.erb +5 -1
- data/app/views/apidae/objects/new.html.erb +32 -4
- data/config/routes.rb +7 -2
- data/db/migrate/20190328122424_add_description_to_apidae_towns.rb +5 -0
- data/lib/apidae/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44c3ad9d98d4c7845e73ba6d2979e9bbc34fc4b3
|
4
|
+
data.tar.gz: 14ba7bc27ce966673c67f4dfff6dda9fd5006ee2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 846477e653788caabc6f5f6240fedf35711bf73d7ffd4c0752ea9d515c680c75c0f009ab5e97636c64b47f3b6b79f74740692186df9fd7eae9a7b1b6c599e903
|
7
|
+
data.tar.gz: 15a4b43ddccf9f665145831dbbb5097d14802f652b38a5e56088657fc7fb90569cbf5afe559880cb750ae2c9200a43092868373bec74202f853fbe7efcd13961
|
@@ -46,7 +46,7 @@ module Apidae
|
|
46
46
|
http.request(req)
|
47
47
|
end
|
48
48
|
e.update(status: Export::COMPLETE)
|
49
|
-
if Rails.application.config.apidae_import_callback
|
49
|
+
if Rails.application.config.respond_to?(:apidae_import_callback)
|
50
50
|
Rails.application.config.apidae_import_callback.call(e)
|
51
51
|
end
|
52
52
|
rescue Exception => ex
|
@@ -2,10 +2,11 @@ require_dependency "apidae/application_controller"
|
|
2
2
|
|
3
3
|
module Apidae
|
4
4
|
class ObjectsController < ApplicationController
|
5
|
-
before_action :set_object, only: [:show, :edit, :update, :destroy]
|
5
|
+
before_action :set_object, only: [:show, :edit, :update, :destroy, :refresh]
|
6
6
|
skip_before_action Rails.application.config.apidae_auth, only: [:index, :show]
|
7
7
|
|
8
8
|
def index
|
9
|
+
session[:referrer] = request.referrer
|
9
10
|
if params[:selection_id]
|
10
11
|
@selection = Selection.find(params[:selection_id])
|
11
12
|
@objects = @selection.objects.select(:id, :apidae_id, :title, :apidae_type, :updated_at)
|
@@ -18,42 +19,52 @@ module Apidae
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def new
|
21
|
-
@
|
22
|
+
@obj = Obj.new
|
22
23
|
end
|
23
24
|
|
24
25
|
def edit
|
25
26
|
end
|
26
27
|
|
27
28
|
def create
|
28
|
-
@
|
29
|
-
|
30
|
-
if @
|
31
|
-
redirect_to
|
29
|
+
@obj = Obj.new(object_params)
|
30
|
+
selection = params[:selection_apidae_id].blank? ? Selection.last : Selection.find_by_apidae_id(params[:selection_apidae_id])
|
31
|
+
if @obj.save && selection.refresh_obj(@obj.apidae_id)
|
32
|
+
redirect_to objects_url, notice: "L'objet a bien été importé"
|
32
33
|
else
|
34
|
+
flash[:alert] = "Une erreur s'est produite lors de l'import de l'objet."
|
33
35
|
render :new
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
39
|
def update
|
38
|
-
if @
|
39
|
-
redirect_to @
|
40
|
+
if @obj.update(object_params)
|
41
|
+
redirect_to @obj, notice: 'Object was successfully updated.'
|
40
42
|
else
|
41
43
|
render :edit
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
47
|
def destroy
|
46
|
-
@
|
48
|
+
@obj.destroy
|
47
49
|
redirect_to objects_url, notice: 'Object was successfully destroyed.'
|
48
50
|
end
|
49
51
|
|
52
|
+
def refresh
|
53
|
+
referrer = (session.delete(:referrer) || objects_url)
|
54
|
+
if @obj && @obj.selections.first.refresh_obj(@obj.apidae_id)
|
55
|
+
redirect_to referrer, notice: "L'objet touristique a bien été mis à jour."
|
56
|
+
else
|
57
|
+
redirect_to referrer, alert: "Une erreur s'est produite lors de la mise à jour de l'objet."
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
50
61
|
private
|
51
62
|
def set_object
|
52
|
-
@
|
63
|
+
@obj = Obj.find(params[:id])
|
53
64
|
end
|
54
65
|
|
55
66
|
def object_params
|
56
|
-
params.require(:
|
67
|
+
params.require(:obj).permit!
|
57
68
|
end
|
58
69
|
end
|
59
70
|
end
|
@@ -20,7 +20,7 @@ module Apidae
|
|
20
20
|
else
|
21
21
|
@project = Project.new(project_params)
|
22
22
|
if @project.save
|
23
|
-
referrer = session.delete(:referrer)
|
23
|
+
referrer = (session.delete(:referrer) || projects_url)
|
24
24
|
redirect_to (referrer + "?apidae_project_id=#{@project.id}"), notice: 'Le projet a bien été créé'
|
25
25
|
else
|
26
26
|
flash.now[:alert] = "Une erreur s'est produite lors la création du projet"
|
@@ -8,6 +8,8 @@ module Apidae
|
|
8
8
|
|
9
9
|
AGENDA_ENDPOINT = 'agenda/detaille/list-identifiants'
|
10
10
|
SELECTION_ENDPOINT = 'recherche/list-identifiants'
|
11
|
+
OBJECTS_ENDPOINT = 'recherche/list-objets-touristiques'
|
12
|
+
|
11
13
|
MAX_COUNT = 100
|
12
14
|
MAX_LOOPS = 10
|
13
15
|
|
@@ -70,6 +72,39 @@ module Apidae
|
|
70
72
|
res
|
71
73
|
end
|
72
74
|
|
75
|
+
def api_objects(opts = {})
|
76
|
+
key = cache_key(:objects)
|
77
|
+
res = $apidae_cache.read(key)
|
78
|
+
unless res
|
79
|
+
query_args = build_args(OBJECTS_ENDPOINT, opts.merge({selection_ids: [apidae_id]}))
|
80
|
+
res = query_objects_api(query_args, true)
|
81
|
+
$apidae_cache.write(key, res)
|
82
|
+
end
|
83
|
+
res
|
84
|
+
end
|
85
|
+
|
86
|
+
def api_object(apidae_obj_id)
|
87
|
+
query_args = build_args(OBJECTS_ENDPOINT, {obj_ids: [apidae_obj_id], fields: ["@all"]})
|
88
|
+
query_objects_api(query_args, true)
|
89
|
+
end
|
90
|
+
|
91
|
+
def refresh_obj(apidae_obj_id)
|
92
|
+
if apidae_project
|
93
|
+
res = api_object(apidae_obj_id)
|
94
|
+
if res[:results] && res[:results].length == 1
|
95
|
+
obj_data = res[:results].first.deep_symbolize_keys
|
96
|
+
obj = Obj.find_by_apidae_id(apidae_obj_id)
|
97
|
+
if obj
|
98
|
+
refreshed = Obj.update_object(obj, obj_data, apidae_project.locales, apidae_project.versions)
|
99
|
+
if refreshed && Rails.application.config.respond_to?(:apidae_obj_refresh_callback)
|
100
|
+
Rails.application.config.apidae_obj_refresh_callback.call(apidae_obj_id)
|
101
|
+
end
|
102
|
+
refreshed
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
73
108
|
def as_text
|
74
109
|
"#{label} (#{apidae_id})"
|
75
110
|
end
|
@@ -110,6 +145,32 @@ module Apidae
|
|
110
145
|
end
|
111
146
|
end
|
112
147
|
|
148
|
+
def query_objects_api(query_args, all_results = false)
|
149
|
+
query_result = {}
|
150
|
+
|
151
|
+
if all_results
|
152
|
+
loops = 0
|
153
|
+
query_args[:first] = 0
|
154
|
+
query_args[:count] = MAX_COUNT
|
155
|
+
response = JSON.parse get_response(query_args), symbolize_names: false
|
156
|
+
total = response['numFound']
|
157
|
+
query_result[:results] = response['objetsTouristiques'] || {}
|
158
|
+
|
159
|
+
while total > results_count(query_result) && loops < MAX_LOOPS
|
160
|
+
loops += 1
|
161
|
+
query_args[:first] += MAX_COUNT
|
162
|
+
response = JSON.parse get_response(query_args), symbolize_names: false
|
163
|
+
merge_objects_results(response, query_result)
|
164
|
+
end
|
165
|
+
query_result[:count] = total
|
166
|
+
else
|
167
|
+
response = JSON.parse get_response(query_args), symbolize_names: false
|
168
|
+
query_result[:results] = response['objetsTouristiques'] || {}
|
169
|
+
query_result[:count] = response['numFound']
|
170
|
+
end
|
171
|
+
query_result
|
172
|
+
end
|
173
|
+
|
113
174
|
def get_response(args)
|
114
175
|
response = ''
|
115
176
|
query = JSON.generate args.except(:url)
|
@@ -137,6 +198,15 @@ module Apidae
|
|
137
198
|
end
|
138
199
|
end
|
139
200
|
|
201
|
+
def merge_objects_results(response, result)
|
202
|
+
objects = response['objetsTouristiques']
|
203
|
+
unless objects.blank?
|
204
|
+
if result[:results] && result[:results].is_a?(Array)
|
205
|
+
result[:results] += objects
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
140
210
|
def build_args(endpoint, opts = {})
|
141
211
|
{
|
142
212
|
url: "#{Rails.application.config.apidae_api_url}/#{endpoint}",
|
@@ -145,6 +215,7 @@ module Apidae
|
|
145
215
|
first: opts[:first] || 0,
|
146
216
|
count: opts[:count] || MAX_COUNT,
|
147
217
|
selectionIds: opts[:selection_ids],
|
218
|
+
identifiants: opts[:obj_ids],
|
148
219
|
dateDebut: opts[:from],
|
149
220
|
dateFin: opts[:to],
|
150
221
|
center: opts[:lat] && opts[:lng] ? {type: 'Point', coordinates: [opts[:lng], opts[:lat]]} : nil,
|
@@ -1,6 +1,7 @@
|
|
1
1
|
<%= render layout: "/layouts/#{Rails.application.config.apidae_layout}" do |styles| %>
|
2
2
|
<div id="apidae_header" class="<%= styles[:header] %>">
|
3
|
-
<%= link_to '
|
3
|
+
<%= link_to 'Importer un objet', apidae.new_object_path, class: styles[:objects] %>
|
4
|
+
<%= link_to 'Retour', @selection ? apidae.selections_path : root_path, class: styles[:back] %>
|
4
5
|
<h1 class="<%= styles[:h1] %>">Apidae - <%= @selection ? "Sélection \"#{@selection.label}\"" : "Tous les objets touristiques" %></h1>
|
5
6
|
</div>
|
6
7
|
<div id="apidae_dashboard" class="<%= styles[:wrapper] %>">
|
@@ -12,6 +13,7 @@
|
|
12
13
|
<th>Identifiant</th>
|
13
14
|
<th>Type</th>
|
14
15
|
<th>Mise à jour</th>
|
16
|
+
<th></th>
|
15
17
|
</tr>
|
16
18
|
</thead>
|
17
19
|
<tbody class="<%= styles[:table_body] %>">
|
@@ -21,6 +23,8 @@
|
|
21
23
|
<td><%= object.apidae_id %></td>
|
22
24
|
<td><%= object.apidae_type %></td>
|
23
25
|
<td><%= object.updated_at.strftime('Le %d/%m/%Y à %H:%M') if object.updated_at %></td>
|
26
|
+
<td><%= link_to 'Rafraîchir', apidae.refresh_object_path(object), method: :post,
|
27
|
+
data: {confirm: 'Voulez-vous vraiment rafraîchir cet objet ? Les données existantes seront écrasées.'} %></td>
|
24
28
|
</tr>
|
25
29
|
<% end %>
|
26
30
|
<% if @objects.empty? %>
|
@@ -1,5 +1,33 @@
|
|
1
|
-
|
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 objet</h1>
|
5
|
+
</div>
|
6
|
+
<div id="apidae_new_object" class="<%= styles[:wrapper] %>">
|
7
|
+
<div id="apidae_form" class="<%= styles[:body] %>">
|
8
|
+
<%= form_for(@obj, url: objects_url, class: styles[:form]) do |f| %>
|
9
|
+
<% if @obj.errors.any? %>
|
10
|
+
<div id="apidae_form_errors">
|
11
|
+
<ul>
|
12
|
+
<% @obj.errors.full_messages.each do |message| %>
|
13
|
+
<li><%= message %></li>
|
14
|
+
<% end %>
|
15
|
+
</ul>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
2
18
|
|
3
|
-
<%=
|
4
|
-
|
5
|
-
|
19
|
+
<div class="<%= styles[:form_field] %>">
|
20
|
+
<div><%= f.label :apidae_id %></div>
|
21
|
+
<div><%= f.text_field :apidae_id %></div>
|
22
|
+
</div>
|
23
|
+
<div class="<%= styles[:form_field] %>">
|
24
|
+
<div><%= label_tag :selection_apidae_id %></div>
|
25
|
+
<div><%= text_field_tag :selection_apidae_id %></div>
|
26
|
+
</div>
|
27
|
+
<div class="<%= styles[:form_actions] %>">
|
28
|
+
<%= f.submit 'Valider' %>
|
29
|
+
</div>
|
30
|
+
<% end %>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
<% end %>
|
data/config/routes.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
Apidae::Engine.routes.draw do
|
2
2
|
|
3
|
-
resources :objects, only: [:index, :show], path: 'objets'
|
3
|
+
resources :objects, only: [:index, :show, :new, :create], path: 'objets' do
|
4
|
+
post 'refresh', on: :member
|
5
|
+
end
|
6
|
+
|
4
7
|
resources :selections, only: [:index] do
|
5
|
-
resources :objects, only: [:index], path: 'objets'
|
8
|
+
resources :objects, only: [:index], path: 'objets' do
|
9
|
+
post 'refresh', on: :member
|
10
|
+
end
|
6
11
|
end
|
7
12
|
resources :references, only: [:index]
|
8
13
|
resources :projects, only: [:index, :new, :create, :edit, :update, :destroy], path: 'projets'
|
data/lib/apidae/version.rb
CHANGED
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: 0.9.
|
4
|
+
version: 0.9.16
|
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: 2019-10-
|
11
|
+
date: 2019-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -168,6 +168,7 @@ files:
|
|
168
168
|
- db/migrate/20190127210921_migrate_localized_apidae_obj_fields.rb
|
169
169
|
- db/migrate/20190127213602_migrate_localized_apidae_references.rb
|
170
170
|
- db/migrate/20190304142446_migrate_desc_apidae_obj_fields.rb
|
171
|
+
- db/migrate/20190328122424_add_description_to_apidae_towns.rb
|
171
172
|
- db/migrate/20190418133435_add_index_on_apidae_obj.rb
|
172
173
|
- db/migrate/20190517153215_add_description_to_apidae_towns.rb
|
173
174
|
- lib/apidae.rb
|