Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the blade component to format table columns #968

Merged
merged 10 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 12 additions & 40 deletions app/Livewire/Table/AllUrlFromGuestTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace App\Livewire\Table;

use App\Helpers\Helper;
use App\Models\Url;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Str;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Footer;
use PowerComponents\LivewirePowerGrid\Header;
Expand Down Expand Up @@ -48,51 +45,26 @@ public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('keyword', function (Url $url) {
return '<a href="'.$url->short_url.'" target="_blank"class="font-light text-sky-800">'.$url->keyword.'</a>';
return view('components.table.keyword', ['url' => $url])
->render();
})
->add('destination', function (Url $url) {
return
'<span title="'.htmlspecialchars($url->title).'">'
.htmlspecialchars(Str::limit($url->title, self::STR_LIMIT)).
'</span>
<br>
<a href="'.$url->destination.'" target="_blank" title="'.$url->destination.'" rel="noopener noreferrer"
class="text-[#6c6c6c]"
>'
.Helper::urlDisplay($url->destination, self::STR_LIMIT).
'</a>';
return view('components.table.destination', [
'url' => $url,
'limit' => self::STR_LIMIT,
])->render();
})
->add('t_clicks', function (Url $url) {
$uClick = numberAbbreviate($url->uniqueClicks);
$tClick = numberAbbreviate($url->clicks);
$icon = Blade::render('@svg(\'icon-bar-chart\', \'ml-2 text-amber-600\')');
$title = $uClick.' '.__('Uniques').' / '.$tClick.' '.__('Clicks');

return '<div title="'.$title.'">'.$uClick.' / '.$tClick.$icon.'</div>';
return view('components.table.visit', ['url' => $url])
->render();
})
->add('created_at_formatted', function (Url $url) {
return
'<span title="'.$url->created_at->toDayDateTimeString().'">'
.$url->created_at->shortRelativeDiffForHumans().
'</span>';
return view('components.table.date-created', ['url' => $url])
->render();
})
->add('action', function (Url $url) {
return
'<a role="button" href="'.route('su_detail', $url->keyword).'" target="_blank" title="'.__('Open front page').'"
class="btn btn-secondary btn-sm"
>'
.Blade::render('@svg(\'icon-open-in-new\')').
'</a>
<a role="button" href="'.route('dashboard.su_edit', $url).'" title="'.__('Edit').'"
class="btn btn-secondary btn-sm"
>'
.Blade::render('@svg(\'icon-edit-alt\')').
'</a>
<a role="button" href="'.route('dashboard.su_delete', $url).'" title="'.__('Delete').'"
class="btn btn-secondary btn-sm hover:text-red-600 active:text-red-700"
>'
.Blade::render('@svg(\'icon-trash-alt\')').
'</a>';
return view('components.table.action-button', ['url' => $url])
->render();
});
}

Expand Down
52 changes: 12 additions & 40 deletions app/Livewire/Table/AllUrlTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace App\Livewire\Table;

use App\Helpers\Helper;
use App\Models\Url;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Str;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Footer;
use PowerComponents\LivewirePowerGrid\Header;
Expand Down Expand Up @@ -51,51 +48,26 @@ public function fields(): PowerGridFields
return '<span class="font-semibold">'.$url->author->name.'</span>';
})
->add('keyword', function (Url $url) {
return '<a href="'.$url->short_url.'" target="_blank"class="font-light text-sky-800">'.$url->keyword.'</a>';
return view('components.table.keyword', ['url' => $url])
->render();
})
->add('destination', function (Url $url) {
return
'<span title="'.htmlspecialchars($url->title).'">'
.htmlspecialchars(Str::limit($url->title, self::STR_LIMIT)).
'</span>
<br>
<a href="'.$url->destination.'" target="_blank" title="'.$url->destination.'" rel="noopener noreferrer"
class="text-[#6c6c6c]"
>'
.Helper::urlDisplay($url->destination, self::STR_LIMIT).
'</a>';
return view('components.table.destination', [
'url' => $url,
'limit' => self::STR_LIMIT,
])->render();
})
->add('t_clicks', function (Url $url) {
$uClick = numberAbbreviate($url->uniqueClicks);
$tClick = numberAbbreviate($url->clicks);
$icon = Blade::render('@svg(\'icon-bar-chart\', \'ml-2 text-amber-600\')');
$title = $uClick.' '.__('Uniques').' / '.$tClick.' '.__('Clicks');

return '<div title="'.$title.'">'.$uClick.' / '.$tClick.$icon.'</div>';
return view('components.table.visit', ['url' => $url])
->render();
})
->add('created_at_formatted', function (Url $url) {
return
'<span title="'.$url->created_at->toDayDateTimeString().'">'
.$url->created_at->shortRelativeDiffForHumans().
'</span>';
return view('components.table.date-created', ['url' => $url])
->render();
})
->add('action', function (Url $url) {
return
'<a role="button" href="'.route('su_detail', $url->keyword).'" target="_blank" title="'.__('Open front page').'"
class="btn btn-secondary btn-sm"
>'
.Blade::render('@svg(\'icon-open-in-new\')').
'</a>
<a role="button" href="'.route('dashboard.su_edit', $url).'" title="'.__('Edit').'"
class="btn btn-secondary btn-sm"
>'
.Blade::render('@svg(\'icon-edit-alt\')').
'</a>
<a role="button" href="'.route('dashboard.su_delete', $url).'" title="'.__('Delete').'"
class="btn btn-secondary btn-sm hover:text-red-600 active:text-red-700"
>'
.Blade::render('@svg(\'icon-trash-alt\')').
'</a>';
return view('components.table.action-button', ['url' => $url])
->render();
});
}

