Skip to content

Commit

Permalink
Add Button for action on constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
vc-urvin committed Jun 26, 2023
1 parent 2013bc0 commit 4cbcf0f
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 3 deletions.
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
Route::get('getAudit', [DisplayController::class, 'getAudit']);
Route::get('getTableData/{table}', [DisplayController::class, 'getTableData']);
Route::get('gettableconstraint/{table}', [DisplayController::class, 'getTableConstraint']);


Route::post('change-constraint', [DisplayController::class, 'changeConstraint']);
});

15 changes: 15 additions & 0 deletions src/Controllers/DisplayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Vcian\LaravelDBAuditor\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Vcian\LaravelDBAuditor\Constants\Constant;
use Vcian\LaravelDBAuditor\Traits\Audit;
use Vcian\LaravelDBAuditor\Traits\Rules;
Expand Down Expand Up @@ -67,6 +68,9 @@ public function getTableData(string $tableName) : JsonResponse
public function getTableConstraint(string $tableName) : JsonResponse
{

$noConstraintFields = $this->getNoConstraintFields($tableName);
$constraintList = $this->getConstraintList($tableName, $noConstraintFields);

$data = [
"fields" => $this->getFieldsDetails($tableName),
'constrain' => [
Expand Down Expand Up @@ -111,11 +115,22 @@ public function getTableConstraint(string $tableName) : JsonResponse
}
}

if($primaryKey === "-" && $indexing === "-" && $uniqueKey === "-" && $foreignKey === "-") {
$indexing = '<img src=' . asset("auditor/icon/add.png") . ' alt="key" class="m-auto add-constraint-'.$table->COLUMN_NAME.'" style="height:30px" onclick="addIndex(`'.$table->COLUMN_NAME.'`)"/>';
}

$response[] = ["column" => $table->COLUMN_NAME, "primaryKey" => $primaryKey, "indexing" => $indexing, "uniqueKey" => $uniqueKey, "foreignKey" => $foreignKey];
}

return response()->json(array(
"data" => $response
));
}

public function changeConstraint(Request $request)
{
$data = $request->all();
$this->addConstraint($data['table_name'], $data['colum_name'], "INDEX");
return $data['colum_name'];
}
}
Binary file added src/resource/images/add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/views/auditor/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
background-image: url({{ asset('auditor/icon/bg.png') }});
}
</style>
@stack('css')
</head>

<body class="bg-black bg-main bg-[length:100%] text-white font-raleway h-[85vh] mb-10">
Expand Down
101 changes: 98 additions & 3 deletions src/views/auditor/pages/audit.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,52 @@
@extends('DBAuditor::auditor.layouts.default')

@push('css')
<style>
#myDialog {
width: 300px;
padding: 20px;
background-color: #f2f2f2;
border: 1px solid #ccc;
}
#myDialog h2 {
margin-top: 0;
}
#myDialog button {
margin-top: 10px;
}
/* Toast Container */
.toast-container {
position: fixed;
top: 20px;
right: 20px;
z-index: 9999;
}
/* Toast Message */
.toast {
background-color: #333;
color: #fff;
padding: 15px;
border-radius: 5px;
font-family: Arial, sans-serif;
font-size: 14px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
opacity: 0;
transition: opacity 0.3s ease-in-out;
}
/* Toast Animation */
.toast.show {
opacity: 1;
}
</style>
@endpush

@section('section')
<div id="toasts"></div>
<div class="tabs flex items-center pt-3 mb-3">
<button data-tab-value="#tab_standard"
class="active uppercase d-flex items-center me-3 text-[13px] pb-2 relative custom-action">
Expand Down Expand Up @@ -93,6 +139,20 @@ class="btn dropdown-toggle bg-light-black border-0 rounded-2xl text-white w-64 t
</table>
</div>
</div>

<div class="toast-container">
<div class="toast">This is a toast message</div>
</div>

<dialog id="myDialog">
<h2>Dialog Title</h2>
<p>This is the content of the dialog.</p>



<button onclick="closeDialog()">Close</button>
</dialog>

@endsection

@section('script')
Expand Down Expand Up @@ -178,11 +238,13 @@ className: 'dt-control',
// Constraint
$('#tbl-dropdown').on('change', function() {
changeTable(this.value);
});
});
setTimeout(function() {
var toast = document.querySelector('.toast');
toast.classList.add('show');
}, 1000);
});
function format(d) {
Expand Down Expand Up @@ -318,6 +380,39 @@ function changeTable(tableName) {
});
}
// function openDialog() {
// var dialog = document.getElementById("myDialog");
// dialog.showModal();
// }
// function closeDialog() {
// var dialog = document.getElementById("myDialog");
// dialog.close();
// }
function addIndex(columnName) {
$.ajax({
url: 'api/change-constraint',
type: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data: JSON.stringify({"colum_name" : columnName, "table_name" : $('#tbl-dropdown').val(), "constraint" : 'index'}),
success: function(response) {
if(response) {
var newElement = $('<img src="auditor/icon/gray-key.svg" alt="key" class="m-auto" />');
$(".add-constraint-"+response).replaceWith(newElement);
}
},
error: function(xhr, status, error) {
console.error(error);
}
});
}
$(document).on("click", ".custom-action", function() {
$("#constraints").DataTable().draw();
$("#standards").DataTable().draw();
Expand Down

0 comments on commit 4cbcf0f

Please sign in to comment.