Skip to content

Commit

Permalink
Update Role datagrid
Browse files Browse the repository at this point in the history
  • Loading branch information
shivendra-webkul committed Jul 19, 2024
1 parent 08caac2 commit 992321c
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 62 deletions.
76 changes: 43 additions & 33 deletions packages/Webkul/Admin/src/DataGrids/Setting/RoleDataGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
namespace Webkul\Admin\DataGrids\Setting;

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

class RoleDataGrid extends DataGrid
{
use ProvideDropdownOptions;

/**
* Prepare query builder.
*
* @return void
*/
public function prepareQueryBuilder()
public function prepareQueryBuilder(): Builder
{
$queryBuilder = DB::table('roles')
->addSelect(
Expand All @@ -26,67 +22,81 @@ public function prepareQueryBuilder()
);

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

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

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

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

$this->addColumn([
'index' => 'description',
'label' => trans('admin::app.datagrid.description'),
'label' => trans('admin::app.settings.roles.index.datagrid.description'),
'type' => 'string',
'sortable' => false,
]);

$this->addColumn([
'index' => 'permission_type',
'label' => trans('admin::app.datagrid.permission_type'),
'type' => 'dropdown',
'dropdown_options' => $this->getRoleDropdownOptions(),
'sortable' => false,
'index' => 'permission_type',
'label' => trans('admin::app.settings.roles.index.datagrid.permission-type'),
'type' => 'string',
'searchable' => true,
'filterable' => true,
'filterable_type' => 'dropdown',
'filterable_options' => [
[
'label' => trans('admin::app.settings.roles.index.datagrid.custom'),
'value' => 'custom',
],
[
'label' => trans('admin::app.settings.roles.index.datagrid.all'),
'value' => 'all',
],
],
'sortable' => true,
]);
}

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

$this->addAction([
'title' => trans('ui::app.datagrid.delete'),
'method' => 'DELETE',
'route' => 'admin.settings.roles.delete',
'confirm_text' => trans('ui::app.datagrid.mass-action.delete', ['resource' => 'user']),
'icon' => 'trash-icon',
'icon' => 'icon-delete',
'title' => trans('admin::app.settings.roles.index.datagrid.delete'),
'method' => 'DELETE',
'url' => function ($row) {
return route('admin.settings.roles.delete', $row->id);
},
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
namespace Webkul\Admin\Http\Controllers\Setting;

use Illuminate\Support\Facades\Event;
use Illuminate\Http\JsonResponse;
use Illuminate\View\View;
use Webkul\Admin\Http\Controllers\Controller;
use Webkul\User\Repositories\RoleRepository;
use Webkul\Admin\DataGrids\Setting\RoleDataGrid;

class RoleController extends Controller
{
Expand All @@ -22,10 +25,10 @@ public function __construct(protected RoleRepository $roleRepository)
*
* @return \Illuminate\View\View
*/
public function index()
public function index(): View|JsonResponse
{
if (request()->ajax()) {
return app(\Webkul\Admin\DataGrids\Setting\RoleDataGrid::class)->toJson();
return datagrid(RoleDataGrid::class)->process();
}

return view('admin::settings.roles.index');
Expand Down
22 changes: 20 additions & 2 deletions packages/Webkul/Admin/src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,26 @@
'id' => 'ID',
'name' => 'Name',
],
]
]
],
],

'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',
],
],
],
],

// ----------------------------------------------------------------Old version locale ----------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
@extends('admin::layouts.master')
<x-admin::layouts>
<x-slot:title>
@lang('admin::app.settings.roles.index.title')
</x-slot>

@section('page_title')
{{ __('admin::app.settings.roles.title') }}
@stop
<div class="flex items-center justify-between rounded-lg border border-gray-200 bg-white px-4 py-2 text-sm dark:border-gray-800 dark:bg-gray-900 dark:text-gray-300">
<div class="flex flex-col">
<div class="flex cursor-pointer items-center">
<i class="icon-left-arrow text-2xl text-gray-800"></i>

@section('content-wrapper')
<div class="content full-page">
<table-component data-src="{{ route('admin.settings.roles.index') }}">
<template v-slot:table-header>
<h1>
{!! view_render_event('admin.settings.roles.index.header.before') !!}
<a
href="{{ route('admin.settings.roles.index') }}"
class="text-xs text-gray-800 dark:text-gray-300"
>
@lang('admin::app.settings.roles.index.settings')
</a>
</div>

{{ Breadcrumbs::render('settings.roles') }}
<div class="pl-3 text-xl font-normal dark:text-gray-300">
@lang('admin::app.settings.roles.index.title')
</div>
</div>

{{ __('admin::app.settings.roles.title') }}
<div class="flex items-center gap-x-2.5">
<!-- Create button Roles -->
<div class="flex items-center gap-x-2.5">
{!! view_render_event('krayin.admin.settings.roles.index.create_button.before') !!}
@if (bouncer()->hasPermission('settings.user.roles.create'))
<a
href="{{ route('admin.settings.roles.create') }}"
class="primary-button"
>
@lang('admin::app.products.index.create-btn')
</a>
@endif
{!! view_render_event('krayin.admin.settings.roles.index.create_button.after') !!}
</div>
</div>
</div>

{!! view_render_event('admin.settings.roles.index.header.after') !!}
</h1>
</template>
{!! view_render_event('krayin.admin.settings.roles.index.datagrid.before') !!}

@if (bouncer()->hasPermission('settings.user.roles.create'))
<template v-slot:table-action>
<a href="{{ route('admin.settings.roles.create') }}" class="btn btn-md btn-primary">
{{ __('admin::app.settings.roles.create-title') }}
</a>
</template>
@endif
<table-component>
</div>
@stop
<x-admin::datagrid src="{{ route('admin.settings.roles.index') }}" />

{!! view_render_event('krayin.admin.settings.roles.index.datagrid.after') !!}
</x-admin::layouts>

0 comments on commit 992321c

Please sign in to comment.