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

Feature - Document and Template thumbnail #63

Open
tring-prabhakaran opened this issue Jun 28, 2024 · 10 comments
Open

Feature - Document and Template thumbnail #63

tring-prabhakaran opened this issue Jun 28, 2024 · 10 comments

Comments

@tring-prabhakaran
Copy link

Can a thumbnail be added for a dynamically created document and template?

@r00dY
Copy link
Contributor

r00dY commented Jul 9, 2024

Hey @tring-prabhakaran, sorry for delay, was on holidays. Could you specify what do you exactly mean by "dynamically created"? The templates in Config.templates have thumbnail property.

@tring-prabhakaran
Copy link
Author

tring-prabhakaran commented Jul 10, 2024

I am creating a dynamic template by using save as template action and it's getting saved in easyblock DB.

Is there a way to add the thumbnail while creating?

Also, I have tried to update the template using thumbnail. But it's not working

config.templates and thumbnail are working fine when we save templates in my source code.

@r00dY
Copy link
Contributor

r00dY commented Jul 10, 2024

Ah, I get it now. It's not possible now but can be possible with a small contribution.

Please look at this line of the EasyblocksBackend.ts:

const templates = data.map<UserDefinedTemplate>((item) => ({
id: item.id,
label: item.label,
entry: item.config.config,
isUserDefined: true,
width: item.width,
widthAuto: item.widthAuto,
}));

As you can see in the code above, the thumbnail property of Template is not set for dynamic templates.

I suggest you to do a PR that extends EasyblocksBackend so that you can provide your own function of generating preview for a specific template/document. Usually it comes down to using some 3rd party service like ScreenshotOne.

Another question is: what to render? Good news is that there's already an endpoint for rendering templates or documents, all you need to do is to set preview=true and provide template or document id:

  1. For templates: http://localhost:3000/easyblocks-editor?template=TEMPLATE_ID&preview=true
  2. For documents: http://localhost:3000/easyblocks-editor?document=DOCUMENT_ID&preview=true

There's another important thing here, namely the template size. When you save as template a card which is 400px wide, or a section that was 1366px wide, we always save the width of the component when the save operation was called. It's a good hint that this size is probably a good looking one and should be used for a screenshot.

When you use above-mentioned endpoints for rendering a template, the component is always rendered in a container <div id="__easyblocks-preview-container">...</div> which has a correct size. So if you use a 3rd party service for taking screenshots (screenshotone), you must specify to take a screenshot of #__easyblocks-preview-container.

@tring-prabhakaran
Copy link
Author

tring-prabhakaran commented Jul 11, 2024

Got it. I have created PR #65

Just want to confirm once

We need to take screenshot and update to template manually.
Is that right?

@tring-prabhakaran
Copy link
Author

tring-prabhakaran commented Jul 11, 2024 via email

@r00dY
Copy link
Contributor

r00dY commented Jul 11, 2024

Hey @tring-prabhakaran,

It's not possible for your PR to work since item.thumbnail is undefined. Please make sure to test the code before submitting next time.

As I suggested above, you should extend EasyblocksBackend to take a callback function that is responsible for generating the thumbnail URL.

@tring-prabhakaran
Copy link
Author

tring-prabhakaran commented Jul 16, 2024 via email

@r00dY
Copy link
Contributor

r00dY commented Jul 17, 2024

I don't think I understand your question @tring-prabhakaran, can you maybe explain it better? How adding an undefined key would help in any way?

@tring-prabhakaran
Copy link
Author

tring-prabhakaran commented Jul 17, 2024 via email

@r00dY
Copy link
Contributor

r00dY commented Jul 24, 2024

Are you suggesting we should do the following things?:

  1. Extend "add/update template" UI widget to make it possible for user to upload a custom thumbnail
  2. Extend EasyblocksBackend to take this into account.

If so, how does your PR solve this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants