Skip to content

Commit 6701f61

Browse files
committed
Merge branch 'master' into feature/third-party-integrations
2 parents 70fb9a9 + 03ede3a commit 6701f61

38 files changed

Lines changed: 314 additions & 133 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ jobs:
2828
2929
- name: Install composer dependencies
3030
run: |
31-
composer install --no-scripts
32-
33-
# - name: Prepare Laravel Application
34-
# run: |
35-
# cp .env.ci .env
36-
# php artisan key:generate
31+
composer install --prefer-dist --no-interaction --no-scripts
3732
3833
- name: Run Testsuite
3934
run: vendor/bin/phpunit tests/

.github/workflows/code-style.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
on: push
2+
name: Code Style
3+
jobs:
4+
php-cs-fixer:
5+
runs-on: ubuntu-latest
6+
container:
7+
image: kirschbaumdevelopment/laravel-test-runner:7.3.0
8+
9+
steps:
10+
- uses: actions/checkout@v1
11+
with:
12+
fetch-depth: 1
13+
14+
- name: Install PHP CS Fixer
15+
run: |
16+
composer global require friendsofphp/php-cs-fixer
17+
18+
- name: Check Coding Standards
19+
run: php-cs-fixer fix --dry-run
20+

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ phpunit.xml
88
.phpunit.result.cache
99
.DS_Store
1010
Thumbs.db
11+
.php_cs.cache

.php_cs

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude('node_modules')
5+
->exclude('vendor')
6+
->in(__DIR__)
7+
->name('*.php')
8+
->notName('*.blade.php')
9+
->ignoreDotFiles(true)
10+
->ignoreVCS(true);
11+
12+
return PhpCsFixer\Config::create()
13+
->setFinder($finder)
14+
->setRules([
15+
'@PSR2' => true,
16+
'phpdoc_no_empty_return' => false,
17+
'phpdoc_var_annotation_correct_order' => true,
18+
'array_syntax' => [
19+
'syntax' => 'short',
20+
],
21+
'no_singleline_whitespace_before_semicolons' => true,
22+
'no_extra_blank_lines' => [
23+
'break', 'case', 'continue', 'curly_brace_block', 'default',
24+
'extra', 'parenthesis_brace_block', 'return',
25+
'square_brace_block', 'switch', 'throw', 'use', 'useTrait', 'use_trait',
26+
],
27+
'cast_spaces' => [
28+
'space' => 'single',
29+
],
30+
'concat_space' => [
31+
'spacing' => 'one',
32+
],
33+
'ordered_imports' => [
34+
'sort_algorithm' => 'length',
35+
],
36+
'single_quote' => true,
37+
'lowercase_cast' => true,
38+
'lowercase_static_reference' => true,
39+
'no_empty_phpdoc' => true,
40+
'no_empty_comment' => true,
41+
'array_indentation' => true,
42+
// TODO: This isn't working, causes fixer to error.
43+
// 'increment_style' => ['style' => 'post'],
44+
'short_scalar_cast' => true,
45+
'class_attributes_separation' => [
46+
'elements' => ['const', 'method', 'property'],
47+
],
48+
'no_mixed_echo_print' => [
49+
'use' => 'echo',
50+
],
51+
'no_unused_imports' => true,
52+
'binary_operator_spaces' => [
53+
'default' => 'single_space',
54+
],
55+
'no_empty_statement' => true,
56+
'unary_operator_spaces' => true, // $number ++ becomes $number++
57+
'hash_to_slash_comment' => true, // # becomes //
58+
'standardize_not_equals' => true, // <> becomes !=
59+
'native_function_casing' => true,
60+
'ternary_operator_spaces' => true,
61+
'ternary_to_null_coalescing' => true,
62+
'declare_equal_normalize' => [
63+
'space' => 'single',
64+
],
65+
'function_typehint_space' => true,
66+
'no_leading_import_slash' => true,
67+
'blank_line_before_statement' => [
68+
'statements' => [
69+
'break', 'case', 'continue',
70+
'declare', 'default', 'die',
71+
'do', 'exit', 'for', 'foreach',
72+
'goto', 'if', 'include',
73+
'include_once', 'require', 'require_once',
74+
'return', 'switch', 'throw', 'try', 'while', 'yield',
75+
],
76+
],
77+
'combine_consecutive_unsets' => true,
78+
'method_chaining_indentation' => true,
79+
'no_whitespace_in_blank_line' => true,
80+
'blank_line_after_opening_tag' => true,
81+
'no_trailing_comma_in_list_call' => true,
82+
'list_syntax' => ['syntax' => 'short'],
83+
// public function getTimezoneAttribute( ? Banana $value) becomes public function getTimezoneAttribute(?Banana $value)
84+
'compact_nullable_typehint' => true,
85+
'explicit_string_variable' => true,
86+
'no_leading_namespace_whitespace' => true,
87+
'trailing_comma_in_multiline_array' => true,
88+
'not_operator_with_successor_space' => true,
89+
'object_operator_without_whitespace' => true,
90+
'single_blank_line_before_namespace' => true,
91+
'no_blank_lines_after_class_opening' => true,
92+
'no_blank_lines_after_phpdoc' => true,
93+
'no_whitespace_before_comma_in_array' => true,
94+
'no_trailing_comma_in_singleline_array' => true,
95+
'multiline_whitespace_before_semicolons' => [
96+
'strategy' => 'no_multi_line',
97+
],
98+
'no_multiline_whitespace_around_double_arrow' => true,
99+
'no_useless_return' => true,
100+
'phpdoc_add_missing_param_annotation' => true,
101+
'phpdoc_order' => true,
102+
'phpdoc_scalar' => true,
103+
'phpdoc_separation' => true,
104+
'phpdoc_single_line_var_spacing' => true,
105+
'single_trait_insert_per_statement' => true,
106+
'ordered_class_elements' => [
107+
'order' => [
108+
'use_trait',
109+
'constant',
110+
'property',
111+
'construct',
112+
'public',
113+
'protected',
114+
'private',
115+
],
116+
'sortAlgorithm' => 'none',
117+
],
118+
'return_type_declaration' => [
119+
'space_before' => 'none',
120+
],
121+
])
122+
->setLineEnding("\n");

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@
22
This document is meant for tracking notable changes to `nova-chartjs`
33

