apidae 0.2.5 → 0.2.6

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: bed82e5136a7e205db9ee923ddc131aea476941b
4
- data.tar.gz: e89e505fce362be0eb0c61f9e19ff51577f0c690
3
+ metadata.gz: a65b8e65f96393ad346b2e3e75c2d9b03fa36917
4
+ data.tar.gz: c294dbec3f0fb0ce086d219a64bf4d926d6be51e
5
5
  SHA512:
6
- metadata.gz: aeb80b9297dcc4f466cc123cd17df110cab2f7c1e31476cbb55ee988f83b3cc4da2f13887aba342818ec267cc587700b212a88e8ba1e5cd0e41bf47a085cd02f
7
- data.tar.gz: ffd85edb55dab227926912329fbb24bfdccd27f1daac42524245fd5c4f86e36ed584036e5b976d157b19471aab5233fea431e305930b4c118205d56a41c3af00
6
+ metadata.gz: 816137aec948bde71a5c5ebd274f630f45c72df31ec19c29c162076fa44949fb64388ae68c8be7aa38665eebef470624e58c76fff0713b736e495edcd77beb14
7
+ data.tar.gz: f7ee150be2b37199b8c21092f0c8760f642cb6dbfd680aaaf2e256f9f1135be7577b81ad3b80959bdbd59c72466bea52a6e6271ef9b2c00b3bca254650429681
@@ -4,25 +4,25 @@ module Apidae
4
4
  class ObjectsController < ApplicationController
5
5
  before_action :set_object, only: [:show, :edit, :update, :destroy]
6
6
 
7
- # GET /objects
8
7
  def index
9
- @objects = Object.all.select(:apidae_id, :title, :apidae_type, :updated_at)
8
+ if params[:selection_id]
9
+ @selection = Selection.find(params[:selection_id])
10
+ @objects = @selection.objects.select(:apidae_id, :title, :apidae_type, :updated_at)
11
+ else
12
+ @objects = Object.all.select(:apidae_id, :title, :apidae_type, :updated_at)
13
+ end
10
14
  end
11
15
 
12
- # GET /objects/1
13
16
  def show
14
17
  end
15
18
 
16
- # GET /objects/new
17
19
  def new
18
20
  @object = Object.new
19
21
  end
20
22
 
21
- # GET /objects/1/edit
22
23
  def edit
23
24
  end
24
25
 
25
- # POST /objects
26
26
  def create
27
27
  @object = Object.new(object_params)
28
28
 
@@ -33,7 +33,6 @@ module Apidae
33
33
  end
34
34
  end
35
35
 
36
- # PATCH/PUT /objects/1
37
36
  def update
38
37
  if @object.update(object_params)
39
38
  redirect_to @object, notice: 'Object was successfully updated.'
@@ -42,21 +41,18 @@ module Apidae
42
41
  end
43
42
  end
44
43
 
45
- # DELETE /objects/1
46
44
  def destroy
47
45
  @object.destroy
48
46
  redirect_to objects_url, notice: 'Object was successfully destroyed.'
49
47
  end
50
48
 
51
49
  private
52
- # Use callbacks to share common setup or constraints between actions.
53
50
  def set_object
54
51
  @object = Object.find(params[:id])
55
52
  end
56
53
 
57
- # Only allow a trusted parameter "white list" through.
58
54
  def object_params
59
- params.require(:object).permit(:address, :apidae_id, :apidae_type, :apidae_subtype, :title, :short_desc, :contact, :long_desc, :type_data, :latitude, :longitude, :openings, :rates, :reservation)
55
+ params.require(:object).permit!
60
56
  end
61
57
  end
62
58
  end
@@ -7,11 +7,12 @@ module Apidae
7
7
  has_many :selections, class_name: 'Apidae::Selection', source: :apidae_selection, through: :apidae_selection_objects
8
8
 
9
9
  store_accessor :pictures_data, :pictures
10
- store_accessor :type_data, :categories, :themes, :capacite, :classement
10
+ store_accessor :type_data, :categories, :themes, :capacite, :classement, :labels
11
11
  store_accessor :entity_data, :entity_id, :entity_name
12
12
  store_accessor :contact, :telephone, :email, :website
13
13
  store_accessor :address, :address_fields
14
- store_accessor :openings, :description, :opening_periods
14
+ store_accessor :openings_data, :openings_desc, :openings
15
+ store_accessor :rates_data, :rates_desc, :rates
15
16
 
16
17
  ACT = 'ACTIVITE'
17
18
  COS = 'COMMERCE_ET_SERVICE'
@@ -70,9 +71,9 @@ module Apidae
70
71
  apidae_obj.town = town(object_data[:localisation][:adresse])
71
72
  apidae_obj.latitude = latitude(object_data[:localisation])
72
73
  apidae_obj.longitude = longitude(object_data[:localisation])
