Front end deps upgrades and fixes

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2019-07-23 17:14:03 +02:00
parent 93984eb53a
commit 1cd511f440
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
4 changed files with 516 additions and 432 deletions

View file

@ -143,8 +143,7 @@ export const CREATE_EVENT = gql`
$organizerActorId: ID!, $organizerActorId: ID!,
$category: String!, $category: String!,
$beginsOn: DateTime!, $beginsOn: DateTime!,
$picture_file: Upload, $picture: PictureInput!
$picture_name: String,
) { ) {
createEvent( createEvent(
title: $title, title: $title,
@ -152,12 +151,7 @@ export const CREATE_EVENT = gql`
beginsOn: $beginsOn, beginsOn: $beginsOn,
organizerActorId: $organizerActorId, organizerActorId: $organizerActorId,
category: $category, category: $category,
picture: { picture: $picture
picture: {
file: $picture_file,
name: $picture_name,
}
}
) { ) {
id, id,
uuid, uuid,

View file

@ -28,7 +28,7 @@
</b-select> </b-select>
</b-field> </b-field>
<picture-upload @change="handlePictureUploadChange" /> <picture-upload v-model="pictureFile" />
<button class="button is-primary"> <button class="button is-primary">
<translate>Create my event</translate> <translate>Create my event</translate>
@ -50,7 +50,6 @@ import {
import { LOGGED_PERSON } from '@/graphql/actor'; import { LOGGED_PERSON } from '@/graphql/actor';
import { IPerson, Person } from '@/types/actor'; import { IPerson, Person } from '@/types/actor';
import PictureUpload from '@/components/PictureUpload.vue'; import PictureUpload from '@/components/PictureUpload.vue';
import { IPictureUpload } from '@/types/picture.model';
import Editor from '@/components/Editor.vue'; import Editor from '@/components/Editor.vue';
import DateTimePicker from '@/components/Event/DateTimePicker.vue'; import DateTimePicker from '@/components/Event/DateTimePicker.vue';
@ -68,8 +67,7 @@ export default class CreateEvent extends Vue {
loggedPerson: IPerson = new Person(); loggedPerson: IPerson = new Person();
categories: string[] = Object.keys(Category); categories: string[] = Object.keys(Category);
event: IEvent = new EventModel(); event: IEvent = new EventModel();
pictureFile?: File; pictureFile: File | null = null;
pictureName?: String;
created() { created() {
const now = new Date(); const now = new Date();
@ -81,23 +79,14 @@ export default class CreateEvent extends Vue {
createEvent(e: Event) { createEvent(e: Event) {
e.preventDefault(); e.preventDefault();
this.event.organizerActor = this.loggedPerson;
this.event.attributedTo = this.loggedPerson;
if (this.event.uuid === '') { if (this.event.uuid === '') {
console.log('event', this.event); console.log('event', this.event);
this.$apollo this.$apollo
.mutate({ .mutate({
mutation: CREATE_EVENT, mutation: CREATE_EVENT,
variables: { variables: this.buildVariables(),
title: this.event.title,
description: this.event.description,
beginsOn: this.event.beginsOn.toISOString(),
category: this.event.category,
organizerActorId: this.event.organizerActor.id,
picture_file: this.pictureFile,
picture_name: this.pictureName,
},
}) })
.then(data => { .then(data => {
console.log('event created', data); console.log('event created', data);
@ -126,10 +115,35 @@ export default class CreateEvent extends Vue {
} }
} }
handlePictureUploadChange(picture: IPictureUpload) { /**
console.log('picture upload change', picture); * Build variables for Event GraphQL creation query
this.pictureFile = picture.file; */
this.pictureName = picture.name; private buildVariables() {
/**
* Transform general variables
*/
let pictureObj = {};
let obj = {
organizerActorId: this.loggedPerson.id,
beginsOn: this.event.beginsOn.toISOString(),
};
let res = Object.assign({}, this.event, obj);
/**
* Transform picture files
*/
if (this.pictureFile) {
pictureObj = {
picture: {
picture: {
name: this.pictureFile.name,
file: this.pictureFile,
},
},
};
}
return Object.assign({}, res, pictureObj);
} }
// getAddressData(addressData) { // getAddressData(addressData) {

File diff suppressed because it is too large Load diff

View file

@ -91,10 +91,12 @@ defmodule MobilizonWeb.Upload do
def remove(url, opts \\ []) do def remove(url, opts \\ []) do
with opts <- get_opts(opts), with opts <- get_opts(opts),
%URI{path: "/media/" <> path, host: host} <- URI.parse(url), %URI{path: "/media/" <> path, host: host} <- URI.parse(url),
true <- host == MobilizonWeb.Endpoint.host() do {:same_host, true} <- {:same_host, host == MobilizonWeb.Endpoint.host()} do
MobilizonWeb.Uploaders.Uploader.remove_file(opts.uploader, path) MobilizonWeb.Uploaders.Uploader.remove_file(opts.uploader, path)
else else
%URI{} = _uri -> {:error, "URL doesn't match pattern"} %URI{} = _uri -> {:error, "URL doesn't match pattern"}
{:same_host, _} ->
Logger.error("Media can't be deleted because its URL doesn't match current host")
end end
end end