Skip to content

Commit

Permalink
Compiled and working hideGroupButtons Prop
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoma committed Jun 1, 2024
1 parent e6166ce commit 13e13e9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
5 changes: 3 additions & 2 deletions dist/js/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -3125,7 +3125,8 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
return {
removeMessage: false,
collapsed: this.group.collapsed,
readonly: this.group.readonly
readonly: this.group.readonly,
hideGroupButtons: this.field.hideGroupButtons
};
},
computed: {
Expand Down Expand Up @@ -3725,7 +3726,7 @@ function render(_ctx, _cache, $props, $setup, $data, $options) {
"class": "align-top",
width: "16",
height: "16"
})], 8 /* PROPS */, _hoisted_4)), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementVNode)("p", _hoisted_5, [(0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementVNode)("span", _hoisted_6, "#" + (0,vue__WEBPACK_IMPORTED_MODULE_0__.toDisplayString)($props.index + 1), 1 /* TEXT */), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createTextVNode)(" " + (0,vue__WEBPACK_IMPORTED_MODULE_0__.toDisplayString)($props.group.title), 1 /* TEXT */)]), !$data.readonly ? ((0,vue__WEBPACK_IMPORTED_MODULE_0__.openBlock)(), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementBlock)("div", _hoisted_7, [(0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementVNode)("button", {
})], 8 /* PROPS */, _hoisted_4)), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementVNode)("p", _hoisted_5, [(0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementVNode)("span", _hoisted_6, "#" + (0,vue__WEBPACK_IMPORTED_MODULE_0__.toDisplayString)($props.index + 1), 1 /* TEXT */), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createTextVNode)(" " + (0,vue__WEBPACK_IMPORTED_MODULE_0__.toDisplayString)($props.group.title), 1 /* TEXT */)]), !$data.readonly && !$data.hideGroupButtons ? ((0,vue__WEBPACK_IMPORTED_MODULE_0__.openBlock)(), (0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementBlock)("div", _hoisted_7, [(0,vue__WEBPACK_IMPORTED_MODULE_0__.createElementVNode)("button", {
dusk: "drag-group",
type: "button",
"class": "group-control btn border-l border-gray-200 dark:border-gray-700 w-8 h-8 block nova-flexible-content-drag-button",
Expand Down
3 changes: 2 additions & 1 deletion resources/js/components/FormGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{{ group.title }}
</p>

<div class="flex" v-if="!readonly">
<div class="flex" v-if="!readonly && !hideGroupButtons">
<button
dusk="drag-group"
type="button"
Expand Down Expand Up @@ -113,6 +113,7 @@ export default {
removeMessage: false,
collapsed: this.group.collapsed,
readonly: this.group.readonly,
hideGroupButtons: this.field.hideGroupButtons,
};
},
Expand Down
54 changes: 33 additions & 21 deletions src/Flexible.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,17 @@ public function fullWidth()
return $this->withMeta(['fullWidth' => true]);
}

/**
* HideGroupButtons. Hide drag and delete buttons
*
* @param bool $value
* @return mixed
*/
public function hideGroupButtons(bool $value = true)
{
return $this->withMeta(['hideGroupButtons' => $value]);
}

/**
* Make the flexible content take up the full width
* of the form. Labels will sit above
Expand Down Expand Up @@ -160,8 +171,8 @@ public function resolver($resolver)
$resolver = new $resolver();
}

if (! ($resolver instanceof ResolverInterface)) {
throw new \Exception('Resolver Class "'.get_class($resolver).'" does not implement ResolverInterface.');
if (!($resolver instanceof ResolverInterface)) {
throw new \Exception('Resolver Class "' . get_class($resolver) . '" does not implement ResolverInterface.');
}

$this->resolver = $resolver;
Expand Down Expand Up @@ -191,8 +202,8 @@ public function addLayout(...$arguments)
$layout = new $layout();
}

if (! ($layout instanceof LayoutInterface)) {
throw new \Exception('Layout Class "'.get_class($layout).'" does not implement LayoutInterface.');
if (!($layout instanceof LayoutInterface)) {
throw new \Exception('Layout Class "' . get_class($layout) . '" does not implement LayoutInterface.');
}

$this->registerLayout($layout);
Expand Down Expand Up @@ -235,7 +246,7 @@ public function collapsed(bool $value = true)
*/
protected function registerLayout(LayoutInterface $layout)
{
if (! $this->layouts) {
if (!$this->layouts) {
$this->layouts = new LayoutsCollection();
$this->withMeta(['layouts' => $this->layouts]);
}
Expand Down Expand Up @@ -306,7 +317,7 @@ public function isShownOnDetail(NovaRequest $request, $resource): bool
*/
protected function fillAttribute(NovaRequest $request, $requestAttribute, $model, $attribute)
{
if (! $request->exists($requestAttribute)) {
if (!$request->exists($requestAttribute)) {
return;
}

Expand Down Expand Up @@ -338,7 +349,7 @@ protected function fillAttribute(NovaRequest $request, $requestAttribute, $model
*/
protected function syncAndFillGroups(NovaRequest $request, $requestAttribute): array
{
if (! ($raw = $this->extractValue($request, $requestAttribute))) {
if (!($raw = $this->extractValue($request, $requestAttribute))) {
$this->fireRemoveCallbacks(collect());
$this->groups = collect();

Expand All @@ -354,7 +365,7 @@ protected function syncAndFillGroups(NovaRequest $request, $requestAttribute): a

$group = $this->findGroup($key) ?? $this->newGroup($layout, $key);

if (! $group instanceof Layout) {
if (!$group instanceof Layout) {
return [];
}

Expand Down Expand Up @@ -382,7 +393,7 @@ protected function fireRemoveCallbacks(Collection $new_groups)
return $item->inUseKey();
});
$removed_groups = $this->groups->filter(function ($item) use ($new_group_keys) {
return ! $new_group_keys->contains($item->inUseKey());
return !$new_group_keys->contains($item->inUseKey());
})->each(function ($group) {
if (method_exists($group, 'fireRemoveCallback')) {
$group->fireRemoveCallback($this);
Expand All @@ -401,11 +412,11 @@ protected function extractValue(NovaRequest $request, $attribute)
{
$value = $request[$attribute];

if (! $value) {
if (!$value) {
return;
}

if (! is_array($value)) {
if (!is_array($value)) {
throw new \Exception('Unable to parse incoming Flexible content, data should be an array.');
}

Expand Down Expand Up @@ -449,7 +460,7 @@ protected function resolveGroupsForDisplay($groups)
*/
protected function buildGroups($resource, $attribute)
{
if (! $this->resolver) {
if (!$this->resolver) {
$this->resolver(Resolver::class);
}

Expand Down Expand Up @@ -480,7 +491,7 @@ protected function newGroup($layout, $key)
{
$layout = $this->layouts->find($layout);

if (! $layout instanceof Layout) {
if (!$layout instanceof Layout) {
return null;
}

Expand Down Expand Up @@ -535,13 +546,13 @@ public function getUpdateRules(NovaRequest $request)
*/
protected function getFlexibleRules(NovaRequest $request, $specificty)
{
if (! ($value = $this->extractValue($request, $this->attribute))) {
if (!($value = $this->extractValue($request, $this->attribute))) {
return [];
}

$rules = $this->generateRules($request, $value, $specificty);

if (! is_a($request, ScopedRequest::class)) {
if (!is_a($request, ScopedRequest::class)) {
// We're not in a nested flexible, meaning we're
// assuming the field is located at the root of
// the model's attributes. Therefore, we should now
Expand Down Expand Up @@ -570,16 +581,16 @@ protected function generateRules(NovaRequest $request, $value, $specificty)
return collect($value)->map(function ($item, $key) use ($request, $specificty) {
$group = $this->newGroup($item['layout'], $item['key']);

if (! $group) {
if (!$group) {
return [];
}

$scope = ScopedRequest::scopeFrom($request, $item['attributes'], $item['key']);

return $group->generateRules($scope, $specificty, $this->attribute.'.'.$key);
return $group->generateRules($scope, $specificty, $this->attribute . '.' . $key);
})
->collapse()
->all();
->collapse()
->all();
}

/**
Expand Down Expand Up @@ -609,7 +620,8 @@ protected static function registerValidationKeys(array $rules)
}, $rules);

static::$validatedKeys = array_merge(
static::$validatedKeys, $validatedKeys
static::$validatedKeys,
$validatedKeys
);
}

Expand Down Expand Up @@ -638,7 +650,7 @@ protected function registerOriginModel($model)
$model = $model->getOriginal();
}

if (! is_a($model, \Illuminate\Database\Eloquent\Model::class)) {
if (!is_a($model, \Illuminate\Database\Eloquent\Model::class)) {
return;
}

Expand Down

0 comments on commit 13e13e9

Please sign in to comment.