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

Introduce layers in designer #6229

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tomako
Copy link
Contributor

@tomako tomako commented Mar 12, 2024

This is about to introduce layers to Poster & Badge Designer.
How it works:

  • By default there is 1 layer and all items are placed on that
  • Additional layers can be created and items can be placed on them
  • Layers' visibility can be switched
  • Layers can be removed one by one and always only the last one (all items on that layer will be removed as well)
  • Only visible layers will be printed

@@ -164,13 +164,31 @@
</div>
{% endif %}
</div>
<div class="designer-tools-row js-hide-on-flip">
<div class="tool">
<span class="f-self-stretch">Layer visibility</span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty much all the strings are missing i18n atm

@tomako tomako force-pushed the introduce_layers_in_designer branch from 6e298b8 to be66513 Compare March 13, 2024 15:14
def _remove_invisible_items(self, tpl_data):
pos_to_remove = [i for i, item in enumerate(tpl_data.items) if not tpl_data.layers[item['layer']]]
for pos in reversed(pos_to_remove):
tpl_data.items.pop(pos)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is dangerous: AFAICT items is passed through directly from the dict that's on the model, so the only reason why this does not affect the stored data is that there's no mutation detection on mutable sqlalchemy data.

I think this is a safer alternative (untested):

tpl_data = tpl_data._replace(items=[item for item in tpl_data.items if tpl_data.layers[item['layer']]])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, indeed. However _replace creates a new instance and self.tpl_data will still refer to the old one. (side note: passing instance attributes to _draw_badge method seems unnecessary)
Actually it would be more reasonable to remove all invisible items only once right at the beginning. However that would break our intention to manipulate item's visibility later per registrations.
So eventually I wouldn't do any destructive modification only skipping invisible items when placing them on the canvas.

<div class="designer-tools-row second-row disappear">
<div class="element-tools hidden">
<div class="tool">
<span class="selection-text f-self-stretch"></span>
<button class="js-remove-element i-button icon-remove icon-only text-color subtle"
title="{% trans %}Remove element{% endtrans %}"></button>
</div>
<div class="tool">
<select id='item-layer-selector' class="js-layer-tool" data-attr="layer">
<option value="1">{{ gettext('Layer {0}').format(1) }}</option>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{% trans %}Layer 1{% endtrans %}

No need to try to use the same gettext pattern as in the JS since JS and python/jinja are separate i18n dicts anyway so they have to be translated twice in any case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. But I tried hard :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW a cleaner way to do this (if it wasn't for the separate dicts) would be this: {% trans n=1 %}Layer {{ n }}{% endtrans %}

(generally using gettext in templates directly is somewhat uncommon)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks. My motivation was indeed to use the same form as in js.

@tomako tomako force-pushed the introduce_layers_in_designer branch from be66513 to f40bab2 Compare March 14, 2024 19:38
@ThiefMaster
Copy link
Member

Just to understand, does this layers functionality do anything by itself in Indico for someone who's not using your UN plugin?
I think it would be interesting to see if we can get some benefit out of it, because adding UI that's "useless" would be a bit weird.

Alternatively I'd be OK with making it opt-in e.g. via a variable coming from a template hook so by default this would not show up and everything would go in the same layer/group.

PS: You need to rebase and fix some conflicts, since we merged another PR related to badges.

@tomako tomako force-pushed the introduce_layers_in_designer branch from f40bab2 to 1357abc Compare March 18, 2024 11:07
@tomako
Copy link
Contributor Author

tomako commented Mar 25, 2024

I very agree in that, it would be a bit weird :) Let me clarify this with my colleagues internally and I'll be back.

@tomako tomako force-pushed the introduce_layers_in_designer branch from 1357abc to 8ffb9d6 Compare April 23, 2024 08:55
@ThiefMaster
Copy link
Member

Let me clarify this with my colleagues internally and I'll be back.

And update on this?

@tomako
Copy link
Contributor Author

tomako commented May 6, 2024

Sorry for the long silence. To be honest we are a bit reluctant to push some hidden feature useful only for us. In many ways it could cause headache in the future. So what if we just keep this here for a while until we see clearer how to integrate it in a better way?

@ThiefMaster
Copy link
Member

Sounds good, I'm changing the PR to draft for the time being.

@ThiefMaster ThiefMaster marked this pull request as draft May 6, 2024 14:32
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

Successfully merging this pull request may close these issues.

None yet

2 participants