Remove last occurences of address_type

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2019-01-14 18:12:52 +01:00
parent 289ba03960
commit 3230381be4
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
4 changed files with 117 additions and 125 deletions

View File

@ -8,14 +8,8 @@
</v-toolbar> </v-toolbar>
<v-card-text> <v-card-text>
<v-form> <v-form>
<v-text-field <v-text-field label="Title" v-model="event.title" :counter="100" required></v-text-field>
label="Title" <v-date-picker v-model="event.begins_on"></v-date-picker>
v-model="event.title"
:counter="100"
required
></v-text-field>
<v-date-picker v-model="event.begins_on">
</v-date-picker>
<v-radio-group v-model="event.location_type" row> <v-radio-group v-model="event.location_type" row>
<v-radio label="Address" value="physical" off-icon="place"></v-radio> <v-radio label="Address" value="physical" off-icon="place"></v-radio>
<v-radio label="Online" value="online" off-icon="link"></v-radio> <v-radio label="Online" value="online" off-icon="link"></v-radio>
@ -33,7 +27,7 @@
types="geocode" types="geocode"
v-on:placechanged="getAddressData" v-on:placechanged="getAddressData"
> >
</vuetify-google-autocomplete> --> </vuetify-google-autocomplete>-->
<v-text-field <v-text-field
v-if="event.location_type === 'online'" v-if="event.location_type === 'online'"
label="Meeting adress" label="Meeting adress"
@ -54,8 +48,7 @@
item-text="title" item-text="title"
item-value="id" item-value="id"
label="Categories" label="Categories"
> ></v-autocomplete>
</v-autocomplete>
<v-btn color="primary" @click="create">Create event</v-btn> <v-btn color="primary" @click="create">Create event</v-btn>
</v-form> </v-form>
</v-card-text> </v-card-text>
@ -66,125 +59,135 @@
</template> </template>
<script lang="ts"> <script lang="ts">
// import Location from '@/components/Location'; // import Location from '@/components/Location';
import VueMarkdown from 'vue-markdown'; import VueMarkdown from "vue-markdown";
import { CREATE_EVENT, EDIT_EVENT } from '@/graphql/event'; import { CREATE_EVENT, EDIT_EVENT } from "@/graphql/event";
import { FETCH_CATEGORIES } from '@/graphql/category'; import { FETCH_CATEGORIES } from "@/graphql/category";
import { AUTH_USER_ACTOR } from '@/constants'; import { AUTH_USER_ACTOR } from "@/constants";
import { Component, Prop, Vue } from 'vue-property-decorator'; import { Component, Prop, Vue } from "vue-property-decorator";
@Component({ @Component({
components: { components: {
VueMarkdown VueMarkdown
}, },
apollo: { apollo: {
categories: { categories: {
query: FETCH_CATEGORIES, query: FETCH_CATEGORIES
},
} }
}) }
export default class CreateEvent extends Vue { })
@Prop({required: false, type: String}) uuid!: string export default class CreateEvent extends Vue {
@Prop({ required: false, type: String }) uuid!: string;
e1 = 0 e1 = 0;
event = { event = {
title: null, title: null,
organizer_actor_id: null, organizer_actor_id: null,
description: '', description: "",
begins_on: (new Date()).toISOString().substr(0, 10), begins_on: new Date().toISOString().substr(0, 10),
ends_on: new Date(), ends_on: new Date(),
seats: null, seats: null,
physical_address: null, physical_address: null,
location_type: 'physical', location_type: "physical",
online_address: null, online_address: null,
tel_num: null, tel_num: null,
price: null, price: null,
category: null, category: null,
category_id: null, category_id: null,
tags: [], tags: [],
participants: [], participants: []
} as any // FIXME: correctly type an event } as any; // FIXME: correctly type an event
categories = [] categories = [];
tags = [] tags = [];
tagsToSend = [] tagsToSend = [];
tagsFetched = [] tagsFetched = [];
loading = false loading = false;
// created() { // created() {
// if (this.uuid) { // if (this.uuid) {
// this.fetchEvent(); // this.fetchEvent();
// } // }
// } // }
create () { create() {
// this.event.seats = parseInt(this.event.seats, 10); // this.event.seats = parseInt(this.event.seats, 10);
// this.tagsToSend.forEach((tag) => { // this.tagsToSend.forEach((tag) => {
// this.event.tags.push({ // this.event.tags.push({
// title: tag, // title: tag,
// // '@type': 'Tag', // // '@type': 'Tag',
// }); // });
// }); // });
// FIXME: correctly parse actor JSON // FIXME: correctly parse actor JSON
const actor = JSON.parse(localStorage.getItem(AUTH_USER_ACTOR) || '{}') const actor = JSON.parse(localStorage.getItem(AUTH_USER_ACTOR) || "{}");
this.event.category_id = this.event.category this.event.category_id = this.event.category;
this.event.organizer_actor_id = actor.id this.event.organizer_actor_id = actor.id;
this.event.participants = [actor.id] this.event.participants = [actor.id];
// this.event.price = parseFloat(this.event.price); // this.event.price = parseFloat(this.event.price);
if (this.uuid === undefined) { if (this.uuid === undefined) {
this.$apollo.mutate({ this.$apollo
.mutate({
mutation: CREATE_EVENT, mutation: CREATE_EVENT,
variables: { variables: {
title: this.event.title, title: this.event.title,
description: this.event.description, description: this.event.description,
organizerActorId: this.event.organizer_actor_id, organizerActorId: this.event.organizer_actor_id,
categoryId: this.event.category_id, categoryId: this.event.category_id,
beginsOn: this.event.begins_on, beginsOn: this.event.begins_on
addressType: this.event.location_type,
} }
}).then((data) => {
this.loading = false
this.$router.push({name: 'Event', params: {uuid: data.data.uuid}})
}).catch((error) => {
console.log(error)
}) })
} else { .then(data => {
this.$apollo.mutate({ this.loading = false;
mutation: EDIT_EVENT, this.$router.push({
}).then((data) => { name: "Event",
this.loading = false params: { uuid: data.data.uuid }
this.$router.push({name: 'Event', params: {uuid: data.data.uuid}}) });
}).catch((error) => {
console.log(error)
}) })
} .catch(error => {
this.event.tags = [] console.log(error);
});
} else {
this.$apollo
.mutate({
mutation: EDIT_EVENT
})
.then(data => {
this.loading = false;
this.$router.push({
name: "Event",
params: { uuid: data.data.uuid }
});
})
.catch(error => {
console.log(error);
});
} }
this.event.tags = [];
}
getAddressData (addressData) { getAddressData(addressData) {
if (addressData !== null) { if (addressData !== null) {
this.event.address = { this.event.address = {
geom: { geom: {
data: { data: {
latitude: addressData.latitude, latitude: addressData.latitude,
longitude: addressData.longitude, longitude: addressData.longitude
},
type: 'point',
}, },
addressCountry: addressData.country, type: "point"
addressLocality: addressData.locality, },
addressRegion: addressData.administrative_area_level_1, addressCountry: addressData.country,
postalCode: addressData.postal_code, addressLocality: addressData.locality,
streetAddress: `${addressData.street_number} ${addressData.route}`, addressRegion: addressData.administrative_area_level_1,
} postalCode: addressData.postal_code,
} streetAddress: `${addressData.street_number} ${addressData.route}`
};
} }
}
}; }
</script> </script>
<style> <style>
.markdown-render h1 { .markdown-render h1 {
font-size: 2em; font-size: 2em;
} }
</style> </style>

View File

@ -85,19 +85,13 @@ export const CREATE_EVENT = gql`
$organizerActorId: Int!, $organizerActorId: Int!,
$categoryId: Int!, $categoryId: Int!,
$beginsOn: DateTime!, $beginsOn: DateTime!,
$addressType: AddressType!,
) { ) {
createEvent( createEvent(
title: $title, title: $title,
description: $description, description: $description,
beginsOn: $beginsOn, beginsOn: $beginsOn,
organizerActorId: $organizerActorId, organizerActorId: $organizerActorId,
categoryId: $categoryId, categoryId: $categoryId
addressType: $addressType) {
uuid,
title,
description,
}
} }
`; `;

View File

@ -2,9 +2,7 @@ defmodule Mobilizon.Repo.Migrations.AddAddressType do
use Ecto.Migration use Ecto.Migration
def up do def up do
Mobilizon.Events.AddressTypeEnum.create_type
alter table(:events) do alter table(:events) do
add :address_type, :address_type
add :online_address, :string add :online_address, :string
add :phone, :string add :phone, :string
end end
@ -17,11 +15,9 @@ defmodule Mobilizon.Repo.Migrations.AddAddressType do
def down do def down do
alter table(:events) do alter table(:events) do
remove :address_type
remove :online_address remove :online_address
remove :phone remove :phone
end end
Mobilizon.Events.AddressTypeEnum.drop_type
drop constraint(:events, "events_physical_address_id_fkey") drop constraint(:events, "events_physical_address_id_fkey")
rename table(:events), :physical_address_id, to: :address_id rename table(:events), :physical_address_id, to: :address_id
alter table(:events) do alter table(:events) do

View File

@ -1,11 +1,10 @@
defmodule Mobilizon.Repo.Migrations.RemoveAddressType do defmodule Mobilizon.Repo.Migrations.RemoveAddressType do
use Ecto.Migration use Ecto.Migration
require Logger
def up do def up do
alter table(:events) do execute "DROP TYPE IF EXISTS address_type"
remove(:address_type) execute "ALTER TABLE \"events\" DROP COLUMN IF EXISTS address_type"
end
execute "DROP TYPE address_type"
rename table(:events), :phone, to: :phone_address rename table(:events), :phone, to: :phone_address
end end
end end