Skip to content

Commit

Permalink
Add Foreign Key awareness and much more (#64)
Browse files Browse the repository at this point in the history
* Add columns comments

* Add tooltips with comments

* Change to local css

* Update README.md

* Update Readme

* Update readme

* Use the SQL COUNT(*) function to count records

* Fix deprecated warning

* Order by first column ASC on default

* Add view, edit and delete buttons

* Fix update and insert statement and show errors

* add error function

* Allow empty values for columns

* Display nullable columns

* Fix booleans and support null

* Show columns and null to the user

* Format date and datetime

* Link to foreign key parent

* Handle SQL errors

* Allow null for FK

* Show references to the current item

* Fix SQL injections

* Rework references to current read

* Remove unused error handling

* Add back button and rework ordering

* update readme

* Add PHP formatter

* Use safe variable names in SQL/PHP

* Add new TODOs

* More todos

* Move domain name to config

* Update readme

* Generate enum select at generation

* Show bools as True/False

* Allow selecting columns for previewing records

* Generate JOIN queries

* Check for key uniqueness or redirect to the index

* update helpers

* Make read/edit/create layout easily adaptable

* Add new layout

* Move JS/CSS to the generator

* Move JS to local storage

* Make external columns searchable

* Make header and footer sticky

* Use textarea properly

* Fix empty dates

* Prepare for PR

* Minor changes to improve usability
  • Loading branch information
tomrusteze authored Nov 17, 2023
1 parent 77ee155 commit aef1114
Show file tree
Hide file tree
Showing 7 changed files with 664 additions and 327 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
core/app/
core/app/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ This is the startpage. For every selected table, Cruddiy has created 5 pages: In

[![N|Cruddiy](https://j11g.com/cruddiy/bs4-cruddiy-app-index.png)](https://cruddiy.com)

You can rename or move the generated 'app' folder anywhere. It is completely self-contained. And you can delete Cruddiy, it is not needed anymore. Or you can can run it many more times (use the back button in the browser), until you get your pages just the way you like them. Each time it will overwrite your existing app.
You can rename or move the generated 'app' folder anywhere. It is completely self-contained. And you can delete Cruddiy, it is not needed anymore. Or you can can run it many more times (use the back button in the browser), until you get your pages just the way you like them. Each time it will overwrite your existing app.
63 changes: 53 additions & 10 deletions core/columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@
</div>

<div class="col-md-10 mx-atuo text-right pr-5 ml-4">
<input type="checkbox" id="checkall">
<label for="checkall">Check/uncheck all</label>
</div>

<div class="mx-atuo text-right ml-4">
<input type="checkbox" id="checkall-1" checked>
<label for="checkall-1">Check/uncheck all</label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" id="checkall-2" checked>
<label for="checkall-2">Check/uncheck all</label>
</div>

<form class="form-horizontal" action="generate.php" method="post">
<fieldset>
Expand Down Expand Up @@ -59,7 +64,22 @@ function get_col_types($table,$column){
$result = mysqli_query($link,$sql);
$row = mysqli_fetch_assoc($result);
return $row['Type'] ;
mysqli_free_result($result);
}

function get_col_comments($table,$column){
global $link;
$sql = "SHOW FULL FIELDS FROM $table where FIELD ="."'".$column."'";
$result = mysqli_query($link,$sql);
$row = mysqli_fetch_assoc($result);
return $row['Comment'] ;
}

function get_col_nullable($table,$column){
global $link;
$sql = "SHOW FULL FIELDS FROM $table where FIELD ="."'".$column."'";
$result = mysqli_query($link,$sql);
$row = mysqli_fetch_assoc($result);
return ($row['Null'] == "YES") ? true : 0;
}

function get_foreign_keys($table){
Expand All @@ -76,7 +96,6 @@ function get_foreign_keys($table){
$fks[] = $row['Foreign Key'];
}
return $fks;
mysqli_free_result($result);
}

$checked_tables_counter=0;
Expand All @@ -98,6 +117,8 @@ function get_foreign_keys($table){
while ($column = mysqli_fetch_array($result)) {

$column_type = get_col_types($tablename,$column[0]);
$column_comment = get_col_comments($tablename,$column[0]);
$column_nullable = get_col_nullable($tablename,$column[0]);

if (in_array ("$column[0]", $primary_keys)) {
$primary = "🔑";
Expand All @@ -123,21 +144,34 @@ function get_foreign_keys($table){
$fk = "";
}

if ($column_nullable) {
$nb = "🫙";
}
else {
$nb = "";
}

echo "<span data-toggle='tooltip' data-placement='top' title='$column_comment'>";
echo '<div class="row align-items-center mb-2">
<div class="col-2 text-right"
<label class="col-form-label" for="'.$tablename.'">'. $primary . $auto . $fk . $column[0] . ' </label>
<label class="col-form-label" for="'.$tablename.'">'. $primary . $auto . $fk . $nb . $column[0] . ' </label>
</div>
<div class="col-md-6">
<input type="hidden" name="'.$tablename.'columns['.$i.'][tablename]" value="'.$tablename.'"/>
<input type="hidden" name="'.$tablename.'columns['.$i.'][tabledisplay]" value="'.$tabledisplay.'"/>
<input type="hidden" name="'.$tablename.'columns['.$i.'][columnname]" value="'.$column[0].'"/>
<input type="hidden" name="'.$tablename.'columns['.$i.'][columntype]" value="'.$column_type.'"/>
<input type="hidden" name="'.$tablename.'columns['.$i.'][columncomment]" value="'.$column_comment.'"/>
<input type="hidden" name="'.$tablename.'columns['.$i.'][columnnullable]" value="'.$column_nullable.'"/>
<input id="textinput_'.$tablename. '-'.$i.'"name="'. $tablename. 'columns['.$i.'][columndisplay]" type="text" placeholder="Display field name in frontend" class="form-control rounded-0">
</div>
<div class="col-md-4">
<input type="checkbox" name="'.$tablename.'columns['.$i.'][columnvisible]" id="checkboxes-'.$checked_tables_counter.'-'.$i.'" value="1">
<div class="col-md-2">
<input type="checkbox" name="'.$tablename.'columns['.$i.'][columnvisible]" id="checkboxes-'.$checked_tables_counter.'-'.$i.'" value="1" checked>
<label for="checkboxes-'.$checked_tables_counter.'-'.$i.'">Visible in overview?</label></div>
</div>';
<div class="col-md-2">
<input type="checkbox" name="'.$tablename.'columns['.$i.'][columninpreview]" id="checkboxes-'.$checked_tables_counter.'-'.$i.'-2" value="1" checked>
<label for="checkboxes-'.$checked_tables_counter.'-'.$i.'-2">Visible in preview?</label></div>
</div></span>';
$i++;
}
$checked_tables_counter++;
Expand Down Expand Up @@ -179,11 +213,20 @@ function get_foreign_keys($table){
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
<script>
$(document).ready(function () {
$('#checkall').click(function(e) {
var chb = $('.form-horizontal').find('input[type="checkbox"]');
$('#checkall-1').click(function(e) {
var chb = $('.form-horizontal').find('input[name$="[columnvisible]"]');
chb.prop('checked', !chb.prop('checked'));
});
});
$(document).ready(function () {
$('#checkall-2').click(function(e) {
var chb = $('.form-horizontal').find('input[name$="[columninpreview]"]');
chb.prop('checked', !chb.prop('checked'));
});
});
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</body>
</html>
Loading

0 comments on commit aef1114

Please sign in to comment.