Skip to content

Commit

Permalink
Merge pull request #312 from FranckKe/tp-shore_length_meters
Browse files Browse the repository at this point in the history
Shore length in meters
  • Loading branch information
FranckKe authored Feb 22, 2020
2 parents 1abe484 + 7aaab28 commit 3341db0
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 96 deletions.
6 changes: 3 additions & 3 deletions app/models/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/components/TracerCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
</p>
<p>
<strong>{{ $t('created_at') }}:</strong>
<time datetime="tracer.created_at | formatDate">
{{ tracer.created_at | formatDate }}</time
>
<time datetime="tracer.created_at | formatDate">{{
tracer.created_at | formatDate
}}</time>
</p>
<p>
<strong>{{ $t('quantity') }}:</strong>
{{ getReportCount()(tracer.id) }}
</p>
<p>
<strong>{{ $t('quantity_by_km') }}:</strong>
{{ $n(getQuantitybyShoreLength()(tracer.id)) }}/km
<strong>{{ $t('distance_between_tracers') }}:</strong>
{{ $n(getReportsEveryKilometers()(tracer.id)) }} km
</p>
</div>
</div>
Expand All @@ -51,7 +51,7 @@ export default {
},
computed: {},
methods: {
...reportsModule.mapGetters(['getReportCount', 'getQuantitybyShoreLength'])
...reportsModule.mapGetters(['getReportCount', 'getReportsEveryKilometers'])
}
}
</script>
Expand Down Expand Up @@ -79,23 +79,23 @@ 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"
},
"fr": {
"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"
},
"es": {
"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"
}
Expand Down
29 changes: 18 additions & 11 deletions frontend/src/components/TracersGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
}})
</button>
</div>
<div v-for="(category, idt) in getCategories()" :key="idt" class="tracers-grid-wrapper">
<div
v-for="(category, idt) in getCategories()"
:key="idt"
class="tracers-grid-wrapper"
>
<h2 class="category-title title is-2">{{ $t(category) }}</h2>
<div class="tracers-grid columns is-multiline is-mobile">
<div
Expand Down Expand Up @@ -72,7 +76,7 @@ export default {
type: 'num',
order: 'asc'
},
shore_length: {
distance_between_tracers: {
active: false,
type: 'num',
order: 'asc'
Expand All @@ -97,7 +101,10 @@ 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
Expand Down Expand Up @@ -127,16 +134,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 {
Expand Down Expand Up @@ -189,7 +196,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",
Expand All @@ -204,7 +211,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",
Expand All @@ -219,7 +226,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",
Expand Down
24 changes: 15 additions & 9 deletions frontend/src/components/TracersList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@
>{{ getReportCount()(props.row.id) }}</b-table-column
>
<b-table-column
field="quantity_by_km"
v-bind:label="$t('quantity_by_km')"
field="distance_between_tracers"
v-bind:label="$t('distance_between_tracers')"
sortable
width="100"
centered
:custom-sort="sortByQuantityPerKm"
>{{ $n(getQuantitybyShoreLength()(props.row.id)) }}</b-table-column
>{{
$n(getReportsEveryKilometers()(props.row.id))
}}
km</b-table-column
>
</template>
<template slot="detail" slot-scope="props">
Expand Down Expand Up @@ -111,16 +114,19 @@ export default {
methods: {
...mapMutations(['setPerPage']),
...mapGetters(['getPerPage']),
...reportsModule.mapGetters(['getReportCount', 'getQuantitybyShoreLength']),
...reportsModule.mapGetters([
'getReportCount',
'getReportsEveryKilometers'
]),
sortByReportedQuantity: function(tracerA, tracerB, isAsc) {
const reportCountA = this.getReportCount()(tracerA.id)
const reportCountB = this.getReportCount()(tracerB.id)
return isAsc ? reportCountA - reportCountB : reportCountB - reportCountA
},
sortByQuantityPerKm: function(tracerA, tracerB, isAsc) {
const reportCountPerKmA = this.getQuantitybyShoreLength()(tracerA.id)
const reportCountPerKmB = this.getQuantitybyShoreLength()(tracerB.id)
const reportCountPerKmA = this.getReportsEveryKilometers()(tracerA.id)
const reportCountPerKmB = this.getReportsEveryKilometers()(tracerB.id)
return isAsc
? reportCountPerKmA - reportCountPerKmB
Expand Down Expand Up @@ -168,7 +174,7 @@ export default {
"origin": "Origin",
"per_page": "per page",
"reported_quantity": "Reported quantity",
"quantity_by_km": "Quantity by km",
"distance_between_tracers": "Distance between tracers",
"research": "Research",
"drift": "Drift",
"container": "Container",
Expand All @@ -183,7 +189,7 @@ export default {
"origin": "Origine",
"per_page": "par page",
"reported_quantity": "Quantité signalée",
"quantity_by_km": "Quantité par km",
"distance_between_tracers": "Distance entre traceurs",
"research": "Recherche",
"drift": "Dérive",
"container": "Conteneur",
Expand All @@ -198,7 +204,7 @@ export default {
"origin": "Origen",
"per_page": "por página",
"reported_quantity": "Cantidad testificada",
"quantity_by_km": "Cantidad por km",
"distance_between_tracers": "Distancia entre trazadores",
"research": "Búsqueda",
"drift": "Dériva",
"container": "Envase",
Expand Down
40 changes: 23 additions & 17 deletions frontend/src/components/tools/AddReport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,11 @@
v-model="shoreLengths[index]"
name="shoreLength"
type="number"
step="1"
min="1"
max="10"
step="0.1"
min="0.1"
max="15"
:data-vv-as="$t('shore_length')"
v-validate="'required|min_value:1|max_value:10'"
v-validate="'required|min_value:0.1|max_value:15'"
></b-input>
<p class="shore-length-unit">km</p>
</div>
Expand Down Expand Up @@ -319,7 +319,7 @@
areSomeReportsSubmitted
"
>
{{ $t('add') }}
<font-awesome-icon icon="plus" /> {{ $t('add_tracer') }}
</a>
</b-field>
<b-message
Expand Down Expand Up @@ -551,6 +551,7 @@ export default {
console.warn(e)
}
}
const postDataJson = {
name: this.$auth.check() ? this.$auth.user().name : this.username,
address: this.address,
Expand All @@ -559,9 +560,10 @@ export default {
reported_at: String(moment(this.reportDate).format('YYYY-MM-DD')),
tracer_id: (this.selectedTracers[index] || {}).id,
quantity: this.quantities[index],
shore_length: this.shoreLengths[index],
shore_length: this.shoreLengths[index] * 1000,
description: this.description
}
if (file64 != null) postDataJson.photo = file64
return this.$http({
Expand Down Expand Up @@ -783,6 +785,10 @@ export default {
margin-top: 0;
}
.add-tracer-input svg {
margin-right: 10px;
}
.close-icon {
align-self: flex-end;
}
Expand Down Expand Up @@ -835,19 +841,19 @@ export default {
}
.quantity-field {
width: 66px;
width: 60px;
}
.shore-length-field {
width: 100px;
width: auto;
.label {
height: 1.5rem;
}
.control,
input {
width: 50px;
width: 66px;
}
.shore-length-unit-wrapper {
Expand Down Expand Up @@ -960,7 +966,7 @@ export default {
{
"en": {
"report_verb": "Report",
"add": "Add a tracer",
"add_tracer": "Add a tracer",
"add_report": "Report a waste",
"address": "Address",
"cancel_report": "Close reporting",
Expand All @@ -976,9 +982,9 @@ export default {
"optional": "optional",
"previous": "Previous",
"quantity": "Quantity",
"shore_length": "Shore kilometers",
"shore_length": "Shore meters",
"shore_length_on": "on",
"shore_length_tooltip": "Collection's kilometers of shore",
"shore_length_tooltip": "Collection's meters of shore",
"report_date": "Date of report",
"report_review": "Thank you for your report. It will soon be reviewed by an administrator",
"report": "Report",
Expand All @@ -995,7 +1001,7 @@ export default {
},
"fr": {
"report_verb": "Signaler",
"add": "Ajouter un traceur",
"add_tracer": "Ajouter un traceur",
"add_report": "Signaler un déchet",
"address": "Adresse",
"cancel_report": "Fermer l'ajout de signalement",
Expand All @@ -1011,9 +1017,9 @@ export default {
"optional": "optionnel",
"previous": "Précédent",
"quantity": "Quantité",
"shore_length": "Kilomètres de rivage",
"shore_length": "mètres de rivage",
"shore_length_on": "sur",
"shore_length_tooltip": "Kilomètre de rivage du ramassage",
"shore_length_tooltip": "Mètre de rivage du ramassage",
"report_date": "Date de signalement",
"report_review": "Merci pour votre signalement. Une validation va bientôt être effectuée.",
"report": "Signalement",
Expand All @@ -1030,7 +1036,7 @@ export default {
},
"es": {
"report_verb": "Informe",
"add": "Añadir un trazador",
"add_tracer": "Añadir un trazador",
"add_report": "Reportar un desperdicio",
"address": "Dirección",
"cancel_report": "Cerrar agrega testimonio",
Expand All @@ -1048,7 +1054,7 @@ export default {
"quantity": "Cantidad",
"shore_length": "Kilómetros de la costa",
"shore_length_on": "en",
"shore_length_tooltip": "Recogida en la costa kilómetro",
"shore_length_tooltip": "Recogida en la costa metro",
"report_date": "Fecha de reporte",
"report_review": "Gracias por su testimonio. Uno administrador revisado soon",
"report": "Testimonio",
Expand Down
Loading

0 comments on commit 3341db0

Please sign in to comment.