Repository navigation
Add multi-upload and ordered gallery support - #124
RandyCupic wants to merge 63 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.
The collectionPayload child holds "[]" for an empty field, which Symfony does not consider empty, so the field and any form containing it were never empty, eg. an optional embedded form got an object out of its empty_data. The child now has an is_empty_callback which treats null, "" and an empty JSON list as empty.
6ea30c7 to
3b7dc1f
Compare
|
Thanks for the thorough review and for testing it in sklepex. I rebased onto current 4.0 first, so the overrides from #128 and the new As you suggested, the per-item alt text and caption in the form field are now the overrides, and they're carried through the payload, so a gallery save keeps them ("Carry alt text and caption overrides through the collection payload", "Edit the alt text and caption overrides in the form field inputs"). Two things follow from that which I decided myself, so please say if you'd rather have them differently:
Everything from "Must fix", "Smaller" and "Tests" is addressed, see the inline replies. In short:
I also migrated sklepex to the new shape: all 11 single fields are collections now, moved with Doctrine migrations that I ran up, down and up on a copy of the dev database. Akeneo stores the attribute values as lists. Still open:
|
RandyCupic
left a comment
There was a problem hiding this comment.
I re-tested 3b7dc1f7 in the Symfony 7.4 test app, with all three fields mapped as collections like in FORM.md, and in sklepex with CKEditor 5. I also ran Version040000 up, down and up again on MySQL. CI is green.
Great work, everything from the first round is fixed and the tests are much better. A few things before merge.
Must fix
- Alt text and caption: I'd rather keep the cloud values editable in the form field, next to the overrides, like in CKEditor. See inline on
Preview.vueandRemoteMediaTransformer. FORM.md, UPGRADE.md and the CHANGELOG need to follow.
Should fix
- The submit block stops Cancel buttons too, and in a hidden tab it fails silently. See inline.
- Docs: the migration order in UPGRADE.md, the
location_idclaim, and a few missing CHANGELOG lines. See inline.
Smaller
- A few upload panel items, two hr strings, the treeselect texts and
loadFromRemote()on a rejected payload. See inline. INSTALL.mdstill sayscomposer require netgen/remote-media-bundle:^3.0.
Enforcing the fixed folder on the endpoint in a separate ticket is fine. I'll rebase platform (#125) once this is in.
| class="media-caption-override data" | ||
| > | ||
| </div> | ||
| <!-- Alt text and caption of this location; in form fields they are the only alt text and caption inputs --> |
There was a problem hiding this comment.
I'd keep the cloud alt text and caption editable here too, with the overrides next to them, like in CKEditor. Editors edit the cloud values from the form today, and the overrides are for per-place exceptions. So altText and caption go back into the payload.
There was a problem hiding this comment.
To be clear, since my first-round comment ("Per-item alt and caption should be the overrides") was badly worded: I meant carry the overrides through the payload as well, not replace the cloud inputs with them. Sorry for the extra round.
The rule is simple: the form field and CKEditor must behave the same. The cloud alt text and caption stay editable in both, and the overrides are just that, an optional override per location on top of them.
There was a problem hiding this comment.
Done. The cloud alt text and caption inputs are back in the form field, with the override inputs next to them, the same as in CKEditor. altText and caption are back in the payload. FORM.md, UPGRADE.md and the CHANGELOG are updated.
| // never changed by the form field, whatever the payload carries. | ||
| // A resource that is gone from the remote is kept, the service logs it. | ||
| $tags = $value['tags'] ?? []; | ||
| $this->service->handleRemoteTagsUpdate($remoteResource, is_array($tags) ? $tags : []); |
There was a problem hiding this comment.
With the cloud fields back, this goes through handleRemoteUpdate() again. On your two points:
''turning intonullon a tag change: normalise empty values the same way when comparing and storing, instead of working around it here;- a stale page writing an old alt text back is the same last-write-wins as any other field, I'm fine with that.
There was a problem hiding this comment.
Done, the form calls handleRemoteUpdate() again and handleRemoteTagsUpdate() is removed. Empty values are already normalised the same way when comparing and when storing, so nothing else changes there.
| // and no response. A slow but moving upload of a big file is never cut off. | ||
| const UPLOAD_IDLE_TIMEOUT_MS = 180000; | ||
| const UPLOAD_TIMEOUT_REASON = 'ngrm-upload-timeout'; | ||
| const SUBMIT_CONTROL_SELECTOR = 'button:not([type]), button[type=submit], input[type=submit], input[type=image]'; |
There was a problem hiding this comment.
This also catches Cancel and Delete draft submit buttons (Ibexa content edit has both), so with a pending row the editor can't leave without removing it first. Skip controls with formnovalidate, maybe add a data-ngrm-skip-submit-block opt-out, and document it next to ngrm-submit-blocked.
There was a problem hiding this comment.
Done. Buttons with formnovalidate or data-ngrm-skip-submit-block are never blocked, for both the click and the submit event. It's documented next to ngrm-submit-blocked in UPGRADE.md and in the CHANGELOG.
| })); | ||
|
|
||
| this.$nextTick(() => { | ||
| if (this.$refs.submitBlocked) { |
There was a problem hiding this comment.
If the field is in an inactive tab (Sylius product edit), the message renders hidden and scrollIntoView() does nothing, so Save just doesn't react. When this.$el.offsetParent === null, show the message somewhere visible too.
There was a problem hiding this comment.
Done. If the field is hidden (offsetParent === null), the message is also shown at the top of the page for a few seconds.
| document.addEventListener('submit', this.formSubmitListener, true); | ||
| document.addEventListener('click', this.submitClickListener, true); | ||
| }, | ||
| beforeDestroy() { |
There was a problem hiding this comment.
Cancel the running uploads here. In CKEditor a debounced change re-renders the widget while a file uploads, the request still finishes, and the resource stays in Cloudinary without being added.
There was a problem hiding this comment.
Done. Running uploads are cancelled when the panel is destroyed, and nothing is emitted after that. A request the server already received can still finish there.
| "portal-vue": "^2.1.7", | ||
| "pretty-bytes": "^5.6.0", | ||
| "regenerator-runtime": "^0.14.1", | ||
| "vue": "^2.6.10", |
There was a problem hiding this comment.
^2.7.16, and the same for vue-template-compiler, so the range matches the lock.
| } | ||
|
|
||
| try { | ||
| return $this->provider->loadFromRemote($remoteId); |
There was a problem hiding this comment.
This runs for every unknown remote ID of a rejected payload, and a rejected payload has no limit by definition. 200 made-up IDs mean 200 Admin API calls on one render. Use only loadByRemoteId() in the view path.
There was a problem hiding this comment.
Done. The view path uses only loadByRemoteId() now, and there's a test that it doesn't call the remote. A resource picked in the media browser that isn't stored locally yet is left out of that view, FORM.md says so.
| php bin/console doctrine:migrations:migrate --configuration=vendor/netgen/remote-media-bundle/migrations/doctrine.yaml | ||
| ``` | ||
|
|
||
| * The migration adds the nullable `position` column to `ngrm_remote_resource_location`. The form stores the order of a field's resources in it. Existing locations have no position. |
There was a problem hiding this comment.
Please say that Version040000 runs before doctrine:migrations:diff for the OneToOne migration below, and that the diff needs the --filter-expression from the 3.0.1 section. Otherwise the diff also adds position, and Version040000 then fails with "Duplicate column name 'position'". The other way round, the example's SET l.position = 0 fails if Version040000 never ran.
There was a problem hiding this comment.
Done. The Database section and the OneToOne section now say to run Version040000 before the diff and to pass the --filter-expression, with both failure cases.
| ### Templates | ||
|
|
||
| * `@NetgenRemoteMedia/form/remote_media_type.html.twig` renders the `collectionPayload` field instead of the `locationId` and `source` fields. | ||
| * `@NetgenRemoteMedia/app/interactions.html.twig` takes three new parameters: `locations` (a list of `RemoteResourceLocation` objects), `upload_limit` and `location_source`. `upload_limit` defaults to `1`, so templates which include it with `location_id` keep working with one resource. The `variation_settings_json` parameter is removed, crop settings are read from the locations. |
There was a problem hiding this comment.
Only half true: it renders, but in a form field the widget posts only collectionPayload. A template that passes location_id and the old input_fields without collectionPayload never saves. Reword it, or drop the location_id fallback. Same in CHANGELOG line 14.
There was a problem hiding this comment.
Dropped the fallback, interactions.html.twig no longer takes location_id. UPGRADE.md and the CHANGELOG say to pass locations and add collectionPayload to input_fields. The Ibexa and Layouts integrations move to locations in their 4.0 releases.
| * the frontend lock file is re-resolved, which upgrades Vue from 2.6 to 2.7, `vue-select` from 3.2 to 3.20 and `@babel/core` from 7.6 to 7.28 | ||
| * `regenerator-runtime` is a direct frontend dependency, the re-resolved Babel needs it | ||
| * the alt text and caption inputs of the form field edit the overrides of the location (`altTextOverride` and `captionOverride`), one alt text and one caption input per item, the form field doesn't change the alt text and caption stored on the cloud anymore, `altText` and `caption` are not part of `collectionPayload` and are ignored if submitted, the CKEditor 5 plugin still shows both, see [form documentation](FORM.md#alt-text-and-caption-overrides) | ||
| * `RemoteResourceService::handleRemoteTagsUpdate()` updates only the tags of a resource on the remote, `RemoteMediaType` uses it instead of `handleRemoteUpdate()` |
There was a problem hiding this comment.
Missing: tags are compared and stored sorted, and handleRemoteUpdate() stores an empty alt text or caption as null. Line 41 changes anyway with the cloud fields back; please split it into single-clause bullets.
There was a problem hiding this comment.
Added both, as single-clause bullets. The old line 41 is removed, since the form edits the cloud values as it did in 3.1.
|
Thanks for re-testing it, and no problem about the extra round.
Still open, as before: the Norwegian check by a native speaker, the |
RandyCupic
left a comment
There was a problem hiding this comment.
I re-tested 0f336616 in the Symfony 7.4 test app and in sklepex with CKEditor 5. CI is green.
Thanks, everything from the second round is fixed. One thing before merge.
Should fix
- The same resource in two fields of one form loses cloud alt text and caption edits. See inline on
RemoteMediaTransformer.
I'll fix the null alt and caption on Cloudinary SDK 3 in platform (#125).
| } | ||
| } | ||
| // A resource that is gone from the remote is kept, the service logs it. | ||
| $this->service->handleRemoteUpdate($remoteResource, $value); |
There was a problem hiding this comment.
If the same resource is in two fields of the form (Image and Gallery in my test), each field posts its own altText and caption, and the last one wins. I changed the alt text in Image only, Gallery posted the old empty value, and it ended up null in the DB and in Cloudinary. Only write a cloud value when the editor changed it, eg. send the loaded value along in the entry and compare with that.
There was a problem hiding this comment.
Fixed in 45c22db, dist rebuilt in 02ab909.
Each payload entry now has loaded: the alt text, caption and tags the widget loaded. The transformer writes only the values that differ from it. The others keep the resource's current value, so Gallery no longer overwrites the alt text changed in Image. A rejected submission keeps loaded too, so the edits still count after the form is shown again. An entry without loaded works as before.
Tests cover Image and Gallery on the same resource, with a change in one field and with changes in both. FORM.md and the changelog describe loaded.
|
Thanks! The alt text and caption from two fields are fixed, see the inline reply. And thanks for taking the While testing it I found one more bug and fixed it in 554971f: the Cloudinary factory read the alt text from |
RandyCupic
left a comment
There was a problem hiding this comment.
I re-tested 554971ff in the Symfony 7.4 test app. CI is green, and the two fields on one resource work now, also with a stale tab.
One more thing before merge.
Should fix
- After a rejected submit, an alt text change in a valid field is lost on the next save. See inline on
RemoteMediaType.
|
|
||
| return [ | ||
| 'remote_media_locations' => is_iterable($data) ? RemoteMediaCollectionTransformer::sortByPosition($data) : [], | ||
| 'remote_media_loaded_values' => [], |
There was a problem hiding this comment.
This is also the path for a valid field in an invalid form, and then the widget takes the edited values as loaded. I changed the alt text in Image and made Gallery go over the limit: 422, and the next Save writes nothing for Image, because altText now equals loaded. The rejected request had already pushed the new alt text to Cloudinary, so DB and Cloudinary stay out of sync. Take loaded from the submitted payload here too whenever the form was submitted.
There was a problem hiding this comment.
Fixed in a39205e. When the form was submitted, the view now takes loaded from the submitted payload for a valid field too, matched to the locations by remote ID. So after the 422 the widget still sends the Image alt text as a change, and the next save writes it to the DB. The test covers a valid Image field with Gallery over the limit.
|
Thanks, fixed, see the inline reply. |
RandyCupic
left a comment
There was a problem hiding this comment.
I re-tested a39205e8 in the Symfony 7.4 test app. A valid field in a rejected form keeps its alt text change now, and after the next save DB and Cloudinary have the same value. Two fields on one resource still work, and CI is green.
Nice work, and thanks for sticking with it through all the rounds. Good to merge from my side.
I'll take the null alt text and caption on SDK 3 in #125 after this is merged.
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.collectionPayload:[]clears it;locationIdis kept once, and location ids that don't belong to the edited value are ignored;validatorsdomain, en/hr/no) shown at the field (error_bubblingisfalse);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. A change of the Cloudinary values or the tags updates the resource in Cloudinary throughRemoteResourceService::handleRemoteUpdate(), as before.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;/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) and describes the payload. CHANGELOG and UPGRADE.md have the 4.0 entries, including the OneToOne to to-many migration as a Doctrine migration class.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.collectionPayload. The named children (locationId,remoteId,altText, ...) and the hiddenuploadLimitfield are gone, so custom form themes that render them must be updated.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 and a failed upload, instead of throwing anInvalidArgumentException(500).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.