Skip to content

Commit

Permalink
resolved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
shivendra-webkul committed Jul 24, 2024
2 parents 31adef1 + db87a27 commit e900102
Show file tree
Hide file tree
Showing 12 changed files with 2,399 additions and 1,583 deletions.
54 changes: 27 additions & 27 deletions packages/Webkul/Admin/src/DataGrids/Settings/WorkflowDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

namespace Webkul\Admin\DataGrids\Settings;

use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;
use Webkul\UI\DataGrid\DataGrid;
use Webkul\DataGrid\DataGrid;

class WorkflowDataGrid extends DataGrid
{
/**
* Prepare query builder.
*
* @return void
*/
public function prepareQueryBuilder()
public function prepareQueryBuilder(): Builder
{
$queryBuilder = DB::table('workflows')
->addSelect(
Expand All @@ -22,51 +21,52 @@ public function prepareQueryBuilder()

$this->addFilter('id', 'workflows.id');

$this->setQueryBuilder($queryBuilder);
return $queryBuilder;
}

/**
* Add columns.
*
* @return void
* Prepare Columns.
*/
public function addColumns()
public function prepareColumns(): void
{
$this->addColumn([
'index' => 'id',
'label' => trans('admin::app.datagrid.id'),
'type' => 'string',
'sortable' => true,
'index' => 'id',
'label' => trans('admin::app.settings.workflows.index.datagrid.id'),
'type' => 'string',
'searchable' => true,
'filterable' => true,
'sortable' => true,
]);

$this->addColumn([
'index' => 'name',
'label' => trans('admin::app.datagrid.name'),
'type' => 'string',
'sortable' => true,
'index' => 'name',
'label' => trans('admin::app.settings.workflows.index.datagrid.name'),
'type' => 'string',
'searchable' => true,
'filterable' => true,
'sortable' => true,
]);
}

/**
* Prepare actions.
*
* @return void
*/
public function prepareActions()
public function prepareActions(): void
{
$this->addAction([
'title' => trans('ui::app.datagrid.edit'),
'index' => 'edit',
'icon' => 'icon-edit',
'title' => trans('admin::app.settings.workflows.index.datagrid.edit'),
'method' => 'GET',
'route' => 'admin.settings.workflows.edit',
'icon' => 'pencil-icon',
'url' => fn ($row) => route('admin.settings.workflows.edit', $row->id),
]);

$this->addAction([
'title' => trans('ui::app.datagrid.delete'),
'index' => 'delete',
'icon' => 'icon-delete',
'title' => trans('admin::app.settings.workflows.index.datagrid.delete'),
'method' => 'DELETE',
'route' => 'admin.settings.workflows.delete',
'confirm_text' => trans('ui::app.datagrid.mass-action.delete', ['resource' => 'type']),
'icon' => 'trash-icon',
'url' => fn ($row) => route('admin.settings.workflows.delete', $row->id),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace Webkul\Admin\Http\Controllers\Settings;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Event;
use Illuminate\View\View;
use Webkul\Admin\DataGrids\Settings\WorkflowDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Workflow\Repositories\WorkflowRepository;

Expand All @@ -17,34 +21,28 @@ public function __construct(protected WorkflowRepository $workflowRepository) {}

/**
* Display a listing of the workflow.
*
* @return \Illuminate\View\View
*/
public function index()
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return app(\Webkul\Admin\DataGrids\Settings\WorkflowDataGrid::class)->toJson();
return datagrid(WorkflowDataGrid::class)->process();
}

return view('admin::settings.workflows.index');
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\View\View
*/
public function create()
public function create(): View
{
return view('admin::settings.workflows.create');
}

/**
* Store a newly created workflow in storage.
*
* @return \Illuminate\Http\Response
*/
public function store()
public function store(): RedirectResponse
{
$this->validate(request(), [
'name' => 'required',
Expand All @@ -56,18 +54,15 @@ public function store()

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

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

return redirect()->route('admin.settings.workflows.index');
}

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

Expand All @@ -76,11 +71,8 @@ public function edit($id)

/**
* Update the specified workflow in storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update($id)
public function update(int $id): RedirectResponse
{
$this->validate(request(), [
'name' => 'required',
Expand All @@ -92,39 +84,36 @@ public function update($id)

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

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

return redirect()->route('admin.settings.workflows.index');
}

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

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

$this->workflowRepository->delete($id);
$workflow->delete($id);

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

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

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

// Workflows Routes
Route::prefix('workflows')->group(function () {
Route::get('', 'WorkflowController@index')->name('admin.settings.workflows.index');

Route::get('create', 'WorkflowController@create')->name('admin.settings.workflows.create');

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

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

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

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

// Tags Routes
Route::prefix('tags')->group(function () {
Route::get('', 'TagController@index')->name('admin.settings.tags.index');
Expand Down
Loading

0 comments on commit e900102

Please sign in to comment.