@@ -172,6 +172,7 @@ class="btn dropdown-toggle bg-light-black border-0 rounded-2xl text-white w-64 t
172
172
</dialog >
173
173
174
174
<p class =" colum-value" ></p >
175
+ <p class =" table-value" ></p >
175
176
<p class =" constraint-value" ></p >
176
177
@endsection
177
178
@@ -201,6 +202,7 @@ class="btn dropdown-toggle bg-light-black border-0 rounded-2xl text-white w-64 t
201
202
});
202
203
203
204
$ (document ).ready (function () {
205
+
204
206
// Standards
205
207
var table = $ (' #standards' ).DataTable ({
206
208
scrollX: true ,
@@ -288,8 +290,6 @@ function format(d) {
288
290
tableComment += ' </tbody>' + ' </table>' ;
289
291
}
290
292
291
-
292
-
293
293
var table =
294
294
' <table class="table table-stripped table-bordered display nowrap w-100 border-gray" cellpadding="5" cellspacing="0" border="0">' +
295
295
' <thead class="bg-black">' +
@@ -411,13 +411,28 @@ function confirmDialog() {
411
411
addConstraint ();
412
412
}
413
413
414
- function add (columnName , constraint ) {
415
- $ (' #confDialog h2' ).replaceWith (" <h2>ADD " + constraint .toUpperCase () + " KEY</h2>" );
416
- $ (' #confDialog p' ).replaceWith (' <p>Do you want to add ' + constraint .toLowerCase () +
417
- ' in <span style="color:red;">' + columnName + ' </span> field?</p>' );
418
- $ (' .colum-value' ).replaceWith (" <p class='colum-value'>" + columnName + " </p>" );
419
- $ (' .constraint-value' ).replaceWith (" <p class='constraint-value'>" + constraint + " </p>" );
420
- openDialog ();
414
+ function add (columnName , constraint , tableName ) {
415
+
416
+ if (constraint .toLowerCase () === " foreign" ) {
417
+ $ (' .colum-value' ).replaceWith (" <p class='colum-value'>" + columnName + " </p>" );
418
+ $ (' .table-value' ).replaceWith (" <p class='table-value'>" + tableName + " </p>" );
419
+ $ (' .constraint-value' ).replaceWith (" <p class='constraint-value'>" + constraint + " </p>" );
420
+ getForeignTables ();
421
+ } else {
422
+ console .log ($ (" .main-dialog" )[0 ]);
423
+ if ( $ (" .main-dialog" )[0 ] ) {
424
+ $ (' #confDialog h2' ).replaceWith (" <h2>ADD " + constraint .toUpperCase () + " KEY</h2>" );
425
+ $ (' .main-dialog' ).replaceWith (' <p>Do you want to add ' + constraint .toLowerCase () + ' in <span style="color:red;">' + columnName + ' </span> field?</p>' );
426
+ $ (' .confirm-dialog-btn' ).replaceWith (' <button onclick="confirmDialog()" class="btn btn-success confirm-dialog-btn">Yes</button>' );
427
+
428
+ } else {
429
+ $ (' #confDialog h2' ).replaceWith (" <h2>ADD " + constraint .toUpperCase () + " KEY</h2>" );
430
+ $ (' #confDialog p' ).replaceWith (' <p>Do you want to add ' + constraint .toLowerCase () + ' in <span style="color:red;">' + columnName + ' </span> field?</p>' );
431
+ }
432
+ $ (' .colum-value' ).replaceWith (" <p class='colum-value'>" + columnName + " </p>" );
433
+ $ (' .constraint-value' ).replaceWith (" <p class='constraint-value'>" + constraint + " </p>" );
434
+ openDialog ();
435
+ }
421
436
}
422
437
423
438
function addConstraint () {
@@ -437,18 +452,17 @@ function addConstraint() {
437
452
}),
438
453
success : function (response ) {
439
454
if (response) {
440
- var key;
455
+ var key = " " ;
441
456
442
457
if (constraint .toLowerCase () === " primary" ) {
443
- key = $ ( ' <img src="auditor/icon/green-key.svg" alt="key" class="m-auto" />' ) ;
458
+ key = ' <img src="auditor/icon/green-key.svg" alt="key" class="m-auto" />' ;
444
459
} else {
445
- key = $ ( ' <img src="auditor/icon/gray-key.svg" alt="key" class="m-auto" />' ) ;
460
+ key = ' <img src="auditor/icon/gray-key.svg" alt="key" class="m-auto" />' ;
446
461
}
447
-
448
- $ (" .add-constraint-" + response + ' - ' + constraint).replaceWith (key);
462
+
463
+ $ (" .add-constraint-" + columnName + " - " + constraint).replaceWith (key);
449
464
$ (" .toast-container" ).css (" display" , " block" );
450
- $ (" .toastCustom" ).replaceWith (" <p class='toastCustom'>" + constraint .toLowerCase () +
451
- " key added successfully</p>" );
465
+ $ (" .toastCustom" ).replaceWith (" <p class='toastCustom'>" + constraint .toLowerCase () + " key added successfully</p>" );
452
466
453
467
setTimeout (function () {
454
468
$ (" .toast-container" ).css (" display" , " none" );;
@@ -461,6 +475,111 @@ function addConstraint() {
461
475
});
462
476
}
463
477
478
+ function getForeignTables ()
479
+ {
480
+ $ .ajax ({
481
+ url: ' api/foreign-key-table' ,
482
+ type: ' get' ,
483
+ headers: {
484
+ ' Content-Type' : ' application/json' ,
485
+ ' X-CSRF-TOKEN' : $ (' meta[name="csrf-token"]' ).attr (' content' )
486
+ },
487
+ success : function (response ) {
488
+ if (response) {
489
+ $ (' #confDialog h2' ).replaceWith (" <h2>Add Foreign Key</h2>" );
490
+
491
+ var html = " <div class='row main-dialog' style='margin-top: 30px;margin-bottom: 20px;'>" ;
492
+
493
+ // foreign table
494
+ html += " <div class='col-md-6 sub-dialog'><select class='form-control select-foreign-table' id='select-foreign-tbl'>" ;
495
+ html += " <option disabled selected>Select Foreign Table</option>" ;
496
+ $ .each (response, function (key , value ) {
497
+ html += " <option value=" + value+ " >" + value+ " </option>" ;
498
+ });
499
+ html += " </select></div>" ;
500
+
501
+ html += " <div class='field-list'></div>"
502
+
503
+ html += " </div>" ;
504
+
505
+ $ (' #confDialog p' ).replaceWith (html);
506
+ $ (' #confDialog .confirm-dialog-btn' ).replaceWith (' <button onclick="addforeignKey()" class="btn btn-success confirm-dialog-btn">Add</button>' );
507
+ openDialog ();
508
+ }
509
+ },
510
+ error : function (xhr , status , error ) {
511
+ console .error (error);
512
+ }
513
+ });
514
+ }
515
+
516
+ $ (document ).on (' change' ,' #select-foreign-tbl' , function () {
517
+
518
+ $ .ajax ({
519
+ url: ' api/foreign-key-field/' + this .value ,
520
+ type: ' get' ,
521
+ headers: {
522
+ ' Content-Type' : ' application/json' ,
523
+ ' X-CSRF-TOKEN' : $ (' meta[name="csrf-token"]' ).attr (' content' )
524
+ },
525
+ success : function (response ) {
526
+ if (response) {
527
+ // foreign column
528
+ var html = " <div class='col-md-6 field-list'><select class='form-control' id='select-foreign-field'>" ;
529
+ html += " <option disabled selected>Select Foreign Column</option>" ;
530
+ $ .each (response, function (key , value ) {
531
+ html += " <option value=" + value .COLUMN_NAME + " >" + value .COLUMN_NAME + " </option>" ;
532
+ });
533
+ html += " </select></div>" ;
534
+
535
+ $ (' .field-list' ).replaceWith (html);
536
+ }
537
+ },
538
+ error : function (xhr , status , error ) {
539
+ console .error (error);
540
+ }
541
+ });
542
+
543
+
544
+ });
545
+
546
+ function addforeignKey ()
547
+ {
548
+ var foreignTable = document .getElementById (' select-foreign-tbl' );
549
+ var foreignField = document .getElementById (' select-foreign-field' );
550
+ var columnName = $ (' .colum-value' ).text ();
551
+ var tableName = $ (' .table-value' ).text ();
552
+ $ .ajax ({
553
+ url: ' api/add-foreign-constraint' ,
554
+ type: ' POST' ,
555
+ headers: {
556
+ ' Content-Type' : ' application/json' ,
557
+ ' X-CSRF-TOKEN' : $ (' meta[name="csrf-token"]' ).attr (' content' )
558
+ },
559
+ data: JSON .stringify ({
560
+ " table_name" : tableName,
561
+ " select_field" : columnName,
562
+ " reference_table" : foreignTable .value ,
563
+ " reference_field" : foreignField .value
564
+ }),
565
+ success : function (response ) {
566
+ if (response) {
567
+ $ (" .add-constraint-" + columnName + ' -FOREIGN' ).replaceWith (' <img src="auditor/icon/gray-key.svg" alt="key" class="m-auto" />' );
568
+ closeDialog ();
569
+ $ (" .toast-container" ).css (" display" , " block" );
570
+ $ (" .toastCustom" ).replaceWith (" <p class='toastCustom'>foreign key added successfully</p>" );
571
+
572
+ setTimeout (function () {
573
+ $ (" .toast-container" ).css (" display" , " none" );;
574
+ }, 1000 );
575
+ }
576
+ },
577
+ error : function (xhr , status , error ) {
578
+ console .error (error);
579
+ }
580
+ });
581
+ }
582
+
464
583
$ (document ).on (" click" , " .custom-action" , function () {
465
584
$ (" #constraints" ).DataTable ().draw ();
466
585
$ (" #standards" ).DataTable ().draw ();
0 commit comments