Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5200e4a
POC
JnMik Feb 6, 2016
953a7bd
Merge pull request #1 from JnMik/images-resolving
JnMik Feb 6, 2016
fc71c50
column name may as well have - in their names, so they should be esca…
JnMik Feb 10, 2016
05a16e5
Merge remote-tracking branch 'origin/master'
JnMik Feb 10, 2016
1ecdac3
Allow the developer to force a foreign key binding if the auto-detect…
JnMik Feb 20, 2016
632cf71
Add the power customize easily the application logo
JnMik Feb 20, 2016
26f9299
Allow to add more menu links in the left panel, with specifics
JnMik Feb 20, 2016
43fad30
Menu links should now trigger redirection, bug fix the previous commit
JnMik Feb 20, 2016
4ed5a28
Change default example values in app.php
JnMik Feb 20, 2016
6a8d78f
Configs of application should be in a non-commited file, as they are …
JnMik Feb 20, 2016
bb6efdd
Add application name in readme title (dashboard - {app-name])
JnMik Feb 21, 2016
304a579
Improve readme
JnMik Feb 21, 2016
ec05617
wysiwyg should have all buttons enabled per default, html editor butt…
JnMik Feb 21, 2016
71d3918
Remove the parser of the wysiwyg
JnMik Feb 22, 2016
465a54e
Wan can now add additional buttons in the action column, to call exte…
JnMik Mar 16, 2016
d5f4076
Admin can now be used with Docker
JnMik Mar 20, 2016
a366510
AUtomated build should include composer dependencies
JnMik Mar 20, 2016
d4aab99
fix warning
JnMik Mar 20, 2016
3347626
Call to actions now refresh the datatable and keep the current page
JnMik Mar 27, 2016
9c81021
remove useless comment
JnMik Mar 28, 2016
1cd7218
add gitignore
JnMik Apr 3, 2016
3c73a40
Add videojs player support on column with video URLs, add text intro …
JnMik Apr 14, 2016
a95c589
fix isset problem and apache.conf server name
JnMik May 22, 2016
8c6cd85
fix array bug
JnMik Jan 21, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
.idea
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea
vendor/
composer.lock
config.php
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#vim:set ft=dockerfile:
FROM jnmik/docker-centos7-httpd-utilities-php5.6:latest
MAINTAINER Jean-Michael Cyr <[email protected]>
ADD . /var/www/html
WORKDIR /var/www/html
COPY ./apache.conf /etc/httpd/conf.d/apache.conf

# Install composer
RUN bash -c "wget http://getcomposer.org/composer.phar && php composer.phar install"

CMD ["/bin/bash", "/var/www/html/boot-init.sh"]
78 changes: 77 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ It has been programmed with the Silex framework, so the resulting code is PHP.
Installation
------------

Here's examples how to use this project with docker

docker run -p <port-you-want>:80 -v /path/to/local/config.php:/var/www/html/config.php <image-id>

or with docker compose

project-name:
image: jnmik/crud-admin-generator:0.0.1
ports:
- <port-you-want>:80
volumes:
- /path/to/local/config.php:/var/www/html/config.php


Clone the repository

git clone https://github.com/jonseg/crud-admin-generator.git admingenerator
Expand All @@ -30,6 +44,10 @@ Install vendors:

php composer.phar install

Prepare your environment configs:

cp -f config.php.dist config.php

You need point the document root of your virtual host to /path_to/admingenerator/web

This is an example of VirtualHost:
Expand Down Expand Up @@ -57,7 +75,7 @@ You can customize the url using the .htaccess file, maybe this will help you:
Generate CRUD backend
---------------------

Edit the file /path_to/admingenerator/src/app.php and set your database conection data:
Edit the file config.php and set your database connection data:

