This repository was archived by the owner on Jan 3, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +75
-11
lines changed Expand file tree Collapse file tree 5 files changed +75
-11
lines changed Original file line number Diff line number Diff line change @@ -80,13 +80,36 @@ return [
80
80
'userModel' => App\User::class,
81
81
82
82
/*
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' ?
85
103
*/
86
104
'clearRootDescendants' => false,
87
105
88
106
/*
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
90
113
*/
91
114
'crud_prefix' => 'admin',
92
115
@@ -102,3 +125,6 @@ return [
102
125
103
126
### Crud Views
104
127
[ 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 )
Original file line number Diff line number Diff line change @@ -88,8 +88,11 @@ public function update($id, Request $request)
88
88
$ menu ->pages ()->detach ();
89
89
90
90
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
+ }
93
96
94
97
// save page hierarchy
95
98
if ($ item ->children ) {
Original file line number Diff line number Diff line change @@ -96,6 +96,11 @@ protected function saveListToDb($list)
96
96
*
97
97
* @return [type] [description]
98
98
*/
99
+ protected function clearNests ($ id )
100
+ {
101
+ return $ this ->findPage ($ id )->destroyDescendants ();
102
+ }
103
+
99
104
protected function clearSelfAndNests ($ id )
100
105
{
101
106
return $ this ->findPage ($ id )->clearSelfAndDescendants ();
Original file line number Diff line number Diff line change @@ -23,6 +23,14 @@ class Page extends Node
23
23
'lft ' , 'rgt ' , 'depth ' ,
24
24
];
25
25
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
+
26
34
public function menus ()
27
35
{
28
36
return $ this ->belongsToMany (Menu::class);
@@ -91,7 +99,11 @@ public function getNestsAttribute()
91
99
92
100
public function destroyDescendants ()
93
101
{
94
- $ this ->clearNests ();
102
+ if (config ('simpleMenu.deletePageAndNests ' )) {
103
+ parent ::destroyDescendants ();
104
+ } else {
105
+ $ this ->clearNests ();
106
+ }
95
107
}
96
108
97
109
public function clearSelfAndDescendants ()
Original file line number Diff line number Diff line change 39
39
'userModel ' => App \User::class,
40
40
41
41
/*
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
43
43
*
44
44
* root
45
45
* | 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"
47
47
* | child 3
48
48
*
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' ?
50
62
*/
51
63
'clearRootDescendants ' => false ,
52
64
53
65
/*
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.*'
56
74
*/
57
75
'crud_prefix ' => 'admin ' ,
58
76
You can’t perform that action at this time.
0 commit comments