Add AspectRatio to attachment

This commit is contained in:
philipp lang 2020-10-27 02:18:30 +01:00
parent b649cf6c8a
commit bffa99b042
6 changed files with 22 additions and 7 deletions

View File

@ -21,7 +21,8 @@ class UploadStorage {
$sourceFile = new SourceFile([ $sourceFile = new SourceFile([
'basename' => pathinfo($this->file->getClientOriginalName(), PATHINFO_FILENAME), 'basename' => pathinfo($this->file->getClientOriginalName(), PATHINFO_FILENAME),
'extension' => $this->file->getClientOriginalExtension(), 'extension' => $this->file->getClientOriginalExtension(),
'tags' => [] 'tags' => [],
'aspect_ratio' => $this->data['resAspectRatio']
]); ]);
$sourceFile->slugAttributes(); $sourceFile->slugAttributes();

View File

@ -73,7 +73,9 @@ class Responsiveimage extends FormWidgetBase
*/ */
protected function prepareVars() protected function prepareVars()
{ {
$this->vars['aspectRatio'] = $this->aspectRatio ?: 'null'; $this->vars['aspectRatio'] = $this->aspectRatio
? str_replace('"', "'", json_encode(explode(' / ', $this->aspectRatio)))
: 'null';
$this->vars['minWidth'] = $this->minWidth ?: '0'; $this->vars['minWidth'] = $this->minWidth ?: '0';
$this->vars['name'] = $this->formField->getName(); $this->vars['name'] = $this->formField->getName();
$this->vars['value'] = $this->getLoadValue() ?: 'null'; $this->vars['value'] = $this->getLoadValue() ?: 'null';

View File

@ -151,7 +151,6 @@ export default {
} }
if (file.width < this.cropOptions.minWidth) { if (file.width < this.cropOptions.minWidth) {
console.log('zu klein');
$.oc.flashMsg({ $.oc.flashMsg({
text: `Dieses Bild ist zu klein. Bitte wähle ein Bild mit mindestens ${this.cropOptions.minWidth} Pixel Breite.`, text: `Dieses Bild ist zu klein. Bitte wähle ein Bild mit mindestens ${this.cropOptions.minWidth} Pixel Breite.`,
class: 'error' class: 'error'
@ -173,10 +172,17 @@ export default {
}); });
}, },
onSend(file, xhr, formData) { onSend(file, xhr, formData) {
formData.append('extraData', JSON.stringify(this.extraData[file.name])); formData.append('extraData', JSON.stringify({
...this.extraData[file.name],
resAspectRatio: this.cropOptions.aspectRatio
}));
formData.append('resAspectRatio', this.aspectRatio);
this.formData.forEach((v) => { this.formData.forEach((v) => {
formData.append(v.name, v.value); formData.append(v.name, v.value);
}); });
Object.keys(this.cropOptions).forEach((v) => {
formData.append(v, this.cropOptions[v]);
});
}, },
onMount() { onMount() {
if (!this.value) { return; } if (!this.value) { return; }

View File

@ -35,7 +35,7 @@ export default {
shade: true, shade: true,
boxWidth: $cropContainer.width(), boxWidth: $cropContainer.width(),
onChange: _cls.onChangeCrop, onChange: _cls.onChangeCrop,
aspectRatio: _cls.cropOptions.aspectRatio, aspectRatio: _cls.realAspectRatio,
minSize: [_cls.cropOptions.minWidth, 0] minSize: [_cls.cropOptions.minWidth, 0]
}; };
@ -67,6 +67,11 @@ export default {
}, },
computed: { computed: {
realAspectRatio() {
return this.cropOptions.aspectRatio
? this.cropOptions.aspectRatio[0] / this.cropOptions.aspectRatio[1]
: null;
},
popupId() { popupId() {
return `subform-popup-${this.formid}`; return `subform-popup-${this.formid}`;
}, },

View File

@ -24,9 +24,9 @@ class SourceFile extends Model
/** /**
* @var array Fillable fields * @var array Fillable fields
*/ */
protected $fillable = ['id', 'basename', 'extension', 'tags', 'slug']; protected $fillable = ['id', 'basename', 'extension', 'tags', 'slug', 'aspect_ratio'];
public $jsonable = ['tags']; public $jsonable = ['tags', 'aspect_ratio'];
/** /**
* @var array Relations * @var array Relations

View File

@ -15,6 +15,7 @@ class CreateResponsiveFilesTable extends Migration
$table->string('slug'); $table->string('slug');
$table->string('extension'); $table->string('extension');
$table->json('tags'); $table->json('tags');
$table->string('aspect_ratio')->nullable();
$table->timestamps(); $table->timestamps();
}); });