Files-gallery: "change position" doesn't update and resets manual sorting

Hi!

I’m running into an issue with files sorting in a gallery section on the panel side. I spent a while reading threads around manual sorting and the attribution of the sort number, so far without luck.

The website in question is an artist’s portfolio with a single files-section as gallery (with list view), used to display images on the main page. The sorting is (hopefully) on its default manual mode and the client needs to freely arrange and rearrange her images through the panel. The files of the gallery are displayed in two places on the panel: on the main page and on the paintings page.

The bug was triggered when the number of files in the section exceeded 20 and a second page was created in the gallery view. Using “change position” on a single file then led to a reset of the sorting of all files, except the selected file. I noticed afterwards that the number of the position didn’t reflect the current value of the sort field.

So as a summary:

– The drag & drop correctly affects the sort number in the .txt file and on the page
– In the panel gallery view, the “change position” select field doesn’t seem to get updated
– Using it resets all previously done manual sorting, and sorts files by filename instead (except on the one selected file, which does reach the intended position)

In the meantime I’ve set the limit of the gallery to a random 300, so the drag & drop stays available and the client can go on building her page. I would advise her to write down her sort pattern somewhere and not use the “change position” function for the moment.

I would love to know where this comes from (maybe something missing in my blueprints? do I need an additional blueprint for the gallery as section?) and/or if there’s a cleaner way to fix it. Thanks for reading and sorry if the message’s a little messy! :slight_smile:

In paintings.yml:

columns:
  - width: 1/2
    sections:
      galerie:
        type: files
        headline: Images
        layout: list
        template: images
        limit: 300
        info: "{{ file.year.toDate('m.Y') }}"

In site.yml:

columns:
  - width: 1/2
    sections:
      paintings:
        type: files
        headline: Peintures
        parent: site.find("paintings")
        layout: list
        template: images
        limit: 300
        info: "{{ file.year.toDate('m.Y')  }}"

In paintings.php:

  <?php foreach($page->files()->sortBy('sort') as $file): ?>

“Change position” select menu displaying “7” for a file showing up in third position in the list and on the website, with a sort field “3” in its text file.

I can reproduce this issue, trying to find out if there is already an issue on GitHub.

1 Like

@texnixe thanks!

Noticing this just now: using files()->last() seems to use the same, non-updated number, and gives me back a file that is then in fact not the last one on the page … tricky for me trying to close a wrapper div :see_no_evil:

You can pass the sorted collection as an argument. By default, the sorting order in the file system is used.

You can pass the sorted collection as an argument. By default, the sorting order in the file system is used.

I think I worked around it doing something similar (I’m not very familiar with php), using $file->sort() and comparing it to a fixed value.

Still something strange there: $files()->count() gives back the correct number of files (matching in the panel and in the file system) and $file->sort() does match the sorting order in the file system but … it jumps straight from number 6 to number 9 and thus returns a 50 for the last (48th) file. So instead of having ten pictures in my first wrapper div, I have 8 :sweat_smile: – which is actually not a problem for this website, but I would be curious to find out where this comes from and how I might fix it.

$file->sort() is pretty useless here, you have to use $files->sortBy('sort'), which you are probably doing anyway.

$files = $files->sortBy('sort', 'asc');
$lastFile = $files->last();
1 Like

Thanks! Doing it this way does return the last file and counts through the collection accurately. I’ve used $file->sort() in order to wrap the first ten pictures in a div, which for the moment also works except for the jump that still skips 7 and 8 while counting. But it’s really a side issue.