Skip to content

Commit

Permalink
Added missing attributes for Attach field
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Jun 6, 2024
1 parent c51d777 commit 9002a25
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 86 deletions.
2 changes: 1 addition & 1 deletion public/css/orchid.css

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions public/css/orchid.rtl.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/css/orchid.rtl.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/orchid.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions public/mix-manifest.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions resources/js/controllers/attach_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export default class extends ApplicationController {
animation: 150,
onEnd: () => {
this.reorderElements();
this.toast('save?');
},
});
}
Expand All @@ -84,7 +83,7 @@ export default class extends ApplicationController {

if (sizeMB > this.sizeValue) {
this.toast(this.errorSizeValue.replace(':name', file.name));
alert(this.errorSizeValue.replace(':name', file.name));
//alert(this.errorSizeValue.replace(':name', file.name));
return;
}

Expand Down Expand Up @@ -137,7 +136,7 @@ export default class extends ApplicationController {
console.error('Error:', error);

this.toast(this.errorTypeValue);
alert(this.errorTypeValue);
//alert(this.errorTypeValue);
});
}

Expand All @@ -156,6 +155,8 @@ export default class extends ApplicationController {
*/
togglePlaceholderShow() {
this.containerTarget.classList.toggle('d-none', this.attachmentValue.length >= this.countValue);
this.filesTarget.disabled = this.attachmentValue.length > 0;


// Disable the nullable field if there is at least one valid value and the count equals 1.
// If there are no values or if there are multiple values, the field will remain enabled and be sent to the server as `null`.
Expand Down
67 changes: 67 additions & 0 deletions resources/sass/plugins/attach.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
.attach {
.spinner-border {
display: none;
}

.attach-image {
object-fit: cover;
aspect-ratio: 1/1;
width: 100%;
border: 1px solid #000;
position: relative;

&:before {
content: " ";
display: block;
position: absolute;
left: 0;
height: 100%;
width: 100%;
@extend .bg-light;
}

&:after {
content: attr(title);
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
text-align: center;
text-wrap: pretty;
@extend .p-3;
@extend .small;
}
}

.attach-image-placeholder {
aspect-ratio: 1/1;
width: 100%;
height: 100%;
display: flex;
cursor: pointer;
align-content: center;
align-items: center;
}

&[aria-busy='true'],
&:not([data-attach-loading-value='0']) {
.spinner-border {
display: inline-block;
}

.choose {
display: none !important;
}
}
}

.was-validated {
.attach-image-placeholder:has(input:invalid) {
border: 1px solid $danger !important;
}
}
64 changes: 1 addition & 63 deletions resources/sass/plugins/plugin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -346,66 +346,4 @@
}
}


.attach {
.spinner-border {
display: none;
}

.attach-image {
object-fit: cover;
aspect-ratio: 1/1;
width: 100%;
border: 1px solid #000;
position: relative;

&:before {
content: " ";
display: block;
position: absolute;
left: 0;
height: 100%;
width: 100%;
@extend .bg-light;
}

&:after {
content: attr(title);
white-space: pre;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
text-align: center;
text-wrap: pretty;
@extend .p-3;
@extend .small;
}
}

.attach-image-placeholder {
aspect-ratio: 1/1;
width: 100%;
height: 100%;
display: flex;
cursor: pointer;
align-content: center;
align-items: center;
}

&[aria-busy='true'],
&:not([data-attach-loading-value='0']) {
.spinner-border {
display: inline-block;
}

.choose {
display: none !important;
}
}
}
@import "attach";
7 changes: 4 additions & 3 deletions resources/views/fields/attach.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class="attach"
data-attach-loading-value="0"
data-attach-attachment-value='@json($value ?? [])'

data-attach-upload-url-value="{{ route('platform.systems.files.upload') }}"
data-attach-sort-url-value="{{ route('platform.systems.files.sort') }}"
data-attach-upload-url-value="{{ $uploadUrl ?? route('platform.systems.files.upload') }}"
data-attach-sort-url-value="{{ $sortUrl ?? route('platform.systems.files.sort') }}"

data-uploader-error-size-value="{{ __('File ":name" is too large to upload') }}"
data-uploader-error-type-value="{{ __('The attached file must be an image') }}"
Expand All @@ -27,6 +27,7 @@ class="attach"
type="file"
data-attach-target="files"
data-action="change->attach#selectFiles"
disabled
{{ $attributes }}
>

Expand All @@ -51,7 +52,7 @@ class="attach"
<input type="hidden" name="{name}" value="{id}">


<img class="attach-image rounded border user-select-none" src="{url}" title="{original_name}"/>
<img class="attach-image rounded border user-select-none overflow-hidden" src="{url}" title="{original_name}"/>

{{--
<object class="attach-image rounded border user-select-none" border="0" data="{url}" type="{mime}" title="test" load="lazy" controls allowfullscreen autoplay="false">
Expand Down
16 changes: 10 additions & 6 deletions src/Screen/Fields/Attach.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
* @method Attach placeholder(string $value)
* @method Attach errorMaxSizeMessage(string $value)
* @method Attach errorTypeMessage(string $value)
* @method CheckBox help(string $value = null)
* @method CheckBox title(string $value = null)
* @method Attach help(string $value = null)
* @method Attach title(string $value = null)
* @method Attach uploadUrl(string $value = null)
* @method Attach sortUrl(string $value = null)
*/
class Attach extends Field
{
Expand All @@ -46,6 +48,8 @@ class Attach extends Field
'placeholder' => 'Upload file',
'errorMaxSizeMessage' => 'File ":name" is too large to upload',
'errorTypeMessage' => 'The attached file must be an image',
'uploadUrl' => null,
'sortUrl' => null,
];

/**
Expand Down Expand Up @@ -86,7 +90,7 @@ public function __construct()
$this->addBeforeRender(function () {
$value = Arr::wrap($this->get('value'));

if (! Assert::isIntArray($value)) {
if (!Assert::isIntArray($value)) {
return;
}

Expand Down Expand Up @@ -115,20 +119,20 @@ public function __construct()

// if is not multiple, then set maxCount to 1
$this->addBeforeRender(function () {
if (! $this->get('multiple')) {
if (!$this->get('multiple')) {
$this->set('maxCount', 1);
}
});
}

/**
* @return $this
* @throws \Throwable
*
* @return $this
*/
public function storage(string $storage): self
{
$disk = config('filesystems.disks.'.$storage);
$disk = config('filesystems.disks.' . $storage);

throw_if($disk === null, 'The selected storage was not found');

Expand Down

0 comments on commit 9002a25

Please sign in to comment.