FrozenNode / Laravel-Administrator

An administrative interface package for Laravel
http://administrator.frozennode.com/
MIT License
1.94k stars 502 forks source link

New field type: FileSelect #130

Open andrewdworn opened 11 years ago

andrewdworn commented 11 years ago

My idea refers to #113, but also refers to every issue about file (and image) uploading (and mass uploading, has many options).

The goal is to handle files that are already uploaded to the server into a specific directory either by elFinder (outside administrator) or FTP; and integrate them into our existing models. The purpose is simple: big sized file upload is best achieved by FTP (and elFinder does have an FTP driver).

I ended up something like this in my model config:

$dh  = opendir(path('public') . 'data/files');
while (false !== ($filename = readdir($dh))) {
    if (($filename != '.') || ($filename != '..')) $dir_list[] = $filename;
}

return array( 
    'title' => 'Files',
    'single' => 'File',
    'model' => 'MyModel',
    'columns' => array
    (
        'file' => array(
            'title' => 'File Name',
        ),
    ),
    'filters' => array
    (
        'file' => array(
            'title' => 'File',
            'type' => 'enum',
            'options' => $dir_list,
        ),
    ),
    'edit_fields' => array
    (
        'file' => array(
            'title' => 'File',
            'type' => 'enum',
            'options' => $dir_list,
        ),
    ),
);

So i simply use the Enum field type to display my file list in a drop down which is generated by some directory listing php code. The file name is saved at the end, and i am quite happy with my solution.

I would be even happier to have a field type that does the same thing, let's call it 'fileselect' for now:

 'edit_fields' => array
    (
        'file' => array(
            'title' => 'File',
            'type' => 'fileselect',
            'location' => path('public') . 'data/files',
        ),
    ),

In case of dealing with a big number of files, i would use the large dataset solution used for relationships:

 'edit_fields' => array
    (
        'file' => array(
            'title' => 'File',
            'type' => 'fileselect',
            'location' => path('public') . 'data/files',
            'autocomplete' => true,
            'num_options' => 5, 
        ),
    ),

And of course this drop down mechanism (with autocomplete) is just perfect for me, but relating to the original issue #113 , an elFinder popup window could come up instead of the drop-down, where besides doing any kind of file operations, double clicking on a file would insert the file name. (or even file names! - saved coma separated, selected by holding Ctrl in elFinder)

janhartigan commented 11 years ago

An interesting idea. At the very least, this should be something that is incorporated into a generic 'file' field where you can bring up something like elfinder and upload/select files. Incidentally, how have your experiences with elfinder been? What issues have you come across? How customizable is it? Do you know of any good open source competitors? I'm left a little unimpressed by their design, but that's not really a big deal at the end of the day.