73
- apidae_obj.openings = openings(object_data[:ouverture])
74
- apidae_obj.rates = rates(object_data[:descriptionTarif])
75
- apidae_obj.reservation = reservation(object_data[:reservation])
74
+ apidae_obj.openings_data = parse_openings(object_data[:ouverture])
75
+ apidae_obj.rates_data = parse_rates(object_data[:descriptionTarif])
76
+ apidae_obj.reservation = parse_reservation(object_data[:reservation])
76
77
  apidae_obj.type_data = object_data[type_fields[:node]]
77
78
  apidae_obj.pictures_data = pictures_urls(object_data[:illustrations])
78
79
  apidae_obj.entity_data = entity_fields(object_data[:informations])
@@ -140,23 +141,21 @@ module Apidae
140
141
  end
141
142
  end
142
143
 
143
- def self.openings(openings_hash)
144
+ def self.parse_openings(openings_hash)
144
145
  if openings_hash && openings_hash[:periodeEnClair]
145
- {description: openings_hash[:periodeEnClair][:libelleFr], opening_periods: openings_hash[:periodesOuvertures]}
146
+ {openings_desc: openings_hash[:periodeEnClair][:libelleFr], openings: openings_hash[:periodesOuvertures]}
146
147
  end
147
148
  end
148
149
 
149
- def self.rates(rates_hash)
150
+ def self.parse_rates(rates_hash)
150
151
  if rates_hash
151
- if rates_hash[:gratuit]
152
- return 'gratuit'
153
- elsif rates_hash[:tarifsEnClair]
154
- rates_hash[:tarifsEnClair][:libelleFr]
155
- end
152
+ desc = rates_hash[:gratuit] ? 'gratuit' : node_value(rates_hash, :tarifsEnClair)
153
+ values = rates_hash[:periodes].blank? ? [] : rates_hash[:periodes].map {|p| build_rate(p)}
154
+ {rates_desc: desc, rates: values}
156
155
  end
157
156
  end
158
157
 
159
- def self.reservation(reservation_hash)
158
+ def self.parse_reservation(reservation_hash)
160
159
  if reservation_hash
161
160
  if reservation_hash[:complement]
162
161
  reservation_hash[:complement][:libelleFr]
@@ -184,6 +183,13 @@ module Apidae
184
183
  pictures.any? ? pictures[0]["url"] : "/#{Rails.application.config.apidae_pictures_path}/default/logo.png"
185
184
  end
186
185
 
186
+ def self.build_rate(rate_period)
187
+ {
188
+ id: rate_period[:identifiant], from: rate_period[:dateDebut], to: rate_period[:dateFin],
189
+ values: rate_period[:tarifs].blank? ? [] : rate_period[:tarifs].map {|t| {min: t[:minimum], max: t[:maximum], type: t[:type][:id], details: node_value(t, :precisionTarif)}}
190
+ }
191
+ end
192
+
187
193
  private
188
194
 
189
195
  def self.node_value(node, key)
@@ -1,7 +1,7 @@
1
1
  <%= render layout: "/layouts/#{Rails.application.config.apidae_layout}" do |styles| %>
2
2
  <div id="apidae_header" class="<%= styles[:header] %>">
3
3
  <%= link_to 'Retour', :back, class: styles[:back] %>
4
- <h1 class="<%= styles[:h1] %>">Apidae - Objets touristiques</h1>
4
+ <h1 class="<%= styles[:h1] %>">Apidae - <%= @selection ? "Sélection \"#{@selection.label}\"" : "Tous les objets touristiques" %></h1>
5
5
  </div>
6
6
  <div id="apidae_dashboard" class="<%= styles[:wrapper] %>">
7
7
  <div id="apidae_imports_panel" class="<%= styles[:body] %>">
@@ -11,7 +11,7 @@
11
11
  <th>Label</th>
12
12
  <th>Reference</th>
13
13
  <th>Identifiant</th>
14
- <th>Nombre d'objets</th>
14
+ <th>Objets</th>
15
15
  </tr>
16
16
  </thead>
17
17
  <tbody class="<%= styles[:table_body] %>">
@@ -20,7 +20,7 @@
20
20
  <td><%= selection.label %></td>
21
21
  <td><%= selection.reference %></td>
22
22
  <td><%= selection.apidae_id %></td>
23
- <td><%= selection.objects.count %></td>
23
+ <td><%= link_to selection.objects.count, selection_objects_path(selection) %></td>
24
24
  </tr>
25
25
  <% end %>
26
26
  <% if @selections.empty? %>
data/config/routes.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  Apidae::Engine.routes.draw do
2
2
 
3
3
  resources :objects, only: [:index], path: 'objets'
4
- resources :selections, only: [:index]
4
+ resources :selections, only: [:index] do
5
+ resources :objects, only: [:index]
6
+ end
5
7
 
6
8
  match 'import/callback', via: :post, to: 'import#callback'
