Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony BOTALLA committed Jul 25, 2019
0 parents commit d10a592
Show file tree
Hide file tree
Showing 22 changed files with 1,007 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{js,json,yml,scss,stylelintrc}]
indent_size = 2
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.idea
/vendor
/node_modules
package-lock.json
composer.phar
composer.lock
phpunit.xml
.phpunit.result.cache
.DS_Store
Thumbs.db
.php_cs.cache
87 changes: 87 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

// Inspired from Laravel php_cs, converted to php-cs-fixer 2, and simplified.
// - https://github.com/laravel/framework/blob/5.4/.php_cs
// - http://cs.sensiolabs.org/
// - https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/UPGRADE.md
// Removed: phpdoc_no_package, phpdoc_summary

$excludes = [
'dist',
'node_modules',
'resources',
'vendor',
];

$rules = [
'@PSR2' => true,
'blank_line_after_opening_tag' => true,
'concat_space' => ['spacing' => 'none'],
'no_multiline_whitespace_around_double_arrow' => true,
'no_empty_statement' => true,
'simplified_null_return' => false,
'encoding' => true,
'single_blank_line_at_eof' => true,
'no_extra_consecutive_blank_lines' => true,
'no_spaces_after_function_name' => true,
'function_declaration' => true,
'include' => true,
'indentation_type' => true,
'no_alias_functions' => true,
'blank_line_after_namespace' => true,
'line_ending' => true,
'no_trailing_comma_in_list_call' => true,
'not_operator_with_successor_space' => false,
'lowercase_constants' => true,
'lowercase_keywords' => true,
'method_argument_space' => true,
'trailing_comma_in_multiline_array' => true,
'no_multiline_whitespace_before_semicolons' => true,
'single_import_per_statement' => true,
'no_leading_namespace_whitespace' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'object_operator_without_whitespace' => true,
'no_spaces_inside_parenthesis' => true,
'phpdoc_indent' => true,
'phpdoc_inline_tag' => true,
'phpdoc_no_access' => true,
'phpdoc_scalar' => true,
'phpdoc_to_comment' => false,
'phpdoc_trim' => true,
'phpdoc_no_alias_tag' => true,
'phpdoc_var_without_name' => true,
'no_leading_import_slash' => true,
'braces' => false,
'blank_line_before_return' => true,
'self_accessor' => true,
'array_syntax' => ['syntax' => 'short'],
'no_short_echo_tag' => true,
'full_opening_tag' => true,
'no_trailing_comma_in_singleline_array' => true,
'single_blank_line_before_namespace' => true,
'single_line_after_imports' => true,
'single_quote' => true,
'no_singleline_whitespace_before_semicolons' => true,
'cast_spaces' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
'no_trailing_whitespace' => true,
'trim_array_spaces' => true,
'binary_operator_spaces' => ['align_equals' => false],
'unary_operator_spaces' => true,
'no_unused_imports' => true,
'visibility_required' => true,
'no_whitespace_in_blank_line' => true,
];

$finder = PhpCsFixer\Finder::create()
->name('*.php')
->exclude($excludes)
->ignoreDotFiles(true)
->in(__DIR__);

return PhpCsFixer\Config::create()
->setRules($rules)
->setFinder($finder)
->setUsingCache(true);
123 changes: 123 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Nova Order Field nestedset

A field that make your resources orderable using [the laravel nestedset package](https://github.com/lazychaser/laravel-nestedset).

## Requirements

* PHP >= 7.1
* Laravel Nova >= 2.0
* Laravel Framework 5.8+

## Installation

```sh
composer require novius/laravel-nova-order-nestedset-field
```

## Usage

**Step 1**

Use Kalnoy\Nestedset `NodeTrait` and Novius\LaravelNovaOrderNestedsetField `Orderable` trait on your model.

Example :

```php
use Kalnoy\Nestedset\NodeTrait;
use Novius\LaravelNovaOrderNestedsetField\Traits\Orderable;

class Foo extends Model {
use NodeTrait;
use Orderable;

public function getLftName()
{
return 'left';
}

public function getRgtName()
{
return 'right';
}

public function getParentIdName()
{
return 'parent';
}
}

```

**Step 2**

Add the field to your resource and specify order for your resources.


```php
use Novius\LaravelNovaOrderNestedsetField\OrderNestedsetField;

class FooResource extends Resource
{
public function fields(Request $request)
{
return [
OrderNestedsetField::make('Order'),
];
}

/**
* @param \Illuminate\Database\Eloquent\Builder $query
* @param array $orderings
* @return \Illuminate\Database\Eloquent\Builder
*/
protected static function applyOrderings($query, array $orderings)
{
return $query->orderBy('left', 'asc');
}
}

```

**Scoping**

Imagine you have `Menu` model and `MenuItems`. There is a one-to-many relationship
set up between these models. `MenuItem` has `menu_id` attribute for joining models
together. `MenuItem` incorporates nested sets. It is obvious that you would want to
process each tree separately based on `menu_id` attribute. In order to do so, you
need to specify this attribute as scope attribute:

```php
protected function getScopeAttributes()
{
return ['menu_id'];
}
```

[Retrieve more information about usage on official doc](https://github.com/lazychaser/laravel-nestedset#scoping).


## Override default languages files

Run:

```sh
php artisan vendor:publish --provider="Novius\LaravelNovaOrderNestedsetField\OrderNestedsetFieldServiceProvider" --tag="lang"
```

## Lint

Run php-cs with:

```sh
composer run-script lint
```

## Contributing

Contributions are welcome!
Leave an issue on Github, or create a Pull Request.


## Licence

This package is under [GNU Affero General Public License v3](http://www.gnu.org/licenses/agpl-3.0.html) or (at your option) any later version.
46 changes: 46 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "novius/laravel-nova-order-nestedset-field",
"description": "A Laravel Nova field that make your resources orderable",
"keywords": [
"laravel",
"nova",
"nestedset",
"trees",
"hierarchies"
],
"license": "AGPL-3.0-or-later",
"authors": [
{
"name": "Novius Agency",
"email": "[email protected]",
"homepage": "https://www.novius.com"
}
],
"require": {
"php": ">=7.1.0",
"kalnoy/nestedset": "^4.3.5"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.15.0"
},
"autoload": {
"psr-4": {
"Novius\\LaravelNovaOrderNestedsetField\\": "src/"
}
},
"scripts": {
"lint": [
"php-cs-fixer fix --dry-run --config .php_cs -vv --diff --allow-risky=yes"
]
},
"extra": {
"laravel": {
"providers": [
"Novius\\LaravelNovaOrderNestedsetField\\OrderNestedsetFieldServiceProvider"
]
}
},
"config": {
"sort-packages": true
}
}
Empty file added dist/css/field.css
Empty file.
Loading

0 comments on commit d10a592

Please sign in to comment.