$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
'dbs.options' => array(
Expand All @@ -83,6 +101,58 @@ For the url of your project, for example:

$app['asset_path'] = 'http://domain.com/crudadmin/resources';

There is also more optional customization you can do

// determine image path for image fields in database
// I.E field value would be image.jpg, result would be <img src="http://somepath/dist/images/image.jpg" />
$app['image_fields'] = array(
//'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(
//'main_table_name.main_table_field' => 'foreign_table_name.foreign_table_field'
);

// Allow user to add additional menu links
$app['menu_links'] = array(
//['name' => 'MENU NAME', 'url' => 'http://menu-url.com', 'fa-icon' => ''],
);

// Allow user to transform column with video url to player
$app['video_fields'] = array(
//'your_table_name.your_column' => '',
);

// add introduction text on list page
$app['table_intro'] = array(
//'your_table_name' => "some text"
);

// Allow user to add additional buttons in the action menu, to call external APIs
$app['call_to_action'] = array(
'synonyms' => array(
0 => array(
'btn_name' => 'btn name 1',
'method' => 'put',
'url' => 'http://some-url/1.0/route/{id}',
'data'=> json_encode(array(
'param' => value
)),
'callback' => 'refresh'
),
1 => array(
'btn_name' => 'btn name 2',
'method' => 'post',
'url' => 'http://some-url/1.0/route/{id}',
'data'=> json_encode(array(
'param' => value
)),
'callback' => 'refresh'
)
)
);

Now, execute the command that will generate the CRUD backend:

Expand All @@ -98,6 +168,8 @@ Customize the result
--------------------

The generated code is fully configurable and editable, you just have to edit the corresponding files.
However, this approach is not recommended. Doing so will prevent you from re-generating the admin, which might
be necessary in case you are doing changes to the database structure.

- The **controller** you can find it in **/web/controllers/TABLE_NAME/index.php**
- The **views** are in **/web/views/TABLE_NAME**
Expand Down Expand Up @@ -125,5 +197,9 @@ Author
* Twitter: *[@jonseg](https://twitter.com/jonseg)*
* CRUD Admin Generator webpage: [http://crud-admin-generator.com](http://crud-admin-generator.com)

Contributors
------------
* Jean-Michael Cyr


[1]: http://crud-admin-generator.com
16 changes: 16 additions & 0 deletions apache.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<VirtualHost *:80>

ServerName _
DocumentRoot /var/www/html/web

<Directory /var/www/html/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order deny,allow
Allow from all
</Directory>

#ErrorLog ${APACHE_LOG_DIR}/error.log
#CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>
7 changes: 7 additions & 0 deletions boot-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
!#/bin/bash

echo "Generate admin based on current mysql schema ... "
php console generate:admin

echo "Start supervisord ... "
/usr/bin/supervisord -n -c /etc/supervisord.conf
75 changes: 75 additions & 0 deletions config.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
$app->register(new Silex\Provider\DoctrineServiceProvider(), array(

'dbs.options' => array(
'db' => array(
'driver' => 'pdo_mysql',
'dbname' => 'DATABASE_NAME',
'host' => '127.0.0.1',
'user' => 'DATABASE_USER',
'password' => 'DATABASE_PASS',
'charset' => 'utf8',
),
)
));

$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 <img src="http://somepath/dist/images/image.jpg" />
$app['image_fields'] = array(
//'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(
//'main_table_name.main_table_field' => 'foreign_table_name.foreign_table_field'
);

// Allow user to add additional menu links
$app['menu_links'] = array(
//['name' => 'MENU NAME', 'url' => 'http://menu-url.com', 'fa-icon' => ''],
);

// Allow user to transform column with video url to player
$app['video_fields'] = array(
//'your_table_name.your_column' => '',
);

// add introduction text on list page
$app['table_intro'] = array(
//'your_table_name' => "some text"
);

$app['debug'] = true;
// array of REGEX column name to display for foreigner key insted of ID
// default used :'name','title','e?mail','username'
$app['usr_search_names_foreigner_key'] = array();

$app['call_to_action'] = array(
/*
'synonyms' => array(
0 => array(
'btn_name' => 'btn name 1',
'method' => 'put',
'url' => 'http://some-url/1.0/route/{id}',
'data'=> json_encode(array(
'param' => value
)),
'callback' => 'refresh'
),
1 => array(
'btn_name' => 'btn name 2',
'method' => 'post',
'url' => 'http://some-url/1.0/route/{id}',
'data'=> json_encode(array(
'param' => value
)),
'callback' => 'refresh'
)
)
*/
);
1 change: 1 addition & 0 deletions console
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require_once __DIR__.'/vendor/autoload.php';

$app = require __DIR__.'/src/app.php';
require_once(__DIR__.'/config.php');
$console = require __DIR__.'/src/console.php';
$console->run();

61 changes: 61 additions & 0 deletions docker/build-docker-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/bin/bash
name=jnmik/crud-admin-generator

version=
while [ -z $version ]; do
printf "\e[1;46mEnter the tag of your image:\e[0m ";
read -r version;
done

branch=$(git branch | grep '*')
echo -e "you are building an image from the following branch of your project : \e[1;41m${branch:2}\e[0m"
echo -e "your image will be \e[1;41m$name:$version\e[0m"
echo -e "do you want to continue? [Y/n]"
read accept

if [ "$accept" != "Y" ]; then
echo -e "\e[0;41mprocess aborted by user!\e[0m";
exit 1;
fi

echo -e "\e[1;30;43m-- Starting to build docker image --\e[0m"
docker build -t $name:$version .

if [ $? -ne 0 ];
then
echo -e "\e[0;41mTask build docker image failed and return an non 0 code. Abort!\e[0m";
exit 4;
else
echo -e "\e[0;42mTask build docker image successfully executed\e[0m"
fi

echo -e "Do you want to push the new image to the repository? [Y/n]"
read push

if [ "$push" != "Y" ]; then
echo -e "\e[0;42mDocker image will not be push. Use can use it localy! Process over.\e[0m";
exit 5;
fi

echo -e "\e[1;30;43m-- Starting to push image to docker hub --\e[0m"
docker push $name:$version

if [ $? -ne 0 ];
then
echo -e "\e[0;41mTask push docker image failed and return an non 0 code. Abort!\e[0m";
exit 6;
else
echo -e "\e[0;42mTask psuh docker image successfully executed\e[0m"
fi

echo -e "Build LATEST and push it ? [Y/n]"
read pushlatest

if [ "$pushlatest" != "Y" ]; then
echo -e "\e[0;42mLatest image will not be built & pushed. Process over.\e[0m";
exit 7;
fi

imageId=$(docker images | grep $name | grep $version | awk '{ print $3; }')
docker tag -f $imageId $name:latest
docker push $name:latest
2 changes: 1 addition & 1 deletion gen/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

require_once __DIR__.'/../../vendor/autoload.php';
require_once __DIR__.'/../../src/app.php';

require_once __DIR__.'/../../config.php';

__BASE_INCLUDES__

Expand Down
53 changes: 50 additions & 3 deletions gen/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
$whereClause = $whereClause . " OR";
}

$whereClause = $whereClause . " " . $col . " LIKE '%". $searchValue ."%'";
$whereClause = $whereClause . " `" . $col . "` LIKE '%". $searchValue ."%'";

$i = $i + 1;
}
Expand Down Expand Up @@ -137,11 +137,58 @@
__TABLECOLUMNS_ARRAY__
);

