Browse Source

Tree view as an @include

Vijayakrishnan 3 years ago
parent
commit
965ef080d5

+ 2 - 25
resources/views/app/stat-tree/stat-trees/sub/dashboard2.blade.php

@@ -1,34 +1,11 @@
 @extends('app.stat-tree.stat-trees.single')
 @section('page')
-<?php
-function renderStatTreeLineNode($line) {
-    echo '<div class="stat-tree-node">' .
-        $line->displayLabel() .
-        '&nbsp;&nbsp;<span class="text-secondary">(' . (is_null($line->last_refresh_count) ? '-' : $line->last_refresh_count) . ')</span>' .
-        '</div>';
-    if(count($line->children)) {
-        echo '<div class="pl-4">';
-        foreach($line->children as $child) {
-            renderStatTreeLineNode($child);
-        }
-        echo '</div>';
-    }
-}
-?>
+
 <div id="statTreeViewPage">
     <div id="statTreeView" class="row">
         @if(count($statTree->lines))
             <div class="col-12">
-                <div class="d-flex align-items-center justify-content-between mb-2">
-                    <h6 class="font-weight-bold">Tree</h6>
-                </div>
-                <div class="stat-tree-view border mb-3">
-                    @foreach($statTree->lines as $line)
-                        @if(!$line->parent_stat_tree_line_id)
-                            <?php renderStatTreeLineNode($line); ?>
-                        @endif
-                    @endforeach
-                </div>
+                @include('app.stat-tree.tree', ['slug' => 'rm-tree'])
             </div>
             <div class="col-12">
                 <div class="d-flex align-items-center justify-content-between mb-2">

+ 31 - 0
resources/views/app/stat-tree/tree.blade.php

@@ -0,0 +1,31 @@
+<?php
+if (!function_exists('renderStatTreeLineNode')) {
+    function renderStatTreeLineNode($line)
+    {
+        echo '<div class="stat-tree-node">' .
+            $line->displayLabel() .
+            '&nbsp;&nbsp;<span class="text-secondary">(' . (is_null($line->last_refresh_count) ? '-' : $line->last_refresh_count) . ')</span>' .
+            '</div>';
+        if (count($line->children)) {
+            echo '<div class="pl-4">';
+            foreach ($line->children as $child) {
+                renderStatTreeLineNode($child);
+            }
+            echo '</div>';
+        }
+    }
+}
+$statTree = \App\Models\StatTree::where('slug', $slug)->first();
+?>
+@if(@$statTree)
+    <div class="d-flex align-items-center justify-content-between mb-2">
+        <h6 class="font-weight-bold m-0">{{$statTree->name}}</h6>
+    </div>
+    <div class="stat-tree-view border mb-3">
+        @foreach($statTree->lines as $line)
+            @if(!$line->parent_stat_tree_line_id)
+                <?php renderStatTreeLineNode($line); ?>
+            @endif
+        @endforeach
+    </div>
+@endif