Merge branch 'feature/event-maps' into 'master'
Feature/event maps See merge request framasoft/mobilizon!105
This commit is contained in:
commit
fc0214c633
25
js/package-lock.json
generated
25
js/package-lock.json
generated
@ -1010,6 +1010,12 @@
|
||||
"integrity": "sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/geojson": {
|
||||
"version": "7946.0.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/geojson/-/geojson-7946.0.7.tgz",
|
||||
"integrity": "sha512-wE2v81i4C4Ol09RtsWFAqg3BUitWbHSpSlIo+bNdsCJijO9sjme+zm+73ZMCa/qMC8UEERxzGbvmr1cffo2SiQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/glob": {
|
||||
"version": "7.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/glob/-/glob-7.1.1.tgz",
|
||||
@ -1021,6 +1027,15 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/leaflet": {
|
||||
"version": "1.4.3",
|
||||
"resolved": "https://registry.npmjs.org/@types/leaflet/-/leaflet-1.4.3.tgz",
|
||||
"integrity": "sha512-jFRBSsPHi1EwQSwrN0cOJLdPhwOZsRl4IMxvm/2ShLh0YM5GfCtQXCzsrv8RE7DWL+AykXdYSAd9bFLWbZT4CQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/geojson": "*"
|
||||
}
|
||||
},
|
||||
"@types/lodash": {
|
||||
"version": "4.14.123",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.123.tgz",
|
||||
@ -8044,6 +8059,11 @@
|
||||
"invert-kv": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"leaflet": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/leaflet/-/leaflet-1.4.0.tgz",
|
||||
"integrity": "sha512-x9j9tGY1+PDLN9pcWTx9/y6C5nezoTMB8BLK5jTakx+H7bPlnbCHfi9Hjg+Qt36sgDz/cb9lrSpNQXmk45Tvhw=="
|
||||
},
|
||||
"levn": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz",
|
||||
@ -13973,6 +13993,11 @@
|
||||
"resolved": "https://registry.npmjs.org/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.6.0.tgz",
|
||||
"integrity": "sha512-x3LV3wdmmERhVCYy3quqA57NJW7F3i6faas++pJQWtknWT+n7k30F4TVdHvCLn48peTJFRvCpxs3UuFPqgeELg=="
|
||||
},
|
||||
"vue2-leaflet": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/vue2-leaflet/-/vue2-leaflet-2.0.2.tgz",
|
||||
"integrity": "sha512-8KAU0mbUp5CDwb5NBlpEoyCO/x+Rv1KeA4599HJqpHeOrzY0+PBoUabM80riUUWJWGhRi3yhV4DJ8Kf1QHRelQ=="
|
||||
},
|
||||
"vuex": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/vuex/-/vuex-3.1.0.tgz",
|
||||
|
@ -22,6 +22,7 @@
|
||||
"easygettext": "^2.7.0",
|
||||
"graphql": "^14.1.1",
|
||||
"graphql-tag": "^2.10.1",
|
||||
"leaflet": "^1.4.0",
|
||||
"lodash": "^4.17.11",
|
||||
"material-design-icons": "^3.0.1",
|
||||
"ngeohash": "^0.6.3",
|
||||
@ -34,10 +35,12 @@
|
||||
"vue-property-decorator": "^8.1.0",
|
||||
"vue-router": "^3.0.2",
|
||||
"vue-simple-markdown": "^1.0.9",
|
||||
"vue2-leaflet": "^2.0.2",
|
||||
"vuex": "^3.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.1.7",
|
||||
"@types/leaflet": "^1.4.3",
|
||||
"@types/lodash": "^4.14.123",
|
||||
"@types/mocha": "^5.2.6",
|
||||
"@vue/cli-plugin-babel": "^3.5.1",
|
||||
|
44
js/src/components/Map.vue
Normal file
44
js/src/components/Map.vue
Normal file
@ -0,0 +1,44 @@
|
||||
<template>
|
||||
<div style="height: 100%; width: 100%">
|
||||
<l-map
|
||||
:zoom="16"
|
||||
style="height: 80%; width: 100%"
|
||||
:center="[lat, lon]"
|
||||
>
|
||||
<l-tile-layer url="http://{s}.tile.osm.org/{z}/{x}/{y}.png"></l-tile-layer>
|
||||
<l-marker :lat-lng="[lat, lon]" >
|
||||
<l-popup v-if="popup">{{ popup }}</l-popup>
|
||||
</l-marker>
|
||||
</l-map>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { Icon } from 'leaflet';
|
||||
import 'leaflet/dist/leaflet.css';
|
||||
import { Component, Prop, Vue } from 'vue-property-decorator';
|
||||
import { LMap, LTileLayer, LMarker, LPopup } from 'vue2-leaflet';
|
||||
|
||||
@Component({
|
||||
components: { LTileLayer, LMap, LMarker, LPopup },
|
||||
})
|
||||
export default class Event extends Vue {
|
||||
@Prop({ type: String, required: true }) coords!: string;
|
||||
@Prop({ type: String, required: false }) popup!: string;
|
||||
|
||||
mounted() {
|
||||
// this part resolve an issue where the markers would not appear
|
||||
// @ts-ignore
|
||||
delete Icon.Default.prototype._getIconUrl;
|
||||
|
||||
Icon.Default.mergeOptions({
|
||||
iconRetinaUrl: require('leaflet/dist/images/marker-icon-2x.png'),
|
||||
iconUrl: require('leaflet/dist/images/marker-icon.png'),
|
||||
shadowUrl: require('leaflet/dist/images/marker-shadow.png'),
|
||||
});
|
||||
}
|
||||
|
||||
get lat() { return this.$props.coords.split(';')[0]; }
|
||||
get lon() { return this.$props.coords.split(';')[1]; }
|
||||
}
|
||||
</script>
|
@ -29,6 +29,16 @@ export const FETCH_EVENT = gql`
|
||||
category,
|
||||
# online_address,
|
||||
# phone_address,
|
||||
physicalAddress {
|
||||
description,
|
||||
floor,
|
||||
street,
|
||||
locality,
|
||||
postal_code,
|
||||
region,
|
||||
country,
|
||||
geom
|
||||
}
|
||||
organizerActor {
|
||||
avatarUrl,
|
||||
preferredUsername,
|
||||
@ -64,6 +74,9 @@ export const FETCH_EVENTS = gql`
|
||||
publishAt,
|
||||
# online_address,
|
||||
# phone_address,
|
||||
physicalAddress {
|
||||
description
|
||||
}
|
||||
organizerActor {
|
||||
avatarUrl,
|
||||
preferredUsername,
|
||||
|
@ -1,7 +1,6 @@
|
||||
// The Vue build version to load with the `import` command
|
||||
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
|
||||
import Vue from 'vue';
|
||||
// import * as VueGoogleMaps from 'vue2-google-maps';
|
||||
import VueSimpleMarkdown from 'vue-simple-markdown';
|
||||
import Buefy from 'buefy';
|
||||
import 'buefy/dist/buefy.css';
|
||||
|
10
js/src/types/address.model.ts
Normal file
10
js/src/types/address.model.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export interface IAddress {
|
||||
description: string;
|
||||
floor: string;
|
||||
street: string;
|
||||
locality: string;
|
||||
postal_code: string;
|
||||
region: string;
|
||||
country: string;
|
||||
geom: string;
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
import { Actor, IActor } from './actor.model';
|
||||
import { IAddress } from '@/types/address.model';
|
||||
|
||||
export enum EventStatus {
|
||||
TENTATIVE,
|
||||
@ -67,8 +68,9 @@ export interface IEvent {
|
||||
attributedTo: IActor;
|
||||
participants: IParticipant[];
|
||||
|
||||
// online_address: Address;
|
||||
// phone_address: string;
|
||||
onlineAddress?: string;
|
||||
phoneAddress?: string;
|
||||
physicalAddress?: IAddress;
|
||||
}
|
||||
|
||||
|
||||
@ -90,4 +92,6 @@ export class EventModel implements IEvent {
|
||||
visibility: EventVisibility = EventVisibility.PUBLIC;
|
||||
attributedTo: IActor = new Actor();
|
||||
organizerActor: IActor = new Actor();
|
||||
onlineAddress: string = '';
|
||||
phoneAddress: string = '';
|
||||
}
|
||||
|
@ -46,6 +46,21 @@
|
||||
<div>
|
||||
<span>{{ event.beginsOn | formatDate }} - {{ event.endsOn | formatDate }}</span>
|
||||
</div>
|
||||
<div class="address" v-if="event.physicalAddress">
|
||||
<h3 class="subtitle">Adresse</h3>
|
||||
<address>
|
||||
<span>{{ event.physicalAddress.description }}</span><br>
|
||||
<span>{{ event.physicalAddress.floor }} {{ event.physicalAddress.street }}</span><br>
|
||||
<span>{{ event.physicalAddress.postal_code }} {{ event.physicalAddress.locality }}</span><br>
|
||||
<span>{{ event.physicalAddress.region }} {{ event.physicalAddress.country }}</span>
|
||||
</address>
|
||||
<div class="map">
|
||||
<map-leaflet
|
||||
:coords="event.physicalAddress.geom"
|
||||
:popup="event.physicalAddress.description"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="actorIsOrganizer()">
|
||||
<translate>You are an organizer.</translate>
|
||||
</p>
|
||||
@ -110,6 +125,9 @@ import 'vue-simple-markdown/dist/vue-simple-markdown.css';
|
||||
import { GRAPHQL_API_ENDPOINT } from '@/api/_entrypoint';
|
||||
|
||||
@Component({
|
||||
components: {
|
||||
'map-leaflet': () => import('@/components/Map.vue'),
|
||||
},
|
||||
apollo: {
|
||||
event: {
|
||||
query: FETCH_EVENT,
|
||||
@ -225,3 +243,10 @@ export default class Event extends Vue {
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style lang="scss">
|
||||
.address div.map {
|
||||
height: 400px;
|
||||
width: 400px;
|
||||
padding: 25px 35px;
|
||||
}
|
||||
</style>
|
||||
|
@ -76,11 +76,11 @@ export default class CreateGroup extends Vue {
|
||||
latitude: addressData.latitude,
|
||||
longitude: addressData.longitude,
|
||||
},
|
||||
addressCountry: addressData.country,
|
||||
addressLocality: addressData.city,
|
||||
addressRegion: addressData.administrative_area_level_1,
|
||||
postalCode: addressData.postal_code,
|
||||
streetAddress: `${addressData.street_number} ${addressData.route}`,
|
||||
country: addressData.country,
|
||||
locality: addressData.city,
|
||||
region: addressData.administrative_area_level_1,
|
||||
postal_code: addressData.postal_code,
|
||||
street: `${addressData.street_number} ${addressData.route}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,8 @@
|
||||
"types": [
|
||||
"webpack-env",
|
||||
"mocha",
|
||||
"chai"
|
||||
"chai",
|
||||
"leaflet"
|
||||
],
|
||||
"paths": {
|
||||
"@/*": [
|
||||
|
@ -8,14 +8,14 @@ defmodule Mobilizon.Addresses.Address do
|
||||
# alias Mobilizon.Actors.Actor
|
||||
|
||||
schema "addresses" do
|
||||
field(:addressCountry, :string)
|
||||
field(:addressLocality, :string)
|
||||
field(:addressRegion, :string)
|
||||
field(:country, :string)
|
||||
field(:locality, :string)
|
||||
field(:region, :string)
|
||||
field(:description, :string)
|
||||
field(:floor, :string)
|
||||
field(:geom, Geo.PostGIS.Geometry)
|
||||
field(:postalCode, :string)
|
||||
field(:streetAddress, :string)
|
||||
field(:postal_code, :string)
|
||||
field(:street, :string)
|
||||
has_one(:event, Event, foreign_key: :physical_address_id)
|
||||
# has_one(:group, Actor)
|
||||
|
||||
@ -29,11 +29,11 @@ defmodule Mobilizon.Addresses.Address do
|
||||
:description,
|
||||
:floor,
|
||||
:geom,
|
||||
:addressCountry,
|
||||
:addressLocality,
|
||||
:addressRegion,
|
||||
:postalCode,
|
||||
:streetAddress
|
||||
:country,
|
||||
:locality,
|
||||
:region,
|
||||
:postal_code,
|
||||
:street
|
||||
])
|
||||
end
|
||||
end
|
||||
|
@ -11,6 +11,16 @@ defmodule Mobilizon.Addresses do
|
||||
|
||||
@geom_types [:point]
|
||||
|
||||
@doc false
|
||||
def data() do
|
||||
Dataloader.Ecto.new(Repo, query: &query/2)
|
||||
end
|
||||
|
||||
@doc false
|
||||
def query(queryable, _params) do
|
||||
queryable
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of addresses.
|
||||
|
||||
@ -168,7 +178,7 @@ defmodule Mobilizon.Addresses do
|
||||
|
||||
query =
|
||||
if country = Keyword.get(options, :country, nil),
|
||||
do: from(a in query, where: ilike(a.addressCountry, ^"%#{country}%")),
|
||||
do: from(a in query, where: ilike(a.country, ^"%#{country}%")),
|
||||
else: query
|
||||
|
||||
Repo.all(query)
|
||||
@ -198,7 +208,7 @@ defmodule Mobilizon.Addresses do
|
||||
|
||||
query =
|
||||
if country,
|
||||
do: from(a in query, where: ilike(a.addressCountry, ^"%#{country}%")),
|
||||
do: from(a in query, where: ilike(a.country, ^"%#{country}%")),
|
||||
else: query
|
||||
|
||||
Repo.all(query)
|
||||
|
@ -4,7 +4,7 @@ defmodule MobilizonWeb.Schema do
|
||||
"""
|
||||
use Absinthe.Schema
|
||||
|
||||
alias Mobilizon.{Actors, Events, Users}
|
||||
alias Mobilizon.{Actors, Events, Users, Addresses}
|
||||
alias Mobilizon.Actors.{Actor, Follower, Member}
|
||||
alias Mobilizon.Events.{Event, Comment, Participant}
|
||||
|
||||
@ -107,6 +107,7 @@ defmodule MobilizonWeb.Schema do
|
||||
|> Dataloader.add_source(Actors, Actors.data())
|
||||
|> Dataloader.add_source(Users, Users.data())
|
||||
|> Dataloader.add_source(Events, Events.data())
|
||||
|> Dataloader.add_source(Addresses, Addresses.data())
|
||||
|
||||
Map.put(ctx, :loader, loader)
|
||||
end
|
||||
|
@ -5,49 +5,37 @@ defmodule MobilizonWeb.Schema.AddressType do
|
||||
use Absinthe.Schema.Notation
|
||||
alias MobilizonWeb.Resolvers
|
||||
|
||||
object :physical_address do
|
||||
field(:type, :address_type)
|
||||
field(:geom, :point)
|
||||
field(:floor, :string)
|
||||
field(:streetAddress, :string)
|
||||
field(:addressLocality, :string)
|
||||
field(:postalCode, :string)
|
||||
field(:addressRegion, :string)
|
||||
field(:addressCountry, :string)
|
||||
object :address do
|
||||
field(:geom, :point, description: "The geocoordinates for the point where this address is")
|
||||
field(:floor, :string, description: "The floor this event is at")
|
||||
field(:street, :string, description: "The address's street name (with number)")
|
||||
field(:locality, :string, description: "The address's locality")
|
||||
field(:postal_code, :string)
|
||||
field(:region, :string)
|
||||
field(:country, :string)
|
||||
field(:description, :string)
|
||||
field(:name, :string)
|
||||
end
|
||||
|
||||
object :phone_address do
|
||||
field(:type, :address_type)
|
||||
field(:phone, :string)
|
||||
field(:info, :string)
|
||||
end
|
||||
|
||||
object :online_address do
|
||||
field(:type, :address_type)
|
||||
field(:url, :string)
|
||||
field(:info, :string)
|
||||
end
|
||||
|
||||
@desc "The list of types an address can be"
|
||||
enum :address_type do
|
||||
value(:physical, description: "The address is physical, like a postal address")
|
||||
value(:url, description: "The address is on the Web, like an URL")
|
||||
value(:phone, description: "The address is a phone number for a conference")
|
||||
value(:other, description: "The address is something else")
|
||||
end
|
||||
|
||||
object :address_queries do
|
||||
@desc "Search for an address"
|
||||
field :search_address, type: list_of(:physical_address) do
|
||||
field :search_address, type: list_of(:address) do
|
||||
arg(:query, non_null(:string))
|
||||
|
||||
resolve(&Resolvers.Address.search/3)
|
||||
end
|
||||
|
||||
@desc "Reverse geocode coordinates"
|
||||
field :reverse_geocode, type: list_of(:physical_address) do
|
||||
field :reverse_geocode, type: list_of(:address) do
|
||||
arg(:longitude, non_null(:float))
|
||||
arg(:latitude, non_null(:float))
|
||||
|
||||
|
@ -3,7 +3,7 @@ defmodule MobilizonWeb.Schema.EventType do
|
||||
Schema representation for Event
|
||||
"""
|
||||
use Absinthe.Schema.Notation
|
||||
alias Mobilizon.Actors
|
||||
alias Mobilizon.{Actors, Addresses}
|
||||
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
||||
import_types(MobilizonWeb.Schema.AddressType)
|
||||
import_types(MobilizonWeb.Schema.Events.ParticipantType)
|
||||
@ -27,7 +27,12 @@ defmodule MobilizonWeb.Schema.EventType do
|
||||
# TODO replace me with banner
|
||||
field(:large_image, :string, description: "A large picture for the event")
|
||||
field(:publish_at, :datetime, description: "When the event was published")
|
||||
field(:physical_address, :physical_address, description: "The type of the event's address")
|
||||
|
||||
field(:physical_address, :address,
|
||||
resolve: dataloader(Addresses),
|
||||
description: "The type of the event's address"
|
||||
)
|
||||
|
||||
field(:online_address, :online_address, description: "Online address of the event")
|
||||
field(:phone_address, :phone_address, description: "Phone address for the event")
|
||||
|
||||
|
@ -44,11 +44,11 @@ defmodule MobilizonWeb.JsonLD.ObjectView do
|
||||
"name" => address.description,
|
||||
"address" => %{
|
||||
"@type" => "PostalAddress",
|
||||
"streetAddress" => address.streetAddress,
|
||||
"addressLocality" => address.addressLocality,
|
||||
"postalCode" => address.postalCode,
|
||||
"addressRegion" => address.addressRegion,
|
||||
"addressCountry" => address.addressCountry
|
||||
"streetAddress" => address.street,
|
||||
"addressLocality" => address.locality,
|
||||
"postalCode" => address.postal_code,
|
||||
"addressRegion" => address.region,
|
||||
"addressCountry" => address.country
|
||||
}
|
||||
}
|
||||
end
|
||||
|
@ -63,14 +63,14 @@ defmodule Mobilizon.Service.Geospatial.Addok do
|
||||
features
|
||||
|> Enum.map(fn %{"geometry" => geometry, "properties" => properties} ->
|
||||
%Address{
|
||||
addressCountry: Map.get(properties, "country"),
|
||||
addressLocality: Map.get(properties, "city"),
|
||||
addressRegion: Map.get(properties, "state"),
|
||||
country: Map.get(properties, "country"),
|
||||
locality: Map.get(properties, "city"),
|
||||
region: Map.get(properties, "state"),
|
||||
description: Map.get(properties, "name") || streetAddress(properties),
|
||||
floor: Map.get(properties, "floor"),
|
||||
geom: Map.get(geometry, "coordinates") |> Provider.coordinates(),
|
||||
postalCode: Map.get(properties, "postcode"),
|
||||
streetAddress: properties |> streetAddress()
|
||||
postal_code: Map.get(properties, "postcode"),
|
||||
street: properties |> streetAddress()
|
||||
}
|
||||
end)
|
||||
end
|
||||
|
@ -96,14 +96,14 @@ defmodule Mobilizon.Service.Geospatial.GoogleMaps do
|
||||
end)
|
||||
|
||||
%Address{
|
||||
addressCountry: Map.get(components, "country"),
|
||||
addressLocality: Map.get(components, "locality"),
|
||||
addressRegion: Map.get(components, "administrative_area_level_1"),
|
||||
country: Map.get(components, "country"),
|
||||
locality: Map.get(components, "locality"),
|
||||
region: Map.get(components, "administrative_area_level_1"),
|
||||
description: description,
|
||||
floor: nil,
|
||||
geom: [lon, lat] |> Provider.coordinates(),
|
||||
postalCode: Map.get(components, "postal_code"),
|
||||
streetAddress: street_address(components)
|
||||
postal_code: Map.get(components, "postal_code"),
|
||||
street: street_address(components)
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -103,14 +103,14 @@ defmodule Mobilizon.Service.Geospatial.MapQuest do
|
||||
|
||||
defp produceAddress(address, lat, lng) do
|
||||
%Address{
|
||||
addressCountry: Map.get(address, "adminArea1"),
|
||||
addressLocality: Map.get(address, "adminArea5"),
|
||||
addressRegion: Map.get(address, "adminArea3"),
|
||||
country: Map.get(address, "adminArea1"),
|
||||
locality: Map.get(address, "adminArea5"),
|
||||
region: Map.get(address, "adminArea3"),
|
||||
description: Map.get(address, "street"),
|
||||
floor: Map.get(address, "floor"),
|
||||
geom: [lng, lat] |> Provider.coordinates(),
|
||||
postalCode: Map.get(address, "postalCode"),
|
||||
streetAddress: Map.get(address, "street")
|
||||
postal_code: Map.get(address, "postalCode"),
|
||||
street: Map.get(address, "street")
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -67,14 +67,14 @@ defmodule Mobilizon.Service.Geospatial.Nominatim do
|
||||
@spec process_data(map()) :: Address.t()
|
||||
defp process_data(%{"address" => address} = body) do
|
||||
%Address{
|
||||
addressCountry: Map.get(address, "country"),
|
||||
addressLocality: Map.get(address, "city"),
|
||||
addressRegion: Map.get(address, "state"),
|
||||
country: Map.get(address, "country"),
|
||||
locality: Map.get(address, "city"),
|
||||
region: Map.get(address, "state"),
|
||||
description: Map.get(body, "display_name"),
|
||||
floor: Map.get(address, "floor"),
|
||||
geom: [Map.get(body, "lon"), Map.get(body, "lat")] |> Provider.coordinates(),
|
||||
postalCode: Map.get(address, "postcode"),
|
||||
streetAddress: street_address(address)
|
||||
postal_code: Map.get(address, "postcode"),
|
||||
street: street_address(address)
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -65,14 +65,14 @@ defmodule Mobilizon.Service.Geospatial.Photon do
|
||||
features
|
||||
|> Enum.map(fn %{"geometry" => geometry, "properties" => properties} ->
|
||||
%Address{
|
||||
addressCountry: Map.get(properties, "country"),
|
||||
addressLocality: Map.get(properties, "city"),
|
||||
addressRegion: Map.get(properties, "state"),
|
||||
country: Map.get(properties, "country"),
|
||||
locality: Map.get(properties, "city"),
|
||||
region: Map.get(properties, "state"),
|
||||
description: Map.get(properties, "name") || streetAddress(properties),
|
||||
floor: Map.get(properties, "floor"),
|
||||
geom: Map.get(geometry, "coordinates") |> Provider.coordinates(),
|
||||
postalCode: Map.get(properties, "postcode"),
|
||||
streetAddress: properties |> streetAddress()
|
||||
postal_code: Map.get(properties, "postcode"),
|
||||
street: properties |> streetAddress()
|
||||
}
|
||||
end)
|
||||
end
|
||||
|
@ -0,0 +1,11 @@
|
||||
defmodule Mobilizon.Repo.Migrations.RenameAddressFields do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
rename(table(:addresses), :addressCountry, to: :country)
|
||||
rename(table(:addresses), :addressLocality, to: :locality)
|
||||
rename(table(:addresses), :addressRegion, to: :region)
|
||||
rename(table(:addresses), :postalCode, to: :postal_code)
|
||||
rename(table(:addresses), :streetAddress, to: :street)
|
||||
end
|
||||
end
|
@ -7,23 +7,23 @@ defmodule Mobilizon.AddressesTest do
|
||||
alias Mobilizon.Addresses.Address
|
||||
|
||||
@valid_attrs %{
|
||||
addressCountry: "some addressCountry",
|
||||
addressLocality: "some addressLocality",
|
||||
addressRegion: "some addressRegion",
|
||||
country: "some addressCountry",
|
||||
locality: "some addressLocality",
|
||||
region: "some addressRegion",
|
||||
description: "some description",
|
||||
floor: "some floor",
|
||||
postalCode: "some postalCode",
|
||||
streetAddress: "some streetAddress",
|
||||
postal_code: "some postalCode",
|
||||
street: "some streetAddress",
|
||||
geom: %Geo.Point{coordinates: {10, -10}, srid: 4326}
|
||||
}
|
||||
@update_attrs %{
|
||||
addressCountry: "some updated addressCountry",
|
||||
addressLocality: "some updated addressLocality",
|
||||
addressRegion: "some updated addressRegion",
|
||||
country: "some updated addressCountry",
|
||||
locality: "some updated addressLocality",
|
||||
region: "some updated addressRegion",
|
||||
description: "some updated description",
|
||||
floor: "some updated floor",
|
||||
postalCode: "some updated postalCode",
|
||||
streetAddress: "some updated streetAddress",
|
||||
postal_code: "some updated postalCode",
|
||||
street: "some updated streetAddress",
|
||||
geom: %Geo.Point{coordinates: {20, -20}, srid: 4326}
|
||||
}
|
||||
# @invalid_attrs %{
|
||||
@ -58,25 +58,25 @@ defmodule Mobilizon.AddressesTest do
|
||||
|
||||
test "create_address/1 with valid data creates a address" do
|
||||
assert {:ok, %Address{} = address} = Addresses.create_address(@valid_attrs)
|
||||
assert address.addressCountry == "some addressCountry"
|
||||
assert address.addressLocality == "some addressLocality"
|
||||
assert address.addressRegion == "some addressRegion"
|
||||
assert address.country == "some addressCountry"
|
||||
assert address.locality == "some addressLocality"
|
||||
assert address.region == "some addressRegion"
|
||||
assert address.description == "some description"
|
||||
assert address.floor == "some floor"
|
||||
assert address.postalCode == "some postalCode"
|
||||
assert address.streetAddress == "some streetAddress"
|
||||
assert address.postal_code == "some postalCode"
|
||||
assert address.street == "some streetAddress"
|
||||
end
|
||||
|
||||
test "update_address/2 with valid data updates the address" do
|
||||
address = address_fixture()
|
||||
assert {:ok, %Address{} = address} = Addresses.update_address(address, @update_attrs)
|
||||
assert address.addressCountry == "some updated addressCountry"
|
||||
assert address.addressLocality == "some updated addressLocality"
|
||||
assert address.addressRegion == "some updated addressRegion"
|
||||
assert address.country == "some updated addressCountry"
|
||||
assert address.locality == "some updated addressLocality"
|
||||
assert address.region == "some updated addressRegion"
|
||||
assert address.description == "some updated description"
|
||||
assert address.floor == "some updated floor"
|
||||
assert address.postalCode == "some updated postalCode"
|
||||
assert address.streetAddress == "some updated streetAddress"
|
||||
assert address.postal_code == "some updated postalCode"
|
||||
assert address.street == "some updated streetAddress"
|
||||
end
|
||||
|
||||
test "delete_address/1 deletes the address" do
|
||||
|
@ -35,10 +35,10 @@ defmodule Mobilizon.Service.Geospatial.AddokTest do
|
||||
test "returns a valid address from search" do
|
||||
use_cassette "geospatial/addok/search" do
|
||||
assert %Address{
|
||||
addressLocality: "Lyon",
|
||||
locality: "Lyon",
|
||||
description: "10 Rue Jangot",
|
||||
postalCode: "69007",
|
||||
streetAddress: "10 Rue Jangot",
|
||||
postal_code: "69007",
|
||||
street: "10 Rue Jangot",
|
||||
geom: %Geo.Point{coordinates: {4.842569, 45.751718}, properties: %{}, srid: 4326}
|
||||
} == Addok.search("10 rue Jangot") |> hd
|
||||
end
|
||||
@ -47,10 +47,10 @@ defmodule Mobilizon.Service.Geospatial.AddokTest do
|
||||
test "returns a valid address from reverse geocode" do
|
||||
use_cassette "geospatial/addok/geocode" do
|
||||
assert %Address{
|
||||
addressLocality: "Lyon",
|
||||
locality: "Lyon",
|
||||
description: "10 Rue Jangot",
|
||||
postalCode: "69007",
|
||||
streetAddress: "10 Rue Jangot",
|
||||
postal_code: "69007",
|
||||
street: "10 Rue Jangot",
|
||||
geom: %Geo.Point{coordinates: {4.842569, 45.751718}, properties: %{}, srid: 4326}
|
||||
} == Addok.geocode(4.842569, 45.751718) |> hd
|
||||
end
|
||||
|
@ -42,12 +42,12 @@ defmodule Mobilizon.Service.Geospatial.GoogleMapsTest do
|
||||
test "returns a valid address from search" do
|
||||
use_cassette "geospatial/google_maps/search" do
|
||||
assert %Address{
|
||||
addressLocality: "Lyon",
|
||||
locality: "Lyon",
|
||||
description: "10 Rue Jangot, 69007 Lyon, France",
|
||||
addressRegion: "Auvergne-Rhône-Alpes",
|
||||
addressCountry: "France",
|
||||
postalCode: "69007",
|
||||
streetAddress: "10 Rue Jangot",
|
||||
region: "Auvergne-Rhône-Alpes",
|
||||
country: "France",
|
||||
postal_code: "69007",
|
||||
street: "10 Rue Jangot",
|
||||
geom: %Geo.Point{
|
||||
coordinates: {4.8424032, 45.75164940000001},
|
||||
properties: %{},
|
||||
@ -60,12 +60,12 @@ defmodule Mobilizon.Service.Geospatial.GoogleMapsTest do
|
||||
test "returns a valid address from reverse geocode" do
|
||||
use_cassette "geospatial/google_maps/geocode" do
|
||||
assert %Address{
|
||||
addressLocality: "Lyon",
|
||||
locality: "Lyon",
|
||||
description: "10 Rue Jangot, 69007 Lyon, France",
|
||||
addressRegion: "Auvergne-Rhône-Alpes",
|
||||
addressCountry: "France",
|
||||
postalCode: "69007",
|
||||
streetAddress: "10 Rue Jangot",
|
||||
region: "Auvergne-Rhône-Alpes",
|
||||
country: "France",
|
||||
postal_code: "69007",
|
||||
street: "10 Rue Jangot",
|
||||
geom: %Geo.Point{
|
||||
coordinates: {4.8424967, 45.751725},
|
||||
properties: %{},
|
||||
|
@ -45,12 +45,12 @@ defmodule Mobilizon.Service.Geospatial.MapQuestTest do
|
||||
test "returns a valid address from search" do
|
||||
use_cassette "geospatial/map_quest/search" do
|
||||
assert %Address{
|
||||
addressLocality: "Lyon",
|
||||
locality: "Lyon",
|
||||
description: "10 Rue Jangot",
|
||||
addressRegion: "Auvergne-Rhône-Alpes",
|
||||
addressCountry: "FR",
|
||||
postalCode: "69007",
|
||||
streetAddress: "10 Rue Jangot",
|
||||
region: "Auvergne-Rhône-Alpes",
|
||||
country: "FR",
|
||||
postal_code: "69007",
|
||||
street: "10 Rue Jangot",
|
||||
geom: %Geo.Point{
|
||||
coordinates: {4.842566, 45.751714},
|
||||
properties: %{},
|
||||
@ -65,12 +65,12 @@ defmodule Mobilizon.Service.Geospatial.MapQuestTest do
|
||||
test "returns a valid address from reverse geocode" do
|
||||
use_cassette "geospatial/map_quest/geocode" do
|
||||
assert %Address{
|
||||
addressLocality: "Lyon",
|
||||
locality: "Lyon",
|
||||
description: "10 Rue Jangot",
|
||||
addressRegion: "Auvergne-Rhône-Alpes",
|
||||
addressCountry: "FR",
|
||||
postalCode: "69007",
|
||||
streetAddress: "10 Rue Jangot",
|
||||
region: "Auvergne-Rhône-Alpes",
|
||||
country: "FR",
|
||||
postal_code: "69007",
|
||||
street: "10 Rue Jangot",
|
||||
geom: %Geo.Point{
|
||||
coordinates: {4.842569, 45.751718},
|
||||
properties: %{},
|
||||
|
@ -28,13 +28,13 @@ defmodule Mobilizon.Service.Geospatial.NominatimTest do
|
||||
test "returns a valid address from search" do
|
||||
use_cassette "geospatial/nominatim/search" do
|
||||
assert %Address{
|
||||
addressLocality: "Lyon",
|
||||
locality: "Lyon",
|
||||
description:
|
||||
"10, Rue Jangot, La Guillotière, Lyon 7e Arrondissement, Lyon, Métropole de Lyon, Departemental constituency of Rhône, Auvergne-Rhône-Alpes, Metropolitan France, 69007, France",
|
||||
addressRegion: "Auvergne-Rhône-Alpes",
|
||||
addressCountry: "France",
|
||||
postalCode: "69007",
|
||||
streetAddress: "10 Rue Jangot",
|
||||
region: "Auvergne-Rhône-Alpes",
|
||||
country: "France",
|
||||
postal_code: "69007",
|
||||
street: "10 Rue Jangot",
|
||||
geom: %Geo.Point{
|
||||
coordinates: {4.8425657, 45.7517141},
|
||||
properties: %{},
|
||||
@ -47,13 +47,13 @@ defmodule Mobilizon.Service.Geospatial.NominatimTest do
|
||||
test "returns a valid address from reverse geocode" do
|
||||
use_cassette "geospatial/nominatim/geocode" do
|
||||
assert %Address{
|
||||
addressLocality: "Lyon",
|
||||
locality: "Lyon",
|
||||
description:
|
||||
"10, Rue Jangot, La Guillotière, Lyon 7e Arrondissement, Lyon, Métropole de Lyon, Circonscription départementale du Rhône, Auvergne-Rhône-Alpes, France métropolitaine, 69007, France",
|
||||
addressRegion: "Auvergne-Rhône-Alpes",
|
||||
addressCountry: "France",
|
||||
postalCode: "69007",
|
||||
streetAddress: "10 Rue Jangot",
|
||||
region: "Auvergne-Rhône-Alpes",
|
||||
country: "France",
|
||||
postal_code: "69007",
|
||||
street: "10 Rue Jangot",
|
||||
geom: %Geo.Point{
|
||||
coordinates: {4.8425657, 45.7517141},
|
||||
properties: %{},
|
||||
|
@ -26,12 +26,12 @@ defmodule Mobilizon.Service.Geospatial.PhotonTest do
|
||||
test "returns a valid address from search" do
|
||||
use_cassette "geospatial/photon/search" do
|
||||
assert %Address{
|
||||
addressLocality: "Lyon",
|
||||
locality: "Lyon",
|
||||
description: "10 Rue Jangot",
|
||||
addressRegion: "Auvergne-Rhône-Alpes",
|
||||
addressCountry: "France",
|
||||
postalCode: "69007",
|
||||
streetAddress: "10 Rue Jangot",
|
||||
region: "Auvergne-Rhône-Alpes",
|
||||
country: "France",
|
||||
postal_code: "69007",
|
||||
street: "10 Rue Jangot",
|
||||
geom: %Geo.Point{
|
||||
coordinates: {4.8425657, 45.7517141},
|
||||
properties: %{},
|
||||
@ -45,12 +45,12 @@ defmodule Mobilizon.Service.Geospatial.PhotonTest do
|
||||
# test "returns a valid address from reverse geocode" do
|
||||
# use_cassette "geospatial/photon/geocode" do
|
||||
# assert %Address{
|
||||
# addressLocality: "Lyon",
|
||||
# locality: "Lyon",
|
||||
# description: "",
|
||||
# addressRegion: "Auvergne-Rhône-Alpes",
|
||||
# addressCountry: "France",
|
||||
# postalCode: "69007",
|
||||
# streetAddress: "10 Rue Jangot",
|
||||
# region: "Auvergne-Rhône-Alpes",
|
||||
# country: "France",
|
||||
# postal_code: "69007",
|
||||
# street: "10 Rue Jangot",
|
||||
# geom: %Geo.Point{
|
||||
# coordinates: {4.8425657, 45.7517141},
|
||||
# properties: %{},
|
||||
|
@ -10,6 +10,7 @@ defmodule MobilizonWeb.Resolvers.AddressResolverTest do
|
||||
query = """
|
||||
{
|
||||
searchAddress(query: "10 Rue Jangot") {
|
||||
street,
|
||||
description,
|
||||
geom
|
||||
}
|
||||
|
@ -72,11 +72,11 @@ defmodule Mobilizon.Factory do
|
||||
description: sequence("MyAddress"),
|
||||
geom: %Geo.Point{coordinates: {45.75, 4.85}, srid: 4326},
|
||||
floor: "Myfloor",
|
||||
addressCountry: "My Country",
|
||||
addressLocality: "My Locality",
|
||||
addressRegion: "My Region",
|
||||
postalCode: "My Postal Code",
|
||||
streetAddress: "My Street Address"
|
||||
country: "My Country",
|
||||
locality: "My Locality",
|
||||
region: "My Region",
|
||||
postal_code: "My Postal Code",
|
||||
street: "My Street Address"
|
||||
}
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user