$primary_key = "__TABLE_PRIMARYKEY__";
$primary_key = "__TABLE_PRIMARYKEY__";

$image_tag_insertion = array();
$video_tag_insertion = array();
$call_to_action = array();
$table_intro = '';

foreach($table_columns as $idx => $table_column) {
if(isset($app['image_fields'])) {
if(isset($app['image_fields']['__TABLENAME__' . '.' . $table_column])) {
$image_tag_insertion[] = array(
'column_idx' => $idx,
'image_path' => $app['image_fields']['__TABLENAME__' . '.' . $table_column],
'column_name' => $table_column
);
}
}
if(isset($app['video_fields'])) {
if(isset($app['video_fields']['__TABLENAME__' . '.' . $table_column])) {
$video_tag_insertion[] = array(
'column_idx' => $idx,
'video_path' => $app['video_fields']['__TABLENAME__' . '.' . $table_column],
'column_name' => $table_column
);
}
}
}

if(isset($app['call_to_action'])) {
if(isset($app['call_to_action']['__TABLENAME__'])) {
$call_to_action = $app['call_to_action']['__TABLENAME__'];
}
}

if(isset($app['table_intro'])) {
if(isset($app['table_intro']['__TABLENAME__'])) {
$table_intro = $app['table_intro']['__TABLENAME__'];
}
}

if(!is_string($table_intro)) {
$table_intro = '';
}


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,
"video_tag_insertion" => $video_tag_insertion,
"call_to_action" => $call_to_action,
"table_intro" => $table_intro
));

})
Expand Down
Loading