UniSharp / laravel-filemanager

Media gallery with CKEditor, TinyMCE and Summernote support. Built on Laravel file system.
https://unisharp.github.io/laravel-filemanager/
MIT License
2.07k stars 720 forks source link

Sort by time default #337

Open josearagon opened 7 years ago

josearagon commented 7 years ago

I need load files order by "time DESC" when the iframe of laravel-filemanager is called. Is posible? I read the code and see that we cant order by time DESC and the code dont have options to configure a default "sort_type"

streamtw commented 7 years ago

Maybe we should add a config to set default sort type.

josearagon commented 7 years ago

Thanks g0110280, When do you think that the changes will be made?

nalorim commented 6 years ago

where in the config file that I can change/modify the sorting, bro?

anasmorahhib commented 6 years ago

To load files order by "time DESC" you can change the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php

   public function sortFilesAndDirectories($arr_items, $sort_type)
    {
        if ($sort_type == 'time') {
            $key_to_sort = 'updated';
        } elseif ($sort_type == 'alphabetic') {
            $key_to_sort = 'name';
        } else {
            $key_to_sort = 'updated';
        }

           return strcmp($a->{$key_to_sort}, $b->{$key_to_sort});
        });

        return $arr_items;
    }

with

   public function sortFilesAndDirectories($arr_items, $sort_type)
    {
        if ($sort_type == 'time') {
            $key_to_sort = 'updated';
        } elseif ($sort_type == 'alphabetic') {
            $key_to_sort = 'name';
        } else {
            $key_to_sort = 'updated';
        }

        uasort($arr_items, function ($a, $b) use ($key_to_sort) {
            if ( $a->$key_to_sort == $b->$key_to_sort )
                return 0;
            else if ( $a->$key_to_sort > $b->$key_to_sort)
                return -1;
            else
                return 1;
        });

        return $arr_items;
    }
josearagon commented 6 years ago

Thanks @anasmorahhib, your code help me a lot, but I also need to change the default sort_type var in vendor/unisharp/laravel-filemanager/public/js/script.js I have replaced this line: var sort_type = 'alphabetic'; for this: var sort_type = 'updated';

arbexmb commented 5 years ago

Is there a way I can order by "time DESC" without changing the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php?

3s777 commented 4 years ago

This is my solution File Vendor/Unisharp/laravel-filemanager/public/js/script.js row 3 instead var sort_type = 'alphabetic'; var sort_type = 'time';

File Vendor/Unisharp/laravel-filemanager/src/Controllers/ItemsController.php instead 'items' => array_map(function ($item) { return $item->fill()->attributes; }, array_merge($this->lfm->folders(), $this->lfm->files())), change to 'items' => array_map(function ($item) { return $item->fill()->attributes; }, array_merge($this->lfm->folders(), array_reverse($this->lfm->files()))),

Sorry for my english

masumbillahbd commented 3 years ago

how to set up sort by time (v2.0.0 2021) by default? last upload position first/top

Ercogx commented 2 years ago

February 2022, I understand the functionality has not been added yet?