From ba87dd13606e7a9da452f8f48664b809a3425e4f Mon Sep 17 00:00:00 2001
From: Julian Prieber <60265788+JulianPrieber@users.noreply.github.com>
Date: Fri, 20 Oct 2023 00:29:37 +0200
Subject: [PATCH 01/10] Livewire Table
---
app/Http/Livewire/UserTable.php | 127 ++++++++++++
config/livewire-tables.php | 8 +
config/livewire.php | 158 +++++++++++++++
.../table-components/action.blade.php | 39 ++++
resources/views/layouts/sidebar.blade.php | 3 +-
resources/views/panel/users.blade.php | 183 ++----------------
6 files changed, 347 insertions(+), 171 deletions(-)
create mode 100644 app/Http/Livewire/UserTable.php
create mode 100644 config/livewire-tables.php
create mode 100644 config/livewire.php
create mode 100644 resources/views/components/table-components/action.blade.php
diff --git a/app/Http/Livewire/UserTable.php b/app/Http/Livewire/UserTable.php
new file mode 100644
index 0000000..eff6be9
--- /dev/null
+++ b/app/Http/Livewire/UserTable.php
@@ -0,0 +1,127 @@
+setPrimaryKey('id');
+ }
+
+ public function columns(): array
+ {
+ return [
+ Column::make("Id", "id")
+ ->sortable()
+ ->searchable(),
+ Column::make("Name", "name")
+ ->sortable()
+ ->searchable(),
+ Column::make("Email", "email")
+ ->sortable()
+ ->searchable(),
+ Column::make("Littlelink name", "littlelink_name")
+ ->sortable()
+ ->searchable()
+ ->format(function ($value, $row, Column $column) {
+ if (!$row->littlelink_name == NULL) {
+ return "littlelink_name . "' target='_blank' class='text-info'> " . $row->littlelink_name . " ";
+ } else {
+ return 'N/A';
+ }
+ })
+ ->html(),
+ Column::make("Role", "role")
+ ->sortable()
+ ->searchable(),
+ Column::make("Test", "id")
+ ->sortable()
+ ->format(function ($value, $row) {
+ $linkCount = Link::where('user_id', $row->id)->count();
+ return $linkCount;
+ }),
+ Column::make("Clicks Sum", "id")
+ ->sortable()
+ ->format(function ($value, $row) {
+ $clicksSum = Link::where('user_id', $row->id)->sum('click_number');
+ return $clicksSum;
+ }),
+ Column::make("E-mail", "email_verified_at")
+ ->sortable()
+ ->format(function ($value, $row, Column $column) {
+ if (env('REGISTER_AUTH') !== 'auth') {
+ if ($row->role == 'admin' && $row->email_verified_at != '') {
+ return '
-';
+ } else {
+ $verifyLink = route('verifyUser', [
+ 'verify' => '-' . $row->email_verified_at,
+ 'id' => $row->id
+ ]);
+ if ($row->email_verified_at == '') {
+ return '' . __('messages.Pending') . '';
+ } else {
+ return '' . __('messages.Verified') . '';
+ }
+ }
+ } else {
+ return '-';
+ }
+ return '';
+ })->html(),
+ Column::make("Blocked", "block")
+ ->sortable()
+ ->format(function ($value, $row, Column $column) {
+ if ($row->role === 'admin' && $row->id === 1) {
+ return '-';
+ } else {
+ $route = route('blockUser', ['block' => $row->block, 'id' => $row->id]);
+ if ($row->block === 'yes') {
+ $badge = ''.__('messages.Pending').'';
+ } elseif ($row->block === 'no') {
+ $badge = ''.__('messages.Approved').'';
+ }
+ return "$badge";
+ }
+ })
+ ->html(),
+ Column::make("Created at", "created_at")
+ ->sortable()
+ ->format(function ($value) {
+ if ($value) {
+ return $value->format('d/m/y');
+ } else {
+ return '';
+ }
+ }),
+ Column::make("Last seen", "updated_at")
+ ->sortable()
+ ->format(function ($value) {
+ $now = now();
+ $diff = $now->diff($value);
+
+ if ($diff->d < 1 && $diff->h < 1) {
+ return 'Now';
+ } elseif ($diff->d < 1 && $diff->h < 24) {
+ return $diff->h . ' hours ago';
+ } elseif ($diff->d < 365) {
+ return $diff->d . ' days ago';
+ } else {
+ return $diff->y . ' years ago';
+ }
+ }),
+ Column::make('Actions', "id")
+ ->format(function ($value, $row, Column $column) {
+ return view('components.table-components.action', ['user' => $row]);
+ }),
+ ];
+ }
+}
diff --git a/config/livewire-tables.php b/config/livewire-tables.php
new file mode 100644
index 0000000..eb949f7
--- /dev/null
+++ b/config/livewire-tables.php
@@ -0,0 +1,8 @@
+ 'bootstrap-5',
+];
diff --git a/config/livewire.php b/config/livewire.php
new file mode 100644
index 0000000..60be6db
--- /dev/null
+++ b/config/livewire.php
@@ -0,0 +1,158 @@
+ 'App\\Http\\Livewire',
+
+ /*
+ |--------------------------------------------------------------------------
+ | View Path
+ |--------------------------------------------------------------------------
+ |
+ | This value sets the path for Livewire component views. This affects
+ | file manipulation helper commands like `artisan make:livewire`.
+ |
+ */
+
+ 'view_path' => resource_path('views/livewire'),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Layout
+ |--------------------------------------------------------------------------
+ | The default layout view that will be used when rendering a component via
+ | Route::get('/some-endpoint', SomeComponent::class);. In this case the
+ | the view returned by SomeComponent will be wrapped in "layouts.app"
+ |
+ */
+
+ 'layout' => 'layouts.app',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Livewire Assets URL
+ |--------------------------------------------------------------------------
+ |
+ | This value sets the path to Livewire JavaScript assets, for cases where
+ | your app's domain root is not the correct path. By default, Livewire
+ | will load its JavaScript assets from the app's "relative root".
+ |
+ | Examples: "/assets", "myurl.com/app".
+ |
+ */
+
+ 'asset_url' => url(''),
+
+ /*
+ |--------------------------------------------------------------------------
+ | Livewire App URL
+ |--------------------------------------------------------------------------
+ |
+ | This value should be used if livewire assets are served from CDN.
+ | Livewire will communicate with an app through this url.
+ |
+ | Examples: "https://my-app.com", "myurl.com/app".
+ |
+ */
+
+ 'app_url' => null,
+
+ /*
+ |--------------------------------------------------------------------------
+ | Livewire Endpoint Middleware Group
+ |--------------------------------------------------------------------------
+ |
+ | This value sets the middleware group that will be applied to the main
+ | Livewire "message" endpoint (the endpoint that gets hit everytime
+ | a Livewire component updates). It is set to "web" by default.
+ |
+ */
+
+ 'middleware_group' => 'web',
+
+ /*
+ |--------------------------------------------------------------------------
+ | Livewire Temporary File Uploads Endpoint Configuration
+ |--------------------------------------------------------------------------
+ |
+ | Livewire handles file uploads by storing uploads in a temporary directory
+ | before the file is validated and stored permanently. All file uploads
+ | are directed to a global endpoint for temporary storage. The config
+ | items below are used for customizing the way the endpoint works.
+ |
+ */
+
+ 'temporary_file_upload' => [
+ 'disk' => null, // Example: 'local', 's3' Default: 'default'
+ 'rules' => null, // Example: ['file', 'mimes:png,jpg'] Default: ['required', 'file', 'max:12288'] (12MB)
+ 'directory' => null, // Example: 'tmp' Default 'livewire-tmp'
+ 'middleware' => null, // Example: 'throttle:5,1' Default: 'throttle:60,1'
+ 'preview_mimes' => [ // Supported file types for temporary pre-signed file URLs.
+ 'png', 'gif', 'bmp', 'svg', 'wav', 'mp4',
+ 'mov', 'avi', 'wmv', 'mp3', 'm4a',
+ 'jpg', 'jpeg', 'mpga', 'webp', 'wma',
+ ],
+ 'max_upload_time' => 5, // Max duration (in minutes) before an upload gets invalidated.
+ ],
+
+ /*
+ |--------------------------------------------------------------------------
+ | Manifest File Path
+ |--------------------------------------------------------------------------
+ |
+ | This value sets the path to the Livewire manifest file.
+ | The default should work for most cases (which is
+ | "/bootstrap/cache/livewire-components.php"), but for specific
+ | cases like when hosting on Laravel Vapor, it could be set to a different value.
+ |
+ | Example: for Laravel Vapor, it would be "/tmp/storage/bootstrap/cache/livewire-components.php".
+ |
+ */
+
+ 'manifest_path' => null,
+
+ /*
+ |--------------------------------------------------------------------------
+ | Back Button Cache
+ |--------------------------------------------------------------------------
+ |
+ | This value determines whether the back button cache will be used on pages
+ | that contain Livewire. By disabling back button cache, it ensures that
+ | the back button shows the correct state of components, instead of
+ | potentially stale, cached data.
+ |
+ | Setting it to "false" (default) will disable back button cache.
+ |
+ */
+
+ 'back_button_cache' => false,
+
+ /*
+ |--------------------------------------------------------------------------
+ | Render On Redirect
+ |--------------------------------------------------------------------------
+ |
+ | This value determines whether Livewire will render before it's redirected
+ | or not. Setting it to "false" (default) will mean the render method is
+ | skipped when redirecting. And "true" will mean the render method is
+ | run before redirecting. Browsers bfcache can store a potentially
+ | stale view if render is skipped on redirect.
+ |
+ */
+
+ 'render_on_redirect' => false,
+
+];
diff --git a/resources/views/components/table-components/action.blade.php b/resources/views/components/table-components/action.blade.php
new file mode 100644
index 0000000..3036f30
--- /dev/null
+++ b/resources/views/components/table-components/action.blade.php
@@ -0,0 +1,39 @@
+@if($user->role == 'admin' and $user->id == 1)-
+@else
+
+@endif
\ No newline at end of file
diff --git a/resources/views/layouts/sidebar.blade.php b/resources/views/layouts/sidebar.blade.php
index e504803..74fb1a2 100755
--- a/resources/views/layouts/sidebar.blade.php
+++ b/resources/views/layouts/sidebar.blade.php
@@ -19,6 +19,7 @@ $usrhandl = Auth::user()->littlelink_name;
+ @livewireStyles
@include('layouts.analytics')
@stack('sidebar-stylesheets')
@include('layouts.notifications')
@@ -791,7 +792,7 @@ $usrhandl = Auth::user()->littlelink_name;
-
+@livewireScripts
@stack('sidebar-scripts')