Pārlūkot izejas kodu

Stat tree edit (wip)

Vijayakrishnan 3 gadi atpakaļ
vecāks
revīzija
90ac38eb8b

+ 14 - 2
app/Http/Controllers/StatTreeController.php

@@ -19,7 +19,7 @@ class StatTreeController extends Controller
 {
     public function list()
     {
-        $statTrees = StatTree::all();
+        $statTrees = StatTree::orderByRaw('is_template DESC NULLS LAST')->orderBy('name')->get();
         return view('app.stat-tree.stat-trees.list', compact('statTrees'));
     }
 
@@ -58,6 +58,17 @@ class StatTreeController extends Controller
         $statTree->name = $name;
         $statTree->model = $model;
         $statTree->slug = $slug;
+
+        $statTree->is_template = (bool)$request->input('isTemplate');
+
+        if($request->input('proUid')) {
+            $pro = Pro::where('uid', $request->input('proUid'))->first();
+            if($pro) {
+                $statTree->pro_id = $pro->id;
+            }
+        }
+        $statTree->pro_scope_clause = $request->input('proScopeClause');
+
         $statTree->save();
 
         return $this->pass($statTree->uid);
@@ -69,6 +80,7 @@ class StatTreeController extends Controller
         $statTree->name = $request->input('name');
         $statTree->model = $request->input('model');
         $statTree->slug = $request->input('slug');
+        $statTree->is_template = (bool)$request->input('isTemplate');
         if($request->input('proUid')) {
             $pro = Pro::where('uid', $request->input('proUid'))->first();
             if($pro) {
@@ -462,7 +474,7 @@ class StatTreeController extends Controller
             $children[] = $this->lineObject($child);
         }
         return [
-            "text" => $line->displayLabel() .
+            "text" => '<span class="stat-tree-anchor">' . $line->displayLabel() . '</span>' .
                 '<span class="ml-2 text-secondary line-count-label">(' .
                 (is_null($line->last_refresh_count) ? '…' :
                     ($line->last_refresh_count === -1 ?

+ 9 - 0
public/css/style.css

@@ -1203,6 +1203,11 @@ body .node input[type="number"] {
     margin-right: 1.5rem;
     margin-left: auto;
 }
+.stag-popup .popup-content-container {
+    margin-top: 1rem;
+    padding-top: 1rem;
+    border-top: 1px solid #e1e1e1;
+}
 
 /* slide-in stag-popups */
 .stag-popup.stag-slide {
@@ -2776,6 +2781,10 @@ table.stag-compact-grid>tbody>tr>td [if-grid-view] {
 .stat-tree-view>.stat-tree-node+.stat-tree-children>.stat-tree-node+.stat-tree-children>.stat-tree-node+.stat-tree-children>.stat-tree-node+.stat-tree-children>.stat-tree-node+.stat-tree-children>.stat-tree-node+.stat-tree-children>.stat-tree-node+.stat-tree-children>.stat-tree-node+.stat-tree-children>.stat-tree-node {
     padding-left: 9.2rem;
 }
+.stat-tree-user-view .stat-tree-anchor {
+    color: rgb(13, 89, 175) !important;
+    text-decoration: none;
+}
 
 /* jstree overrides */
 .stat-tree-view .jstree-wholerow {

+ 1 - 1
resources/views/app/stat-tree/stat-tree-lines/view-data.blade.php

@@ -1,4 +1,4 @@
-<div class="mcp-theme-1 p-3 border-top mt-3">
+<div class="mcp-theme-1 popup-content-container p-3">
     @if(@$rows === 'error')
         <div class="text-secondary">
             <i class="fa fa-exclamation-triangle"></i>

+ 34 - 2
resources/views/app/stat-tree/stat-trees/list.blade.php

@@ -34,6 +34,20 @@
                                         <label class="text-secondary text-sm mb-1">Slug *</label>
                                         <input type="text" class="form-control form-control-sm" name="slug" required>
                                     </div>
+                                    <label class="my-3 d-flex align-items-center">
+                                        <span class="mr-2">Is Template?</span>
+                                        <input type="checkbox" name="isTemplate">
+                                    </label>
+                                    <div class="mb-2">
+                                        <label class="text-secondary text-sm mb-1">Pro</label>
+                                        <select name="proUid" class="form-control input-sm" provider-search provider-type="hcp">
+                                            <option value="">--select--</option>
+                                        </select>
+                                    </div>
+                                    <div class="mb-2">
+                                        <label class="text-secondary text-sm mb-1">Pro Scope Clause</label>
+                                        <input type="text" class="form-control form-control-sm" name="proScopeClause">
+                                    </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>
@@ -60,10 +74,28 @@
                                             @foreach($statTrees as $statTree)
                                             <tr>
                                                 <td>{{ $statTree->id }}</td>
-                                                <td><a href="{{ route('practice-management.statTrees.view.edit', $statTree) }}">{{ $statTree->name }}</a></td>
+                                                <td><a href="{{ route('practice-management.statTrees.view.edit', $statTree) }}">{{ $statTree->name }}</a>
+                                                    @if($statTree->is_template)
+                                                        <span class="mt-1 text-sm bg-info rounded text-white d-inline-block px-2 py-1 ml-1 font-weight-bold">TEMPLATE</span>
+                                                    @endif
+                                                </td>
                                                 <td>{{ $statTree->model }}</td>
                                                 <td>{{ $statTree->slug }}</td>
-                                                <td><a href="{{ route('practice-management.statTrees.view.edit', $statTree) }}">Edit</a></td>
+                                                <td>
+                                                    <div class="d-flex align-items-baseline">
+                                                        <a href="{{ route('practice-management.statTrees.view.edit', $statTree) }}">Edit</a>
+                                                        @if($statTree->is_template)
+                                                            <div class="position-relative on-click-menu ml-2">
+                                                                <span class="text-primary c-pointer px-2 py-1 border rounded bg-aliceblue">…</span>
+                                                                <div menu class="bg-white border">
+                                                                    <a native target="_blank" href="#" class="px-2 py-1 d-block text-nowrap">Instantiate</a>
+                                                                    <a native target="_blank" href="#" class="px-2 py-1 d-block text-nowrap">Instantiate for multiple pros</a>
+                                                                    <a native target="_blank" href="#" class="px-2 py-1 d-block text-nowrap">Clone</a>
+                                                                </div>
+                                                            </div>
+                                                        @endif
+                                                    </div>
+                                                </td>
                                             </tr>
                                             @endforeach
                                         </tbody>

+ 10 - 6
resources/views/app/stat-tree/stat-trees/sub/edit.blade.php

@@ -59,6 +59,10 @@
                                 <label class="text-secondary text-sm mb-1">Slug *</label>
                                 <input type="text" class="form-control form-control-sm" name="slug" value="{{$statTree->slug}}" required>
                             </div>
+                            <label class="my-3 d-flex align-items-center">
+                                <span class="mr-2">Is Template?</span>
+                                <input type="checkbox" name="isTemplate" {{@$statTree->is_template ? 'checked' : ''}}>
+                            </label>
                             <div class="mb-2">
                                 <label class="text-secondary text-sm mb-1">Pro</label>
                                 <select name="proUid" class="form-control input-sm" provider-search provider-type="hcp" data-pro-uid="{{ @$statTree->pro->uid }}">
@@ -293,12 +297,12 @@
                             </div>
                             <div class="flex-grow-1 overflow-overlay-on-hover">
                                 @if(!$multiProView)
-                                    <div class="stat-tree-view overflow-auto" id="stat-tree-view-{{$statTree->id}}"></div>
+                                    <div class="stat-tree-view overflow-auto min-height-300px" id="stat-tree-edit-{{$statTree->id}}"></div>
                                 @else
                                     <div class="d-flex align-items-start">
                                         <div class="">
                                             <div class="multi-pro-view-stat-label">Stat</div>
-                                            <div class="stat-tree-view overflow-auto" id="stat-tree-view-{{$statTree->id}}"></div>
+                                            <div class="stat-tree-view overflow-auto" id="stat-tree-edit-{{$statTree->id}}"></div>
                                         </div>
                                         <div class="flex-grow-1">
                                             <table class="table table-sm multi-pro-stats-table">
@@ -523,7 +527,7 @@
 
                             // stat tree
                             let StatTree = {
-                                el: $('#stat-tree-view-{{$statTree->id}}'),
+                                el: $('#stat-tree-edit-{{$statTree->id}}'),
                                 changed: false,
 
                                 setDirty: function(_changed = true) {
@@ -544,7 +548,7 @@
                                     }
                                     catch (e) {}
 
-                                    this.el = $('#stat-tree-view-{{$statTree->id}}');
+                                    this.el = $('#stat-tree-edit-{{$statTree->id}}');
 
                                     // get data
                                     showMask();
@@ -1061,13 +1065,13 @@
                             $(document)
                                 .off('click', '.tree-expand-all')
                                 .on('click', '.tree-expand-all', function() {
-                                    $('#stat-tree-view-{{$statTree->id}}').jstree('open_all');
+                                    $('#stat-tree-edit-{{$statTree->id}}').jstree('open_all');
                                     return false;
                                 });
                             $(document)
                                 .off('click', '.tree-collapse-all')
                                 .on('click', '.tree-collapse-all', function() {
-                                    $('#stat-tree-view-{{$statTree->id}}').jstree('close_all');
+                                    $('#stat-tree-edit-{{$statTree->id}}').jstree('close_all');
                                     return false;
                                 });
 

+ 7 - 0
resources/views/app/stat-tree/stat-trees/sub/view.blade.php

@@ -0,0 +1,7 @@
+@extends ('layouts/template')
+@section('content')
+    <div class="mcp-theme-1">
+        <h3 class="font-size-16 text-seondary mb-3 border-bottom p-3">{{ $statTree->name }}</h3>
+        @include('app.stat-tree.view')
+    </div>
+@endsection

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

@@ -0,0 +1,143 @@
+{{-- resolve --}}
+@if(!@$statTree)
+    @if(!@$slug)
+        <div class="alert alert-danger m-0">Slug missing!</div>
+    @endif
+    <?php $statTree = \App\Models\StatTree::where('slug', $slug)->first(); ?>
+    @if(!@$statTree)
+        <div class="alert alert-danger m-0">Stat tree no found!</div>
+    @endif
+@endif
+<link rel="stylesheet" href="/jstree/themes/default/style.min.css" />
+<script src="/jstree/jstree.min.js"></script>
+<div id="statTreeView-{{$statTree->id}}">
+    <div class="stat-tree-view stat-tree-user-view overflow-auto min-height-300px" id="stat-tree-view-{{$statTree->id}}"></div>
+</div>
+<script>
+    (function() {
+        function init() {
+
+            (function ($, undefined) {
+                "use strict";
+                $.jstree.plugins.noclose = function () {
+                    this.close_node = $.noop;
+                };
+            })(jQuery);
+
+            // stat tree
+            let StatTree = {
+                el: $('#stat-tree-view-{{$statTree->id}}'),
+                changed: false,
+
+                onSelected: function(_e, _data) {
+                    @if(!@$reportTarget)
+                        openDynamicStagPopup('/practice-management/stat-tree-lines/view-data/' + _data.node.data.uid,
+                            null,
+                            _data.node.data.displayLabel,
+                            false,
+                            'medium');
+                    @else
+                        $.get('/practice-management/stat-tree-lines/view-data/' + _data.node.data.uid, _data => {
+                            $('{{$reportTarget}}').html(_data);
+                        });
+                    @endif
+                },
+
+                load: function() {
+
+                    // destroy if existing
+                    try {
+                        this.el.jstree('destroy');
+                    }
+                    catch (e) {}
+
+                    this.el = $('#stat-tree-view-{{$statTree->id}}');
+
+                    // get data
+                    showMask();
+                    $.get('{{ route('practice-management.statTrees.view.linesJSON', $statTree) }}', _data => {
+
+                        // init tree with data
+                        this.el
+                            .on('redraw.jstree', () => { StatTree.dropVisualize(); })
+                            .on('select_node.jstree', (_e, _data) => { StatTree.onSelected(_e, _data); })
+                            .jstree({
+                                "core": {
+                                    "multiple": false,
+                                    "animation": 0,
+                                    'data': _data
+                                },
+                                "contextmenu": {
+                                    show_at_node: false,
+                                    items: function (node) {
+                                        if(node.data.type === 'stat_tree_line') { // stat_tree_line
+                                            return {
+                                                "data": {
+                                                    "label": "<span class='text-sm'>View Data</span>",
+                                                    "action": function (obj) {
+                                                        openDynamicStagPopup('/practice-management/stat-tree-lines/view-data/' + node.data.uid,
+                                                            null,
+                                                            node.data.displayLabel,
+                                                            false,
+                                                            'medium');
+                                                    }
+                                                },
+                                            }
+                                        }
+                                    },
+                                },
+                                "plugins": [
+                                    "wholerow",
+                                    "contextmenu",
+                                    "noclose"
+                                ]
+                            });
+                    }, 'json').then(hideMask);
+                },
+
+                dropVisualize: function() {
+                    console.log('redrawn')
+                    function calculateDropPercent(node, parent = null) {
+                        let realNode = StatTree.el.jstree(true).get_node(node.id);
+                        if(!realNode.data) return;
+                        if(parent && parent.data.lastRefreshCount !== null) {
+                            if(node.data.lastRefreshCount !== null) {
+                                realNode.data.dropPercent = (((parent.data.lastRefreshCount - node.data.lastRefreshCount) / parent.data.lastRefreshCount) * 100);
+                                if(realNode.data.dropPercent) {
+                                    let element = StatTree.el.jstree(true).get_node(node.id, true), cssClass = '';
+                                    if(realNode.data.dropPercent > 75) {
+                                        cssClass = 'drop-76-100';
+                                    }
+                                    else if(realNode.data.dropPercent > 50 && realNode.data.dropPercent <= 75) {
+                                        cssClass = 'drop-51-75';
+                                    }
+                                    else if(realNode.data.dropPercent > 25 && realNode.data.dropPercent <= 50) {
+                                        cssClass = 'drop-26-50';
+                                    }
+                                    else if(realNode.data.dropPercent > 0 && realNode.data.dropPercent <= 25) {
+                                        cssClass = 'drop-0-25';
+                                    }
+                                    element.find('>a.jstree-anchor')
+                                        .addClass('has-drop-visualization')
+                                        .addClass(cssClass)
+                                        .attr('data-drop-percent', (realNode.data.dropPercent.toFixed(1)) + '% ⤵');
+                                }
+                            }
+                        }
+                        for (let i = 0; i < node.children.length; i++) {
+                            calculateDropPercent(node.children[i], node);
+                        }
+                    }
+                    let raw = this.el.jstree('get_json');
+                    for (let i = 0; i < raw.length; i++) {
+                        calculateDropPercent(raw[i]);
+                    }
+                },
+            };
+
+            StatTree.load();
+
+        }
+        addMCInitializer('stat-tree-view-{{$statTree->id}}', init, '#statTreeView-{{$statTree->id}}');
+    }).call(window);
+</script>