From b8ae047db235a80fe60c4b628a3411468ba85e08 Mon Sep 17 00:00:00 2001 From: f Date: Sun, 16 Feb 2020 19:51:43 -0300 Subject: [PATCH] metadata geo --- app/models/metadata_geo.rb | 23 +++++++++++++++++++++++ app/views/posts/attribute_ro/_geo.haml | 9 +++++++++ app/views/posts/attributes/_geo.haml | 19 +++++++++++++++++++ config/locales/en.yml | 3 +++ config/locales/es.yml | 3 +++ 5 files changed, 57 insertions(+) create mode 100644 app/models/metadata_geo.rb create mode 100644 app/views/posts/attribute_ro/_geo.haml create mode 100644 app/views/posts/attributes/_geo.haml diff --git a/app/models/metadata_geo.rb b/app/models/metadata_geo.rb new file mode 100644 index 0000000..3b7c31b --- /dev/null +++ b/app/models/metadata_geo.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +# Define un campo de coordenadas geográficas +class MetadataGeo < MetadataTemplate + def default_value + { 'lat' => nil, 'lng' => nil } + end + + def empty? + value == default_value + end + + def to_param + { name => %i[lat lng] } + end + + def save + self[:value] = { + 'lat' => self[:value]['lat'].to_f, + 'lng' => self[:value]['lng'].to_f + } + end +end diff --git a/app/views/posts/attribute_ro/_geo.haml b/app/views/posts/attribute_ro/_geo.haml new file mode 100644 index 0000000..feeacf2 --- /dev/null +++ b/app/views/posts/attribute_ro/_geo.haml @@ -0,0 +1,9 @@ +- lat = metadata.value['lat'] +- lng = metadata.value['lng'] +%tr{ id: attribute } + %th= post_label_t(attribute, post: post) + %td + = link_to t('posts.attributes.geo.uri'), "geo:#{lat},#{lng}" + %br/ + = link_to t('posts.attributes.geo.osm'), + "https://www.openstreetmap.org/?mlat=#{lat}&mlon=#{lng}#map=9/#{lat}/#{lng}" diff --git a/app/views/posts/attributes/_geo.haml b/app/views/posts/attributes/_geo.haml new file mode 100644 index 0000000..839393d --- /dev/null +++ b/app/views/posts/attributes/_geo.haml @@ -0,0 +1,19 @@ +.row + .col + .form-group + = label_tag "post_#{attribute}_lat", + post_label_t(attribute, :lat, post: post) + = text_field(*field_name_for('post', attribute, :lat), + value: metadata.value['lat'], + **field_options(attribute, metadata)) + = render 'posts/attribute_feedback', + post: post, attribute: [attribute, :lat], metadata: metadata + .col + .form-group + = label_tag "post_#{attribute}_lng", + post_label_t(attribute, :lng, post: post) + = text_field(*field_name_for('post', attribute, :lng), + value: metadata.value['lng'], + **field_options(attribute, metadata)) + = render 'posts/attribute_feedback', + post: post, attribute: [attribute, :lat], metadata: metadata diff --git a/config/locales/en.yml b/config/locales/en.yml index 1a452b5..a6a6370 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -365,6 +365,9 @@ en: feedback: 'This field cannot be empty!' uuid: label: 'Unique identifier' + geo: + uri: 'Open in app' + osm: 'Open in web map' reorder: 'Reorder posts' sort: by: 'Sort by' diff --git a/config/locales/es.yml b/config/locales/es.yml index 163f3f3..832d8fa 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -373,6 +373,9 @@ es: feedback: '¡Este campo no puede estar vacío!' uuid: label: 'Identificador único' + geo: + uri: 'Abrir en aplicación' + osm: 'Abrir en mapa web' reorder: 'Reordenar artículos' sort: by: 'Ordenar por'