Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng-admin and RESTful API #412

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 5 additions & 1 deletion app/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@
'Zizaco\Entrust\EntrustServiceProvider', // Entrust Provider for roles
'Bllim\Datatables\DatatablesServiceProvider', // Datatables

/* Laravel ng-admin Required */
'Marcelgwerder\ApiHandler\ApiHandlerServiceProvider',

/* Uncomment for use in development */
// 'Way\Generators\GeneratorsServiceProvider', // Generators
// 'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider', // IDE Helpers
Expand Down Expand Up @@ -191,7 +194,8 @@
'String' => 'Andrew13\Helpers\String', // String
'Carbon' => 'Carbon\Carbon', // Carbon
'Datatables' => 'Bllim\Datatables\Datatables', // DataTables

/* ng-admin Require */
'ApiHandler' => 'Marcelgwerder\ApiHandler\Facades\ApiHandler',
),

'available_language' => array('en', 'pt', 'es'),
Expand Down
157 changes: 157 additions & 0 deletions app/config/packages/barryvdh/laravel-debugbar/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php

use Illuminate\Support\Facades\Config;

return array(

/*
|--------------------------------------------------------------------------
| Debugbar Settings
|--------------------------------------------------------------------------
|
| Debugbar is enabled by default, when debug is set to true in app.php.
|
*/

'enabled' => Config::get('app.debug'),

/*
|--------------------------------------------------------------------------
| Storage settings
|--------------------------------------------------------------------------
|
| DebugBar stores data for session/ajax requests.
| You can disable this, so the debugbar stores data in headers/session,
| but this can cause problems with large data collectors.
| By default, file storage (in the storage folder) is used. Redis and PDO
| can also be used. For PDO, run the package migrations first.
|
*/
'storage' => array(
'enabled' => true,
'driver' => 'file', // redis, file, pdo
'path' => storage_path() . '/debugbar', // For file driver
'connection' => null, // Leave null for default connection (Redis/PDO)
),

/*
|--------------------------------------------------------------------------
| Vendors
|--------------------------------------------------------------------------
|
| Vendor files are included by default, but can be set to false.
| This can also be set to 'js' or 'css', to only include javascript or css vendor files.
| Vendor files are for css: font-awesome (including fonts) and highlight.js (css files)
| and for js: jquery and and highlight.js
| So if you want syntax highlighting, set it to true.
| jQuery is set to not conflict with existing jQuery scripts.
|
*/

'include_vendors' => true,

/*
|--------------------------------------------------------------------------
| Capture Ajax Requests
|--------------------------------------------------------------------------
|
| The Debugbar can capture Ajax requests and display them. If you don't want this (ie. because of errors),
| you can use this option to disable sending the data through the headers.
|
*/

'capture_ajax' => true,

/*
|--------------------------------------------------------------------------
| Capture Console Commands
|--------------------------------------------------------------------------
|
| The Debugbar can listen to Artisan commands. You can view them with the browse button in the Debugbar.
|
*/

'capture_console' => false,

/*
|--------------------------------------------------------------------------
| DataCollectors
|--------------------------------------------------------------------------
|
| Enable/disable DataCollectors
|
*/

'collectors' => array(
'phpinfo' => true, // Php version
'messages' => true, // Messages
'time' => true, // Time Datalogger
'memory' => true, // Memory usage
'exceptions' => true, // Exception displayer
'log' => true, // Logs from Monolog (merged in messages if enabled)
'db' => true, // Show database (PDO) queries and bindings
'views' => true, // Views with their data
'route' => true, // Current route information
'laravel' => false, // Laravel version and environment
'events' => false, // All events fired
'default_request' => false, // Regular or special Symfony request logger
'symfony_request' => true, // Only one can be enabled..
'mail' => true, // Catch mail messages
'logs' => false, // Add the latest log messages
'files' => false, // Show the included files
'config' => false, // Display config settings
'auth' => false, // Display Laravel authentication status
'session' => false, // Display session data in a separate tab
),

/*
|--------------------------------------------------------------------------
| Extra options
|--------------------------------------------------------------------------
|
| Configure some DataCollectors
|
*/

'options' => array(
'auth' => array(
'show_name' => false, // Also show the users name/email in the debugbar
),
'db' => array(
'with_params' => true, // Render SQL with the parameters substituted
'timeline' => false, // Add the queries to the timeline
'backtrace' => false, // EXPERIMENTAL: Use a backtrace to find the origin of the query in your files.
'explain' => array( // EXPERIMENTAL: Show EXPLAIN output on queries
'enabled' => false,
'types' => array('SELECT'), // array('SELECT', 'INSERT', 'UPDATE', 'DELETE'); for MySQL 5.6.3+
),
'hints' => true, // Show hints for common mistakes
),
'mail' => array(
'full_log' => false
),
'views' => array(
'data' => false, //Note: Can slow down the application, because the data can be quite large..
),
'route' => array(
'label' => true // show complete route on bar
),
'logs' => array(
'file' => null
),
),

/*
|--------------------------------------------------------------------------
| Inject Debugbar in Response
|--------------------------------------------------------------------------
|
| Usually, the debugbar is added just before <body>, by listening to the
| Response after the App is done. If you disable this, you have to add them
| in your template yourself. See http://phpdebugbar.com/docs/rendering.html
|
*/

'inject' => true,

);
3 changes: 3 additions & 0 deletions app/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ public function __construct()
{
parent::__construct();
}
public function ngadmin(){
return View::make('admin.ngadmin');
}

}
2 changes: 1 addition & 1 deletion app/controllers/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class BaseController extends Controller {
*/
public function __construct()
{
$this->beforeFilter('csrf', array('on' => 'post'));
$this->beforeFilter('csrf', ['on' => ['post', 'put', 'patch', 'delete']]);
}

/**
Expand Down
92 changes: 92 additions & 0 deletions app/controllers/api/APIController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

class APIController extends BaseController {

/**
* Initializer.
*
* @return \APIController
*/
public function __construct()
{
parent::__construct();

}

/**
* Transform ng-admin request into Laravel Api Handler
* @param $table_name
* @return array
*/
public function passParams($table_name){
//Print out all table's columns
$columns = Schema::getColumnListing($table_name);
$params = [
'_limit' => 10,
'_offset' => 0,
];
// If have _sort is a valid column
if (in_array(Input::get('_sort'), $columns))
{
// Default sortDir is ASC
$sortDir = (!empty(Input::get('_sortDir'))) ? Input::get('_sortDir') : 'ASC';
// ASC --> null DESC --> -
$sort = ($sortDir === 'ASC' ) ? '' : '-';
$sort .= Input::get('_sort');
$params ['_sort'] = $sort;
}
if (!empty(Input::get('page')) && !empty(Input::get('per_page')))
{
$params['_limit'] = Input::get('per_page');
$params['_offset'] = (Input::get('page') - 1)*Input::get('per_page');
}
if (!empty(Input::get('q')) && Input::get('q') != '{}')
{
$query = json_decode(Input::get('q'));
$params['_q'] = $query->query;
}

foreach ($columns as $column)
{
// Use strlen == 0 instead of !empty to prevent boolean filter broken
if (strlen(Input::get($column)) != 0)
{
$params[$column] = Input::get($column);
}
}
// Return number of total rows in query (for pagination)
$params ['_config'] = 'meta-filter-count';
return $params;
}

/**
* Make a quick response with pagination supported
* @param $response
* @param $statusCode
* @param $builder
* @return mixed
*/
public function makeResponse($response,$statusCode, $builder){
return Response::json($response,$statusCode)->header('X-Total-Count', $builder->getHeaders()['Meta-Filter-Count']);
}

/* Testing purpose
public function returnIndex($eloquentModel, $fulltext = [], $table_name){
try{
$statusCode = 200;
$builder = ApiHandler::parseMultiple($eloquentModel, $fulltext = [], $this->passParams($table_name));
$users = $builder->getResult();
$response = [];

foreach($users as $user){
$response[] = $this->responseMap($user);
}

return Response::json($response,$statusCode)->header('X-Total-Count', $builder->getHeaders()['Meta-Filter-Count']);
} catch (Exception $e){
$statusCode = 500;
$message = $e->getMessage();
return Response::json($message, $statusCode);
}
}*/
}
Loading