7
9
  match 'import/run', via: :post, to: 'import#run'
@@ -0,0 +1,6 @@
1
+ class AddRatesDataToApidaeObjects < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :apidae_objects, :rates_data, :jsonb
4
+ remove_column :apidae_objects, :rates
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class RenameOpeningsToOpeningsData < ActiveRecord::Migration[5.1]
2
+ def change
3
+ rename_column :apidae_objects, :openings, :openings_data
4
+ end
5
+ end
data/lib/apidae/engine.rb CHANGED
@@ -3,5 +3,9 @@ require 'paperclip'
3
3
  module Apidae
4
4
  class Engine < Rails::Engine
5
5
  isolate_namespace Apidae
6
+ # Include all helpers from main app
7
+ config.to_prepare do
8
+ ApplicationController.helper(ActionView::Helpers::ApplicationHelper)
9
+ end
6
10
  end
7
11
  end
@@ -1,3 +1,3 @@
1
1
  module Apidae
2
- VERSION = "0.2.5"
2
+ VERSION = "0.2.6"
3
3
  end
@@ -10,7 +10,7 @@
10
10
  #
11
11
  # It's strongly recommended that you check this file into your version control system.
12
12
 
13
- ActiveRecord::Schema.define(version: 20180218231319) do
13
+ ActiveRecord::Schema.define(version: 20180222105302) do
14
14
 
15
15
  # These are extensions that must be enabled in order to support this database
16
16
  enable_extension "plpgsql"
@@ -62,8 +62,7 @@ ActiveRecord::Schema.define(version: 20180218231319) do
62
62
  t.jsonb "type_data"
63
63
  t.float "latitude"
64
64
  t.float "longitude"
65
- t.jsonb "openings"
66
- t.text "rates"
65
+ t.jsonb "openings_data"
67
66
  t.text "reservation"
68
67
  t.datetime "created_at", null: false
69
68
  t.datetime "updated_at", null: false
@@ -71,6 +70,7 @@ ActiveRecord::Schema.define(version: 20180218231319) do
71
70
  t.jsonb "pictures_data"
72
71
  t.jsonb "entity_data"
73
72
  t.jsonb "service_data"
73
+ t.jsonb "rates_data"
74
74
  end
75
75
 
76
76
  create_table "apidae_objects_selections", id: :serial, force: :cascade do |t|
@@ -283,3 +283,27 @@ Migrating to AddServiceDataToApidaeObjects (20180218231319)
283
283
   (0.1ms) COMMIT
284
284
   (0.3ms) SELECT pg_advisory_unlock(6140174353533887940)
285
285
   (0.3ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
286
+  (0.4ms) SELECT pg_try_advisory_lock(6140174353533887940)
287
+  (0.9ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
288
+ Migrating to AddRatesDataToApidaeObjects (20180222104915)
289
+  (12.2ms) BEGIN
290
+  (18.3ms) ALTER TABLE "apidae_objects" ADD "rates_data" jsonb
291
+  (3.4ms) ALTER TABLE "apidae_objects" DROP "rates"
292
+ SQL (1.0ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20180222104915"]]
293
+  (1.3ms) COMMIT
294
+ Migrating to RenameOpeningsToOpeningsData (20180222105302)
295
+  (0.2ms) BEGIN
296
+  (0.1ms) ROLLBACK
297
+  (0.2ms) SELECT pg_advisory_unlock(6140174353533887940)
298
+  (0.2ms) SELECT pg_try_advisory_lock(6140174353533887940)
299
+  (0.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
300
+ Migrating to RenameOpeningsToOpeningsData (20180222105302)
301
+  (0.2ms) BEGIN
302
+  (2.4ms) ALTER TABLE "apidae_objects" RENAME COLUMN "openings" TO "openings_data"
303
+ SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES ($1) RETURNING "version" [["version", "20180222105302"]]
304
+  (0.4ms) COMMIT
305
+ ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", "environment"], ["LIMIT", 1]]
306
+  (0.1ms) BEGIN
307
+  (0.1ms) COMMIT
308
+  (0.2ms) SELECT pg_advisory_unlock(6140174353533887940)
309
+  (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
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.2.5
4
+ version: 0.2.6
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: 2018-02-19 00:00:00.000000000 Z
11
+ date: 2018-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -125,6 +125,8 @@ files:
125
125
  - db/migrate/20180217222410_create_apidae_selection_objects.rb
126
126
  - db/migrate/20180218172704_change_text_columns_to_json.rb
127
127
  - db/migrate/20180218231319_add_service_data_to_apidae_objects.rb
128
+ - db/migrate/20180222104915_add_rates_data_to_apidae_objects.rb
129
+ - db/migrate/20180222105302_rename_openings_to_openings_data.rb
128
130
  - lib/apidae.rb
129
131
  - lib/apidae/engine.rb
130
132
  - lib/apidae/version.rb