mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-18 00:53:10 +01:00
Working on CRUD
This commit is contained in:
parent
ce724fe1c9
commit
ce4571a187
@ -34,18 +34,20 @@ class MakeClass extends GeneratorCommand
|
|||||||
protected function getArguments()
|
protected function getArguments()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
['name', InputArgument::REQUIRED, 'The name of the datatable.'],
|
['name', InputArgument::REQUIRED, 'The name of the module.'],
|
||||||
['module', InputArgument::REQUIRED, 'The name of module will be used.'],
|
['module', InputArgument::REQUIRED, 'The name of module will be used.'],
|
||||||
['class', InputArgument::REQUIRED, 'The name of the class.'],
|
['class', InputArgument::REQUIRED, 'The name of the class.'],
|
||||||
|
['prefix', InputArgument::OPTIONAL, 'The prefix of the class.'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTemplateContents()
|
public function getTemplateContents()
|
||||||
{
|
{
|
||||||
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||||
|
$path = str_replace('/', '\\', config('modules.paths.generator.' . $this->argument('class')));
|
||||||
|
|
||||||
return (new Stub('/' . $this->argument('class') . '.stub', [
|
return (new Stub('/' . $this->argument('prefix') . $this->argument('class') . '.stub', [
|
||||||
'NAMESPACE' => $this->getClassNamespace($module) . "\\" . config('modules.paths.generator.' . $this->argument('class')),
|
'NAMESPACE' => $this->getClassNamespace($module) . "\\" . $path,
|
||||||
'LOWER_NAME' => $module->getLowerName(),
|
'LOWER_NAME' => $module->getLowerName(),
|
||||||
'CLASS' => $this->getClass(),
|
'CLASS' => $this->getClass(),
|
||||||
'STUDLY_NAME' => Str::studly($module->getLowerName()),
|
'STUDLY_NAME' => Str::studly($module->getLowerName()),
|
||||||
@ -65,7 +67,7 @@ class MakeClass extends GeneratorCommand
|
|||||||
*/
|
*/
|
||||||
protected function getFileName()
|
protected function getFileName()
|
||||||
{
|
{
|
||||||
return studly_case($this->argument('name')) . Str::studly($this->argument('class'));
|
return studly_case($this->argument('prefix')) . studly_case($this->argument('name')) . Str::studly($this->argument('class'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,11 @@ class MakeModule extends Command
|
|||||||
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'repository']);
|
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'repository']);
|
||||||
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'policy']);
|
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'policy']);
|
||||||
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'auth-provider']);
|
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'auth-provider']);
|
||||||
|
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'presenter']);
|
||||||
|
|
||||||
|
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request']);
|
||||||
|
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request', 'prefix' => 'create']);
|
||||||
|
Artisan::call('ninja:make-class', ['name' => $name, 'module' => $name, 'class' => 'request', 'prefix' => 'edit']);
|
||||||
|
|
||||||
Artisan::call('module:dump');
|
Artisan::call('module:dump');
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ class $CLASS$ extends BaseController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDatatable(DatatableService $datatableService)
|
public function datatable(DatatableService $datatableService)
|
||||||
{
|
{
|
||||||
$search = request()->input('test');
|
$search = request()->input('test');
|
||||||
$userId = Auth::user()->filterId();
|
$userId = Auth::user()->filterId();
|
||||||
@ -70,20 +70,37 @@ class $CLASS$ extends BaseController
|
|||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$client = $this->$LOWER_NAME$Repo->save($request->input());
|
$$LOWER_NAME$ = $this->$LOWER_NAME$Repo->save($request->input());
|
||||||
|
|
||||||
Session::flash('message', trans('texts.created_$LOWER_NAME$'));
|
return redirect()->to($$LOWER_NAME$->present()->editUrl)
|
||||||
|
->with('message', trans('texts.created_$LOWER_NAME$'));
|
||||||
return redirect()->to($$LOWER_NAME$->getRoute());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function edit()
|
public function edit($STUDLY_NAME$Request $request)
|
||||||
{
|
{
|
||||||
return view('$LOWER_NAME$::edit');
|
$$LOWER_NAME$ = $request->entity();
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'$LOWER_NAME$' => $$LOWER_NAME$,
|
||||||
|
'method' => 'PUT',
|
||||||
|
'url' => '$LOWER_NAME$/' . $$LOWER_NAME$->public_id,
|
||||||
|
'title' => trans('texts.edit_$LOWER_NAME$'),
|
||||||
|
];
|
||||||
|
|
||||||
|
return view('$LOWER_NAME$::edit', $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the form for editing a resource.
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
|
public function show(Request $request)
|
||||||
|
{
|
||||||
|
return redirect()->to("$LOWER_NAME$/{$request->$LOWER_NAME$}/edit");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
28
app/Console/Commands/stubs/createrequest.stub
Normal file
28
app/Console/Commands/stubs/createrequest.stub
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace $NAMESPACE$;
|
||||||
|
|
||||||
|
class Create$CLASS$Request extends $CLASS$Request
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->can('create', '$LOWER_NAME$');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -14,9 +14,21 @@ class $CLASS$ extends EntityModel
|
|||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $presenter = 'App\Ninja\Presenters\$CLASS$Presenter';
|
protected $presenter = 'Modules\$CLASS$\Presenters\$CLASS$Presenter';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected $fillable = $FILLABLE$;
|
protected $fillable = $FILLABLE$;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected $table = '$LOWER_NAME$';
|
protected $table = '$LOWER_NAME$';
|
||||||
|
|
||||||
|
public function getEntityType()
|
||||||
|
{
|
||||||
|
return '$LOWER_NAME$';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
10
app/Console/Commands/stubs/presenter.stub
Normal file
10
app/Console/Commands/stubs/presenter.stub
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace $NAMESPACE$;
|
||||||
|
|
||||||
|
use App\Ninja\Presenters\EntityPresenter;
|
||||||
|
|
||||||
|
class $STUDLY_NAME$Presenter extends EntityPresenter
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -22,6 +22,7 @@ class $STUDLY_NAME$Repository extends BaseRepository
|
|||||||
->select(
|
->select(
|
||||||
'$LOWER_NAME$.public_id',
|
'$LOWER_NAME$.public_id',
|
||||||
'$LOWER_NAME$.deleted_at',
|
'$LOWER_NAME$.deleted_at',
|
||||||
|
'$LOWER_NAME$.created_at',
|
||||||
'$LOWER_NAME$.is_deleted',
|
'$LOWER_NAME$.is_deleted',
|
||||||
'$LOWER_NAME$.user_id'
|
'$LOWER_NAME$.user_id'
|
||||||
);
|
);
|
||||||
@ -56,7 +57,7 @@ class $STUDLY_NAME$Repository extends BaseRepository
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$entity->fill($data);
|
//$entity->fill($data);
|
||||||
$entity->save();
|
$entity->save();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -2,29 +2,9 @@
|
|||||||
|
|
||||||
namespace $NAMESPACE$;
|
namespace $NAMESPACE$;
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use App\Http\Requests\EntityRequest;
|
||||||
|
|
||||||
class $CLASS$ extends FormRequest
|
class $CLASS$Request extends EntityRequest
|
||||||
{
|
{
|
||||||
/**
|
protected $entityType = '$LOWER_NAME$';
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function rules()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function authorize()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -3,5 +3,5 @@
|
|||||||
Route::group(['middleware' => 'auth', 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'], function()
|
Route::group(['middleware' => 'auth', 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'], function()
|
||||||
{
|
{
|
||||||
Route::resource('$LOWER_NAME$', '$STUDLY_NAME$Controller');
|
Route::resource('$LOWER_NAME$', '$STUDLY_NAME$Controller');
|
||||||
Route::get('api/$LOWER_NAME$', '$STUDLY_NAME$Controller@getDatatable');
|
Route::get('api/$LOWER_NAME$', '$STUDLY_NAME$Controller@datatable');
|
||||||
});
|
});
|
||||||
|
28
app/Console/Commands/stubs/updaterequest.stub
Normal file
28
app/Console/Commands/stubs/updaterequest.stub
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace $NAMESPACE$;
|
||||||
|
|
||||||
|
class Update$CLASS$Request extends $CLASS$Request
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return $this->user()->can('edit', '$LOWER_NAME$');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
<?php namespace App\Ninja\Presenters;
|
<?php namespace App\Ninja\Presenters;
|
||||||
|
|
||||||
|
use Utils;
|
||||||
use URL;
|
use URL;
|
||||||
use Laracasts\Presenter\Presenter;
|
use Laracasts\Presenter\Presenter;
|
||||||
|
|
||||||
@ -10,13 +11,18 @@ class EntityPresenter extends Presenter
|
|||||||
*/
|
*/
|
||||||
public function url()
|
public function url()
|
||||||
{
|
{
|
||||||
$type = $this->entity->getEntityType();
|
$type = Utils::pluralizeEntityType($this->entity->getEntityType());
|
||||||
$id = $this->entity->public_id;
|
$id = $this->entity->public_id;
|
||||||
$link = sprintf('/%ss/%s', $type, $id);
|
$link = sprintf('/%s/%s', $type, $id);
|
||||||
|
|
||||||
return URL::to($link);
|
return URL::to($link);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function editUrl()
|
||||||
|
{
|
||||||
|
return $this->url() . '/edit';
|
||||||
|
}
|
||||||
|
|
||||||
public function statusLabel()
|
public function statusLabel()
|
||||||
{
|
{
|
||||||
$class = $text = '';
|
$class = $text = '';
|
||||||
|
@ -116,6 +116,7 @@ return [
|
|||||||
'datatable' => 'Datatables',
|
'datatable' => 'Datatables',
|
||||||
'policy' => 'Policies',
|
'policy' => 'Policies',
|
||||||
'auth-provider' => 'AuthProviders',
|
'auth-provider' => 'AuthProviders',
|
||||||
|
'presenter' => 'Presenters',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user