Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
stepanenko3 committed May 13, 2022
1 parent 3845eb7 commit 995ee72
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions resources/js/components/DetailField.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<PanelItem :index="index" :field="field">
<template #value>
<div class="relative block">
<div v-if="field.image" class="relative block">
<img
class="rounded-lg block w-full"
ref="picture"
:src="resource.fields.filter(f => f.attribute === field.imageAttribute)[0].value"
:src="field.image"
>

<div
Expand All @@ -18,6 +18,9 @@
}"
></div>
</div>
<template v-else>
-
</template>
</template>
</PanelItem>
</template>
Expand Down
4 changes: 2 additions & 2 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@
this.loading = true;
this.loadingError = false;
this.toDataURL(this.currentField.dependsOn[this.currentField.imageAttribute])
this.toDataURL(this.currentField.image)
.then(dataUrl => {
if (dataUrl && dataUrl.indexOf('image/') !== -1) {
this.loadingError = false;
this.image = this.currentField.dependsOn[this.currentField.imageAttribute]
this.image = this.currentField.image
} else {
this.loadingError = true;
this.image = null;
Expand Down
23 changes: 18 additions & 5 deletions src/NovaImageTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,26 @@ public function fields($fields = [])
], $fields));
}

public function image($attribute)
public function image($attribute, $value, $formatter = null)
{
if (is_callable($formatter)) {
$value = call_user_func($formatter, $value);
}

return $this
->withMeta([
'imageAttribute' => $attribute,
])
->dependsOn('image', fn () => null);
->withMeta(['image' => $value])
->dependsOn(
$attribute,
function (NovaImageTags $field, NovaRequest $request, FormData $formData) use($attribute, $formatter) {
$value = $formData->{$attribute};

if (is_callable($formatter)) {
$value = call_user_func($formatter, $value);
}

$field->withMeta(['image' => $value]);
},
);
}

public function minRows($minRows = null)
Expand Down

0 comments on commit 995ee72

Please sign in to comment.