Bläddra i källkod

Auto-hide UID, ID & friendly datetime values

Vijayakrishnan Krishnan 5 år sedan
förälder
incheckning
4bd97106c4
2 ändrade filer med 45 tillägg och 0 borttagningar
  1. 32 0
      app/Console/Commands/GenerateTreeCommand.php
  2. 13 0
      app/Helpers/Helper.php

+ 32 - 0
app/Console/Commands/GenerateTreeCommand.php

@@ -573,13 +573,24 @@ class GenController {
             });
         }
 
+        // ensure uid column is at the start
+        $columns = array_merge(['uid'], array_filter($columns, function($x) {
+            return $x !== 'uid';
+        }));
+
         foreach ($columns as $column) {
 
+            if($column === 'id') continue;
+
             $columnTitle = $this->snakeToTitleCase($column);
             $columnValue = "<?= \$record->$column ?>";
             $hasLink = $controller->hasView && $column === $method->viewLinkField;
             $linkTarget = "/{$controller->name}/view/<?= \$record->uid ?>";
 
+            if(substr($column, -3) === '_at') {
+                $columnValue = "<?= friendly_date_time(\$record->$column) ?>";
+            }
+
             // check if this column has column spec
             if(isset($method->columns[$column])) {
                 $columnTitle = $method->columns[$column]["label"];
@@ -596,6 +607,11 @@ class GenController {
                     $linkTarget = $method->columns[$column]["link"];
                 }
             }
+            else if($column === 'uid') {
+                $columnTitle = '&nbsp;';
+                $columnValue = '<i class="fas fa-share-square"></i>';
+                $hasLink = true;
+            }
 
             $ths[] = "<th>$columnTitle</th>";
             $tds[] = "<td>" .
@@ -750,13 +766,24 @@ class GenController {
             });
         }
 
+        // ensure uid column is at the start
+        $columns = array_merge(['uid'], array_filter($columns, function($x) {
+            return $x !== 'uid';
+        }));
+
         foreach ($columns as $column) {
 
+            if($column === 'id') continue;
+
             $columnTitle = $this->snakeToTitleCase($column);
             $columnValue = "<?= \$subRecord->$column ?>";
             $hasLink = $method->exitURL && $column === $method->viewLinkField;
             $linkTarget = $method->exitURL;
 
+            if(substr($column, -3) === '_at') {
+                $columnValue = "<?= friendly_date_time(\$record->$column) ?>";
+            }
+
             // check if this column has column spec
             if(isset($method->columns[$column])) {
                 $columnTitle = $method->columns[$column]["label"];
@@ -770,6 +797,11 @@ class GenController {
                     $linkTarget = $method->columns[$column]["link"];
                 }
             }
+            else if($column === 'uid') {
+                $columnTitle = '&nbsp;';
+                $columnValue = '<i class="fas fa-share-square"></i>';
+                $hasLink = true;
+            }
 
             $ths[] = "<th>$columnTitle</th>";
             $tds[] = "<td>" .

+ 13 - 0
app/Helpers/Helper.php

@@ -72,3 +72,16 @@ if (!function_exists('value_from_rs')) {
         return $result;
     }
 }
+
+if(!function_exists('friendly_date_time')) {
+    function friendly_date_time($value) {
+        try {
+            $result = strtotime($value);
+            $result = date("j M o, H:i");
+            return $result;
+        }
+        catch (Exception $e) {
+            return $value;
+        }
+    }
+}