Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images are not resized on "replace" #2

Open
mullema opened this issue May 1, 2019 · 6 comments
Open

Images are not resized on "replace" #2

mullema opened this issue May 1, 2019 · 6 comments

Comments

@mullema
Copy link

mullema commented May 1, 2019

When replacing an image in the files section it is uploaded in the original size.

@rasteiner
Copy link
Owner

thanks for the issue.

The latest version should now resize images that are uploaded via replace from the file section dropdown menu.

However, files replaced from inside the "File View" still don't get resized.
I'm not sure I can do something about this, because I don't think I can change stuff on that view.

I have to research this further.

@mullema
Copy link
Author

mullema commented May 1, 2019

Nice, it works.

Unfortunately there's no easy access to views yet. I use a hacky way via router to change methods in the views:

this.$router.options.routes.find(route => route.name === "PageFile").component

There are several different File Views: SiteFile, PageFile, UserFile (Names from here: https://github.com/getkirby/kirby/blob/master/panel/src/config/routes.js)

@rasteiner
Copy link
Owner

Thanks for info.
Globally registering the views is now considered for the 3.2 milestone :), which is scheduled for June 11. getkirby/kirby#1742

@rasteiner
Copy link
Owner

We also need to get the max pixels option into the File View, therefore it can't stay in the files section (a file might belong "to many sections").

My idea would be to move the option from the section into the file blueprints.

However to transfer the value from the server to the client I either have to make an extra api request to a custom endpoint, or change the response for the current endpoint.
Imho, the cleanest way to alter the current api response, would be the ability to edit API models, like described here: getkirby/ideas#275

If you think the same, upvote that issue :)

@mullema
Copy link
Author

mullema commented May 3, 2019

I like the idea and it is one way to do it.

Extending the Section itself could be another way.
I changed the accept property to an array. It seems to be used in the upload property only, therefore there a small change aswell.

<?php

use Kirby\Cms\File;

$base = require kirby()->root('kirby') . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'sections' . DIRECTORY_SEPARATOR . 'files.php';

Kirby::plugin('rasteiner/k3-maxpixels-option', [
    'sections' => [
        'files' => array_replace_recursive($base, [
            'computed' => [
                'accept' => function () {
                    if ($this->template) {
                        $file = new File([
                            'filename' => 'tmp',
                            'template' => $this->template
                        ]);
                        return $file->blueprint()->accept();
                    }
                    return null;
                },
                'upload' => function () {
                    if ($this->isFull() === true) {
                        return false;
                    }
                    // count all uploaded files
                    $total = count($this->data);
                    $max   = $this->max ? $this->max - $total : null;
                    if ($this->max && $total === $this->max - 1) {
                        $multiple = false;
                    } else {
                        $multiple = true;
                    }
                    return [
                        'accept'     => $this->accept['mime'] ?? '*',
                        'multiple'   => $multiple,
                        'max'        => $max,
                        'api'        => $this->parent->apiUrl(true) . '/files',
                        'attributes' => array_filter([
                            'template' => $this->template
                        ])
                    ];
                }
            ]
        ])
    ]
]);
updated: function() {
   this.$nextTick(() => {
      if(this.$refs.upload) {
         this.$refs.upload.maxpixels = this.options.accept.maxpixels
      }
   })
}

and I just realized that accept is not fetched in the FileView sigh...

@mullema
Copy link
Author

mullema commented May 3, 2019

It took me a while to understand what you mean. I agree, the model is the only clean way in to the File View.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants