OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.43k stars 2.4k forks source link

Media Field random image order #1749

Closed jan-chvojka closed 6 years ago

jan-chvojka commented 6 years ago

If you have multiple images in Meida Field, images does not retain your sort order, you have to reorder them before each publish/save. The order is saved fine, but when the Content Item Edit page reloads, they are displayed randomly. The script mediafield.js is checking them whether they exits via ajax and that is causing this error.

I think this part of code causes the problem (OrchardCore.Media\Assets\js\mediafield.js, line 23-43)

                set: function (values) {
                    var self = this;
                    var mediaPaths = values || [];
                    var signal = $.Deferred();
                    mediaPaths.forEach(function (x, i) {
                        promise = $.when(signal).done(function () {
                            $.ajax({
                                url: mediaItemUrl + "?path=" + encodeURIComponent(x),
                                method: 'GET',
                                success: function (data) {
                                    self.mediaItems.push(data);
                                },
                                error: function (error) {
                                    console.log(JSON.stringify(error));
                                }
                            });
                        });
                    });

                    signal.resolve();
                }
matiasmolleja commented 6 years ago

By reading the code I think you are right. But I can't repro :) For me the order is always OK. What steps are you following to make it fail?

jan-chvojka commented 6 years ago

Maybe it's because I load images from Azure Blob Storage. I'm going to try it tomorrow with default media provider and I will see if it's behave correctly.

matiasmolleja commented 6 years ago

Closing after testing in azure blobstorage. Fixed by #1751