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

Livewire Test on Widget #792

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions app/Livewire/EntityListing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace App\Livewire;

use Illuminate\Support\Collection;
use Livewire\Component;
use Livewire\WithPagination;
use App\Models\Campaign;
use App\Facades\CampaignLocalization;
use App\Facades\UserCache;
use App\Facades\Avatar;
use App\Facades\CampaignCache;

class EntityListing extends Component
{
use WithPagination;

public $entities;

public Campaign $campaign;

public $pageNumber = 1;

public $hasMorePages;

public function mount(Campaign $campaign)
{

$this->entities = new Collection();
$this->campaign = $campaign;

$this->loadEntities();
}

public function loadEntities()
{
CampaignLocalization::forceCampaign($this->campaign);
UserCache::campaign($this->campaign);
Avatar::campaign($this->campaign);
CampaignCache::campaign($this->campaign);

$campaign = $this->campaign;

$this->authorize('access', $campaign);
$entities = $campaign->entities()
->lastSync(request()->get('lastSync'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lastSync param is for the api?

->paginate(12, ['*'], 'page', $this->pageNumber);

$this->pageNumber += 1;

$this->hasMorePages = $entities->hasMorePages();

$this->entities->push(...$entities->items());
}

public function render()
{
return view('livewire.entity-listing');
}
}
12 changes: 6 additions & 6 deletions app/Policies/CampaignPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,27 +246,27 @@ public function unboost(?User $user, Campaign $campaign): bool
public function galleryManage(?User $user, Campaign $campaign): bool
{
return $user && (
UserCache::user($user)->admin() ||
UserCache::user($user)->admin() ||
$this->checkPermission(CampaignPermission::ACTION_GALLERY, $user, $campaign)
);
);
}

public function galleryBrowse(?User $user, Campaign $campaign): bool
{
return $user && (
UserCache::user($user)->admin() ||
UserCache::user($user)->admin() ||
$this->checkPermission(CampaignPermission::ACTION_GALLERY, $user, $campaign) ||
$this->checkPermission(CampaignPermission::ACTION_GALLERY_BROWSE, $user, $campaign)
);
);
}

public function galleryUpload(?User $user, Campaign $campaign): bool
{
return $user && (
UserCache::user($user)->admin() ||
UserCache::user($user)->admin() ||
$this->checkPermission(CampaignPermission::ACTION_GALLERY, $user, $campaign) ||
$this->checkPermission(CampaignPermission::ACTION_GALLERY_UPLOAD, $user, $campaign)
);
);
}


Expand Down
2 changes: 1 addition & 1 deletion app/Renderers/DatagridRenderer2.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,6 @@ public function rowAttributes(mixed $row): string
foreach($row->rowAttributes() as $attr => $val) {
$attributes[] = 'data-' . $attr . '="' . $val . '"';
}
return implode(' ' , $attributes);
return implode(' ', $attributes);
}
}
8 changes: 4 additions & 4 deletions app/Services/Permissions/PermissionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ public function createTemporaryTable(): self
if (count($batch) > 0) {
DB::statement("INSERT INTO tmp_permissions (id) VALUES (" . implode(') ,(', $batch) . ")");
}
// dump(in_array(329259, $batch));
// $wa = DB::table('tmp_permissions')
// ->where('id', 329259)->get();
// dd($wa);
// dump(in_array(329259, $batch));
// $wa = DB::table('tmp_permissions')
// ->where('id', 329259)->get();
// dd($wa);
$this->tempPermissionCreated = true;
return $this;
}
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"laravel/ui": "^4.2.1",
"laravelcollective/html": "^6.0",
"league/flysystem-aws-s3-v3": "^3.5",
"livewire/livewire": "^3.3",
"mailerlite/mailerlite-php": "^1.0",
"mcamara/laravel-localization": "^1.7",
"orhanerday/open-ai": "^4.7",
Expand Down
74 changes: 74 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 3 additions & 46 deletions resources/views/dashboard/widgets/_recent_list.blade.php
Original file line number Diff line number Diff line change
@@ -1,47 +1,4 @@
<?php /** @var \App\Models\Entity[]|\Illuminate\Pagination\LengthAwarePaginator $entities */?>
<div class="flex flex-col gap-2">
@foreach ($entities as $entity)
<div class="flex items-center gap-2">
<a class="entity-picture inline-block rounded-full cover-background w-9 h-9 flex-shrink-0" style="background-image: url('{{ Avatar::entity($entity)->fallback()->size(40)->thumbnail() }}');"
title="{{ $entity->name }}"
href="{{ $entity->url() }}">
</a>

