aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilly Micieli <micieli@laposte.net>2019-10-23 16:25:03 +0200
committerWilly Micieli <micieli@laposte.net>2019-10-23 16:25:03 +0200
commit20373c2af9fe806d1b129b8b2702fcd54a6fb1d2 (patch)
tree667ceba7b2a71e22c6680ee3b41ec3252bc6cd16
parent2dbf7b8d7afae56883313c7f6ffa5a74ab1d9515 (diff)
downloadimperium-20373c2af9fe806d1b129b8b2702fcd54a6fb1d2.zip
imperium-20373c2af9fe806d1b129b8b2702fcd54a6fb1d2.tar.gz
add truncate table possibilities
-rw-r--r--config/crud.yaml4
-rw-r--r--helpers/web.php3
-rw-r--r--imperium/Action/Crud.php42
3 files changed, 47 insertions, 2 deletions
diff --git a/config/crud.yaml b/config/crud.yaml
index fa2d741..2eb557a 100644
--- a/config/crud.yaml
+++ b/config/crud.yaml
@@ -10,4 +10,6 @@ select_table_text: 'select a table'
edit_text: 'edit'
remove_text: 'remove'
edit_class: 'btn btn-outline-primary'
-remove_class: 'btn btn-outline-danger' \ No newline at end of file
+remove_class: 'btn btn-outline-danger'
+truncated: 'The table has been empty successfully'
+no_truncated: 'The table has not been altered'
diff --git a/helpers/web.php b/helpers/web.php
index 011970c..8591f06 100644
--- a/helpers/web.php
+++ b/helpers/web.php
@@ -373,6 +373,9 @@
$admin_r = Admin::where('name', EQUAL, $name)->fetch(true)->all();
$web = Web::where('name', EQUAL, $name)->fetch(true)->all();
+ is_true($admin && not_def($admin_r) || !$admin && not_def($web),true,"The $name route was not found");
+
+
$x = $admin ? $admin_r : $web;
diff --git a/imperium/Action/Crud.php b/imperium/Action/Crud.php
index 9c6c3ed..71a816c 100644
--- a/imperium/Action/Crud.php
+++ b/imperium/Action/Crud.php
@@ -97,6 +97,23 @@
* @var string
*/
private $current;
+ /**
+ *
+ * The failure truncate message
+ *
+ * @var string
+ *
+ */
+ private $no_truncated;
+
+ /**
+ *
+ * The truncated table success message
+ *
+ * @var string
+ *
+ */
+ private $truncated;
/**
@@ -158,6 +175,7 @@
public function show(string $table): Response
{
$this->current = $table;
+
$all = '<div class="table-responsive"><table class="table table-bordered"><thead>';
foreach ($this->sql($table)->columns() as $column)
append($all,"<th>$column</th>");
@@ -171,6 +189,25 @@
/**
*
+ * Truncate a table
+ *
+ * @param string $table
+ *
+ * @return RedirectResponse
+ *
+ * @throws DependencyException
+ * @throws Kedavra
+ * @throws NotFoundException
+ */
+ public function clear(string $table): RedirectResponse
+ {
+ $this->init();
+
+ return $this->truncate($table) ? $this->to(route('show',true,[$table]),$this->truncated) : $this->to(route('show',true,[$table]),$this->no_truncated,false);
+ }
+
+ /**
+ *
* Generate a form to update a record
*
* @param string $table
@@ -329,7 +366,10 @@
$this->deleted = config($file,'deleted');
- $this->no_deleted = config($file,'no_deleted');
+ $this->no_truncated = config($file,'no_truncated');
+
+ $this->truncated = config($file,'truncated');
+
}