From 6c36eb4dbc132e7176ffd6d3bc668ac0ff4b4b94 Mon Sep 17 00:00:00 2001 From: Franck Kerbiriou Date: Tue, 11 Feb 2020 23:29:15 +0100 Subject: [PATCH 1/4] Update shore_length in meters, fix distance --- app/models/report.rb | 6 +-- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- config/locales/fr.yml | 2 +- frontend/src/components/TracerCard.vue | 12 +++--- frontend/src/components/TracersGrid.vue | 20 +++++----- frontend/src/components/TracersList.vue | 18 ++++----- frontend/src/components/tools/AddReport.vue | 40 +++++++++++--------- frontend/src/store/modules/reports.js | 26 ++++++++----- frontend/src/views/MyReports.vue | 6 +-- lib/tasks/populate_shore_length.rake | 16 ++++---- lib/tasks/update_shore_length.rake | 16 ++++++++ spec/factories/report.rb | 2 +- spec/requests/api_spec.rb | 4 +- spec/requests/reports_spec.rb | 4 +- spec/support/api/schemas/geojson-report.json | 2 +- spec/support/api/schemas/report.json | 2 +- 17 files changed, 106 insertions(+), 74 deletions(-) create mode 100644 lib/tasks/update_shore_length.rake diff --git a/app/models/report.rb b/app/models/report.rb index 963b4479..15fc5427 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -36,10 +36,10 @@ class Report < ApplicationRecord belongs_to :tracer belongs_to :user, optional: true - validates :tracer_id, :name, :latitude, :longitude, :reported_at, :quantity, :shore_length, presence: true + validates :tracer_id, :name, :latitude, :longitude, :reported_at, :quantity, presence: true validates :photo, attached: true, content_type: ['image/png', 'image/jpeg', 'image/tiff', 'image/webp'], if: -> { !self.user&.senior && self.status != 'accepted' } - validates :shore_length, numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: 10 } - validates :quantity, numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: 500 } + validates :quantity, numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: 1000 } + validates :shore_length, numericality: { greater_than_or_equal_to: 100, less_than_or_equal_to: 15000 } end diff --git a/config/locales/en.yml b/config/locales/en.yml index 8ea6ad2e..91d66a43 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -37,7 +37,7 @@ en: reported_at: Reported at tracer: Tracer quantity: Quantity - shore_length: Shore kilometers + shore_length: Shore meters date: Date of report status: Status user: diff --git a/config/locales/es.yml b/config/locales/es.yml index b1e11c56..4b4307e9 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -37,7 +37,7 @@ es: reported_at: Informado a tracer: Localizador quantity: Cantidad - shore_length: kilómetro costero + shore_length: metro costero date: Fecha del informe status: Status user: diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 1b3c6973..2bb8ef96 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -37,7 +37,7 @@ fr: reported_at: Signalé le tracer: Traceur quantity: Quantité - shore_length: Kilomètre de rivages + shore_length: Mètre de rivages date: Date du signalement status: Statut user: diff --git a/frontend/src/components/TracerCard.vue b/frontend/src/components/TracerCard.vue index d6ed5f0f..fe8bec3c 100644 --- a/frontend/src/components/TracerCard.vue +++ b/frontend/src/components/TracerCard.vue @@ -29,8 +29,8 @@ {{ getReportCount()(tracer.id) }}

- {{ $t('quantity_by_km') }}: - {{ $n(getQuantitybyShoreLength()(tracer.id)) }}/km + {{ $t('distance_between_tracers') }}: + {{ $n(getReportsEveryKilometers()(tracer.id)) }}/km

@@ -51,7 +51,7 @@ export default { }, computed: {}, methods: { - ...reportsModule.mapGetters(['getReportCount', 'getQuantitybyShoreLength']) + ...reportsModule.mapGetters(['getReportCount', 'getReportsEveryKilometers']) } } @@ -79,7 +79,7 @@ export default { "created_at": "Created at", "origin": "Origin", "quantity": "Reported quantity", - "quantity_by_km": "Quantity by km", + "distance_between_tracers": "Distance between tracers", "name": "Name", "kind": "Type" }, @@ -87,7 +87,7 @@ export default { "created_at": "Créé le", "origin": "Origine", "quantity": "Quantité signalée", - "quantity_by_km": "Quantité par km", + "distance_between_tracers": "Distance entre traceurs", "name": "Nom", "kind": "Type" }, @@ -95,7 +95,7 @@ export default { "created_at": "Creado en", "origin": "Origen", "quantity": "Cantidad testificada", - "quantity_by_km": "Cantidad por km", + "distance_between_tracers": "Distancia entre trazadores", "name": "Apellido", "kind": "Tipo" } diff --git a/frontend/src/components/TracersGrid.vue b/frontend/src/components/TracersGrid.vue index e11599db..af16046e 100644 --- a/frontend/src/components/TracersGrid.vue +++ b/frontend/src/components/TracersGrid.vue @@ -72,7 +72,7 @@ export default { type: 'num', order: 'asc' }, - shore_length: { + distance_between_tracers: { active: false, type: 'num', order: 'asc' @@ -97,7 +97,7 @@ export default { }, methods: { ...mapGetters(['getTracers', 'getCategories']), - ...reportsModule.mapGetters(['getReportCount', 'getQuantitybyShoreLength']), + ...reportsModule.mapGetters(['getReportCount', 'getReportsEveryKilometers']), sortTracersBy: function(field, order) { if (order == null) { order = this.sortFields[field].order @@ -127,16 +127,16 @@ export default { }) } - if (field === 'shore_length') { + if (field === 'distance_between_tracers') { this.sortedTracers.sort((a, b) => { if ( - this.getQuantitybyShoreLength()(a.id) < - this.getQuantitybyShoreLength()(b.id) + this.getReportsEveryKilometers()(a.id) < + this.getReportsEveryKilometers()(b.id) ) { return 0 - modifier } else if ( - this.getQuantitybyShoreLength()(a.id) > - this.getQuantitybyShoreLength()(b.id) + this.getReportsEveryKilometers()(a.id) > + this.getReportsEveryKilometers()(b.id) ) { return modifier } else { @@ -189,7 +189,7 @@ export default { "created_at": "Created at", "origin": "Origin", "quantity": "Reported quantity", - "shore_length": "Quantity by km", + "distance_between_tracers": "Distance between tracers", "name": "Name", "research": "Research", "drift": "Drift", @@ -204,7 +204,7 @@ export default { "created_at": "Créé le", "origin": "Origine", "quantity": "Quantité signalée", - "shore_length": "Quantité par km", + "distance_between_tracers": "Distance entre traceurs", "name": "Nom", "research": "Recherche", "drift": "Dérive", @@ -219,7 +219,7 @@ export default { "created_at": "Creado en", "origin": "Origen", "quantity": "Cantidad testificada", - "shore_length": "Cantidad por km", + "distance_between_tracers": "Distancia entre trazadores", "name": "Apellido", "research": "Búsqueda", "drift": "Dériva", diff --git a/frontend/src/components/TracersList.vue b/frontend/src/components/TracersList.vue index 63a6b1ed..daea5574 100644 --- a/frontend/src/components/TracersList.vue +++ b/frontend/src/components/TracersList.vue @@ -53,13 +53,13 @@ >{{ getReportCount()(props.row.id) }} {{ $n(getQuantitybyShoreLength()(props.row.id)) }}{{ $n(getReportsEveryKilometers()(props.row.id)) }}