substanced
substanced copied to clipboard
Add a column in folder contents for "icons"
Add-ons like sdexternaledit need to decorate editable items with icons. Right now it does that by overriding the base folder content view, but it's a bit too fragile because someone/something else may also want to override the base folder contents view too. Instead we should probably provide a plug point where icons can be associated with items in a folder. This would also let us put lock icons next to locked items.
I have two questions for @mcdonc and @reebalazs. To make replies easier, I'll number the comments.
Question 1: Badge Column or put badges in an existing column?
First, I found that Chris was right. get_default_columns calculates server-side the html that should be jammed into a cell and is run on every resource that goes into the JSON payload. Thus, we can have complete server-side control over, for example, whether a particular item is locked and if so, what the badge should look like.
That said, we have to decide where to put it. If we make a column for badges, we'll have to reserve enough width in advance for all possible badges and the space will be taken even if no rows need badges. That's just the way SlickGrid works. (Balazs can tell me if I'm wrong about that.)
I think this defeats the purpose of the pluggability in this ticket. The get_default_columns in the core won't know how many plugins might want to inject a badge, or what is the width of the badge, etc. It won't know what is the maximum possible width needed.
As a second choice, I think in general we have some default-sorted column that has the primary text for that resource. Sometimes "name", sometimes "title", perhaps something else. It is usually pretty wide. We could have the badge group as a float-right in the cell of the "main" column. I just gave it a try and it worked ok. Inside that group we could insert the various registered badges.
We'd then need a way in the column defs to say which of the columns should get the badges, to let people override that behavior.
Ok, on to question 2 for @mcdonc and @reebalazs ... how to do the extensibility. The goal is that an add-on can register some HTML that is part of a "badge box" somewhere on the row in the default folder contents and/or a custom folder contents view. This HTML is under the control of the add-on and is recalculated for each needed resource (meaning, it isn't some framework-side template that is handed data by the add-on.)
I'm not good at this so I don't really know how such a registration system would work. Do we have any existing examples of extending the folder contents from the outside without overriding it? The content decorator has an argument buttons= that lets you supply a callable that affects the buttons appearing above the grid. But that's on the content type and I don't believe it allows something external injecting more into the content type.
Stated differently, how does the default folder contents view know that the sdexternaleditor plugin has a badge that should be show in a grid row?