Code Monkey home page Code Monkey logo

Comments (6)

SWEET1S avatar SWEET1S commented on June 16, 2024

Thanks for your feedback, will make a fix soon.

from moonshine-filemanager.

SWEET1S avatar SWEET1S commented on June 16, 2024

Hi, I uploaded version 1.0.1 where I made it possible to have more fields on the page

from moonshine-filemanager.

ronnyexp avatar ronnyexp commented on June 16, 2024

Hello i think still got error
Screenshot 2024-03-13 at 11 37 25

i just changed to like this and its work.

@use('Sweet1s\MoonshineFileManager\FileManagerTypeEnum')

@php
    $uniqueId = uniqid();
@endphp

<x-moonshine::form.input
    type="hidden"
    id="lfm-input-{{ $uniqueId }}"
    class="lfm-input-{{ $uniqueId }}"
    :name="$element->name()"
    :value="implode(',', $element->getFullPathValues())"
/>

<div class="form-group form-group-dropzone">
    <x-moonshine::form.button
        data-input="lfm-input-{{ $uniqueId }}"
        class="lfm-{{ $uniqueId }}"
    >
        {{ $element->getTitle() }}
    </x-moonshine::form.button>

    @php($raw = is_iterable($value) ? $value : [$value])
    @php($files = $element->getFullPathValues())


    @if(is_array($files) ? array_filter($files) : $files->isNotEmpty())
        <div class="dropzone">
            <div class="dropzone-items"
                 x-data="sortable"
                 data-handle=".dropzone-item"
            >
                @foreach($files as $index => $file)
       
                    <x-moonshine::form.file-item
                        :attributes="$element->attributes()->merge([
                            'id' => $element->id(),
                            'name' => $element->name()
                        ])"
                        :raw="$raw[$index]"
                        :file="$file"
                        :download="$element->getTypeOfFileManager() === FileManagerTypeEnum::Image ? false : $element->canDownload()"
                        :removable="$element->isRemovable()"
                        :removableAttributes="$element->getRemovableAttributes()"
                        :imageable="$element->getTypeOfFileManager() === FileManagerTypeEnum::Image"
                    />
                @endforeach
            </div>
        </div>
    @endif
</div>

<script>
    let lfm{{ $uniqueId }} = function (id, options) {
        let buttons = document.querySelectorAll(`.${id}`);

        buttons.forEach((button) => {
            button.addEventListener('click', function () {
                let route_prefix = (options && options.prefix) ? options.prefix : '/filemanager';
                let target_input = document.getElementById(button.getAttribute('data-input'));

                window.open(route_prefix + '?type=' + '{{ $element->getTypeOfFileManager()->value }}', 'FileManager', 'width=900,height=600');
                window.SetUrl = function (items) {
                    let file_path = items.map(function (item) {
                        return item.url;
                    }).join(',');

                    // set the value of the desired input to image url
                    target_input.value = file_path;
                    target_input.dispatchEvent(new Event('change'));

                    // set or change the preview image src
                    items.forEach(function (item) {
                        let img = document.createElement('img')
                        img.setAttribute('style', 'height: 5rem')
                        img.setAttribute('src', item.thumb_url)
                    });
                };
            });
        });
    };

    let route_prefix{{ $uniqueId }} = "{{ url('filemanager') }}";
    lfm{{ $uniqueId }}('lfm-{{ $uniqueId }}', {prefix: route_prefix{{ $uniqueId }}});

    let lfmInput{{ $uniqueId }} = document.querySelector('.lfm-input-{{ $uniqueId }}');

    let initialValues{{ $uniqueId }} = JSON.parse('{!! json_encode($element->getFullPathValues()) !!}');

    document.querySelectorAll('.lfm-{{ $uniqueId }} + * button').forEach((button) => {
        button.addEventListener('click', function () {
            let image = button.nextElementSibling.getAttribute('src');

            let values = lfmInput{{ $uniqueId }}.value.split(',');

            if (values.includes(image)) {
                values = values.filter(function (value) {
                    return value !== image;
                });
            } else {
                values.push(image);
            }

            lfmInput{{ $uniqueId }}.value = values.join(',');
        });
    });

    lfmInput{{ $uniqueId }}.addEventListener('change', function () {
        let values = lfmInput{{ $uniqueId }}.value.split(',');

        let newValues = new Set(initialValues{{ $uniqueId }}.concat(values));

        lfmInput{{ $uniqueId }}.value = Array.from(newValues).join(',') || null;

        document.querySelector('.lfm-{{ $uniqueId }}').innerText = `{{ $element->getTitle() }} (${newValues.size})`
    });
</script>


and I want to ask is this only for field updates? because when i use to create, i got error
Screenshot 2024-03-13 at 11 44 54

from moonshine-filemanager.

SWEET1S avatar SWEET1S commented on June 16, 2024

Strange, the project works in my project, I'll be sure to check again

from moonshine-filemanager.

ronnyexp avatar ronnyexp commented on June 16, 2024

i think i got a problem, i forgot to adding cast in my model
protected $casts = [ 'image_array' => 'collection', ];
im also adding custom so can multiple or not, using custom disk.
Screenshot 2024-03-13 at 20 23 07

Really thanks this field very useful and helpful.

from moonshine-filemanager.

SWEET1S avatar SWEET1S commented on June 16, 2024

Glad you found the bug, we should add it to the documentation so other people don't run into the same problem. Enjoy using the package if you have any ideas, I look forward to hearing them :)

from moonshine-filemanager.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.