Skip to content

Commit

Permalink
Merge pull request #1670 from krayin/2.0
Browse files Browse the repository at this point in the history
feat: 2.0 updates
  • Loading branch information
devansh-webkul authored Oct 8, 2024
2 parents e1ec37c + 2154b96 commit b0a91fc
Show file tree
Hide file tree
Showing 63 changed files with 776 additions and 711 deletions.
4 changes: 2 additions & 2 deletions packages/Webkul/Admin/src/Config/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@
'icon-class' => 'icon-settings-mail',
], [
'key' => 'settings.automation.webhooks',
'name' => 'Webhooks',
'info' => 'Add Edit Delete Webhooks from CRM',
'name' => 'admin::app.layouts.webhooks',
'info' => 'admin::app.layouts.webhooks-info',
'route' => 'admin.settings.webhooks.index',
'sort' => 2,
'icon-class' => 'icon-settings-webhooks',
Expand Down
18 changes: 13 additions & 5 deletions packages/Webkul/Admin/src/DataGrids/Settings/AttributeDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;
use Webkul\Attribute\Repositories\AttributeRepository;
use Webkul\DataGrid\DataGrid;

class AttributeDataGrid extends DataGrid
Expand Down Expand Up @@ -66,17 +67,24 @@ public function prepareColumns(): void
'index' => 'entity_type',
'label' => trans('admin::app.settings.attributes.index.datagrid.entity-type'),
'type' => 'string',
'sortable' => true,
'searchable' => false,
'filterable' => true,
'closure' => fn ($row) => ucfirst($row->entity_type),
]);

$this->addColumn([
'index' => 'type',
'label' => trans('admin::app.settings.attributes.index.datagrid.type'),
'type' => 'string',
'sortable' => true,
'filterable' => true,
'index' => 'type',
'label' => trans('admin::app.settings.attributes.index.datagrid.type'),
'type' => 'string',
'sortable' => true,
'filterable' => true,
'filterable_type' => 'dropdown',
'filterable_options' => app(AttributeRepository::class)
->select('type as label', 'type as value')
->distinct()
->get()
->toArray(),
]);

$this->addColumn([
Expand Down
36 changes: 11 additions & 25 deletions packages/Webkul/Admin/src/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@ public function render($request, Throwable $exception)
return parent::render($request, $exception);
}

/**
* Report the exception.
*
* @return void
*/
public function report(Throwable $exception)
{
//
}

/**
* Convert an authentication exception into a response.
*
Expand All @@ -84,48 +74,44 @@ protected function unauthenticated($request, AuthenticationException $exception)
*/
private function renderCustomResponse(Throwable $exception)
{
$path = request()->routeIs('admin.*') ? 'admin' : 'front';

if ($path == 'front') {
return redirect()->route('admin.session.create');
}

if ($exception instanceof HttpException) {
$statusCode = in_array($exception->getStatusCode(), [401, 403, 404, 503])
? $exception->getStatusCode()
: 500;

return $this->response($path, $statusCode);
return $this->response($statusCode);
}

if ($exception instanceof ValidationException) {
return parent::render(request(), $exception);
}

if ($exception instanceof ModelNotFoundException) {
return $this->response($path, 404);
return $this->response(404);
} elseif ($exception instanceof PDOException || $exception instanceof \ParseError) {
return $this->response($path, 500);
return $this->response(500);
} else {
return $this->response(500);
}
}

/**
* Return custom response.
*
* @param string $path
* @param string $statusCode
* @param string $errorCode
* @return mixed
*/
private function response($path, $statusCode)
private function response($errorCode)
{
if (request()->expectsJson()) {
return response()->json([
'message' => isset($this->jsonErrorMessages[$statusCode])
? $this->jsonErrorMessages[$statusCode]
'message' => isset($this->jsonErrorMessages[$errorCode])
? $this->jsonErrorMessages[$errorCode]
: trans('admin::app.common.something-went-wrong'),
], $statusCode);
], $errorCode);
}

return response()->view("{$path}::errors.{$statusCode}", [], $statusCode);
return response()->view('admin::errors.index', compact('errorCode'));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Webkul\Activity\Repositories\FileRepository;
use Webkul\Admin\DataGrids\Activity\ActivityDataGrid;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\Admin\Http\Requests\MassDestroyRequest;
use Webkul\Admin\Http\Requests\MassUpdateRequest;
use Webkul\Admin\Http\Resources\ActivityResource;
use Webkul\Attribute\Repositories\AttributeRepository;
Expand Down Expand Up @@ -184,9 +185,13 @@ public function massUpdate(MassUpdateRequest $massUpdateRequest): JsonResponse
*/
public function download(int $id): StreamedResponse
{
$file = $this->fileRepository->findOrFail($id);
try {
$file = $this->fileRepository->findOrFail($id);

return Storage::download($file->path);
return Storage::download($file->path);
} catch (\Exception $exception) {
abort(404);
}
}

/*
Expand Down Expand Up @@ -216,9 +221,9 @@ public function destroy(int $id): JsonResponse
/**
* Mass Delete the specified resources.
*/
public function massDestroy(MassUpdateRequest $massUpdateRequest): JsonResponse
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
{
$activities = $this->activityRepository->findWhereIn('id', $massUpdateRequest->input('indices'));
$activities = $this->activityRepository->findWhereIn('id', $massDestroyRequest->input('indices'));

try {
foreach ($activities as $activity) {
Expand All @@ -230,11 +235,11 @@ public function massDestroy(MassUpdateRequest $massUpdateRequest): JsonResponse
}

return response()->json([
'message' => trans('admin::app.response.destroy-success'),
'message' => trans('admin::app.activities.mass-destroy-success'),
]);
} catch (\Exception $exception) {
return response()->json([
'message' => trans('admin::app.response.destroy-failed'),
'message' => trans('admin::app.activities.mass-delete-failed'),
], 400);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public function get(): JsonResponse

$stage->lead_value = (clone $query)->sum('lead_value');

$data[$stage->id] = (new StageResource($stage))->jsonSerialize();
$data[$stage->sort_order] = (new StageResource($stage))->jsonSerialize();

$data[$stage->id]['leads'] = [
$data[$stage->sort_order]['leads'] = [
'data' => LeadResource::collection($paginator = $query->with([
'tags',
'type',
Expand Down
1 change: 1 addition & 0 deletions packages/Webkul/Admin/src/Http/Resources/StageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function toArray($request)
'lead_value' => $this->lead_value,
'formatted_lead_value' => core()->formatBasePrice($this->lead_value),
'is_user_defined' => $this->is_user_defined,
'sort_order' => $this->sort_order,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
Expand Down
Loading

0 comments on commit b0a91fc

Please sign in to comment.