From 5200e4a44d3a74bb3c2f449a05d22b5d4ce5eae7 Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 6 Feb 2016 11:12:16 -0500 Subject: [PATCH 01/22] POC --- gen/controller.php | 17 +++++++++++++++-- gen/list.html.twig | 4 ++++ src/app.php | 7 +++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gen/controller.php b/gen/controller.php index 6e1cd6a7..50e7c330 100644 --- a/gen/controller.php +++ b/gen/controller.php @@ -137,11 +137,24 @@ __TABLECOLUMNS_ARRAY__ ); - $primary_key = "__TABLE_PRIMARYKEY__"; + $primary_key = "__TABLE_PRIMARYKEY__"; + + $image_tag_insertion = array(); + + foreach($table_columns as $idx => $table_column) { + if(isset($app['image_fields']['__TABLENAME__' . '.' . $table_column])) { + $image_tag_insertion[] = array( + 'column_idx' => $imageIdx = $idx, + 'image_path' => $app['image_fields']['__TABLENAME__' . '.' . $table_column], + 'column_name' => $table_column + ); + } + } return $app['twig']->render('__TABLENAME__/list.html.twig', array( "table_columns" => $table_columns, - "primary_key" => $primary_key + "primary_key" => $primary_key, + "image_tag_insertion" => $image_tag_insertion )); }) diff --git a/gen/list.html.twig b/gen/list.html.twig index 72b8647c..e3c21be6 100644 --- a/gen/list.html.twig +++ b/gen/list.html.twig @@ -23,6 +23,10 @@ rowCallback: function( row, data ) { var actions = 'Edit Delete'; $('td:eq({{ table_columns|length }})', row).html( actions ); + + {% for image_tag_info in image_tag_insertion %} + $('td:eq({{ image_tag_info.column_idx }})', row).append('
'); + {% endfor %} } }); }); diff --git a/src/app.php b/src/app.php index 3a57a57f..f85c9bee 100644 --- a/src/app.php +++ b/src/app.php @@ -49,6 +49,13 @@ function queryData() { )); $app['asset_path'] = '/resources'; + +// determine image path for image fields in database +// I.E field value would be image.jpg, result would be +$app['image_fields'] = array( + //'table_name.field_name' => 'http://somepath/dist/images/', +); + $app['debug'] = true; // array of REGEX column name to display for foreigner key insted of ID // default used :'name','title','e?mail','username' From fc71c5088215b6c2bfe4e3953633094c1ba4a58c Mon Sep 17 00:00:00 2001 From: Jm Date: Wed, 10 Feb 2016 00:24:28 -0500 Subject: [PATCH 02/22] column name may as well have - in their names, so they should be escaped with `` just like the table names --- gen/controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gen/controller.php b/gen/controller.php index 6e1cd6a7..a86febfa 100644 --- a/gen/controller.php +++ b/gen/controller.php @@ -63,7 +63,7 @@ $whereClause = $whereClause . " OR"; } - $whereClause = $whereClause . " " . $col . " LIKE '%". $searchValue ."%'"; + $whereClause = $whereClause . " `" . $col . "` LIKE '%". $searchValue ."%'"; $i = $i + 1; } From 1ecdac3e6ea7f35a25f7d2bdba13a5cc48afd4ea Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 20 Feb 2016 16:28:13 -0500 Subject: [PATCH 03/22] Allow the developer to force a foreign key binding if the auto-detection does the job for his needs. (If the column name does not match the pre-defined search patterns). --- src/app.php | 6 ++++++ src/console.php | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/app.php b/src/app.php index f85c9bee..f38b38ca 100644 --- a/src/app.php +++ b/src/app.php @@ -56,6 +56,12 @@ function queryData() { //'table_name.field_name' => 'http://somepath/dist/images/', ); +// If the automapping of foreign key for drop down list does not the job, you can +// force a mapping here +$app['foreign_key_mapping'] = array( + //'column_mapping.import_configs_id' => 'import_configs.default_site_name' +); + $app['debug'] = true; // array of REGEX column name to display for foreigner key insted of ID // default used :'name','title','e?mail','username' diff --git a/src/console.php b/src/console.php index b2649e5b..f783c31c 100644 --- a/src/console.php +++ b/src/console.php @@ -209,15 +209,28 @@ $search_names_foreigner_key); } - // pattern to match a name column, with or whitout a 3 to 4 Char prefix + // pattern to match a name column, with or whitout a 3 to 4 Char prefix $search_names_foreigner_key = '#^(.{3,4}_)?('.implode('|',$search_names_foreigner_key).')$#i'; + // find foreign key mapping for the drop down list foreach($external_table['columns'] as $external_column){ if( preg_match($search_names_foreigner_key, $external_column['name'])){ $external_select_field = $external_column['name']; } } + // if there is a custom mapping provided, use it instead + if(isset($app['foreign_key_mapping'])) { + $currentTableColumnKey = $TABLENAME . '.' . $table_column['name']; + if(array_key_exists($currentTableColumnKey, $app['foreign_key_mapping'])) { + $valueOfMapping = $app['foreign_key_mapping'][$currentTableColumnKey]; + if(substr($valueOfMapping, 0, strlen($table_column['external'])) == $table_column['external']) { + $tableNameToTrim = $table_column['external'] . '.'; + $external_select_field = str_replace($tableNameToTrim, '', $valueOfMapping); + } + } + } + if(!$external_select_field){ $external_select_field = $external_primary_key; } From 632cf712ebc10cdb987940ecfb5f8fa169b43505 Mon Sep 17 00:00:00 2001 From: Jm Date: Sat, 20 Feb 2016 16:43:24 -0500 Subject: [PATCH 04/22] Add the power customize easily the application logo --- src/app.php | 2 ++ web/views/ag_base/base.html.twig | 2 +- web/views/ag_header.html.twig | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/app.php b/src/app.php index f38b38ca..6430581f 100644 --- a/src/app.php +++ b/src/app.php @@ -50,6 +50,8 @@ function queryData() { $app['asset_path'] = '/resources'; +$app['application_name'] = 'Admin Generator'; + // determine image path for image fields in database // I.E field value would be image.jpg, result would be $app['image_fields'] = array( diff --git a/web/views/ag_base/base.html.twig b/web/views/ag_base/base.html.twig index 66dfc16b..4c10c398 100644 --- a/web/views/ag_base/base.html.twig +++ b/web/views/ag_base/base.html.twig @@ -3,7 +3,7 @@ - {% block title %}Admin Generator{% endblock %} + {% block title %}{{ app.application_name }}{% endblock %} {% block stylesheets %}{% endblock %} {% block head_javascripts %}{% endblock %} diff --git a/web/views/ag_header.html.twig b/web/views/ag_header.html.twig index e4a4db6f..3c702c27 100644 --- a/web/views/ag_header.html.twig +++ b/web/views/ag_header.html.twig @@ -1,5 +1,5 @@
- +