From 7aa17c2d3c2c90f71a074aec866302a13449e1df Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Wed, 12 Apr 2023 17:06:33 +0700 Subject: [PATCH] update modeule directorat --- app/DataTables/DirectoratDataTable.php | 19 +-- app/Http/Controllers/DirectoratController.php | 26 ++-- app/Http/Requests/StoreDirectoratRequest.php | 23 ++- app/Http/Requests/UpdateDirectoratRequest.php | 23 ++- app/Models/Directorat.php | 2 +- composer.json | 2 + composer.lock | 131 +++++++++++++++++- config/app.php | 1 - ..._04_10_024720_create_directorats_table.php | 2 +- ...10_024731_create_sub_directorats_table.php | 4 +- .../2023_04_10_024809_create_jobs_table.php | 4 +- ...023_04_10_024820_create_sub_jobs_table.php | 2 +- resources/views/layout/master.blade.php | 16 +++ .../sidebar-layout/_page-title.blade.php | 10 +- .../sidebar-layout/_toolbar.blade.php | 15 +- .../masters/directorat/_action.blade.php | 13 ++ .../pages/masters/directorat/_form.blade.php | 70 ++++++++++ .../pages/masters/directorat/_table.blade.php | 66 +++++++-- .../pages/masters/directorat/index.blade.php | 128 ++++++++++++++--- 19 files changed, 471 insertions(+), 86 deletions(-) create mode 100644 resources/views/pages/masters/directorat/_form.blade.php diff --git a/app/DataTables/DirectoratDataTable.php b/app/DataTables/DirectoratDataTable.php index 42d008e..5a1c7e2 100644 --- a/app/DataTables/DirectoratDataTable.php +++ b/app/DataTables/DirectoratDataTable.php @@ -26,15 +26,15 @@ class DirectoratDataTable extends DataTable if (request()->has('search')) { $search = request()->get('search'); $query->where('kode', 'like', "%" . $search['value'] . "%") - ->orWhere('nama', 'like', "%" . $search['value'] . "%"); + ->orWhere('name', 'like', "%" . $search['value'] . "%"); } }) ->addIndexColumn() ->addColumn('kode', function ($model) { return $model->kode; }) - ->addColumn('nama', function ($model) { - return $model->nama; + ->addColumn('name', function ($model) { + return $model->name; }) ->addColumn('action', 'pages.masters.directorat._action') ->setRowId('id'); @@ -57,15 +57,10 @@ class DirectoratDataTable extends DataTable ->setTableId('directorat-table') ->columns($this->getColumns()) ->minifiedAjax() + ->stateSave(false) + ->responsive() + ->autoWidth(true) ->orderBy(1) - ->selectStyleSingle() - ->buttons([ - Button::make('excel'), - Button::make('csv'), - Button::make('pdf'), - Button::make('print'), - Button::make('reload') - ]) ->parameters([ 'scrollX' => true, 'drawCallback' => 'function() { KTMenu.createInstances(); }', @@ -81,7 +76,7 @@ class DirectoratDataTable extends DataTable return [ Column::make('DT_RowIndex')->title('No')->orderable(false)->searchable(false), Column::make('kode'), - Column::make('nama'), + Column::make('name'), Column::make('created_at'), Column::make('updated_at'), Column::computed('action') diff --git a/app/Http/Controllers/DirectoratController.php b/app/Http/Controllers/DirectoratController.php index a6e114f..bb8a62a 100644 --- a/app/Http/Controllers/DirectoratController.php +++ b/app/Http/Controllers/DirectoratController.php @@ -35,13 +35,7 @@ class DirectoratController extends Controller /** * Show the form for creating a new resource. */ - public function create() - { - /*if (is_null($this->user) || !$this->user->can('masters.create')) { - abort(403, 'Sorry !! You are Unauthorized to create any master data !'); - }*/ - return view('pages.masters.directorat.create'); - } + public function create(){} /** * Store a newly created resource in storage. @@ -52,6 +46,7 @@ class DirectoratController extends Controller abort(403, 'Sorry !! You are Unauthorized to create any master data !'); }*/ + // Validate the request... $validated = $request->validated(); @@ -59,9 +54,11 @@ class DirectoratController extends Controller if($validated){ try{ Directorat::create($validated); - return redirect()->route('directorat.index')->with('success', 'Directorat created successfully.'); + //return redirect()->route('directorat.index')->with('success', 'Directorat created successfully.'); + echo json_encode(['status' => 'success', 'message' => 'Directorat created successfully.']); }catch(\Exception $e){ - return redirect()->route('directorat.index')->with('error', 'Directorat created failed.'); + //return redirect()->route('directorat.index')->with('error', 'Directorat created failed.'); + echo json_encode(['status' => 'error', 'message' => 'Directorat created failed.']); } } @@ -79,10 +76,9 @@ class DirectoratController extends Controller /** * Show the form for editing the specified resource. */ - public function edit($id) - { + public function edit($id){ $directorat = Directorat::find($id); - return view('pages.masters.directorat.edit', compact('directorat')); + echo json_encode($directorat); } /** @@ -101,9 +97,11 @@ class DirectoratController extends Controller if($validated){ try{ $directorat->update($validated); - return redirect()->route('directorat.index')->with('success', 'Directorat updated successfully.'); + //return redirect()->route('directorat.index')->with('success', 'Directorat updated successfully.'); + echo json_encode(['status' => 'success', 'message' => 'Directorat updated successfully.']); }catch(\Exception $e){ - return redirect()->route('directorat.index')->with('error', 'Directorat updated failed.'); + //return redirect()->route('directorat.index')->with('error', 'Directorat updated failed.'); + echo json_encode(['status' => 'error', 'message' => 'Directorat updated failed.']); } } diff --git a/app/Http/Requests/StoreDirectoratRequest.php b/app/Http/Requests/StoreDirectoratRequest.php index f5b7382..ca42eed 100644 --- a/app/Http/Requests/StoreDirectoratRequest.php +++ b/app/Http/Requests/StoreDirectoratRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Validation\Validator; class StoreDirectoratRequest extends FormRequest { @@ -11,7 +12,7 @@ class StoreDirectoratRequest extends FormRequest */ public function authorize(): bool { - return false; + return true; } /** @@ -22,7 +23,25 @@ class StoreDirectoratRequest extends FormRequest public function rules(): array { return [ - // + 'kode' => 'required|string|max:2|min:2|unique:directorats,kode', + 'name' => 'required|string|max:50' ]; } + + /** + * Configure the validator instance. + */ + public function withValidator(Validator $validator): void + { + $validator->after(function (Validator $validator) { + if($validator->errors()->any()) { + $error = json_decode($validator->errors()->toJson(), true); + foreach ($error as $key => $value) { + flash( $value[0]); + } + + return redirect()->route('directorat.index')->with('error', 'Directorat created failed.'); + } + }); + } } diff --git a/app/Http/Requests/UpdateDirectoratRequest.php b/app/Http/Requests/UpdateDirectoratRequest.php index 61a1379..360bb67 100644 --- a/app/Http/Requests/UpdateDirectoratRequest.php +++ b/app/Http/Requests/UpdateDirectoratRequest.php @@ -3,6 +3,7 @@ namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Validation\Validator; class UpdateDirectoratRequest extends FormRequest { @@ -11,7 +12,7 @@ class UpdateDirectoratRequest extends FormRequest */ public function authorize(): bool { - return false; + return true; } /** @@ -22,7 +23,25 @@ class UpdateDirectoratRequest extends FormRequest public function rules(): array { return [ - // + 'kode' => 'required|string|max:2|min:2|unique:directorats,kode,'.$this->id, + 'name' => 'required|string|max:50' ]; } + + /** + * Configure the validator instance. + */ + public function withValidator(Validator $validator): void + { + $validator->after(function (Validator $validator) { + if($validator->errors()->any()) { + $error = json_decode($validator->errors()->toJson(), true); + foreach ($error as $key => $value) { + flash( $value[0]); + } + + return redirect()->route('directorat.index')->with('error', 'Directorat updated failed.'); + } + }); + } } diff --git a/app/Models/Directorat.php b/app/Models/Directorat.php index 10bcd04..6c09ad1 100644 --- a/app/Models/Directorat.php +++ b/app/Models/Directorat.php @@ -14,7 +14,7 @@ class Directorat extends Model protected $fillable = [ 'kode', - 'nama' + 'name' ]; public function getActivitylogOptions(): LogOptions diff --git a/composer.json b/composer.json index 470b640..0d67670 100644 --- a/composer.json +++ b/composer.json @@ -7,9 +7,11 @@ "require": { "php": "^8.0.2", "guzzlehttp/guzzle": "^7.2", + "laracasts/flash": "^3.2", "laravel/framework": "^10.0", "laravel/sanctum": "^3.0", "laravel/tinker": "^2.7", + "laravelcollective/html": "^6.4", "spatie/laravel-activitylog": "^4.7", "yajra/laravel-datatables": "^10.0", "yajra/laravel-datatables-oracle": "^10.3.1" diff --git a/composer.lock b/composer.lock index 92d32f6..5d8df37 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "13056cf887653c387f2ff134ce499ad0", + "content-hash": "b9f7e562d6d509796b8064720f017880", "packages": [ { "name": "brick/math", @@ -1041,6 +1041,63 @@ ], "time": "2021-10-07T12:57:01+00:00" }, + { + "name": "laracasts/flash", + "version": "3.2.2", + "source": { + "type": "git", + "url": "https://github.com/laracasts/flash.git", + "reference": "6330bc3c027d3c03188b41c58133016f8226b8fb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laracasts/flash/zipball/6330bc3c027d3c03188b41c58133016f8226b8fb", + "reference": "6330bc3c027d3c03188b41c58133016f8226b8fb", + "shasum": "" + }, + "require": { + "illuminate/support": "~5.0|^6.0|^7.0|^8.0|^9.0|^10.0", + "php": ">=5.4.0" + }, + "require-dev": { + "mockery/mockery": "dev-master", + "phpunit/phpunit": "^6.1|^9.5.10" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Laracasts\\Flash\\FlashServiceProvider" + ], + "aliases": { + "Flash": "Laracasts\\Flash\\Flash" + } + } + }, + "autoload": { + "files": [ + "src/Laracasts/Flash/functions.php" + ], + "psr-0": { + "Laracasts\\Flash": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jeffrey Way", + "email": "jeffrey@laracasts.com" + } + ], + "description": "Easy flash notifications", + "support": { + "source": "https://github.com/laracasts/flash/tree/3.2.2" + }, + "time": "2023-01-30T20:31:40+00:00" + }, { "name": "laravel/framework", "version": "v10.7.1", @@ -1434,6 +1491,78 @@ }, "time": "2023-02-15T16:40:09+00:00" }, + { + "name": "laravelcollective/html", + "version": "v6.4.0", + "source": { + "type": "git", + "url": "https://github.com/LaravelCollective/html.git", + "reference": "ac74f580459a5120079b8def0404e5d312a09504" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/LaravelCollective/html/zipball/ac74f580459a5120079b8def0404e5d312a09504", + "reference": "ac74f580459a5120079b8def0404e5d312a09504", + "shasum": "" + }, + "require": { + "illuminate/http": "^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/routing": "^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/session": "^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0", + "illuminate/view": "^6.0|^7.0|^8.0|^9.0|^10.0", + "php": ">=7.2.5" + }, + "require-dev": { + "illuminate/database": "^6.0|^7.0|^8.0|^9.0|^10.0", + "mockery/mockery": "~1.0", + "phpunit/phpunit": "~8.5|^9.5.10" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.x-dev" + }, + "laravel": { + "providers": [ + "Collective\\Html\\HtmlServiceProvider" + ], + "aliases": { + "Form": "Collective\\Html\\FormFacade", + "Html": "Collective\\Html\\HtmlFacade" + } + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Collective\\Html\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Adam Engebretson", + "email": "adam@laravelcollective.com" + }, + { + "name": "Taylor Otwell", + "email": "taylorotwell@gmail.com" + } + ], + "description": "HTML and Form Builders for the Laravel Framework", + "homepage": "https://laravelcollective.com", + "support": { + "issues": "https://github.com/LaravelCollective/html/issues", + "source": "https://github.com/LaravelCollective/html" + }, + "time": "2023-02-13T18:15:35+00:00" + }, { "name": "league/commonmark", "version": "2.4.0", diff --git a/config/app.php b/config/app.php index 3703e0c..78912cd 100644 --- a/config/app.php +++ b/config/app.php @@ -181,7 +181,6 @@ return [ Illuminate\Translation\TranslationServiceProvider::class, Illuminate\Validation\ValidationServiceProvider::class, Illuminate\View\ViewServiceProvider::class, - /* * Package Service Providers... */ diff --git a/database/migrations/2023_04_10_024720_create_directorats_table.php b/database/migrations/2023_04_10_024720_create_directorats_table.php index 6295294..98b7b8e 100644 --- a/database/migrations/2023_04_10_024720_create_directorats_table.php +++ b/database/migrations/2023_04_10_024720_create_directorats_table.php @@ -14,7 +14,7 @@ return new class extends Migration Schema::create('directorats', function (Blueprint $table) { $table->id(); $table->string('kode',2); - $table->string('nama',50); + $table->string('name',50); $table->timestamps(); $table->softDeletes(); }); diff --git a/database/migrations/2023_04_10_024731_create_sub_directorats_table.php b/database/migrations/2023_04_10_024731_create_sub_directorats_table.php index 4196455..ce32fad 100644 --- a/database/migrations/2023_04_10_024731_create_sub_directorats_table.php +++ b/database/migrations/2023_04_10_024731_create_sub_directorats_table.php @@ -13,9 +13,9 @@ return new class extends Migration { Schema::create('sub_directorats', function (Blueprint $table) { $table->id(); - $table->foreignId('directorate_id'); + $table->foreignId('directorat_id'); $table->string('kode',2); - $table->string('nama',50); + $table->string('name',50); $table->timestamps(); $table->softDeletes(); }); diff --git a/database/migrations/2023_04_10_024809_create_jobs_table.php b/database/migrations/2023_04_10_024809_create_jobs_table.php index b0d7471..56a6e26 100644 --- a/database/migrations/2023_04_10_024809_create_jobs_table.php +++ b/database/migrations/2023_04_10_024809_create_jobs_table.php @@ -13,9 +13,9 @@ return new class extends Migration { Schema::create('jobs', function (Blueprint $table) { $table->id(); - $table->foreignId('sub_directorate_id'); + $table->foreignId('sub_directorat_id'); $table->string('kode',2); - $table->string('nama',50); + $table->string('name',50); $table->timestamps(); $table->softDeletes(); }); diff --git a/database/migrations/2023_04_10_024820_create_sub_jobs_table.php b/database/migrations/2023_04_10_024820_create_sub_jobs_table.php index a6c4f68..a0f5d4f 100644 --- a/database/migrations/2023_04_10_024820_create_sub_jobs_table.php +++ b/database/migrations/2023_04_10_024820_create_sub_jobs_table.php @@ -15,7 +15,7 @@ return new class extends Migration $table->id(); $table->foreignId('job_id'); $table->string('kode',2); - $table->string('nama',50); + $table->string('name',50); $table->timestamps(); $table->softDeletes(); }); diff --git a/resources/views/layout/master.blade.php b/resources/views/layout/master.blade.php index 230f3c4..abc04a3 100644 --- a/resources/views/layout/master.blade.php +++ b/resources/views/layout/master.blade.php @@ -70,6 +70,22 @@ @yield('scripts') @stack('customscript') + + diff --git a/resources/views/layout/partials/sidebar-layout/_page-title.blade.php b/resources/views/layout/partials/sidebar-layout/_page-title.blade.php index 1248ea5..d1f19aa 100644 --- a/resources/views/layout/partials/sidebar-layout/_page-title.blade.php +++ b/resources/views/layout/partials/sidebar-layout/_page-title.blade.php @@ -1,13 +1,17 @@
+ @php + $route = explode('.',Route::currentRouteName()); + @endphp + -

Multipurpose

+

List {{ $route[0] }}

diff --git a/resources/views/layout/partials/sidebar-layout/_toolbar.blade.php b/resources/views/layout/partials/sidebar-layout/_toolbar.blade.php index cc19724..5031fd7 100644 --- a/resources/views/layout/partials/sidebar-layout/_toolbar.blade.php +++ b/resources/views/layout/partials/sidebar-layout/_toolbar.blade.php @@ -3,16 +3,19 @@
@include(config('settings.KT_THEME_LAYOUT_DIR').'/partials/sidebar-layout/_page-title') - -
- - Rollover - + @php + $route = explode('.',Route::currentRouteName()); + @endphp + + @if($route[1] == 'index') + + + @endif
diff --git a/resources/views/pages/masters/directorat/_action.blade.php b/resources/views/pages/masters/directorat/_action.blade.php index e69de29..a763751 100644 --- a/resources/views/pages/masters/directorat/_action.blade.php +++ b/resources/views/pages/masters/directorat/_action.blade.php @@ -0,0 +1,13 @@ +@php + $route = explode('.', Route::currentRouteName()); +@endphp +
+ + {!! getIcon("pencil", "fs-1 text-info","duotune") !!} + + + {!! Form::open(['method' => 'DELETE','route' => [$route[0].'.destroy', $model->id],'class'=>'']) !!} + {{ Form::button(getIcon("trash", "fs-1 text-danger","duotune"), ['type' => 'submit', 'class' => 'delete btn btn-icon btn-bg-light btn-active-light-danger btn-sm'] ) }} + {!! Form::close() !!} +
diff --git a/resources/views/pages/masters/directorat/_form.blade.php b/resources/views/pages/masters/directorat/_form.blade.php new file mode 100644 index 0000000..08736c5 --- /dev/null +++ b/resources/views/pages/masters/directorat/_form.blade.php @@ -0,0 +1,70 @@ +@php + $route = explode('.', Route::currentRouteName()); +@endphp + + + + diff --git a/resources/views/pages/masters/directorat/_table.blade.php b/resources/views/pages/masters/directorat/_table.blade.php index 0cd3518..e1c39ac 100644 --- a/resources/views/pages/masters/directorat/_table.blade.php +++ b/resources/views/pages/masters/directorat/_table.blade.php @@ -8,23 +8,38 @@ @endsection @push('customscript') - + @php + $route = explode('.', Route::currentRouteName()); + @endphp + + @endpush