Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 1 addition & 25 deletions dist/css/field.css

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

17,535 changes: 2 additions & 17,533 deletions dist/js/field.js

Large diffs are not rendered by default.

17 changes: 8 additions & 9 deletions dist/js/field.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/*!
* Determine if an object is a Buffer
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @author Feross Aboukhadijeh <http://feross.org>
* @license MIT
*/

/**
* @license
* Lodash <https://lodash.com/>
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
/*!
* vuex v3.6.2
* (c) 2021 Evan You
* @license MIT
*/

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
"production": "mix --production"
},
"devDependencies": {
"laravel-nova": "^1.0",
"@inertiajs/inertia": "^0.11.0",
"@vue/babel-plugin-jsx": "^1.1.1",
"@vue/compiler-sfc": "^3.2.22",
"@vueform/multiselect": "^2.3.3",
"laravel-mix": "^6.0.41",
"laravel-nova": "^1.0",
"postcss": "^8.2",
"resolve-url-loader": "^3.1.2",
"sass": "^1.32.8",
"sass-loader": "10.*",
"vue-loader": "^16.8.3",
"@vue/babel-plugin-jsx": "^1.1.1",
"@vueform/multiselect": "^2.3.3"
"vuex": "^3.6.2"
}
}
1 change: 1 addition & 0 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@move-up="moveUp(group.key)"
@move-down="moveDown(group.key)"
@remove="remove(group.key)"
@file-deleted="$emit('file-deleted')"
/>
</div>

Expand Down
1 change: 1 addition & 0 deletions resources/js/components/FormGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
:errors="errors"
:show-help-text="item.helpText != null"
:class="{ 'remove-bottom-border': index == group.fields.length - 1 }"
@file-deleted="$emit('file-deleted')"
/>
</div>
</div>
Expand Down
115 changes: 115 additions & 0 deletions src/Collections/FieldCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

namespace Whitecube\NovaFlexibleContent\Collections;

use Laravel\Nova\Fields\Field;
use Laravel\Nova\Fields\FieldCollection as NovaFieldCollection;
use Laravel\Nova\Http\Requests\NovaRequest;
use Whitecube\NovaFlexibleContent\Flexible;

class FieldCollection extends NovaFieldCollection
{
/**
* Find a given field by its attribute.
*
* @param string $attribute
* @param mixed $default
*
* @return null|\Laravel\Nova\Fields\Field
*/
public function findFieldByAttribute($attribute, $default = null)
{
if (false !== strpos($attribute, '__')) {
$request = resolve(NovaRequest::class);
$resource = $request->findResourceOrFail();
$fields = $resource->updateFields($request);

$attribute_parts = explode('__', $attribute, 2);

$groups = [];
foreach ($fields as $i => $field) {
if ($field instanceof Flexible) {
$field->index = $i;
$groups = array_merge($groups, $this->flattenGroups($field));
}
}

foreach ($groups as $group) {
if ($group->inUseKey() !== $attribute_parts[0]) {
continue;
}

$field = $group->collectionFields()->first(function ($field) use ($attribute_parts, $group) {
$field->group = $group;

return isset($field->attribute)
&& $field->attribute == $attribute_parts[1];
}, $default);

return $this->addDeleteCallback($field);
}
}

return $this->first(function ($field) use ($attribute) {
return isset($field->attribute)
&& $field->attribute == $attribute;
}, $default);
}

/**
* Flatten all groups into a single array.
*
* @param $parentGroup
*
* @return array
*/
private function flattenGroups(Field $field, $parentGroup = null)
{
if (!$field->groups()) {
return [];
}

$flattened = [];

foreach ($field->groups() as $groupIndex => $group) {
$group->originalField = ($parentGroup ? $parentGroup->originalField.(isset($field->index) ? '.'.$field->index : '').'.attributes.' : '').$field->attribute.'.'.$groupIndex;

foreach ($group->collectionFields() as $groupField) {
if ($groupField instanceof Flexible) {
$flattened = array_merge($flattened, $this->flattenGroups($groupField, $group));
}
}

$flattened[] = $group;
}

return $flattened;
}

/**
* Add the delete callback helper.
*
* @return null|Field
*/
private function addDeleteCallback(?Field $field)
{
if (!$field || !isset($field->deleteCallback)) {
return $field;
}

$callback = false;
if (is_callable($field->deleteCallback)) {
$callback = $field->deleteCallback;
}

$field->delete(function (NovaRequest $request, $model) use ($callback, $field) {
if ($callback && true === $callback->call($field, ...func_get_args())) {
return true;
}

return Flexible::deleteFile($request, $model, $field);
});

return $field;
}
}
32 changes: 15 additions & 17 deletions src/Commands/CreateCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ class CreateCast extends Command
protected $description = 'Generate a new Flexible Content cast class';

/**
* The layout's classname
* The layout's classname.
*
* @var string
*/
protected $classname;

/**
* Create a new command instance.
*
* @return void
*/
public function __construct(Filesystem $files)
{
Expand All @@ -48,8 +46,6 @@ public function __construct(Filesystem $files)

/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
Expand All @@ -59,66 +55,68 @@ public function handle()

$this->files->put($path, $this->buildClass());

$this->info('Created ' . $path);
$this->info('Created '.$path);
}

/**
* Get the classname
* Get the classname.
*
* @return string
*/
public function getClassnameArgument()
{
if(!$this->argument('classname')) {
if (!$this->argument('classname')) {
return $this->ask('Please provide a class name for your layout');
}

return $this->argument('classname');
}

/**
* Build the layout's file path
* Build the layout's file path.
*
* @return string
*/
protected function getPath()
{
return $this->makeDirectory(
app_path('Casts/' . $this->classname . '.php')
app_path('Casts/'.$this->classname.'.php')
);
}

/**
* Create the directories if they do not exist yet
* Create the directories if they do not exist yet.
*
* @param string $path
*
* @return string
*/
protected function makeDirectory($path)
{
$directory = dirname($path);

if(!$this->files->isDirectory($directory)) {
if (!$this->files->isDirectory($directory)) {
$this->files->makeDirectory($directory, 0755, true, true);
}

return $path;
}

/**
* Generate the file's content
* Generate the file's content.
*
* @return string
*/
protected function buildClass()
{
return str_replace([
return str_replace(
[
':classname',
], [
],
[
$this->classname,
],
$this->files->get(__DIR__ . '/../Stubs/Cast.php')
$this->files->get(__DIR__.'/../Stubs/Cast.php')
);
}

}
Loading