Expand Down
50 changes: 12 additions & 38 deletions app/Livewire/Table/MyUrlTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace App\Livewire\Table;

use App\Helpers\Helper;
use App\Models\Url;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Str;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Footer;
use PowerComponents\LivewirePowerGrid\Header;
Expand Down Expand Up @@ -48,49 +45,26 @@ public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('keyword', function (Url $url) {
return '<a href="'.$url->short_url.'" target="_blank" class="font-light text-sky-800">'.$url->keyword.'</a>';
return view('components.table.keyword', ['url' => $url])
->render();
})
->add('destination', function (Url $url) {
return
'<span title="'.htmlspecialchars($url->title).'">'
.htmlspecialchars(Str::limit($url->title, self::STR_LIMIT)).
'</span>
<br>
<a href="'.$url->destination.'" target="_blank" title="'.$url->destination.'" rel="noopener noreferrer" class="text-[#6c6c6c]">'
.Helper::urlDisplay($url->destination, self::STR_LIMIT).
'</a>';
return view('components.table.destination', [
'url' => $url,
'limit' => self::STR_LIMIT,
])->render();
})
->add('t_clicks', function (Url $url) {
$uClick = numberAbbreviate($url->uniqueClicks);
$tClick = numberAbbreviate($url->clicks);
$icon = Blade::render('@svg(\'icon-bar-chart\', \'ml-2 text-amber-600\')');
$title = $uClick.' '.__('Uniques').' / '.$tClick.' '.__('Clicks');

return '<div title="'.$title.'">'.$uClick.' / '.$tClick.$icon.'</div>';
return view('components.table.visit', ['url' => $url])
->render();
})
->add('created_at_formatted', function (Url $url) {
return
'<span title="'.$url->created_at->toDayDateTimeString().'">'
.$url->created_at->shortRelativeDiffForHumans().
'</span>';
return view('components.table.date-created', ['url' => $url])
->render();
})
->add('action', function (Url $url) {
return
'<a role="button" href="'.route('su_detail', $url->keyword).'" target="_blank" title="'.__('Go to front page').'"
class="btn btn-secondary btn-sm"
>'
.Blade::render('@svg(\'icon-open-in-new\')').
'</a>
<a role="button" href="'.route('dashboard.su_edit', $url).'" title="'.__('Edit').'"
class="btn btn-secondary btn-sm"
>'
.Blade::render('@svg(\'icon-edit-alt\')').
'</a>
<a role="button" href="'.route('dashboard.su_delete', $url).'" title="'.__('Delete').'"
class="btn btn-secondary btn-sm hover:text-red-600 active:text-red-700"
>'
.Blade::render('@svg(\'icon-trash-alt\')').
'</a>';
return view('components.table.action-button', ['url' => $url])
->render();
});
}

Expand Down
17 changes: 17 additions & 0 deletions resources/views/components/table/action-button.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div>
<a role="button" href="{{route('su_detail', $url->keyword)}}" target="_blank" title="{{__('Go to front page')}}"
class="btn btn-secondary btn-sm"
>
@svg('icon-open-in-new')
</a>
<a role="button" href="{{route('dashboard.su_edit', $url)}}" title="{{__('Edit')}}"
class="btn btn-secondary btn-sm"
>
@svg('icon-edit-alt')
</a>
<a role="button" href="{{route('dashboard.su_delete', $url)}}" title="{{__('Delete')}}"
class="btn btn-secondary btn-sm hover:text-red-600 active:text-red-700"
>
@svg('icon-trash-alt')
</a>
</div>
5 changes: 5 additions & 0 deletions resources/views/components/table/date-created.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<span title="{{ $url->created_at->toDayDateTimeString()}} ">
{{ $url->created_at->shortRelativeDiffForHumans() }}
</span>
</div>
14 changes: 14 additions & 0 deletions resources/views/components/table/destination.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@use('App\Helpers\Helper')
@use('Illuminate\Support\Str')

<div>
<span title="{{ htmlspecialchars($url->title)}} ">
{{ htmlspecialchars(Str::limit($url->title, $limit)) }}
</span>

<br>

<a href="{{ $url->destination }}" target="_blank" title="{{ $url->destination }}" rel="noopener noreferrer" class="text-[#6c6c6c]">
{{ Helper::urlDisplay($url->destination, $limit) }}
</a>
</div>
5 changes: 5 additions & 0 deletions resources/views/components/table/keyword.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<a href="{{$url->short_url}}" target="_blank" class="font-light text-sky-800">
{{$url->keyword}}
</a>
</div>
10 changes: 10 additions & 0 deletions resources/views/components/table/visit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@php
$uClick = numberAbbreviate($url->uniqueClicks);
$tClick = numberAbbreviate($url->clicks);
$title = $uClick.' '.__('Uniques').' / '.$tClick.' '.__('Clicks');
@endphp

<div title="{{ $title }}">
{{ $uClick }} / {{ $tClick }}
@svg('icon-bar-chart', 'ml-2 text-amber-600')
</div>