Skip to content

Commit

Permalink
feat(filters): add filters behaviour (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasalexandre9 authored Feb 2, 2022
1 parent 920af78 commit bba17bc
Show file tree
Hide file tree
Showing 26 changed files with 3,177 additions and 91 deletions.
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<exclude-pattern>*/*.blade.php</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/tests/ExampleTest.php*</exclude-pattern>
<exclude-pattern>*/tests/Pest.php</exclude-pattern>
<exclude-pattern>*/tests/Unit/Traits/HasFiltersDateOperatorsTest.php</exclude-pattern>

<rule ref="PSR12"/>
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
Expand Down
1 change: 1 addition & 0 deletions src/Facades/ForestSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*
* @method static JsonObject getSchema()
* @method static array getFields(string $collection)
* @method static null|string getTypeByField(string $collection, string $field)
* @method static array getRelatedData(string $collection)
*
* @see ForestSchemaInstrospection
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function login()
public function callback()
{
$token = $this->auth->verifyCodeAndGenerateToken(route('forest.auth.callback'), request()->all());
$tokenData = JWT::decode($token, config('forest.api.auth-secret'), array('HS256'));
$tokenData = JWT::decode($token, config('forest.api.auth-secret'), ['HS256']);

return response()->json(compact('token', 'tokenData'));
}
Expand Down
1 change: 0 additions & 1 deletion src/Http/Controllers/ResourcesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Doctrine\DBAL\Exception;
use ForestAdmin\LaravelForestAdmin\Exceptions\ForestException;
use ForestAdmin\LaravelForestAdmin\Facades\ForestSchema;
use ForestAdmin\LaravelForestAdmin\Facades\JsonApi;
use ForestAdmin\LaravelForestAdmin\Repositories\ResourceGetter;
use ForestAdmin\LaravelForestAdmin\Repositories\ResourceCreator;
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/ForestCors.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ protected function getCorsOptions(): array
return [
'allowedHeaders' => ['*'],
'allowedMethods' => ['GET', 'POST', 'PUT', 'DELETE'],
'allowedOrigins' => ['*.forestadmin.com', 'localhost:(\d){4}'],
'allowedOrigins' => ['*.forestadmin.com'],
'allowedOriginsPatterns' => ['#^.*\.forestadmin\.com\z#u'],
'exposedHeaders' => false,
'maxAge' => 86400,
Expand Down
8 changes: 4 additions & 4 deletions src/Schema/Concerns/DataTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ trait DataTypes
* @var array
*/
protected array $dbTypes = [
Types::ARRAY => 'unknown',
Types::ARRAY => 'array',
Types::ASCII_STRING => 'String',
Types::BIGINT => 'Number',
Types::BINARY => 'unknown',
Types::BLOB => 'unknown',
Types::BOOLEAN => 'Boolean',
Types::DATE_MUTABLE => 'Date',
Types::DATE_IMMUTABLE => 'Date',
Types::DATE_MUTABLE => 'Dateonly',
Types::DATE_IMMUTABLE => 'Dateonly',
Types::DATEINTERVAL => 'unknown',
Types::DATETIME_MUTABLE => 'Date',
Types::DATETIME_IMMUTABLE => 'Date',
Expand All @@ -36,7 +36,7 @@ trait DataTypes
Types::INTEGER => 'Number',
Types::JSON => 'Json',
Types::OBJECT => 'unknown',
Types::SIMPLE_ARRAY => 'unknown',
Types::SIMPLE_ARRAY => 'array',
Types::SMALLINT => 'Number',
Types::STRING => 'String',
Types::TEXT => 'String',
Expand Down
18 changes: 2 additions & 16 deletions src/Schema/ForestModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ class ForestModel
*/
protected string $table;

/**
* @var array
*/
protected array $fields = [];

/**
* @param LaravelModel $laravelModel
*/
Expand Down Expand Up @@ -129,7 +124,8 @@ public function getFields(): array
{
$fields = $this->fetchFieldsFromTable();

foreach ($this->fields as $field) {
$schemaFields = method_exists($this->model, 'schemaFields') ? $this->model->schemaFields() : [];
foreach ($schemaFields as $field) {
$values = $fields->firstWhere('field', $field['field']) ?: $this->fieldDefaultValues($field['field']);
if (array_key_exists('enums', $field)) {
$values['type'] = 'Enum';
Expand All @@ -140,16 +136,6 @@ public function getFields(): array
return $fields->values()->toArray();
}

/**
* @param array $fields
* @return ForestModel
*/
public function setFields(array $fields): ForestModel
{
$this->fields = $fields;
return $this;
}

/**
* @return string
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Services/Concerns/ForestCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
*/
trait ForestCollection
{
/**
* @return array
* @codeCoverageIgnore
*/
public function schemaFields(): array
{
return [];
}

/**
* @return array
* @codeCoverageIgnore
Expand Down
Loading

0 comments on commit bba17bc

Please sign in to comment.