[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use image-uploader and image-uploader-modal to handle image uploads #20564

Open
4 tasks
AFZL210 opened this issue Jun 24, 2024 · 41 comments
Open
4 tasks

Use image-uploader and image-uploader-modal to handle image uploads #20564

AFZL210 opened this issue Jun 24, 2024 · 41 comments
Labels
bug Label to indicate an issue is a regression good first issue Impact: Medium Will improve quality-of-life for at least 30% of users. Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet.

Comments

@AFZL210
Copy link
Member
AFZL210 commented Jun 24, 2024

We have a lot of components and modals just to handle image uploads, and recently we created two components: (1) image-uploader and (2) image-uploader-modal. These two components can handle any type of image needed for our use case. This issue aims to remove all the other image upload-related components and use this newly created image-uploader and image-uploader-modal component.

oppia-image-uploader-modal

Data returned when closed:

  • newImageDataUrl(string)
  • dimensions({height: number, width: number})
  • newBgColor(string)

Props:

  • maxImageSizeInKB (number)
  • aspectRatio (string)
  • imageName (string)
  • bgColor (string)
  • allowedBgColors (string[])
  • allowedImageFormats (string[])
  • previewImageUrl (optional(string))
  • previewDescriptionBgColor (optional(string))
  • previewTitle (optional(string))
  • previewDescription (optional(string))
  • previewFooter (optional(string))

oppia-image-uploader

This is the highest level component which takes all the props and shows the preview, and handles all the events.

ImageUploaderData {
filename: string;
bg_color: string;
image_data: Blob;
}

Emitted Events:

  • imageSave (ImageUploaderData)

Props:

  • maxImageSizeInKB (number)
  • aspectRatio (string)
  • imageName (string)
  • bgColor (string)
  • allowedImageFormats (string[])
  • orientation (string) - landscape/portrait
  • previewDescriptionBgColor (optional(string))
  • previewTitle (optional(string))
  • previewDescription (optional(string))
  • previewFooter (optional(string))
  • filename (optional(string))
  • disabled (optional(boolean))

Steps to Follow

  1. If we are showing a custom preview then use oppia-image-uploader modal and if not then use oppia-image-uploader. and create a function to listen to the imageSave event.
  2. Update the backend handler and add new image field of type bytes - Check which request is made when saving an entity like topic, story etc. example.
  3. Update the frontend backend service which sends the data and add a new field for image of type Blob to it.
@AFZL210 AFZL210 added Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet. Impact: Low -- ONLY DO IF GOOD FIRST ISSUE Postponing for now, since it doesn't affect users much. good first issue labels Jun 24, 2024
Copy link

Hi @AFZL210, thanks for proposing this as a good first issue. I am removing the label for now and looping in @DubeySandeep to approve the label. It will be added back if approved. Thanks!

@seanlip seanlip added good first issue Impact: Medium Will improve quality-of-life for at least 30% of users. and removed Impact: Low -- ONLY DO IF GOOD FIRST ISSUE Postponing for now, since it doesn't affect users much. labels Jun 30, 2024
@Nabanita29
Copy link
Nabanita29 commented Jul 14, 2024

Task Overview:
The task involves removing redundant image upload-related components and replacing them with the newly created oppia-image-uploader and oppia-image-uploader-modal components. This includes updating modals and editor tabs, modifying the backend handler to support a new image field, and updating the frontend service to handle this new field.

Approach:
Replace oppia-thumbnail-uploader with oppia-image-uploader or oppia-image-uploader-modal in the respective components and modals.
Update the backend handler to add a new image field of type bytes and adjust request handling.
Update the frontend backend service to include the new image field.
Write tests for the new components and modals, and ensure that the image data is saved and retrieved correctly.
Clean up deprecated components and update documentation.
Please assign this issue to me, and let me know if there are any additional guidelines or details I should be aware of.

Thanks!
Nabanita

@AFZL210
Copy link
Member Author
AFZL210 commented Jul 14, 2024

@Nabanita29 The approch sounds good.

I'm assigning you the create new topic modal part.

Note: For now just replace the old component with new one don't delete the old component code now, we will remove it once we have fully replaced the old one.

Setps to create a topic:

  1. Click on profile icon > Admin
  2. Go to roles tab and enter your username and assign yourself curriculum admin role
  3. Go to home > click on profile icon > topic and skills dashboard
  4. Click on create topic

Here you will the the image uploader component this is the one which you have to replace.

@seanlip seanlip added the bug Label to indicate an issue is a regression label Aug 6, 2024
@sankshaypusa
Copy link

Hi may i know is this issue resolved ,I want to try this out

@AFZL210
Copy link
Member Author
AFZL210 commented Aug 9, 2024

@sankshaypusa This issue is still open, if you want to work on it just tell me which sub-part you would like to work and Per the usual guidance at https://github.com/oppia/oppia/wiki/Contributing-code-to-Oppia#choosing-a-good-first-issue, please provide proof that you are able to solve the issue locally. If it looks good, we can assign you to this issue.

Please also follow the other instructions on that wiki page if you have not yet done so. Thanks.

@AFZL210
Copy link
Member Author
AFZL210 commented Aug 9, 2024

Unassigning @Nabanita29 due to inactivity.

@sankshaypusa
Copy link
sankshaypusa commented Aug 9, 2024

HI AFZL210 thanks for your response i would like to work on the Create new subtopic modal and I am new to open-source contribution and would like to solve this issue,I will provide proof of the solution as well

@AFZL210
Copy link
Member Author
AFZL210 commented Aug 10, 2024

@sankshaypusa Yes sure, you can start working on it and once it's fixed I will assign it to you.

@sankshaypusa
Copy link

Hi AFZL210 I would like to know what result you expect from this issue, do we need any admin privileges to access?

@KartikSuryavanshi
Copy link
Collaborator

Hi @HardikGoyal2003 ,

I hope this message finds you well. I would like to request assignment for the issue regarding the use of image-uploader and image-uploader-modal to handle image uploads (#20564).

Files to be Changed:-
Create New Topic Modal: create-new-topic-modal.component.ts
Topic Editor Tab: topic-editor-tab.directive.ts
Create New Subtopic Modal: create-new-subtopic-modal.component.ts
Subtopic Editor Tab: subtopic-editor-tab.component.ts

I understand that the task involves replacing the oppia-thumbnail-uploader with the new components and updating the backend handler and frontend service accordingly. I am eager to contribute to this issue and will ensure to follow the guidelines and provide proof of the solution as required.

Thank you for considering my request. I look forward to your response.

Best regards,
Kartik Suryavanshi

@HardikGoyal2003
Copy link
Member

Hey @KartikSuryavanshi, could you please specify the changes for one file, including the lines you’ll modify and the new content? Thanks!

@KartikSuryavanshi
Copy link
Collaborator
KartikSuryavanshi commented Sep 29, 2024
Screenshot 2024-09-29 at 11 31 15 PM

Hey @seanlip
Changes in create-new-topic-modal.component.html:-
Lines to modify:
I will be replacing the oppia-thumbnail-uploader component with the new image-uploader component in the template file associated with this modal. Here’s a breakdown of the specific changes:

Before:
for example :-

<oppia-thumbnail-uploader
(updateFilename)="updateTopicThumbnailFilename($event)"
[useLocalStorage]="false"
[bgColor]="editableThumbnailBgColor"
(updateBgColor)="updateTopicThumbnailBgColor($event)"
[allowedBgColors]="allowedBgColors"
[aspectRatio]="'4:3'"
[previewTitle]="newlyCreatedTopic.name"
previewDescriptionBgColor="#BE563C">

After:-
<image-uploader
[maxImageSizeInKB]="1024"
[aspectRatio]="'4:3'"
[imageName]="newlyCreatedTopic.name"
[bgColor]="'#fff'"
[allowedImageFormats]="['jpg', 'png']"
(imageSave)="onImageSave($event)">

Explanation:
Component Replacement: The oppia-thumbnail-uploader has been replaced with image-uploader to use the new implementation for image uploads.
Input Properties: The new component includes properties for maximum image size, aspect ratio, image name, background color, and allowed formats.
Event Handling: The event (imageSave) is maintained to handle the saved image when uploaded.

@HardikGoyal2003
Copy link
Member

Hey @KartikSuryavanshi, could you provide a video demo showing that this implementation works correctly with the feature? If everything is functioning well, I'd be happy to assign you this issue. Thanks!

@KartikSuryavanshi
Copy link
Collaborator
KartikSuryavanshi commented Oct 1, 2024

Hey @HardikGoyal2003 i made the changes and the new thumbnail uploader is working quite good!!

Uploading Screen Recording 2024-10-01 at 12.mp4…

@HardikGoyal2003
Copy link
Member

Hey @KartikSuryavanshi I don't see any video demo, I think it isn't uploaded properly, kindly check. Thanks!

@KartikSuryavanshi
Copy link
Collaborator

Hey @HardikGoyal2003 i tried doing many attempts but it shows uploading .Can u check the below link!!
https://github.com/user-attachments/assets/e2d6ecb8-d9cc-44e2-b538-43ee0bc12605

@HardikGoyal2003
Copy link
Member

Hey @KartikSuryavanshi This looks good, feel free to make a Pr, assigning this issue to you!! Thanks!

@KartikSuryavanshi
Copy link
Collaborator

Hey @HardikGoyal2003 ,

Thank you for assigning the issue to me! I will begin working on it right away and create a PR shortly. I'll keep you updated with my progress.

@KartikSuryavanshi
Copy link
Collaborator

Hey @HardikGoyal2003,

I'm facing persistent linter issues, and despite my attempts to fix them, the errors keep appearing. The main issues highlighted are related to:

Trailing whitespaces (e.g., lines 28, 119, and 120 in the HTML file).
Comment formatting in the TypeScript file (line 28).
I've tried removing the whitespaces and correcting the comments, but when I run the linter again, it still fails. Additionally, when I try to use git stash to clear my repo, the changes get reset, and the same whitespace and comments reappear.

I’ve attached a screenshot for reference. Could you please help me figure out why these issues keep coming back and what I can do to resolve them?

Thanks in advance for your help!

Screenshot 2024-10-03 at 10 47 03 AM

@HardikGoyal2003
Copy link
Member

@KartikSuryavanshi Whitespace characters remain and haven't been fully removed. Please verify the specified position for any whitespace. Also, comments should begin with a capital letter and end with a period. Let me know if this issue persists.

@KartikSuryavanshi
Copy link
Collaborator
KartikSuryavanshi commented Oct 3, 2024

Hey @HardikGoyal2003
Thank you for your feedback. I’ve attempted multiple times to remove the whitespace characters, but I keep encountering an issue where it prompts me to stash my changes. After doing that, the same whitespace issue reappears when I proceed.It also says "Your repo is in a dirty state which prevents the linting from working".

I’ll continue troubleshooting, but please let me know if there are any suggestions for resolving this.

@HardikGoyal2003
Copy link
Member

Hey @KartikSuryavanshi, the issue is that after you remove your changes, you're not using git add before committing or pushing. Please try that to see if it resolves the problem!

@KartikSuryavanshi
Copy link
Collaborator

Hey @HardikGoyal2003 Plz have a look!!
Screenshot 2024-10-03 at 9 27 58 PM
Screenshot 2024-10-03 at 9 28 42 PM

@HardikGoyal2003
Copy link
Member

Hey @KartikSuryavanshi, look at the second image at the top center. It displays a modified file marked in red, indicating it hasn’t been added yet, which is causing the error.

@KartikSuryavanshi
Copy link
Collaborator

Okay, I’ll check that out! Thanks for pointing it out.I will keep u updated!

@KartikSuryavanshi
Copy link
Collaborator
KartikSuryavanshi commented Oct 3, 2024

Hey @HardikGoyal2003
Screenshot 2024-10-03 at 11 25 26 PM
This error continues to appear based on the code I've provided in the picture below. What changes should I make in lines 117 and 118?
Screenshot 2024-10-03 at 11 29 49 PM

@HardikGoyal2003
Copy link
Member

@KartikSuryavanshi Move the pointer after the comma on line 117 and press the right arrow key. If the pointer moves to the next line, there is no whitespace; otherwise, you'll find out a whitespace there.

@KartikSuryavanshi
Copy link
Collaborator

Hey @HardikGoyal2003 Can u help me with this issue?
Screenshot 2024-10-04 at 8 56 17 PM

@HardikGoyal2003
Copy link
Member

Hey @HardikGoyal2003 Can u help me with this issue? Screenshot 2024-10-04 at 8 56 17 PM

@jayam04 @gp201 PTAL!! Thanks!!

@KartikSuryavanshi
Copy link
Collaborator
KartikSuryavanshi commented Oct 5, 2024

Hey @HardikGoyal2003 plz help with this linting issues!!
Screenshot 2024-10-05 at 5 05 41 PM
Screenshot 2024-10-05 at 6 10 07 PM

@seanlip
Copy link
Member
seanlip commented Oct 7, 2024

@KartikSuryavanshi Are you using tabs instead of spaces? In general you should use spaces everywhere.

Also usually you'll want to put [previewTitle] just a single space after the tag name (and align everything else to that).

@HardikGoyal2003
Copy link
Member

Hey @KartikSuryavanshi Are you working on this or should I unassign this??

@KartikSuryavanshi
Copy link
Collaborator
KartikSuryavanshi commented Oct 13, 2024

Hey @HardikGoyal2003,

I wanted to clarify that this issue needs to be addressed in parts, as @AFZL210 mentioned. Here’s a breakdown of the components that require changes:

Create New Topic Modal: create-new-topic-modal.component.ts
Component used: oppia-thumbnail-uploader

Topic Editor Tab: topic-editor-tab.directive.ts
Component used: oppia-thumbnail-uploader

Create New Subtopic Modal: create-new-subtopic-modal.component.ts
Component used: oppia-thumbnail-uploader

Subtopic Editor Tab: subtopic-editor-tab.component.ts
Component used: oppia-thumbnail-uploader

For now, I will replace the old component with the new one but do not delete the old component code just yet. We can remove it later once we’ve fully transitioned to the new one.

However, I encountered an issue when implementing a function to listen to the imageSave event—it seems to break the topic editor. I will need some time to dig deeper into this issue and would appreciate any guidance you can provide.

Thanks!

@HardikGoyal2003
Copy link
Member

@KartikSuryavanshi Retaining the old code complicates maintenance. We need to address this together. If you need assistance, please share the stack trace of the error for better clarity!

@KartikSuryavanshi
Copy link
Collaborator

Hi @HardikGoyal2003,

Thank you for your feedback! I understand the importance of maintaining clean code. I will gather the stack trace of the error and provide it shortly for better clarity on the issue.

@seanlip
Copy link
Member
seanlip commented Nov 19, 2024

For some reason @KartikSuryavanshi is assigned to this issue but his PR hasn't been worked on for ages: #21036. Deassigning him.

@KartikSuryavanshi If you are not working on an issue, please deassign yourself. Don't leave issues hanging, because that also blocks them for new contributors. Thanks.

@KartikSuryavanshi
Copy link
Collaborator

@seanlip Apologies for the delay. I'll ensure to deassign myself from issues I'm not actively working on in the future. Thanks for pointing it out!

@torack51
Copy link
torack51 commented Nov 25, 2024

Hi,
I'm having some issues regarding the implementation of onImageSave that I must add in create-new-topic-modal.component.ts. To save the image in the imageLocalStorageService,

private imageLocalStorageService: ImageLocalStorageService,
I believe I need to use the functions setThumbnailBgColor and saveImage (in image-local-storage.service.ts). The issue is that for saveImage, the input needs to be a raw image and not a blob, which my image_data is currently. I see 3 possibilities :

  • I change the blob from a raw file from the modal component, and call saveImage with that new data, but it's probably not the component's original purpose to do such things
  • I write a new function in the image-local-service allowing me to save an image using a blob, there the transition from blob to raw file is done within that function.
  • I use the _blobtoBase64 function that does precisely what I want, that would need to make it a public function instead of a private one, which is probably not the best idea since i'm guessing it's private for a reason

Which one do you think is the best?
Also, regardless of the solution I choose, console errors come up saying that "String contains an invalid character". This error is triggered by getStoreedImagesData() when an image has been saved in the topic creator modal, but I don't understand where that comes from.
When I upload a random image and I print the raw image value of it, it displays "PHN2ZyB2ZXJzaW9uPSIxLjAiIHhtbG5zPSJodHRwO.....and so on". Can you also help me understand why that error appears?

@seanlip
Copy link
Member
seanlip commented Nov 27, 2024

@torack51 I think the second one is the best, although it might be worth looking into why we seem to be saving images to local storage in different ways throughout the app. Is there any possibility for standardization, so that all the callers of the image local storage service use a single approach?

I'm not sure if I can give you much guidance on the last question, it will probably need more debugging. If you still have trouble, please put all the relevant information (including repro steps and things you've tried) in a debugging doc and we can take a look. Thanks!

@torack51
Copy link
torack51 commented Dec 4, 2024

Hello @seanlip , sorry for the late reply but my devserver stopped working, similarly to this discussion topic : https://github.com/oppia/oppia/discussions/21158.
I managed to solve the console issues I mentioned before, and I can also suggest eventually another solution to the dilemma I talked about in my last message : emit imageSave with image_data as a raw string rather than a blob, which is very possible since newImageDataUrl is the correct format in the following code, even though we use imageBlobData in imageSave.emit as you can see here-->

modalRef.result.then(
data => {
this.editableImageDataUrl = data.newImageDataUrl;
const imageBlobData =
this.imageUploadHelperService.convertImageDataToImageFile(
data.newImageDataUrl
);
if (!imageBlobData) {
return;
}
const imageFilename =
this.imageUploadHelperService.generateImageFilename(
data.dimensions.height,
data.dimensions.width,
// SVGs are XML-based; hence, the MIME type for them is image/svg+xml.
// When saving the image, we need .svg as the extension, which is why we need
// to omit the +xml part.
imageBlobData?.type?.split('/')[1]?.replace('+xml', '')
);
this.hidePlaceholder = true;
this.imageBgColor = data.newBgColor;
this.imageSave.emit({
filename: imageFilename,
bg_color: data.newBgColor,
image_data: imageBlobData,
});
},
() => {
// Note to developers:
// This callback is triggered when the Cancel button is clicked.
// No further action is needed.
}
);

Apart from that, I believe that my implementation for create-new-topic-modal is complete. I'll start working on the rest and keep you updated with my progress.

@seanlip
Copy link
Member
seanlip commented Dec 4, 2024

Thanks @torack51. Did you get a solution to the "devserver stopped working" issue? If so, it would be helpful if you could post it in the discussion thread since other folks seem to be having trouble as well.

Other than that, it would be great to hear more about your analysis and your progress -- I think it's worth cataloguing the different instances where we save images and what their differences are, and proposing how you plan to standardize them. Thanks for keeping the thread updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Label to indicate an issue is a regression good first issue Impact: Medium Will improve quality-of-life for at least 30% of users. Work: Medium The means to find the solution is clear, but it isn't at good-first-issue level yet.
Projects
Status: Todo
Development

No branches or pull requests

8 participants