Repository navigation
Add multi-upload and ordered gallery support - #124
RandyCupic wants to merge 103 commits into
Conversation
|
@mivancic When you select multiple images in gallery, and then you go to select more, it doesn't show these that are already added as selected or grayed out. In fact, you can select them again. It won't add them again but it messes up with limitation. For example, I've put limit to 5 and I've selected 3 images. Then I went to select more, and again I've selected 2 of the same images so I was not able to select more (as I already had 5 images in total) but when you actually go to add them, there are only 3. |
|
Thanks, reproduced. The picker only got the number of items already in the gallery, not which ones, so you could pick them again. They counted towards the limit, which blocked selecting more, and were then dropped as duplicates when added. Interactions now passes the IDs of the items already in the field through MediaModal to MediaGallery. Those items show as "Added", greyed out and not clickable, and they don't count towards the selection. The selection bar messages are now translated as well (en, hr, no, nb) |
RandyCupic
left a comment
There was a problem hiding this comment.
I went through the code, translations and docs. I ran it in a Symfony 7.4 test app (with the #125 commits applied) and, at the exact head, in sklepex with CKEditor 5. I tested uploads in both folder modes, the picker, reorder, crops, protected files, the limits and tampered payloads.
Nice work. The per-file upload, folder for all files or per file, rename, the picker with "Added", and the server-side limit and ownership checks all work. A few things before merge.
Rebase first
I merged 3.0 into 4.0 (58299f95), and #133 is in too. 4.0 now has the Doctrine migrations (#129, #132), the alt/caption overrides (#128), the CKEditor 5 changes (#126) and generateLocationHtmlTag() on ProviderInterface. Please rebase multiupload onto it before the rework, so the overrides and the new position migration go in once.
- A test merge conflicts in
Interactions.vue,Preview.vue,interactions.html.twig,RemoteMediaTransformerTest.php,CHANGELOG.md,UPGRADE.mdand the three dist files. For the dist files, take either side and rebuild (Node 12). RemoteMediaTransformerandRemoteMediaTypemerge cleanly, but the collection path then dropsaltTextOverride/captionOverride, and every gallery save resets them to null. Per-item alt and caption should be the overrides, so carry them through the payload.
Must fix
- The data is always a collection, limit 1 too, and the core keeps the order. See inline on
isCollection()andRemoteMediaCollectionTransformer. - A missing
collectionPayloadempties the field, see inline. - CKEditor: focus is lost while typing, the embed CSS class and variation inputs are gone, and some labels are blank. See inline on
Preview.vueandConfiguration.php. - Upload panel: replacing at limit 1,
parent_folder, a fixedfolder, upload guards, retry, the row limit, folder create. See inline. - Entry type validation, missing resource handling, docs. See inline.
Smaller
- "Clear completed" also removes error rows, including 409s with "use existing".
- The same file queued twice isn't detected. "Use existing" for something already in the field shows success and adds nothing.
- An empty filename can be uploaded.
- An empty field now says "Manage media" (it was "Select media"). The visibility select shows even with a single option.
.limit-indicatoris only styled insideMultiUploadInline. vuedraggable's:optionsis deprecated and warns in the console.- The per-row inputs and the icon buttons need labels or aria-labels.
Translations
- no/nb: the new UI mixes Norwegian and English ("Overwrite (bruk på alle filer)", "Select" next to "Fjern markering"), because the new components reuse keys that were never translated. Please translate those and have someone who speaks Norwegian check them.
- Dead keys:
multi_upload.title,multi_upload.status.uploading,limit_info, andupload.button.use_existing_resource(mapped, but nothing reads it). Remove them or wire them up. - en: use sentence case like the rest of the file ('Upload all', 'Clear completed').
Tests
- An owned location is kept in collection mode.
- Reorder and removal of persisted items, with the real transformer.
- Non-string entry fields.
- An omitted field.
- buildView after an invalid submit.
- The
Configurationkeys. - One end-to-end test (POST → entity → flush → reload) that checks the order.
Please also update the PR description, it still mentions RemoteMediaCollectionType. I'll rebase platform (#125) after your rebase. allowed_types being checked only after the upload, allowed_tags without a server check and hide_filename doing nothing are older than this PR, so I'll take them as separate tickets.
Implement upload-limited multi-resource handling with multi-select and reorderable gallery cards, split RemoteMediaType into single and collection form types, convert the multi-gallery components to props-down/events-up data flow, and improve the multi-upload UX, i18n and wire format. Add a Norwegian Bokmål (nb) translation file. Fix the CKEditor "Manage Media" modal so the gallery renders in collection mode (default the embed to single-select and guard the missing multi-select translation key that was blanking the gallery). Includes rebuilt NGRM frontend assets (remotemedia.js + remotemedia.css).
Clearing a gallery now sticks, folder placeholders no longer create Cloudinary folders and existing CKEditor embeds load their media. Malformed payloads fail the form instead of emptying the collection.
Browsing or uploading into a gallery now skips resources that are already in it and stops at the upload limit, and replacing a single image keeps its watermark.
…mote The metadata is still saved locally, and the warning names the remote id so missing assets can be found.
Import order and missing function imports, no short ternary in the collection transformer, and intersection-typed provider mocks in the form type tests.
The multi-upload rewrite dropped the always-present remoteId input, so removing the media from a single field sent nothing and forms that keep the previous value on a missing field could not clear it. Dist rebuilt with Node 12.
Nothing in the Vue app reads the legacy label block, so keep it as on 4.0.
Items already in the field can no longer be picked again and use up the upload limit. Dist rebuilt with Node 12.
upload_limit 1 returns a single location, anything else a collection. Single fields need 'upload_limit' => 1, see UPGRADE.md.
Dist rebuilt with Node 12.
Nothing reads them; the interface uses the ngrm.edit.vue.* keys.
Load more now sits between the grid and the selection bar instead of covering it. Dist rebuilt with Node 12.
Keys like 'limit_reached': 'limit_reached' won over the English fallbacks in the Vue components, so CKEditor showed the raw key whenever /configuration did not send the translation. The isCollection flag is gone as well: form fields always submit a collection.
- Typing in a preview field only updates the state; the debounced handler sends one change event, so CKEditor no longer re-renders the widget after the first character. - Bring back the CSS class and variation inputs for embeds and the preview.*_info tooltips. - Gallery cards load previewUrl first and fall back to the original. - Form fields always post collectionPayload, also with upload_limit 1; a limit of 1 only switches the picker to single select and makes new items replace the current one. - An empty field shows "Select media" again. - Labels for the per-item inputs, aria-labels for the reorder buttons, and vuedraggable options as props instead of the deprecated :options.
- "Create" opens the input on a real click. The menu is appended to <body>, so the click-outside handler cancelled the form; a click now only counts as outside when its mousedown also started outside the picker and its menu. - Clearing the picker falls back to the configured parent folder instead of the root. - Translate "Create folder in:", the root label and the create error, and read .detail before .message like the other requests.
… are not uploaded
…n dropped files are not taken
…d another one is picked
…he other fields of the page
…on a hanging request
…e blocked untyped buttons
|
Thanks for the approval, and sorry for coming back after it. Before merging I ran a full review of Data loss and wrong saves
Server side
Regressions from 4.0 and smaller things
Tests 836 tests, up from 769. They're green on PHP 8.1 with Symfony 5.4 (lowest and normal) and 6.4, and on PHP 8.4 with 6.4. phpstan and cs-fixer are clean. The new tests cover:
The dist is rebuilt with Node 12 and is reproducible from the source. The browser runs in sklepex and akeneo, rerun on Left for separate PRs These are older than this PR:
Also left for separate PRs:
The |
RandyCupic
left a comment
There was a problem hiding this comment.
Re-tested e39f222d in the Symfony lab and in sylius1, form fields and CKEditor embeds. Nice work, everything from your list holds up.
One thing before merge: a form field and a CKEditor embed have to behave the same, and they still don't in two places, see inline.
| // CKEditor embeds stay out of it: they store a change right away, so a value | ||
| // taken over from a form field would be saved before the form is. | ||
| announceCloudValue(resource, field, value) { | ||
| if (this.config.mode === "embed" || !resource.id || !CLOUD_VALUE_FIELDS.includes(field)) { |
There was a problem hiding this comment.
Same resource in a form field and in a CKEditor embed on one page: alt, caption and tags aren't shared in either direction. I set alt r6-from-field in the field and r6-from-embed in the embed, and the page shows both. On save the field writes its value over the one the embed already stored, so the editor's last edit is lost.
I get why the embed shouldn't store a value taken over from the form, but it doesn't have to. Let the embed announce its own edits (they're already stored), and on an announced value only update what it shows, without the PUT. The field still sends its value as a change, so the form save writes it.
There was a problem hiding this comment.
Fixed in 608606f, dist rebuilt in e977ac5. Done as you suggested: the embed announces its own edits, and the form field takes them over and saves them with the form. A value announced to the embed is only shown there, without the PUT. When the embed saves something else later (eg. the caption), it sends that value in takenOver, and location/update keeps the stored value for it. FORM.md and the CHANGELOG describe it.
| // In a form field with a limit of 1 the watermark text outlives the item: | ||
| // the next one picked or uploaded takes it over, also after the item was | ||
| // removed. Not in a CKEditor embed, a removed embed leaves nothing behind. | ||
| watermarkText: this.isSingleMode && this.config.mode !== "embed" ? this.localSelectedImage.watermarkText || "" : "", |
There was a problem hiding this comment.
Same thing with the watermark. In a field with limit 1, the text is kept after remove + pick (r6-wm). In the embed it's cleared (r6-wm-embed is gone). Drop the mode !== "embed" check so both keep it.
There was a problem hiding this comment.
Done in ccd46b1, the check is dropped, so the embed keeps the watermark text after remove and pick too.
|
@mivancic ive run this locallly in a small sandbox scaffold symfony app just to test. I ran into an error - when i used the same cloudinary image in two fields, it threw a db error about unique keys. According to my LLM, this case is the only one where it should happen, because its a new image not yet saved in the DB, so its not reused in any way from the DB and tries to create the same remote id image twice. And supposedly it does not happen if its the same image but uploaded from the machine instead of from cloudinary, but that's only my LLM's guess Example of error: Note - I haven't been checking the myriad of comments before me, so I don't know if it's already been mentioned. cc @RandyCupic |
Hmm, this sounds familiar. It might be a bug that is also happening on the current version. I remember some issues with duplicate entry from Sentry but I was never able to reproduce them or discover what's going on, probably because I was testing the image that Sentry reported, which was at that moment already added in the database. |
|
Thanks! Both are fixed, see inline. Tested in sklepex with the same image in a contributor's image field and in a CKEditor embed: an alt text typed in the field shows in the embed and isn't stored until the form is saved, an embed edit is stored right away and shows in the field, the form save keeps the last edit, and the embed keeps the watermark after remove and pick. |
Replaces #122, rebased onto 4.0 (the branch was renamed from
3.0-multiuploadtomultiupload, which closed #122).Lets a remote media form field hold several resources. Editors can select or upload several resources at once, reorder them, and edit alt text, caption, tags and crops per item. The field data is always an ordered collection of
RemoteResourceLocationobjects;upload_limitonly limits how many items the field accepts.RemoteMediaType, with a newupload_limitoption (nullfor unlimited, the default, or an integer >= 1). Its data is always anArrayCollection<int, RemoteResourceLocation>, also with'upload_limit' => 1(0 or 1 items), so changing the limit never changes the entity mapping or the stored data. A required field usesCount(min: 1), becauseNotBlankandNotNullaccept an empty collection.collectionPayload:[]clears it. Once the widget is loaded it disables the rendered input, so the field is posted once;locationIdis kept once, a new entry which repeats a resource of the field is ignored, and location ids that don't belong to the edited value are ignored;validatorsdomain, en/hr/no), shown at the field (error_bubblingisfalse);upload_limitlooks up at most 100 resources that aren't stored locally per submission (RemoteMediaCollectionTransformer::MAX_REMOTE_LOOKUPS), each of them is a Cloudinary call;altTextOverride,captionOverride) from JGLWEB-1835 add local alt text and caption overrides #128 next to each other, the same as the CKEditor plugin. Both are carried through the payload, with aloadedsnapshot, so only changed values are written. A change of the Cloudinary values or the tags updates the resource in Cloudinary throughRemoteResourceService::handleRemoteUpdate(), as before. Fields of one page which show the same resource share its cloud alt text, caption and tags.isEmpty()), also with the[]payload, so an optional embedded form whose fields are all empty doesn't get an object created from itsempty_data.positioncolumn onngrm_remote_resource_location(migrationVersion040000). The form sets it on submit and sorts by it; entities add#[ORM\OrderBy(['position' => 'ASC'])].parent_folder, shows a fixedfolderread-only on every row;detail, so it shows in prod too);loadableform don't freeze, and anngrm-submit-blockedevent lets other hosts undo their own submit state. Buttons withformnovalidateordata-ngrm-skip-submit-block(eg. Cancel, Delete draft) are never blocked, and in a hidden tab the message is also shown at the top of the page;window.ngrmBlockSubmitIfUploadsPending(root)before saving, and every panel carriesdata-ngrm-uploads-pending;/configurationreturns all labels of the new UI. A widget's old Vue instance is destroyed when CKEditor renders it again./configurationbuild their translations from one list (VueTranslations,ngrm_vue_translations()), checked by a test against the keys the Vue app reads. Norwegian translates the whole UI now, Croatian has the new keys, the folder picker's own texts are translated,ngremotemedia.nb.yamlis removed (Symfony falls back fromnbtono), dead keys are removed.OrderByonposition,addX/removeXso orphan removal works), describes the payload, the required field, uploading files and saving while files aren't uploaded. CHANGELOG and UPGRADE.md have the 4.0 entries, including the OneToOne to to-many migration as a Doctrine migration class and the removed elements of the interface.Version040000migration (up, down, up), the lookup limit, repeated entries and the upload name limit.bundle/Resources/publicrebuilt (Node 12).Behaviour changes:
RemoteMediaTypedata is always a collection. Single fields need a to-many relation and'upload_limit' => 1; a field bound to a singleRemoteResourceLocationfails with aTransformationFailedException. UPGRADE.md has the migration.null, soNotBlankandNotNullno longer make it required. UseCount(min: 1).collectionPayload. The named children (locationId,remoteId,altText, ...) and the hiddenuploadLimitfield are gone, so custom form themes that render them must be updated..ngremotemedia-remove-file,.ngremotemedia-scale, the quick upload button with its file input (new_file), and the hiddeninput.media-idinputs. UPGRADE.md lists what replaces them.location/create,location/update), the local resource and its locations are kept and a warning with the remote id is logged. A submitted resource that exists neither locally nor in Cloudinary is left out as before, now with a warning too. Before, it was deleted locally, which also removed it from every other field using it. The Cloudinary delete notification andnetgen:remote_media:refresh --deletestill delete.interactions.html.twigno longer takeslocation_id. Templates passlocations, andcollectionPayloadininput_fields.isEmpty(), so optionalCollectionTypeentries withdelete_emptywhose fields are all empty are removed.handleRemoteUpdate()compares and stores tags sorted, so a different tag order no longer triggers a Cloudinary update on every save, and it stores an empty alt text or caption asnull.ngrm-changeevent also carriesconfig, andselectedImage.uploadedResourceslists all items of the field.detail) for a missing file, an unsupported visibility, a failed upload and a folder and file name over 240 characters, instead of throwing anInvalidArgumentException(500) or uploading. It uploads to the root folder also forundefinedand(root), the values the interface sends for the root. TheUploadcontroller takes the folder mode anduse_asset_folder_as_public_id_prefixas optional 4th and 5th arguments.RemoteMediaTypeerrors are attached to the field, not to the parent form (error_bubblingisfalse).@babel/core7.6 to 7.28, andregenerator-runtimebecame a direct dependency.vuedraggableis new. Builds use Node 12.Notes:
netgen/remote-media-bundle^4.0and passeslocationsinstead oflocation_idtointeractions.html.twig.folderon the upload endpoint is left for a separate ticket; this PR enforces it in the UI.allowed_typeschecked only after the upload,allowed_tagswithout a server check andhide_filenamedoing nothing are older than this PR and are tracked separately. So are the missing CSRF protection of the endpoints, the 500 on an empty or oversized upload and on a missing folder, and thestoreLocation()flush, which also flushes other pending changes of the host.ngrmBlockSubmitIfUploadsPending(). Browser tests in both cover the product, taxon, contributor, channel, CMS, Author and attribute fields.