Skip to content

Commit

Permalink
Merge pull request #1288 from shivendra-webkul/krayin-update
Browse files Browse the repository at this point in the history
Added roles page translation and compleate types page
  • Loading branch information
jitendra-webkul authored Jul 22, 2024
2 parents d9edfb7 + 559347e commit b9bfe96
Show file tree
Hide file tree
Showing 8 changed files with 381 additions and 110 deletions.
4 changes: 3 additions & 1 deletion packages/Webkul/Admin/src/DataGrids/Setting/TypeDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ public function prepareColumns(): void
public function prepareActions(): void
{
$this->addAction([
'index' => 'edit',
'icon' => 'icon-edit',
'title' => trans('admin::app.settings.roles.index.datagrid.edit'),
'method' => 'GET',
'url' => function ($row) {
return route('admin.settings.types.edit', $row->id);
return route('admin.settings.types.update', $row->id);
},
]);

$this->addAction([
'index' => 'delete',
'icon' => 'icon-delete',
'title' => trans('admin::app.settings.roles.index.datagrid.delete'),
'method' => 'DELETE',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Validator;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Setting\TypeDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
Expand Down Expand Up @@ -33,96 +32,79 @@ public function index(): View|JsonResponse

/**
* Store a newly created type in storage.
*
* @return \Illuminate\Http\Response
*/
public function store()
public function store(): JsonResponse
{
$validator = Validator::make(request()->all(), [
'name' => 'required|unique:lead_types,name',
$this->validate(request(), [
'name' => ['required', 'unique:lead_types,name'],
]);

if ($validator->fails()) {
session()->flash('error', trans('admin::app.settings.types.name-exists'));

return redirect()->back();
}

Event::dispatch('settings.type.create.before');

$type = $this->typeRepository->create(request()->all());
$type = $this->typeRepository->create(request()->only(['name']));

Event::dispatch('settings.type.create.after', $type);

session()->flash('success', trans('admin::app.settings.types.create-success'));

return redirect()->route('admin.settings.types.index');
return new JsonResponse([
'data' => $type,
'message' => trans('admin::app.settings.types.index.create-success'),
]);
}

/**
* Show the form for editing the specified type.
*
* @param int $id
* @return \Illuminate\View\View
*/
public function edit($id)
public function edit(int $id): View|JsonResponse
{
$type = $this->typeRepository->findOrFail($id);

return view('admin::settings.types.edit', compact('type'));
return new JsonResponse([
'data' => $type,
]);
}

/**
* Update the specified type in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update($id)
public function update(int $id): JsonResponse
{
$this->validate(request(), [
'name' => 'required|unique:lead_types,name,'.$id,
]);

Event::dispatch('settings.type.update.before', $id);

$type = $this->typeRepository->update(request()->all(), $id);
$type = $this->typeRepository->update(request()->only(['name']), $id);

Event::dispatch('settings.type.update.after', $type);

session()->flash('success', trans('admin::app.settings.types.update-success'));

return redirect()->route('admin.settings.types.index');
return new JsonResponse([
'data' => $type,
'message' => trans('admin::app.settings.types.index.update-success'),
]);
}

/**
* Remove the specified type from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
public function destroy(int $id): JsonResponse
{
$type = $this->typeRepository->findOrFail($id);

try {
Event::dispatch('settings.type.delete.before', $id);

$this->typeRepository->delete($id);
$type->delete($id);

Event::dispatch('settings.type.delete.after', $id);

return response()->json([
'message' => trans('admin::app.settings.types.delete-success'),
return new JsonResponse([
'message' => trans('admin::app.settings.types.index.delete-success'),
], 200);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.settings.types.delete-failed'),
return new JsonResponse([
'message' => trans('admin::app.settings.types.index.delete-failed'),
], 400);
}

return response()->json([
'message' => trans('admin::app.settings.types.delete-failed'),
], 400);
}
}
12 changes: 0 additions & 12 deletions packages/Webkul/Admin/src/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,18 +352,6 @@
Route::delete('{id}', 'SourceController@destroy')->name('admin.settings.sources.delete');
});

// Lead Types Routes
Route::prefix('types')->group(function () {
Route::get('', 'TypeController@index')->name('admin.settings.types.index');

Route::post('create', 'TypeController@store')->name('admin.settings.types.store');

Route::get('edit/{id?}', 'TypeController@edit')->name('admin.settings.types.edit');

Route::put('edit/{id}', 'TypeController@update')->name('admin.settings.types.update');

Route::delete('{id}', 'TypeController@destroy')->name('admin.settings.types.delete');
});

// Email Templates Routes
Route::prefix('email-templates')->group(function () {
Expand Down
3 changes: 3 additions & 0 deletions packages/Webkul/Admin/src/Providers/AdminServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Webkul\Admin\Http\Middleware\Locale;
use Illuminate\Support\Facades\Route;

class AdminServiceProvider extends ServiceProvider
{
Expand All @@ -18,6 +19,8 @@ public function boot(Router $router): void
{
include __DIR__.'/../Http/helpers.php';

Route::middleware('web')->group(__DIR__.'/../Routes/web.php');

$this->loadRoutesFrom(__DIR__.'/../Http/routes.php');

$this->loadMigrationsFrom(__DIR__.'/../Database/Migrations');
Expand Down
75 changes: 75 additions & 0 deletions packages/Webkul/Admin/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,11 @@
'id' => 'ID',
'name' => 'Name',
],

'edit' => [
'title' => 'Edit Group',
],

'create' => [
'name' => 'Name',
'title' => 'Create Group',
Expand All @@ -157,6 +159,79 @@
],
],
],

'roles' => [
'index' => [
'create-btn' => 'Create Roles',
'title' => 'Roles',
'settings' => 'Settings',
'datagrid' => [
'all' => 'All',
'custom' => 'Custom',
'delete' => 'Delete',
'description' => 'Description',
'edit' => 'Edit',
'id' => 'ID',
'name' => 'Name',
'permission-type' => 'Permission Type',
],
],

'create' => [
'access-control' => 'Access Control',
'all' => 'All',
'back-btn' => 'Back',
'custom' => 'Custom',
'description' => 'Description',
'general' => 'General',
'name' => 'Name',
'permissions' => 'Permissions',
'save-btn' => 'Save Role',
'title' => 'Create Role',
],

'edit' => [
'access-control' => 'Access Control',
'all' => 'All',
'back-btn' => 'Back',
'custom' => 'Custom',
'description' => 'Description',
'general' => 'General',
'name' => 'Name',
'permissions' => 'Permissions',
'save-btn' => 'Save Role',
'title' => 'Edit Role',
],
],

'types' => [
'index' => [
'create-btn' => 'Create Type',
'title' => 'Types',
'create-success' => 'Type created successfully.',
'update-success' => 'Type updated successfully.',
'delete-success' => 'Type deleted successfully.',
'delete-failed' => 'Type can not be deleted.',

'datagrid' => [
'delete' => 'Delete',
'description' => 'Description',
'edit' => 'Edit',
'id' => 'ID',
'name' => 'Name',
],

'create' => [
'name' => 'Name',
'save-btn' => 'Save Type',
'title' => 'Create Type',
],

'edit' => [
'title' => 'Edit Type',
],
],
],
],

// ----------------------------------------------------------------Old version locale ----------------------------------
Expand Down
Loading

0 comments on commit b9bfe96

Please sign in to comment.