mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on CRUD
This commit is contained in:
parent
2762debd59
commit
bb55beaa64
@ -49,6 +49,7 @@ class MakeModule extends Command
|
|||||||
Artisan::call('module:make-model', ['model' => $name, 'module' => $name]);
|
Artisan::call('module:make-model', ['model' => $name, 'module' => $name]);
|
||||||
|
|
||||||
Artisan::call('ninja:make-datatable', ['name' => $name, 'module' => $name]);
|
Artisan::call('ninja:make-datatable', ['name' => $name, 'module' => $name]);
|
||||||
|
Artisan::call('ninja:make-repository', ['name' => $name, 'module' => $name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getArguments()
|
protected function getArguments()
|
||||||
|
70
app/Console/Commands/MakeRepository.php
Normal file
70
app/Console/Commands/MakeRepository.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
|
||||||
|
use Nwidart\Modules\Commands\GeneratorCommand;
|
||||||
|
use Nwidart\Modules\Support\Stub;
|
||||||
|
use Nwidart\Modules\Traits\ModuleCommandTrait;
|
||||||
|
|
||||||
|
class MakeRepository extends GeneratorCommand
|
||||||
|
{
|
||||||
|
use ModuleCommandTrait;
|
||||||
|
|
||||||
|
protected $argumentName = 'name';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $name = 'ninja:make-repository';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Create repository stub';
|
||||||
|
|
||||||
|
protected function getArguments()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['name', InputArgument::REQUIRED, 'The name of the datatable.'],
|
||||||
|
['module', InputArgument::OPTIONAL, 'The name of module will be used.'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTemplateContents()
|
||||||
|
{
|
||||||
|
$module = $this->laravel['modules']->findOrFail($this->getModuleName());
|
||||||
|
|
||||||
|
return (new Stub('/repository.stub', [
|
||||||
|
'NAMESPACE' => $this->getClassNamespace($module) . "\\" . config('modules.paths.generator.repository'),
|
||||||
|
'LOWER_NAME' => $module->getLowerName(),
|
||||||
|
'CLASS' => $this->getClass(),
|
||||||
|
'STUDLY_NAME' => Str::studly($module->getLowerName()),
|
||||||
|
]))->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDestinationFilePath()
|
||||||
|
{
|
||||||
|
$path = $this->laravel['modules']->getModulePath($this->getModuleName());
|
||||||
|
$seederPath = $this->laravel['modules']->config('paths.generator.repository');
|
||||||
|
|
||||||
|
return $path . $seederPath . '/' . $this->getFileName() . '.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function getFileName()
|
||||||
|
{
|
||||||
|
return studly_case($this->argument('name')) . 'Repository';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,14 +2,27 @@
|
|||||||
|
|
||||||
namespace $CLASS_NAMESPACE$;
|
namespace $CLASS_NAMESPACE$;
|
||||||
|
|
||||||
|
use Auth;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\Routing\Controller;
|
use Illuminate\Routing\Controller;
|
||||||
use App\Http\Controllers\BaseController;
|
use App\Http\Controllers\BaseController;
|
||||||
|
use App\Services\DatatableService;
|
||||||
|
use Modules\$STUDLY_NAME$\Repositories\$STUDLY_NAME$Repository;
|
||||||
use Modules\$STUDLY_NAME$\Datatables\$STUDLY_NAME$Datatable;
|
use Modules\$STUDLY_NAME$\Datatables\$STUDLY_NAME$Datatable;
|
||||||
|
|
||||||
class $CLASS$ extends BaseController
|
class $CLASS$ extends BaseController
|
||||||
{
|
{
|
||||||
|
protected $$STUDLY_NAME$Repo;
|
||||||
|
//protected $entityType = '$LOWER_NAME$';
|
||||||
|
|
||||||
|
public function __construct($STUDLY_NAME$Repository $$LOWER_NAME$Repo)
|
||||||
|
{
|
||||||
|
//parent::__construct();
|
||||||
|
|
||||||
|
$this->$LOWER_NAME$Repo = $$LOWER_NAME$Repo;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the resource.
|
* Display a listing of the resource.
|
||||||
* @return Response
|
* @return Response
|
||||||
@ -23,6 +36,17 @@ class $CLASS$ extends BaseController
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDatatable(DatatableService $datatableService)
|
||||||
|
{
|
||||||
|
$search = request()->input('test');
|
||||||
|
$userId = Auth::user()->filterId();
|
||||||
|
|
||||||
|
$datatable = new $STUDLY_NAME$Datatable();
|
||||||
|
$query = $this->$LOWER_NAME$Repo->find($search, $userId);
|
||||||
|
|
||||||
|
return $datatableService->createDatatable($datatable, $query);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new resource.
|
* Show the form for creating a new resource.
|
||||||
* @return Response
|
* @return Response
|
||||||
|
@ -12,5 +12,6 @@
|
|||||||
"files": [
|
"files": [
|
||||||
"start.php"
|
"start.php"
|
||||||
],
|
],
|
||||||
"icon": "th-large"
|
"icon": "th-large",
|
||||||
|
"plural": "$LOWER_NAME$"
|
||||||
}
|
}
|
||||||
|
78
app/Console/Commands/stubs/repository.stub
Normal file
78
app/Console/Commands/stubs/repository.stub
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Ninja\Repositories;
|
||||||
|
|
||||||
|
use DB;
|
||||||
|
use App\Models\$STUDLY_NAME$;
|
||||||
|
//use App\Events\$STUDLY_NAME$WasCreated;
|
||||||
|
//use App\Events\$STUDLY_NAME$WasUpdated;
|
||||||
|
|
||||||
|
class $STUDLY_NAME$Repository extends BaseRepository
|
||||||
|
{
|
||||||
|
public function getClassName()
|
||||||
|
{
|
||||||
|
return '$NAMESPACE$\$STUDLY_NAME$';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function find($filter = null, $userId = false)
|
||||||
|
{
|
||||||
|
$query = DB::table('$LOWER_NAME$')
|
||||||
|
->where('$LOWER_NAME$.account_id', '=', \Auth::user()->account_id)
|
||||||
|
->select(
|
||||||
|
'$LOWER_NAME$.public_id',
|
||||||
|
'$LOWER_NAME$.deleted_at',
|
||||||
|
'$LOWER_NAME$.is_deleted',
|
||||||
|
'$LOWER_NAME$.user_id'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->applyFilters($query, '$LOWER_NAME$');
|
||||||
|
|
||||||
|
/*
|
||||||
|
if ($filter) {
|
||||||
|
$query->where(function ($query) use ($filter) {
|
||||||
|
$query->where('clients.name', 'like', '%'.$filter.'%')
|
||||||
|
->orWhere('contacts.first_name', 'like', '%'.$filter.'%')
|
||||||
|
->orWhere('contacts.last_name', 'like', '%'.$filter.'%')
|
||||||
|
->orWhere('contacts.email', 'like', '%'.$filter.'%');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($userId) {
|
||||||
|
$query->where('clients.user_id', '=', $userId);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save($data, $client = null)
|
||||||
|
{
|
||||||
|
$publicId = isset($data['public_id']) ? $data['public_id'] : false;
|
||||||
|
|
||||||
|
if ($client) {
|
||||||
|
// do nothing
|
||||||
|
} elseif (!$publicId || $publicId == '-1') {
|
||||||
|
$client = Client::createNew();
|
||||||
|
} else {
|
||||||
|
$client = Client::scope($publicId)->with('contacts')->firstOrFail();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($client->is_deleted) {
|
||||||
|
return $client;
|
||||||
|
}
|
||||||
|
|
||||||
|
$client->fill($data);
|
||||||
|
$client->save();
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (!$publicId || $publicId == '-1') {
|
||||||
|
event(new ClientWasCreated($client));
|
||||||
|
} else {
|
||||||
|
event(new ClientWasUpdated($client));
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
return $client;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -4,3 +4,8 @@ Route::group(['middleware' => 'auth', 'prefix' => '$LOWER_NAME$', 'namespace' =>
|
|||||||
{
|
{
|
||||||
Route::get('/', '$STUDLY_NAME$Controller@index');
|
Route::get('/', '$STUDLY_NAME$Controller@index');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Route::group(['middleware' => 'auth', 'namespace' => '$MODULE_NAMESPACE$\$STUDLY_NAME$\Http\Controllers'], function()
|
||||||
|
{
|
||||||
|
Route::get('api/$LOWER_NAME$', '$STUDLY_NAME$Controller@getDatatable');
|
||||||
|
});
|
||||||
|
@ -25,6 +25,7 @@ class Kernel extends ConsoleKernel
|
|||||||
'App\Console\Commands\TestOFX',
|
'App\Console\Commands\TestOFX',
|
||||||
'App\Console\Commands\MakeModule',
|
'App\Console\Commands\MakeModule',
|
||||||
'App\Console\Commands\MakeDatatable',
|
'App\Console\Commands\MakeDatatable',
|
||||||
|
'App\Console\Commands\MakeRepository',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -121,7 +121,7 @@ class ClientController extends BaseController
|
|||||||
'gatewayLink' => $token ? $token->gatewayLink() : false,
|
'gatewayLink' => $token ? $token->gatewayLink() : false,
|
||||||
'gatewayName' => $token ? $token->gatewayName() : false,
|
'gatewayName' => $token ? $token->gatewayName() : false,
|
||||||
];
|
];
|
||||||
|
|
||||||
return View::make('clients.show', $data);
|
return View::make('clients.show', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,6 +431,12 @@ class Utils
|
|||||||
|
|
||||||
public static function pluralizeEntityType($type)
|
public static function pluralizeEntityType($type)
|
||||||
{
|
{
|
||||||
|
if ( ! Utils::isNinjaProd()) {
|
||||||
|
if ($module = \Module::find($type)) {
|
||||||
|
return $module->get('plural', $type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($type === ENTITY_EXPENSE_CATEGORY) {
|
if ($type === ENTITY_EXPENSE_CATEGORY) {
|
||||||
return 'expense_categories';
|
return 'expense_categories';
|
||||||
} else {
|
} else {
|
||||||
|
@ -24,7 +24,7 @@ return [
|
|||||||
|
|
||||||
'stubs' => [
|
'stubs' => [
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
'path' => base_path() . '/storage/stubs',
|
'path' => base_path() . '/app/Console/Commands/stubs',
|
||||||
'files' => [
|
'files' => [
|
||||||
'start' => 'start.php',
|
'start' => 'start.php',
|
||||||
'routes' => 'Http/routes.php',
|
'routes' => 'Http/routes.php',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user