44
## 0.1.0
5-
1. Initial Release
5+
- Initial Release
6+
7+
## 0.2.0
8+
- Fixed title underscore issue
9+
- Using proper title based on plurality
10+
- Github actions for PHPUnit and PHPCS Fixer
11+
- Visibility and can methods working
12+
- Added `requireChild()` method to force the creation of a child relationship
13+
- Ensure parent model updates properly in `BelongsTo` relationship. Thanks to [@mahentoo](https://github.com/mahentoo) [#29](https://github.com/kirschbaum-development/nova-inline-select/pull/29).
14+
- Inline relationships within `Panel` now works. Thanks to [@timvanuum](https://github.com/timvanuum) [#24](https://github.com/kirschbaum-development/nova-inline-select/pull/24).
15+
- Check if value is instance of model or collection with proper model key. Thanks to [@gabrielkoerich](https://github.com/gabrielkoerich) [#18](https://github.com/kirschbaum-development/nova-inline-select/pull/18).

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Nova Inline Relationship
44

5+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/kirschbaum-development/nova-inline-relationship.svg)](https://packagist.org/packages/kirschbaum-development/nova-inline-relationship)
6+
[![Total Downloads](https://img.shields.io/packagist/dt/kirschbaum-development/nova-inline-relationship.svg)](https://packagist.org/packages/kirschbaum-development/nova-inline-relationship)
57
[![Actions Status](https://github.com/kirschbaum-development/nova-inline-relationship/workflows/CI/badge.svg)](https://github.com/kirschbaum-development/nova-inline-relationship/actions)
68

79
Nova Inline Relationship allows you to manage (add/edit/update/delete/reorder) an object's relationships directly from the parent object's create/edit screens. By presenting relationships as inline properties you can provide content editors with a streamlined and efficient workflow for managing complex data.

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
}
1717
],
1818
"require-dev": {
19-
"orchestra/testbench": "^3.8",
20-
"phpunit/phpunit": "^7.5",
19+
"codedungeon/phpunit-result-printer": "^0.26.2",
20+
"orchestra/testing": "^4.0",
21+
"phpunit/phpunit": "^8.3",
2122
"mockery/mockery": "^1.1",
22-
"laravel/nova": "^2.5"
23+
"laravel/nova": "*"
2324
},
2425
"autoload": {
2526
"psr-4": {
@@ -28,7 +29,7 @@
2829
},
2930
"autoload-dev": {
3031
"psr-4": {
31-
"KirschbaumDevelopment\\NovaInlineRelationship\\Tests\\": "tests/"
32+
"Tests\\": "tests/"
3233
}
3334
},
3435
"extra": {

phpunit.xml.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false"
12+
printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer">
13+
<testsuites>
14+
<testsuite name="Nova Inline Relationship Test Suite">
15+
<directory>tests</directory>
16+
</testsuite>
17+
</testsuites>
18+
<filter>
19+
<whitelist>
20+
<directory suffix=".php">src/</directory>
21+
</whitelist>
22+
</filter>
23+
</phpunit>

src/Contracts/RelationshipObservable.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface RelationshipObservable
1212
* @param Model $model
1313
* @param $attribute
1414
* @param $value
15+
*
1516
* @return mixed
1617
*/
1718
public function updating(Model $model, $attribute, $value);
@@ -22,6 +23,7 @@ public function updating(Model $model, $attribute, $value);
2223
* @param Model $model
2324
* @param $attribute
2425
* @param $value
26+
*
2527
* @return mixed
2628
*/
2729
public function creating(Model $model, $attribute, $value);
@@ -32,6 +34,7 @@ public function creating(Model $model, $attribute, $value);
3234
* @param Model $model
3335
* @param $attribute
3436
* @param $value
37+
*
3538
* @return mixed
3639
*/
3740
public function created(Model $model, $attribute, $value);

src/NovaInlineRelationship.php

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function resourceClass(string $class): self
6767
*
6868
* @param mixed $resource
6969
* @param string|null $attribute
70+
*
7071
* @return void
7172
*/
7273
public function resolveForDisplay($resource, $attribute = null)
@@ -103,49 +104,6 @@ public function resolve($resource, $attribute = null)
103104
}
104105
}
105106

106-
/**
107-
* Resolve the fields for the resource.
108-
*
109-
* @param $resource
110-
* @param $attribute
111-
* @param $properties
112-
*/
113-
protected function resolveResourceFields($resource, $attribute, $properties)
114-
{
115-
$this->rules = [$this->getRelationshipRule($attribute, $properties)];
116-
117-
$this->withMeta([
118-
'defaults' => $this->getDefaultsFromProperties($properties)->all(),
119-
'settings' => $properties->all(),
120-
'models' => $this->modelIds(),
121-
'modelKey' => Str::plural(Str::kebab(class_basename(optional($this->value)->first() ?? $resource->{$attribute}()->getRelated()->newInstance()))),
122-
'singularLabel' => Str::title(Str::singular($this->name)),
123-
'pluralLabel' => Str::title(Str::plural($this->name)),
124-
'singular' => $this->isSingularRelationship($resource, $attribute),
125-
'deletable' => $this->isRelationshipDeletable($resource, $attribute),
126-
'addChildAtStart' => $this->requireChild,
127-
]);
128-
129-
$this->updateFieldValue($resource, $attribute, $properties);
130-
}
131-
132-
/**
133-
* Pluck id's from the model or collection.
134-
*
135-
* @return array
136-
*/
137-
protected function modelIds()
138-
{
139-
if ($this->value instanceof Model) {
140-
$models = [$this->value->{$this->value->getKeyName()}];
141-
} elseif ($this->value instanceof Collection && $this->value->isNotEmpty()) {
142-
$key = $this->value->first()->getKeyName();
143-
$models = $this->value->pluck($key)->all();
144-
}
145-
146-
return $models ?? [];
147-
}
148-
149107
/**
150108
* Fetch default values from collection
151109
*
@@ -206,7 +164,7 @@ public function getPropertiesWithMetaForForms($resource, $attribute): Collection
206164
->keyBy('attribute')
207165
->map(function ($value, $key) {
208166
return $this->setMetaFromClass($value, $key);
209-
});;
167+
});
210168
}
211169

212170
/**
@@ -276,6 +234,49 @@ public function getValueFromField(Field $field, NovaInlineRelationshipRequest $r
276234
return $temp->{$attribute} ?? null;
277235
}
278236

237+
/**
238+
* Resolve the fields for the resource.
239+
*
240+
* @param $resource
241+
* @param $attribute
242+
* @param $properties
243+
*/
244+
protected function resolveResourceFields($resource, $attribute, $properties)
245+
{
246+
$this->rules = [$this->getRelationshipRule($attribute, $properties)];
247+
248+
$this->withMeta([
249+
'defaults' => $this->getDefaultsFromProperties($properties)->all(),
250+
'settings' => $properties->all(),
251+
'models' => $this->modelIds(),
252+
'modelKey' => Str::plural(Str::kebab(class_basename(optional($this->value)->first() ?? $resource->{$attribute}()->getRelated()->newInstance()))),
253+
'singularLabel' => Str::title(Str::singular($this->name)),
254+
'pluralLabel' => Str::title(Str::plural($this->name)),
255+
'singular' => $this->isSingularRelationship($resource, $attribute),
256+
'deletable' => $this->isRelationshipDeletable($resource, $attribute),
257+
'addChildAtStart' => $this->requireChild,
258+
]);
259+
260+
$this->updateFieldValue($resource, $attribute, $properties);
261+
}
262+
263+
/**
264+
* Pluck id's from the model or collection.
265+
*
266+
* @return array
267+
*/
268+
protected function modelIds()
269+
{
270+
if ($this->value instanceof Model) {
271+
$models = [$this->value->{$this->value->getKeyName()}];
272+
} elseif ($this->value instanceof Collection && $this->value->isNotEmpty()) {
273+
$key = $this->value->first()->getKeyName();
274+
$models = $this->value->pluck($key)->all();
275+
}
276+
277+
return $models ?? [];
278+
}
279+
279280
/**
280281
* Set Meta Values using Field
281282
*
@@ -439,7 +440,7 @@ protected function getPropertiesFromFields(Collection $fields): Collection
439440
'label' => $value->name,
440441
'options' => $value->meta,
441442
'rules' => $value->rules,
442-
'attribute' => $value->attribute
443+
'attribute' => $value->attribute,
443444
];
444445
});
445446
}
@@ -462,7 +463,6 @@ protected function updateFieldValue($resource, $attribute, Collection $propertie
462463
return $properties->has($key) ? $this->setMetaFromClass($properties->get($key), $key, $value) : null;
463464
})->filter();
464465
});
465-
466466
}
467467

468468
/**

0 commit comments

Comments
 (0)