Added ability to toggle full width of cover image in blogs
This commit is contained in:
parent
d1615c6b52
commit
c4e5349689
18
backend/apimanager/migrations/0016_blog_full_with_image.py
Normal file
18
backend/apimanager/migrations/0016_blog_full_with_image.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0.6 on 2024-06-25 09:55
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('apimanager', '0015_alter_userdata_dark_theme_alter_userdata_light_theme'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='blog',
|
||||||
|
name='full_with_image',
|
||||||
|
field=models.BooleanField(default=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0.6 on 2024-06-25 10:00
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('apimanager', '0016_blog_full_with_image'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='blog',
|
||||||
|
old_name='full_with_image',
|
||||||
|
new_name='full_width_cover_image',
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -26,5 +26,6 @@ class Blog(models.Model):
|
|||||||
description = models.CharField(null=False, blank=False, max_length=200)
|
description = models.CharField(null=False, blank=False, max_length=200)
|
||||||
tagline = models.CharField(null=False, blank=False, max_length=200)
|
tagline = models.CharField(null=False, blank=False, max_length=200)
|
||||||
cover_image = models.CharField(null=True, blank=True, max_length=500)
|
cover_image = models.CharField(null=True, blank=True, max_length=500)
|
||||||
|
full_width_cover_image = models.BooleanField(default=True)
|
||||||
content_body = models.CharField(default='<p></p>', null=False, blank=False, max_length=100000)
|
content_body = models.CharField(default='<p></p>', null=False, blank=False, max_length=100000)
|
||||||
parent_category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="blogs")
|
parent_category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="blogs")
|
||||||
@ -134,6 +134,7 @@ class Publish(APIView):
|
|||||||
"name": eachBlog.name,
|
"name": eachBlog.name,
|
||||||
"description": eachBlog.description,
|
"description": eachBlog.description,
|
||||||
"coverImage": self.sanitize_media_link(eachBlog.cover_image),
|
"coverImage": self.sanitize_media_link(eachBlog.cover_image),
|
||||||
|
"fullWidthCoverImage": eachBlog.full_width_cover_image,
|
||||||
"tagLine": eachBlog.tagline,
|
"tagLine": eachBlog.tagline,
|
||||||
"parentCategory": str(eachBlog.parent_category.category_id),
|
"parentCategory": str(eachBlog.parent_category.category_id),
|
||||||
"contentBody": self.sanitize_media_link(eachBlog.content_body, 'content_media')
|
"contentBody": self.sanitize_media_link(eachBlog.content_body, 'content_media')
|
||||||
|
|||||||
@ -49,6 +49,7 @@ class BlogSerializer(serializers.ModelSerializer):
|
|||||||
'description',
|
'description',
|
||||||
'tagline',
|
'tagline',
|
||||||
'cover_image',
|
'cover_image',
|
||||||
|
'full_width_cover_image',
|
||||||
'content_body',
|
'content_body',
|
||||||
'parent_category'
|
'parent_category'
|
||||||
]
|
]
|
||||||
@ -76,6 +77,7 @@ class UnifiedCategoryBlogSerializer(serializers.ModelSerializer):
|
|||||||
'name': blog.name,
|
'name': blog.name,
|
||||||
'description': blog.description,
|
'description': blog.description,
|
||||||
'cover_image': blog.cover_image,
|
'cover_image': blog.cover_image,
|
||||||
|
'full_width_cover_image': blog.full_width_cover_image,
|
||||||
'tagline': blog.tagline,
|
'tagline': blog.tagline,
|
||||||
'parent_category': blog.parent_category.category_id
|
'parent_category': blog.parent_category.category_id
|
||||||
} for blog in blogs]
|
} for blog in blogs]
|
||||||
|
|||||||
@ -60,6 +60,17 @@ function Blog(props) {
|
|||||||
toggle()
|
toggle()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const setCoverImageWidth = () => {
|
||||||
|
EditableDataService.updateData(`/data/blog/update/${blogID}/`,{
|
||||||
|
'full_width_cover_image': !blogData.fullWidthCoverImage
|
||||||
|
}).then(() => {
|
||||||
|
props.notificationToggler('Blog data saved!');
|
||||||
|
getInfo()
|
||||||
|
}).catch(() => {
|
||||||
|
props.notificationToggler('Failed to update blog!', 'danger');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const deleteResource = () => {
|
const deleteResource = () => {
|
||||||
EditableDataService.deleteData(`/data/blog/delete/${blogData.id}/`).then(() => {
|
EditableDataService.deleteData(`/data/blog/delete/${blogData.id}/`).then(() => {
|
||||||
props.notificationToggler('Blog successfully deleted')
|
props.notificationToggler('Blog successfully deleted')
|
||||||
@ -79,6 +90,7 @@ function Blog(props) {
|
|||||||
'description': responseData['description'],
|
'description': responseData['description'],
|
||||||
'tagLine': responseData['tagline'],
|
'tagLine': responseData['tagline'],
|
||||||
'coverImage': responseData['cover_image'],
|
'coverImage': responseData['cover_image'],
|
||||||
|
'fullWidthCoverImage': responseData['full_width_cover_image'],
|
||||||
'parentCategory': responseData['parent_category']
|
'parentCategory': responseData['parent_category']
|
||||||
})
|
})
|
||||||
setBlogContent(responseData['content_body'])
|
setBlogContent(responseData['content_body'])
|
||||||
@ -110,8 +122,8 @@ function Blog(props) {
|
|||||||
<img
|
<img
|
||||||
src={EditableMediaService.getMedia(blogData.coverImage)}
|
src={EditableMediaService.getMedia(blogData.coverImage)}
|
||||||
alt='Banner'
|
alt='Banner'
|
||||||
className='rounded'
|
className={`rounded ${blogData.fullWidthCoverImage ? '' : 'mx-auto d-block'}`}
|
||||||
style={{ width: '100%', height: 'auto', maxHeight: '50vh', objectFit: 'cover' }}
|
style={{ width: blogData.fullWidthCoverImage ? '100%' : 'auto', height: 'auto', maxHeight: '50vh', objectFit: 'cover' }}
|
||||||
/>:''
|
/>:''
|
||||||
}
|
}
|
||||||
</Col>
|
</Col>
|
||||||
@ -136,6 +148,9 @@ function Blog(props) {
|
|||||||
Remove Cover Image
|
Remove Cover Image
|
||||||
</Button>
|
</Button>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
|
<Button outline active={blogData.fullWidthCoverImage} color={ThemeConfig[GlobalTheme].buttonColor} onClick={() => setCoverImageWidth()} className='mb-5 ms-3'>
|
||||||
|
Full Width Image: {blogData.fullWidthCoverImage ? 'Yes' : 'No'}
|
||||||
|
</Button>
|
||||||
<InputGroup className='mb-3'>
|
<InputGroup className='mb-3'>
|
||||||
<InputGroupText>Name</InputGroupText>
|
<InputGroupText>Name</InputGroupText>
|
||||||
<Input innerRef={nameField} defaultValue={blogData.name} />
|
<Input innerRef={nameField} defaultValue={blogData.name} />
|
||||||
|
|||||||
@ -93,9 +93,9 @@ function Blog(props) {
|
|||||||
blogData.coverImage ?
|
blogData.coverImage ?
|
||||||
<img
|
<img
|
||||||
src={MediaService.getMedia(blogData.coverImage)}
|
src={MediaService.getMedia(blogData.coverImage)}
|
||||||
alt="Banner"
|
alt='Banner'
|
||||||
className='rounded'
|
className={`rounded ${blogData.fullWidthCoverImage ? '' : 'mx-auto d-block'}`}
|
||||||
style={{ width: '100%', height: 'auto', maxHeight: '50vh', objectFit: 'cover' }}
|
style={{ width: blogData.fullWidthCoverImage ? '100%' : 'auto', height: 'auto', maxHeight: '50vh', objectFit: 'cover' }}
|
||||||
/>:''
|
/>:''
|
||||||
}
|
}
|
||||||
</Col>
|
</Col>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user