Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 31e85ce

Browse files
committed
add more options to config
better desc Update README.md
1 parent 83a8e72 commit 31e85ce

File tree

5 files changed

+75
-11
lines changed

5 files changed

+75
-11
lines changed

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,36 @@ return [
8080
'userModel' => App\User::class,
8181

8282
/*
83-
* by default when removing a nested page, all of its 'Descendants' gets cleared.
84-
* but what about when removing the root, do you also want the same behavior ?
83+
* when adding a page which is a nest of a nother to a menu
84+
*
85+
* root
86+
* | child 1
87+
* | child 2 "add this along with its childrens to another menu"
88+
* | child 3
89+
*
90+
* do you want to clear its parent and make it a root ?
91+
*/
92+
'clearPartialyNestedParent'=> false,
93+
94+
/*
95+
* when removing a root page from a menu, ex.
96+
*
97+
* root "remove"
98+
* | child 1
99+
* | child 2
100+
* | child 3
101+
*
102+
* do you want clear all of its 'Descendants' ?
85103
*/
86104
'clearRootDescendants' => false,
87105

88106
/*
89-
* crud views url prefix
107+
* when deleteing a page "from the db", do you also want to delete all of its childrens ?
108+
*/
109+
'deletePageAndNests' => false,
110+
111+
/*
112+
* package routes url & name prefix
90113
*/
91114
'crud_prefix' => 'admin',
92115

@@ -102,3 +125,6 @@ return [
102125

103126
### Crud Views
104127
[Wiki](https://github.com/ctf0/SimpleMenu/wiki/Crud-Views)
128+
129+
## Todo
130+
- find a way to add new nesting levels in [vuedraggable](https://github.com/SortableJS/Vue.Draggable)

src/Controllers/Admin/MenusController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ public function update($id, Request $request)
8888
$menu->pages()->detach();
8989

9090
foreach (json_decode($request->saveList) as $item) {
91-
// make sure page is not included under any other pages
92-
$this->clearSelfAndNests($item->id);
91+
if (config('simpleMenu.clearPartialyNestedParent')) {
92+
$this->clearSelfAndNests($item->id);
93+
} else {
94+
$this->clearNests($item->id);
95+
}
9396

9497
// save page hierarchy
9598
if ($item->children) {

src/Controllers/Admin/Traits/MenuOps.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ protected function saveListToDb($list)
9696
*
9797
* @return [type] [description]
9898
*/
99+
protected function clearNests($id)
100+
{
101+
return $this->findPage($id)->destroyDescendants();
102+
}
103+
99104
protected function clearSelfAndNests($id)
100105
{
101106
return $this->findPage($id)->clearSelfAndDescendants();

src/Models/Page.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ class Page extends Node
2323
'lft', 'rgt', 'depth',
2424
];
2525

26+
// protected static function boot()
27+
// {
28+
// parent::boot();
29+
// static::addGlobalScope('url', function (Illuminate\Database\Eloquent\Builder $builder) {
30+
// $builder->where('url->' . LaravelLocalization::getCurrentLocale(), '!=', '');
31+
// });
32+
// }
33+
2634
public function menus()
2735
{
2836
return $this->belongsToMany(Menu::class);
@@ -91,7 +99,11 @@ public function getNestsAttribute()
9199

92100
public function destroyDescendants()
93101
{
94-
$this->clearNests();
102+
if (config('simpleMenu.deletePageAndNests')) {
103+
parent::destroyDescendants();
104+
} else {
105+
$this->clearNests();
106+
}
95107
}
96108

97109
public function clearSelfAndDescendants()

src/config/simpleMenu.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,38 @@
3939
'userModel' => App\User::class,
4040

4141
/*
42-
* by default when removing a nested page, all of its 'Descendants' gets cleared ex.
42+
* when adding a page which is a nest of a nother to a menu
4343
*
4444
* root
4545
* | child 1
46-
* | child 2 "delete" (now "child 2" & "child 3" wont be a descendants of any page)
46+
* | child 2 "add this along with its childrens to another menu"
4747
* | child 3
4848
*
49-
* but what about when removing the root, do you also want the same behavior ?
49+
* do you want to clear its parent and make it a root ?
50+
*/
51+
'clearPartialyNestedParent'=> false,
52+
53+
/*
54+
* when removing a root page from a menu, ex.
55+
*
56+
* root "remove"
57+
* | child 1
58+
* | child 2
59+
* | child 3
60+
*
61+
* do you want clear all of its 'Descendants' ?
5062
*/
5163
'clearRootDescendants' => false,
5264

5365
/*
54-
* crud views url prefix ex.'admin/pages'
55-
* this is also the same name for the route name ex.'admin.pages.*'
66+
* when deleteing a page "from the db", do you also want to delete all of its childrens ?
67+
*/
68+
'deletePageAndNests' => false,
69+
70+
/*
71+
* package routes url & name prefix ex.
72+
* url = 'admin/pages'
73+
* name = 'admin.pages.*'
5674
*/
5775
'crud_prefix' => 'admin',
5876

0 commit comments

Comments
 (0)