Browse Source

Stattree - goal percent - read/edit ui + save/load

Vijayakrishnan 3 years ago
parent
commit
2fe30d6f52

+ 3 - 1
app/Http/Controllers/StatTreeController.php

@@ -605,7 +605,8 @@ class StatTreeController extends Controller
                 "lastRefreshCount" => $line->last_refresh_count,
                 "lastRefreshCount" => $line->last_refresh_count,
                 "treeOrderPositionIndex" => $line->tree_order_position_index,
                 "treeOrderPositionIndex" => $line->tree_order_position_index,
                 "columns" => $columns,
                 "columns" => $columns,
-                "clause" => $clause
+                "clause" => $clause,
+                "goalPercent" => (is_null($line->goal_percent) ? -1 : $line->goal_percent)
             ],
             ],
             "a_attr" => [
             "a_attr" => [
                 "title" => $line->displayLineClause()->clause->clause_text
                 "title" => $line->displayLineClause()->clause->clause_text
@@ -653,6 +654,7 @@ class StatTreeController extends Controller
         $statTreeLine->tree_order_position_index = $position;
         $statTreeLine->tree_order_position_index = $position;
         $statTreeLine->last_refresh_count = null;
         $statTreeLine->last_refresh_count = null;
         $statTreeLine->tsv_text_for_report_columns = null;
         $statTreeLine->tsv_text_for_report_columns = null;
+        $statTreeLine->goal_percent = ($line->goalPercent === -1 ? null : $line->goalPercent);
         $statTreeLine->parent_stat_tree_line_id = $parentLine ? $parentLine->id : null;
         $statTreeLine->parent_stat_tree_line_id = $parentLine ? $parentLine->id : null;
         $statTreeLine->save();
         $statTreeLine->save();
 
 

+ 26 - 0
resources/views/app/stat-tree/stat-trees/sub/edit.blade.php

@@ -362,6 +362,11 @@
                                             <div class="flex-grow-1 overflow-overlay-on-hover">
                                             <div class="flex-grow-1 overflow-overlay-on-hover">
                                                 <div class="mb-3 d-flex align-items-baseline p-2 border-bottom font-weight-bold">
                                                 <div class="mb-3 d-flex align-items-baseline p-2 border-bottom font-weight-bold">
                                                     <span line-label></span>
                                                     <span line-label></span>
+                                                    <div class="ml-3 pl-3 border-left d-inline-flex align-items-baseline">
+                                                        <span class="mr-1 font-weight-normal">Goal:</span>
+                                                        <span line-goal class="mr-2"></span>
+                                                        <a href="#" class="btn-edit-goal"><i class="fa fa-edit"></i></a>
+                                                    </div>
                                                 </div>
                                                 </div>
                                                 <div class="d-flex align-items-baseline mb-2 px-2">
                                                 <div class="d-flex align-items-baseline mb-2 px-2">
                                                     <h6 class="font-weight-bold m-0 text-secondary">Argument Values</h6>
                                                     <h6 class="font-weight-bold m-0 text-secondary">Argument Values</h6>
@@ -1082,6 +1087,7 @@
                                             displayLabel: node.data.displayLabel,
                                             displayLabel: node.data.displayLabel,
                                             clause: node.data.clause,
                                             clause: node.data.clause,
                                             columns: node.data.columns,
                                             columns: node.data.columns,
+                                            goalPercent: node.data.goalPercent,
                                         };
                                         };
                                         let children = [];
                                         let children = [];
                                         for (let i = 0; i < node.children.length; i++) {
                                         for (let i = 0; i < node.children.length; i++) {
@@ -1145,6 +1151,7 @@
 
 
                                     linePropsColumn.removeClass('d-none');
                                     linePropsColumn.removeClass('d-none');
                                     linePropsColumn.find('[line-label]').text(selected.data.displayLabel);
                                     linePropsColumn.find('[line-label]').text(selected.data.displayLabel);
+                                    linePropsColumn.find('[line-goal]').text(selected.data.goalPercent === -1 ? '-' : selected.data.goalPercent + '%');
 
 
                                     // fill args
                                     // fill args
                                     let tbody = linePropsColumn.find('[line-args]');
                                     let tbody = linePropsColumn.find('[line-args]');
@@ -1323,6 +1330,25 @@
                                     return false;
                                     return false;
                                 });
                                 });
 
 
+                            $(document)
+                                .off('click', '.btn-edit-goal')
+                                .on('click', '.btn-edit-goal', function() {
+                                    let selected = StatTree.selectedNode();
+                                    let value = window.prompt('New goal (%):', (selected.data.goalPercent !== -1 ? selected.data.goalPercent : ''));
+                                    if(value !== null) {
+                                        if($.trim(value) === '') {
+                                            value = -1;
+                                        }
+                                        else {
+                                            value = +value;
+                                        }
+                                        selected.data.goalPercent = value;
+                                        StatTree.onSelected();
+                                        StatTree.setDirty();
+                                    }
+                                    return false;
+                                });
+
                             $(document)
                             $(document)
                                 .off('click', '.clause-expand-all')
                                 .off('click', '.clause-expand-all')
                                 .on('click', '.clause-expand-all', function() {
                                 .on('click', '.clause-expand-all', function() {