Rafactoring Module.heroImage

This commit is contained in:
Lorenz Padberg 2024-04-25 11:43:26 +02:00
parent cd0eb08153
commit 74820f52b6
8 changed files with 2065 additions and 39 deletions

View File

@ -30,9 +30,9 @@
<div class="module__hero"> <div class="module__hero">
<wagtail-image class="module__hero-image" <wagtail-image class="module__hero-image"
:src="module.heroImageJson.src" :src="module.heroImage.src"
:original-width="module.heroImageJson.width" :original-width="module.heroImage.width"
:original-height="module.heroImageJson.height"></wagtail-image> :original-height="module.heroImage.height"></wagtail-image>
<pre></pre> <pre></pre>
<h5 <h5
class="module__hero-source" class="module__hero-source"

View File

@ -3,11 +3,12 @@
:to="moduleLink" :to="moduleLink"
:class="['module-teaser', { 'module-teaser--small': !teaser }]" :class="['module-teaser', { 'module-teaser--small': !teaser }]"
> >
<!-- <div--> <wagtail-image
<!-- :style="{ backgroundImage: 'url(' + heroImage + ')' }"--> class="module-teaser__image"
<!-- class="module-teaser__image"--> :src="heroImage.src"
<!-- />--> :original-height="heroImage.height"
<wagtail-image class="module-teaser__image" :src="heroImage"></wagtail-image> :original-width="heroImage.width"
></wagtail-image>
<div class="module-teaser__body"> <div class="module-teaser__body">
<div class="module-teaser__content"> <div class="module-teaser__content">
<h3 class="module-teaser__content-meta-title">{{ metaTitle }}</h3> <h3 class="module-teaser__content-meta-title">{{ metaTitle }}</h3>
@ -34,7 +35,7 @@
import Pill from '@/components/ui/Pill.vue'; import Pill from '@/components/ui/Pill.vue';
import { ModuleCategoryNode, ModuleLevelNode } from '@/__generated__/graphql'; import { ModuleCategoryNode, ModuleLevelNode } from '@/__generated__/graphql';
import { computed } from '@vue/reactivity'; import { computed } from '@vue/reactivity';
import WagtailImage from "@/components/ui/WagtailImage.vue"; import WagtailImage from '@/components/ui/WagtailImage.vue';
export interface Props { export interface Props {
metaTitle: string; metaTitle: string;

View File

@ -66,7 +66,6 @@ const placeholderStyle = computed(() => {
}; };
if (width.value) { if (width.value) {
const scalingFactor = width.value / props.originalWidth; const scalingFactor = width.value / props.originalWidth;
console.log(props.originalWidth, width.value);
const scaledHeight = Math.round(props.originalHeight * scalingFactor); const scaledHeight = Math.round(props.originalHeight * scalingFactor);
const scaledWidth = Math.round(props.originalWidth * scalingFactor); const scaledWidth = Math.round(props.originalWidth * scalingFactor);

View File

@ -1,4 +1,6 @@
#import "./highlightParts.gql" #import "./highlightParts.gql"
#import "./wagtailIMageParts.gql"
fragment ModuleLegacyParts on ModuleNode { fragment ModuleLegacyParts on ModuleNode {
id id
title title
@ -6,14 +8,9 @@ fragment ModuleLegacyParts on ModuleNode {
teaser teaser
intro intro
slug slug
heroImage
heroSource heroSource
heroImageJson{ heroImage {
src ...WagtailImageParts
alt
width
height
title
} }
solutionsEnabled solutionsEnabled
highlights { highlights {

View File

@ -0,0 +1,8 @@
fragment WagtailImageParts on WagtailImageNode {
id
src
alt
width
height
title
}

2042
schema.graphql Normal file

File diff suppressed because it is too large Load Diff

View File

@ -5,25 +5,9 @@ from api.graphene_wagtail import generate_image_url
class ModuleInterface(relay.Node): class ModuleInterface(relay.Node):
pk = graphene.Int() pk = graphene.Int()
hero_image = graphene.String(required=True) hero_image = graphene.Field('books.schema.nodes.WagtailImageNode')
topic = graphene.Field('books.schema.nodes.TopicNode') topic = graphene.Field('books.schema.nodes.TopicNode')
hero_image_json = graphene.Field('books.schema.nodes.WagtailImageNode')
@staticmethod @staticmethod
def resolve_pk(parent, info, **kwargs): def resolve_pk(parent, info, **kwargs):
return parent.id return parent.id
@staticmethod
def resolve_hero_image(parent, info, **kwargs):
if parent.hero_image:
image = Image.objects.get(id=parent.hero_image.id)
return generate_image_url(image, 'original')
@staticmethod
def resolve_hero_image_json(parent, info, **kwargs):
if parent.hero_image:
return Image.objects.get(id=parent.hero_image.id)

View File

@ -58,7 +58,6 @@ class ModuleNode(DjangoObjectType):
level = graphene.Field(ModuleLevelNode) level = graphene.Field(ModuleLevelNode)
category = graphene.Field(ModuleCategoryNode) category = graphene.Field(ModuleCategoryNode)
language = graphene.String() language = graphene.String()
hero_image_json = graphene.Field("books.schema.nodes.WagtailImageNode")
highlights = graphene.List("notes.schema.HighlightNode") highlights = graphene.List("notes.schema.HighlightNode")
my_highlights = graphene.List( my_highlights = graphene.List(
graphene.NonNull("notes.schema.HighlightNode"), required=True graphene.NonNull("notes.schema.HighlightNode"), required=True
@ -170,10 +169,6 @@ class ModuleNode(DjangoObjectType):
def resolve_path(root: Module, info, **kwargs): def resolve_path(root: Module, info, **kwargs):
return root.route return root.route
@staticmethod
def resolve_hero_image_json(root: Module, info, **kwargs):
return root.hero_image
class RecentModuleNode(DjangoObjectType): class RecentModuleNode(DjangoObjectType):
class Meta: class Meta: