Set up frontend/backend to add imageAspectRatio

- on create and update
This commit is contained in:
mattwr18 2019-11-21 11:32:42 +01:00
parent 647e92fe7d
commit b9d28e5a69
9 changed files with 39 additions and 48 deletions

View File

@ -121,7 +121,6 @@ export default {
} finally { } finally {
session.close() session.close()
} }
return post return post
}, },
UpdatePost: async (_parent, params, context, _resolveInfo) => { UpdatePost: async (_parent, params, context, _resolveInfo) => {
@ -297,7 +296,15 @@ export default {
}, },
Post: { Post: {
...Resolver('Post', { ...Resolver('Post', {
undefinedToNull: ['activityId', 'objectId', 'image', 'language', 'pinnedAt', 'pinned', 'teaserImageHeight'], undefinedToNull: [
'activityId',
'objectId',
'image',
'language',
'pinnedAt',
'pinned',
'imageAspectRatio',
],
hasMany: { hasMany: {
tags: '-[:TAGGED]->(related:Tag)', tags: '-[:TAGGED]->(related:Tag)',
categories: '-[:CATEGORIZED]->(related:Category)', categories: '-[:CATEGORIZED]->(related:Category)',

View File

@ -118,7 +118,7 @@ type Post {
contentExcerpt: String contentExcerpt: String
image: String image: String
imageUpload: Upload imageUpload: Upload
teaserImageHeight: String imageAspectRatio: Float
visibility: Visibility visibility: Visibility
deleted: Boolean deleted: Boolean
disabled: Boolean disabled: Boolean
@ -183,6 +183,7 @@ type Mutation {
language: String language: String
categoryIds: [ID] categoryIds: [ID]
contentExcerpt: String contentExcerpt: String
imageAspectRatio: Float
): Post ): Post
UpdatePost( UpdatePost(
id: ID! id: ID!
@ -195,7 +196,7 @@ type Mutation {
visibility: Visibility visibility: Visibility
language: String language: String
categoryIds: [ID] categoryIds: [ID]
teaserImageHeight: String imageAspectRatio: Float
): Post ): Post
DeletePost(id: ID!): Post DeletePost(id: ID!): Post
AddPostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED AddPostEmotions(to: _PostInput!, data: _EMOTEDInput!): EMOTED
@ -220,6 +221,7 @@ type Query {
offset: Int offset: Int
orderBy: [_PostOrdering] orderBy: [_PostOrdering]
filter: _PostFilter filter: _PostFilter
imageAspectRatio: Float
): [Post] ): [Post]
PostsEmotionsCountByEmotion(postId: ID!, data: _EMOTEDInput!): Int! PostsEmotionsCountByEmotion(postId: ID!, data: _EMOTEDInput!): Int!
PostsEmotionsByCurrentUser(postId: ID!): [String] PostsEmotionsByCurrentUser(postId: ID!): [String]

View File

@ -7,7 +7,11 @@
@submit="submit" @submit="submit"
> >
<template slot-scope="{ errors }"> <template slot-scope="{ errors }">
<hc-teaser-image :contribution="contribution" @addTeaserImage="addTeaserImage" @addTeaserImageHeight="addTeaserImageHeight"> <hc-teaser-image
:contribution="contribution"
@addTeaserImage="addTeaserImage"
@addImageAspectRatio="addImageAspectRatio"
>
<img <img
v-if="contribution" v-if="contribution"
class="contribution-image" class="contribution-image"
@ -128,6 +132,7 @@ export default {
title: '', title: '',
content: '', content: '',
teaserImage: null, teaserImage: null,
imageAspectRatio: null,
image: null, image: null,
language: null, language: null,
categoryIds: [], categoryIds: [],
@ -190,12 +195,10 @@ export default {
content, content,
image, image,
teaserImage, teaserImage,
teaserImageHeight, imageAspectRatio,
categoryIds, categoryIds,
} = this.form } = this.form
this.loading = true this.loading = true
console.log('file', teaserImage)
console.log('imageHeight', typeof teaserImageHeight)
this.$apollo this.$apollo
.mutate({ .mutate({
mutation: this.id ? PostMutations().UpdatePost : PostMutations().CreatePost, mutation: this.id ? PostMutations().UpdatePost : PostMutations().CreatePost,
@ -207,7 +210,7 @@ export default {
language, language,
image, image,
imageUpload: teaserImage, imageUpload: teaserImage,
teaserImageHeight imageAspectRatio,
}, },
}) })
.then(({ data }) => { .then(({ data }) => {
@ -231,9 +234,8 @@ export default {
addTeaserImage(file) { addTeaserImage(file) {
this.form.teaserImage = file this.form.teaserImage = file
}, },
addTeaserImageHeight(height) { addImageAspectRatio(aspectRatio) {
console.log(height.toString()) this.form.imageAspectRatio = aspectRatio
this.form.teaserImageHeight = height.toString()
}, },
categoryIds(categories) { categoryIds(categories) {
return categories.map(c => c.id) return categories.map(c => c.id)

View File

@ -22,24 +22,11 @@ export default {
content: content, content: content,
duration: [400, 200], duration: [400, 200],
inertia: true, inertia: true,
<<<<<<< Updated upstream
interactive: true, interactive: true,
=======
// interactive: true,
>>>>>>> Stashed changes
placement, placement,
showOnInit, showOnInit,
theme: 'human-connection', theme: 'human-connection',
trigger, trigger,
<<<<<<< Updated upstream
=======
onCreate(instance) {
instance.popperInstance.reference = {
...virtualNode,
// popperOptions: { positionFixed: true },
}
},
>>>>>>> Stashed changes
onMount(instance) { onMount(instance) {
const input = instance.popper.querySelector('input') const input = instance.popper.querySelector('input')
@ -92,7 +79,6 @@ export default {
.tippy-roundarrow { .tippy-roundarrow {
fill: $color-primary; fill: $color-primary;
} }
<<<<<<< Updated upstream
.tippy-popper[x-placement^='top'] & .tippy-arrow { .tippy-popper[x-placement^='top'] & .tippy-arrow {
border-top-color: $color-primary; border-top-color: $color-primary;
} }
@ -105,10 +91,5 @@ export default {
.tippy-popper[x-placement^='right'] & .tippy-arrow { .tippy-popper[x-placement^='right'] & .tippy-arrow {
border-right-color: $color-primary; border-right-color: $color-primary;
} }
=======
// .tippy-popper {
// pointer-events: auto;
// }
>>>>>>> Stashed changes
} }
</style> </style>

View File

@ -4,7 +4,7 @@
:image="post.image | proxyApiUrl" :image="post.image | proxyApiUrl"
:class="{ 'post-card': true, 'disabled-content': post.disabled, 'post--pinned': isPinned }" :class="{ 'post-card': true, 'disabled-content': post.disabled, 'post--pinned': isPinned }"
> >
<ds-placeholder v-if="showPlaceholder && post.teaserImageHeight" class="placeholder-image"> <ds-placeholder v-if="showPlaceholder && post.imageAspectRatio" class="placeholder-image">
I'm a placeholder I'm a placeholder
</ds-placeholder> </ds-placeholder>
<!-- Post Link Target --> <!-- Post Link Target -->
@ -104,7 +104,7 @@ export default {
showPlaceholder: { showPlaceholder: {
type: Boolean, type: Boolean,
default: true, default: true,
} },
}, },
data() { data() {
return { return {
@ -135,10 +135,10 @@ export default {
}, },
cssVars() { cssVars() {
return { return {
'--height': this.post.teaserImageHeight + 'px' '--height': this.post.imageAspectRatio + 'px',
}
} }
}, },
},
methods: { methods: {
async deletePostCallback() { async deletePostCallback() {
try { try {
@ -158,9 +158,8 @@ export default {
this.$emit('unpinPost', post) this.$emit('unpinPost', post)
}, },
hidePlaceholder() { hidePlaceholder() {
console.log('this has been called')
this.imageLoading = false this.imageLoading = false
} },
}, },
} }
</script> </script>
@ -207,6 +206,6 @@ export default {
} }
.placeholder-image { .placeholder-image {
height: var(--height) height: var(--height);
} }
</style> </style>

View File

@ -9,7 +9,7 @@
@vdropzone-thumbnail="transformImage" @vdropzone-thumbnail="transformImage"
> >
<div class="crop-overlay" ref="cropperOverlay" v-show="showCropper"> <div class="crop-overlay" ref="cropperOverlay" v-show="showCropper">
<ds-button @click="cropImage" class="crop-confirm" primary> <ds-button @click.native="cropImage" class="crop-confirm" primary>
{{ $t('contribution.teaserImage.cropperConfirm') }} {{ $t('contribution.teaserImage.cropperConfirm') }}
</ds-button> </ds-button>
<ds-button @click="cancelCrop" class="crop-cancel" icon="close"></ds-button> <ds-button @click="cancelCrop" class="crop-cancel" icon="close"></ds-button>
@ -111,15 +111,13 @@ export default {
cropImage() { cropImage() {
this.showCropper = false this.showCropper = false
const canvas = this.cropper.getCroppedCanvas() const canvas = this.cropper.getCroppedCanvas()
console.log('canvas', canvas)
canvas.toBlob(blob => { canvas.toBlob(blob => {
const imageAspectRatio = canvas.width / canvas.height
this.setupPreview(canvas) this.setupPreview(canvas)
this.removeCropper() this.removeCropper()
console.log(blob)
const croppedImageFile = new File([blob], this.file.name, { type: this.file.type }) const croppedImageFile = new File([blob], this.file.name, { type: this.file.type })
console.log('croppedImageFile', croppedImageFile)
this.$emit('addTeaserImage', croppedImageFile) this.$emit('addTeaserImage', croppedImageFile)
this.$emit('addTeaserImageHeight', canvas.height) this.$emit('addImageAspectRatio', imageAspectRatio)
}) })
}, },
setupPreview(canvas) { setupPreview(canvas) {

View File

@ -64,7 +64,7 @@ export const postFragment = lang => gql`
role role
} }
pinnedAt pinnedAt
teaserImageHeight imageAspectRatio
} }
` `
export const commentFragment = lang => gql` export const commentFragment = lang => gql`

View File

@ -9,6 +9,7 @@ export default () => {
$language: String $language: String
$categoryIds: [ID] $categoryIds: [ID]
$imageUpload: Upload $imageUpload: Upload
$imageAspectRatio: Float
) { ) {
CreatePost( CreatePost(
title: $title title: $title
@ -16,6 +17,7 @@ export default () => {
language: $language language: $language
categoryIds: $categoryIds categoryIds: $categoryIds
imageUpload: $imageUpload imageUpload: $imageUpload
imageAspectRatio: $imageAspectRatio
) { ) {
title title
slug slug
@ -34,7 +36,7 @@ export default () => {
$imageUpload: Upload $imageUpload: Upload
$categoryIds: [ID] $categoryIds: [ID]
$image: String $image: String
$teaserImageHeight: String $imageAspectRatio: Float
) { ) {
UpdatePost( UpdatePost(
id: $id id: $id
@ -44,7 +46,7 @@ export default () => {
imageUpload: $imageUpload imageUpload: $imageUpload
categoryIds: $categoryIds categoryIds: $categoryIds
image: $image image: $image
teaserImageHeight: $teaserImageHeight imageAspectRatio: $imageAspectRatio
) { ) {
id id
title title
@ -57,7 +59,7 @@ export default () => {
name name
role role
} }
teaserImageHeight imageAspectRatio
} }
} }
`, `,

View File

@ -208,7 +208,7 @@ export default {
}, },
hidePlaceholder() { hidePlaceholder() {
this.showPlaceholder = false this.showPlaceholder = false
} },
}, },
apollo: { apollo: {
Post: { Post: {