<div class="grow break-all">
{!! $entity->tooltipedLink($entity->name, false) !!}

@if ($entity->is_private)
<i class="fa-solid fa-lock" title="{{ __('crud.is_private') }}" aria-hidden="true"></i>
@endif
</div>

<div class="blame flex-none text-right text-xs">
<span class="author block">
@if ($entity->created_at->equalTo($entity->updated_at))
{{ !empty($entity->created_by) ? \App\Facades\UserCache::name($entity->created_by) : __('crud.history.unknown') }}
@else
{{ !empty($entity->updated_by) ? \App\Facades\UserCache::name($entity->updated_by) : __('crud.history.unknown') }}
@endif
</span>
@can('history', [$entity, $campaign])
@if (!empty($entity->updated_at))
<span class="elapsed text-neutral-content text-xs" title="{{ $entity->updated_at }} UTC">
{{ $entity->updated_at->diffForHumans() }}
</span>
@endif
@endcan
</div>
</div>

@endforeach

@if($entities->hasMorePages())
<div class="text-center">
<a href="#" class="widget-recent-more"
data-url="{{ route('dashboard.recent', [$campaign, 'id' => $widget->id, 'page' => $entities->currentPage() + 1]) }}">
<span class="inline-block p-3">{{ __('crud.actions.next') }}</span>
<i class="fa-solid fa-spinner fa-spin spinner" style="display: none;" aria-hidden="true"></i>
</a>
</div>
@endif
</div>
<div>
@livewire('entity-listing', ['campaign' => $campaign])
</div>
3 changes: 3 additions & 0 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
@endif
@includeWhen(!empty($campaign), 'layouts._theme')
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto&display=swap">
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wtf

@livewireStyles
</head>
{{-- Hide the sidebar if the there is no current campaign --}}
<body class=" @if(\App\Facades\DataLayer::groupB())ab-testing-second @else ab-testing-first @endif @if(isset($miscModel) && !empty($miscModel->entity)){{ $miscModel->bodyClasses($entity ?? null) }}@endif @if(isset($dashboard))dashboard-{{ $dashboard->id }}@endif @if(isset($bodyClass)){{ $bodyClass }}@endif @if (!empty($campaign) && auth()->check() && auth()->user()->isAdmin()) is-admin @endif @if(!app()->isProduction()) env-{{ app()->environment() }} @endif @if(!$showSidebar) sidebar-collapse @endif" @if(!empty($specificTheme)) data-theme="{{ $specificTheme }}" @endif @if (!empty($campaign)) data-user-member="{{ auth()->check() && $campaign->userIsMember() ? 1 : 0 }}" @endif>
Expand Down Expand Up @@ -170,5 +172,6 @@
@yield('scripts')

@includeWhen(config('tracking.consent'), 'partials.cookieconsent')
@livewireScripts
</body>
</html>
50 changes: 50 additions & 0 deletions resources/views/livewire/entity-listing.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<div>

<?php /** @var \App\Models\Entity[]|\Illuminate\Pagination\LengthAwarePaginator $entities */?>
<div class="flex flex-col gap-2">

@foreach ($entities as $entity)
<div class="flex items-center gap-2">
<a class="entity-picture inline-block rounded-full cover-background w-9 h-9 flex-shrink-0" style="background-image: url('{{ Avatar::entity($entity)->fallback()->size(40)->thumbnail() }}');"
title="{{ $entity->name }}"
href="{{ $entity->url() }}">
</a>

<div class="grow break-all">
{!! $entity->tooltipedLink($entity->name, false) !!}

@if ($entity->is_private)
<i class="fa-solid fa-lock" title="{{ __('crud.is_private') }}" aria-hidden="true"></i>
@endif
</div>

<div class="blame flex-none text-right text-xs">
<span class="author block">
{{ !empty($entity->updated_by) ? \App\Facades\UserCache::name($entity->updated_by) : __('crud.history.unknown') }}
</span>
@can('history', [$entity, $campaign])
@if (!empty($entity->updated_at))
<span class="elapsed text-neutral-content text-xs" title="{{ $entity->updated_at }} UTC">
{{ $entity->updated_at->diffForHumans() }}
</span>
@endif
@endcan
</div>
</div>

@endforeach

@if($hasMorePages)
<div class="text-center">
<button
class="px-4 py-3 text-lg font-semibold text-white rounded-xl bg-green-500 hover:bg-green-400"
wire:click="loadEntities"
>
Load More
</button>
</div>
@endif

</div>

</div>