apidae 0.7.6 → 0.7.7

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: 50f3213a4c2753e079a8a564b9cbff4199370119
4
- data.tar.gz: 323d35e564e7863142fd8384877ec9d1e3c74b6c
3
+ metadata.gz: 6c720ab33eaef78cb4204c9a762bb8a99cc9b789
4
+ data.tar.gz: ba76e69c7b40c4b4e6236567879c74983d18744d
5
5
  SHA512:
6
- metadata.gz: ff0caea0932ed8948d58ceee7641565e37e8767db7ec6ff47e65366a8f0b8b4decde0dc4929fe34dfad39a9d96b05bece8b3387740e16e6fde8c7ce9d4f18919
7
- data.tar.gz: 0340df6cfbc78fcd72fc3fb6a373e59a9aec13fefffb4fabe52fc4daeace61afaa787e03e5c93640cf118257ceafc25e3b446e506fe8f2d1fb2d43f273359100
6
+ metadata.gz: 4885ebfb95a966eb54cdee590498a24c5e6bced783d61d12edd5c13f53c8792421bc46dc1b3000f5a2fd89573fe0ef73ba213b575f285fc074fd36de40b4cef9
7
+ data.tar.gz: 0fa597db6dd22bc8a78e79ce64079828d23f7c8d89c82a303e6641800c907a748bf608ac1b6d9eb76c74e2d2419e838b14db211ba454ba1e36d7adf5fbce087a
@@ -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
@@ -19,38 +19,39 @@ module Apidae
19
19
  end
20
20
 
21
21
  def new
22
- @object = Obj.new
22
+ @obj = Obj.new
23
23
  end
24
24
 
25
25
  def edit
26
26
  end
27
27
 
28
28
  def create
29
- @object = Obj.new(object_params)
30
-
31
- if @object.save
32
- redirect_to @object, notice: 'Object was successfully created.'
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é"
33
33
  else
34
+ flash[:alert] = "Une erreur s'est produite lors de l'import de l'objet."
34
35
  render :new
35
36
  end
36
37
  end
37
38
 
38
39
  def update
39
- if @object.update(object_params)
40
- redirect_to @object, notice: 'Object was successfully updated.'
40
+ if @obj.update(object_params)
41
+ redirect_to @obj, notice: 'Object was successfully updated.'
41
42
  else
42
43
  render :edit
43
44
  end
44
45
  end
45
46
 
46
47
  def destroy
47
- @object.destroy
48
+ @obj.destroy
48
49
  redirect_to objects_url, notice: 'Object was successfully destroyed.'
49
50
  end
50
51
 
51
52
  def refresh
52
53
  referrer = session.delete(:referrer)
53
- if @object && @object.selections.first.refresh_obj(@object.apidae_id)
54
+ if @obj && @obj.selections.first.refresh_obj(@obj.apidae_id)
54
55
  redirect_to referrer, notice: "L'objet touristique a bien été mis à jour."
55
56
  else
56
57
  redirect_to referrer, alert: "Une erreur s'est produite lors de la mise à jour de l'objet."
@@ -59,7 +60,7 @@ module Apidae
59
60
 
60
61
  private
61
62
  def set_object
62
- @object = Obj.find(params[:id])
63
+ @obj = Obj.find(params[:id])
63
64
  end
64
65
 
65
66
  def object_params
@@ -1,7 +1,7 @@
1
1
  module Apidae
2
2
  class Obj < ActiveRecord::Base
3
3
 
4
- belongs_to :town, class_name: 'Apidae::Town', foreign_key: :town_insee_code, primary_key: :insee_code
4
+ belongs_to :town, class_name: 'Apidae::Town', foreign_key: :town_insee_code, primary_key: :insee_code, optional: true
5
5
  has_many :apidae_selection_objects, class_name: 'Apidae::SelectionObject', foreign_key: :apidae_object_id
6
6
  has_many :selections, class_name: 'Apidae::Selection', source: :apidae_selection, through: :apidae_selection_objects
7
7
 
@@ -95,7 +95,7 @@ module Apidae
95
95
  obj = Obj.find_by_apidae_id(apidae_obj_id)
96
96
  if obj
97
97
  refreshed = Obj.update_object(obj, obj_data)
98
- if refreshed && Rails.application.config.apidae_obj_refresh_callback
98
+ if refreshed && Rails.application.config.respond_to?(:apidae_obj_refresh_callback)
99
99
  Rails.application.config.apidae_obj_refresh_callback.call(apidae_obj_id)
100
100
  end
101
101
  refreshed
@@ -2,5 +2,5 @@
2
2
 
3
3
  <%= render 'form' %>
4
4
 
5
- <%= link_to 'Show', @object %> |
5
+ <%= link_to 'Show', @obj %> |
6
6
  <%= link_to 'Back', objects_path %>
@@ -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 'Retour', @selection ? selections_path : root_path, class: styles[:back] %>
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] %>">
@@ -22,7 +23,7 @@
22
23
  <td><%= object.apidae_id %></td>
23
24
  <td><%= object.apidae_type %></td>
24
25
  <td><%= object.updated_at.strftime('Le %d/%m/%Y à %H:%M') if object.updated_at %></td>
25
- <td><%= link_to 'Rafraîchir', refresh_object_path(object), method: :post,
26
+ <td><%= link_to 'Rafraîchir', apidae.refresh_object_path(object), method: :post,
26
27
  data: {confirm: 'Voulez-vous vraiment rafraîchir cet objet ? Les données existantes seront écrasées.'} %></td>
27
28
  </tr>
28
29
  <% end %>
@@ -1,5 +1,33 @@
1
- <h1>New Object</h1>
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, 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
- <%= render 'form' %>
4
-
5
- <%= link_to 'Back', objects_path %>
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,6 +1,6 @@
1
1
  Apidae::Engine.routes.draw do
2
2
 
3
- resources :objects, only: [:index, :show], path: 'objets' do
3
+ resources :objects, only: [:index, :show, :new, :create], path: 'objets' do
4
4
  post 'refresh', on: :member
5
5
  end
6
6
 
@@ -1,3 +1,3 @@
1
1
  module Apidae
2
- VERSION = "0.7.6"
2
+ VERSION = "0.7.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apidae
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Baptiste Vilain