Commit c6eb4c4b authored by bvipul's avatar bvipul

Refactoring Module Manager To a different Controller --pending

parent e2e155d7
...@@ -22,3 +22,5 @@ Todo.rtf ...@@ -22,3 +22,5 @@ Todo.rtf
npm-debug.log npm-debug.log
yarn-error.log yarn-error.log
phpunit.txt phpunit.txt
public/css
public/js
...@@ -45,7 +45,7 @@ class DummyRepoName extends BaseRepository ...@@ -45,7 +45,7 @@ class DummyRepoName extends BaseRepository
public function create(array $input) public function create(array $input)
{ {
$dummy_small_model_name = self::MODEL; $dummy_small_model_name = self::MODEL;
if ($dummy_small_model_name->save()) { if ($dummy_small_model_name->save($input)) {
return true; return true;
} }
throw new GeneralException(trans('exceptions.backend.dummy_small_plural_model_name.create_error')); throw new GeneralException(trans('exceptions.backend.dummy_small_plural_model_name.create_error'));
...@@ -61,7 +61,7 @@ class DummyRepoName extends BaseRepository ...@@ -61,7 +61,7 @@ class DummyRepoName extends BaseRepository
*/ */
public function update(dummy_model_name $dummy_small_model_name, array $input) public function update(dummy_model_name $dummy_small_model_name, array $input)
{ {
if ($dummy_small_model_name->update()) if ($dummy_small_model_name->update($input))
return true; return true;
throw new GeneralException(trans('exceptions.backend.dummy_small_plural_model_name.update_error')); throw new GeneralException(trans('exceptions.backend.dummy_small_plural_model_name.update_error'));
......
...@@ -13,6 +13,7 @@ use Illuminate\Filesystem\Filesystem; ...@@ -13,6 +13,7 @@ use Illuminate\Filesystem\Filesystem;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use App\Http\Utilities\Generator;
class ModuleController extends Controller class ModuleController extends Controller
{ {
...@@ -21,6 +22,7 @@ class ModuleController extends Controller ...@@ -21,6 +22,7 @@ class ModuleController extends Controller
public $table; public $table;
public $repository; public $repository;
public $directory; public $directory;
public $generator;
public $attribute = 'Attribute'; public $attribute = 'Attribute';
public $trait_directory = 'Traits'; public $trait_directory = 'Traits';
public $relationship = 'Relationship'; public $relationship = 'Relationship';
...@@ -42,6 +44,7 @@ class ModuleController extends Controller ...@@ -42,6 +44,7 @@ class ModuleController extends Controller
{ {
$this->files = $files; $this->files = $files;
$this->repository = $repository; $this->repository = $repository;
$this->generator = new Generator();
} }
/** /**
...@@ -80,37 +83,19 @@ class ModuleController extends Controller ...@@ -80,37 +83,19 @@ class ModuleController extends Controller
*/ */
public function store(StoreModuleRequest $request) public function store(StoreModuleRequest $request)
{ {
//If Directory Name is available $this->generator->initialize($request->all());
if (!empty($request->directory_name)) { $this->generator->createMigration();
$this->directory = $request->directory_name; $this->generator->createModel();
$this->model_namespace .= $this->directory; $this->generator->createRequests();
$this->controller_namespace .= $this->directory; $this->generator->createRepository();
$this->event_namespace .= $this->directory; $this->generator->createController();
$this->view_path .= $this->directory; $this->generator->createTableController();
$this->repo_namespace .= $this->directory; $this->generator->createRouteFiles();
$this->request_namespace .= $this->directory; $this->generator->insertToLanguageFiles();
} $this->generator->createViewFiles();
//If Model name is given $this->generator->createEvents();
if (!empty($request->model_name)) {
$this->model = ucfirst($request->model_name);
}
$input = $request->all();
//If table name is given
if (!empty($request->table_name)) {
$this->table = $request->table_name;
//Creating Migration
$this->createMigration($input);
} else {
$this->table = strtolower(str_plural($this->model));
}
//Creating Model
$model = $this->createModel($input);
//Creating Controller
$this->createController($input, $model);
// //Creating Event And Listeners
$this->createEvents($input);
//Creating the Module //Creating the Module
$this->repository->create($input); $this->repository->create( $request->all(), $this->generator->getPermissions() );
return redirect()->route('admin.modules.index')->withFlashSuccess('Module Generated Successfully!'); return redirect()->route('admin.modules.index')->withFlashSuccess('Module Generated Successfully!');
} }
......
...@@ -42,29 +42,33 @@ class ModuleRepository extends BaseRepository ...@@ -42,29 +42,33 @@ class ModuleRepository extends BaseRepository
* *
* @return bool * @return bool
*/ */
public function create(array $input) public function create(array $input, array $permissions)
{ {
$module = Module::where('name', $input['name'])->first(); $module = Module::where('name', $input['name'])->first();
if (!$module) { if (!$module) {
$name = $input['model_name']; $name = $input['model_name'];
$model = strtolower($name); $model = strtolower($name);
$permissions = // $permissions =
[ // [
['name' => "view-$model-permission", 'display_name' => 'View '.ucwords($model).' Permission'], // ['name' => "view-$model-permission", 'display_name' => 'View '.ucwords($model).' Permission'],
['name' => "create-$model-permission", 'display_name' => 'Create '.ucwords($model).' Permission'], // ['name' => "create-$model-permission", 'display_name' => 'Create '.ucwords($model).' Permission'],
['name' => "edit-$model-permission", 'display_name' => 'Edit '.ucwords($model).' Permission'], // ['name' => "edit-$model-permission", 'display_name' => 'Edit '.ucwords($model).' Permission'],
['name' => "delete-$model-permission", 'display_name' => 'Delete '.ucwords($model).' Permission'], // ['name' => "delete-$model-permission", 'display_name' => 'Delete '.ucwords($model).' Permission'],
]; // ];
foreach ($permissions as $permission) { foreach ($permissions as $permission) {
$perm = [
'name' => $permission,
'display_name' => title_case( str_replace( '-', ' ', $permission ) ) . " Permission"
];
//Creating Permission //Creating Permission
$per = Permission::firstOrCreate($permission); $per = Permission::firstOrCreate($perm);
} }
$mod = [ $mod = [
'view_permission_id' => "view-$model-permission", 'view_permission_id' => "view-$model-permission",
'name' => $input['name'], 'name' => $input['name'],
'url' => 'admin.'.str_plural($model).'.index', 'url' => 'admin.' . str_plural( $model ) . '.index',
'created_by' => access()->user()->id, 'created_by' => access()->user()->id,
]; ];
......
...@@ -81,11 +81,11 @@ ...@@ -81,11 +81,11 @@
dom: 'lBfrtip', dom: 'lBfrtip',
buttons: { buttons: {
buttons: [ buttons: [
{ extend: 'copy', className: 'copyButton', exportOptions: {columns: [ 0, 1, 2, 3, 4 ] }}, { extend: 'copy', className: 'copyButton', exportOptions: {columns: [ 0, 1, 2 ] }},
{ extend: 'csv', className: 'csvButton', exportOptions: {columns: [ 0, 1, 2, 3, 4 ] }}, { extend: 'csv', className: 'csvButton', exportOptions: {columns: [ 0, 1, 2 ] }},
{ extend: 'excel', className: 'excelButton', exportOptions: {columns: [ 0, 1, 2, 3, 4 ] }}, { extend: 'excel', className: 'excelButton', exportOptions: {columns: [ 0, 1, 2 ] }},
{ extend: 'pdf', className: 'pdfButton', exportOptions: {columns: [ 0, 1, 2, 3, 4 ] }}, { extend: 'pdf', className: 'pdfButton', exportOptions: {columns: [ 0, 1, 2 ] }},
{ extend: 'print', className: 'printButton', exportOptions: {columns: [ 0, 1, 2, 3, 4 ] }} { extend: 'print', className: 'printButton', exportOptions: {columns: [ 0, 1, 2 ] }}
] ]
} }
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment