Commit c6eb4c4b authored by bvipul's avatar bvipul

Refactoring Module Manager To a different Controller --pending

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