Skip to content

Commit

Permalink
Default input to readonly | Avoid getimagesize warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Lagarda committed Jun 8, 2020
1 parent a03b95c commit f9c98f0
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/js/field/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

<UploadProgress ref="uploader" :current="currentPath" :visibility="field.visibility" :rules="field.upload_rules" v-on:removeFile="removeFileFromUpload"></UploadProgress>

<file-select :id="field.name" :field="field" :css="errorClasses" v-model="value" v-on:open-modal="openFilemanagerModal"></file-select>
<file-select :id="field.name" :field="field" :is-readonly="field.readonly" :css="errorClasses" v-model="value" v-on:open-modal="openFilemanagerModal"></file-select>

<p class="mt-3 flex items-center text-sm" v-if="value">
<button type="button" class="cursor-pointer dim btn btn-link text-primary inline-flex items-center" @click="openRemoveModal">
Expand Down
4 changes: 2 additions & 2 deletions resources/js/field/custom/FileSelect.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div class="flex flex-wrap items-stretch w-full mb-2 relative">
<input type="text" class="flex-shrink flex-grow flex-auto leading-normal w-px flex-1 form-control form-input form-input-bordered-l relative"
:placeholder="__('Select a file')" v-model="value">
:placeholder="__('Select a file')" v-model="value" :disabled="isReadonly">
<div class="flex -mr-px">
<span class="filemanager-open flex items-center leading-normal rounded-lg rounded-l-none border border-l-0 border-grey-light bg-40 px-3 whitespace-no-wrap text-grey-dark text-sm cursor-pointer" @click="openModalFilemanager">{{ __('Open FileManager') }}</span>
</div>
Expand All @@ -10,7 +10,7 @@

<script>
export default {
props: ['value', 'field'],
props: ['value', 'field', 'isReadonly'],
methods: {
openModalFilemanager() {
Expand Down
56 changes: 56 additions & 0 deletions src/FilemanagerField.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Infinety\Filemanager\Traits\CoverHelpers;
use Laravel\Nova\Contracts\Cover;
use Laravel\Nova\Fields\Field;
use Laravel\Nova\Http\Requests\NovaRequest;

class FilemanagerField extends Field implements Cover
{
Expand Down Expand Up @@ -66,6 +67,13 @@ class FilemanagerField extends Field implements Cover
*/
protected $downloadFileButton;

/**
* The callback used to determine if the field is readonly.
*
* @var Closure
*/
public $readonlyCallback;

/**
* Create a new field.
*
Expand Down Expand Up @@ -252,6 +260,54 @@ public function noDragAndDropUpload()
return $this;
}

/**
* Set the callback used to determine if the field is readonly.
*
* @param Closure|bool $callback
* @return $this
*/
public function readonly($callback = true)
{
$this->readonlyCallback = $callback;

return $this;
}

/**
* Determine if the field is readonly.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return bool
*/
public function isReadonly(NovaRequest $request)
{
return with($this->readonlyCallback, function ($callback) use ($request) {
if ($callback === true || (is_callable($callback) && call_user_func($callback, $request))) {
$this->setReadonlyAttribute();

return true;
}

if ($callback !== false) {
return true;
}

return false;
});
}

/**
* Set the field to a readonly field.
*
* @return $this
*/
protected function setReadonlyAttribute()
{
$this->withMeta(['extraAttributes' => ['readonly' => true]]);

return $this;
}

/**
* Resolve the thumbnail URL for the field.
*
Expand Down
16 changes: 10 additions & 6 deletions src/Http/Services/FileManagerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Infinety\Filemanager\Events\FileUploaded;
use Infinety\Filemanager\Events\FolderRemoved;
use Infinety\Filemanager\Events\FolderUploaded;
use Infinety\Filemanager\Exceptions\Http\InvalidConfig;
use Infinety\Filemanager\Http\Exceptions\InvalidConfig;
use InvalidArgumentException;

class FileManagerService
Expand Down Expand Up @@ -87,14 +87,14 @@ public function ajaxGetFilesAndFolders(Request $request)
{
$folder = $this->cleanSlashes($request->get('folder'));

if (! $this->folderExists($folder)) {
if (!$this->folderExists($folder)) {
$folder = '/';
}

$this->setRelativePath($folder);

$order = $request->get('sort');
if (! $order) {
if (!$order) {
$order = config('filemanager.order', 'mime');
}

Expand Down Expand Up @@ -189,7 +189,7 @@ public function uploadFile($file, $currentFolder, $visibility, $uploadingFolder
if ($this->storage->putFileAs($currentFolder, $file, $fileName)) {
$this->setVisibility($currentFolder, $fileName, $visibility);

if (! $uploadingFolder) {
if (!$uploadingFolder) {
$this->checkJobs($this->storage, $currentFolder.$fileName);
event(new FileUploaded($this->storage, $currentFolder.$fileName));
}
Expand All @@ -200,9 +200,13 @@ public function uploadFile($file, $currentFolder, $visibility, $uploadingFolder
}
}

/**
* @param $file
* @return mixed
*/
public function downloadFile($file)
{
if (! config('filemanager.buttons.download_file')) {
if (!config('filemanager.buttons.download_file')) {
return response()->json(['success' => false, 'message' => 'File not available for Download'], 403);
}

Expand Down Expand Up @@ -241,7 +245,7 @@ public function getFileInfo($file)
*/
public function getFileInfoAsArray($file)
{
if (! $this->storage->exists($file)) {
if (!$this->storage->exists($file)) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Services/GetFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public function getThumb($file, $folder = false)
public function getImageDimesions($file)
{
if ($this->disk == 'public') {
return getimagesize($this->storage->path($file['path']));
return @getimagesize($this->storage->path($file['path']));
}

if (in_array(config('filemanager.disk'), $this->cloudDisks)) {
Expand Down

0 comments on commit f9c98f0

Please sign in to comment.