Browse Source

Stat tree edit (wip)

Vijayakrishnan 3 years ago
parent
commit
ab81608d1a

+ 5 - 0
app/Http/Controllers/StatTreeController.php

@@ -104,6 +104,11 @@ class StatTreeController extends Controller
         return $this->pass($instance->uid);
         return $this->pass($instance->uid);
     }
     }
 
 
+    public function clone(Request $request, StatTree $statTree) {
+        $instance = $statTree->clone($request->input('name'));
+        return $this->pass($instance->uid);
+    }
+
     private function traverseLines($_lines, &$result) {
     private function traverseLines($_lines, &$result) {
         foreach ($_lines as $line) {
         foreach ($_lines as $line) {
             $result[] = $line;
             $result[] = $line;

+ 24 - 0
app/Models/StatTree.php

@@ -53,4 +53,28 @@ class StatTree extends Model
         return $instance;
         return $instance;
 
 
     }
     }
+
+    public function clone($name) {
+
+        // create stat tree
+        $instance = new StatTree();
+        $nextId = DB::select("select nextval('stat_tree_id_seq')");
+        $instance->id = $nextId[0]->nextval;
+        $instance->uid = Uuid::uuid4();
+        $instance->name = $name;
+        $instance->model = $this->model;
+        $instance->slug = $this->slug . '-' . rand(100, 999);
+        $instance->is_template = $this->is_template;
+        $instance->pro_id = $this->pro_id;
+        $instance->pro_scope_clause = $this->pro_scope_clause;
+        $instance->save();
+
+        // create tree lines
+        foreach ($this->rootLines as $line) {
+            $line->copy(null, $instance);
+        }
+
+        return $instance;
+
+    }
 }
 }

+ 16 - 1
resources/views/app/stat-tree/stat-trees/list.blade.php

@@ -109,7 +109,22 @@
                                                         </div>
                                                         </div>
                                                     </form>
                                                     </form>
                                                 </div>
                                                 </div>
-
+                                                <span class="mx-2 text-secondary text-sm">|</span>
+                                                <div moe relative>
+                                                    <a href="#" start show class="text-nowrap">Clone</a>
+                                                    <form url="{{ route('practice-management.statTrees.clone', $statTree) }}" right redir="/practice-management/stat-trees/view/[data]/edit">
+                                                        @csrf
+                                                        <p class="mb-2 font-weight-bold">Clone</p>
+                                                        <div class="mb-2">
+                                                            <label class="text-sm mb-1">Name</label>
+                                                            <input type="text" name="name" class="form-control form-control-sm" value="{{$statTree->name}} (clone)" required>
+                                                        </div>
+                                                        <div class="d-flex align-items-center">
+                                                            <button class="btn btn-sm btn-primary mr-2" type="button" submit>Save</button>
+                                                            <button class="btn btn-sm btn-default mr-2 border" type="button" cancel>Cancel</button>
+                                                        </div>
+                                                    </form>
+                                                </div>
                                             @endif
                                             @endif
                                         </div>
                                         </div>
                                     </td>
                                     </td>

+ 1 - 0
routes/web.php

@@ -325,6 +325,7 @@ Route::middleware('pro.auth')->group(function () {
                 Route::get('old', 'StatTreeController@dashboard')->name('dashboard2');
                 Route::get('old', 'StatTreeController@dashboard')->name('dashboard2');
             });
             });
             Route::post('instantiate/{statTree}', 'StatTreeController@instantiate')->name('instantiate');
             Route::post('instantiate/{statTree}', 'StatTreeController@instantiate')->name('instantiate');
+            Route::post('clone/{statTree}', 'StatTreeController@clone')->name('clone');
         });
         });
         Route::name('statTreeLines.')->prefix('stat-tree-lines/')->group(function () {
         Route::name('statTreeLines.')->prefix('stat-tree-lines/')->group(function () {
             Route::get('', 'StatTreeLineController@list')->name('list');
             Route::get('', 'StatTreeLineController@list')->name('list');