Skip to content

Commit

Permalink
user in snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
inikoo committed Oct 7, 2023
1 parent 39eb4c1 commit 57cb843
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
1 change: 1 addition & 0 deletions app/Actions/Helpers/Snapshot/UI/IndexSnapshots.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function tableStructure(Banner|Webpage $parent, ?array $modelOperations =


$table->column(key: 'state', label: ['fal', 'fa-yin-yang'])
->column(key: 'publisher', label: __('publisher'), sortable: true)
->column(key: 'published_at', label: __('date published'), sortable: true)
->column(key: 'published_until', label: __('published until'))
->column(key: 'comment', label: __('comment'))
Expand Down
19 changes: 13 additions & 6 deletions app/Actions/Portfolio/Banner/PublishBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public function handle(Banner $banner, array $modelData): Banner
]);
}

$layout = Arr::pull($modelData, 'layout');
list($layout, $slides) = ParseBannerLayout::run($layout);
$layout = Arr::pull($modelData, 'layout');
list($layout, $slides) = ParseBannerLayout::run($layout);

/** @var Snapshot $snapshot */
$snapshot = StoreBannerSnapshot::run(
Expand All @@ -53,7 +53,10 @@ public function handle(Banner $banner, array $modelData): Banner
'published_at' => now(),
'layout' => $layout,
'first_commit' => $firstCommit,
'comment' => Arr::get($modelData, 'comment')
'comment' => Arr::get($modelData, 'comment'),
'user_id' => Arr::get($modelData, 'user_id'),
'user_type' => Arr::get($modelData, 'user_type'),


],
$slides
Expand Down Expand Up @@ -98,16 +101,20 @@ public function authorize(ActionRequest $request): bool
public function rules(): array
{
return [
'layout' => ['required', 'array:delay,common,components'],
'comment' => ['sometimes', 'required', 'string', 'max:1024']
'layout' => ['required', 'array:delay,common,components'],
'comment' => ['sometimes', 'required', 'string', 'max:1024'],
'user_id' => ['sometimes'],
'user_type' => ['sometimes', 'string'],
];
}

public function prepareForValidation(ActionRequest $request): void
{
$request->merge(
[
'layout' => $request->only(['delay', 'common', 'components']),
'layout' => $request->only(['delay', 'common', 'components']),
'user_id' => $request->get('customerUser')->id,
'user_type' => 'CustomerUser'
]
);
}
Expand Down
29 changes: 20 additions & 9 deletions app/Http/Resources/Portfolio/SnapshotResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Resources\Portfolio;

use App\Enums\Portfolio\Snapshot\SnapshotStateEnum;
use App\Models\Auth\CustomerUser;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

Expand All @@ -19,21 +20,31 @@ public function toArray(Request $request): array
$snapshot = $this;


$comment=$snapshot->comment;
$comment = $snapshot->comment;

if($snapshot->first_commit) {
$comment=__('First commit');
if ($snapshot->first_commit) {
$comment = __('First commit');
}

$publisher = '';
$publisher_avatar = null;
if ($snapshot->user_id) {
/** @var CustomerUser $customerUser */
$customerUser = $snapshot->user;

$publisher = $customerUser->user->contact_name;
$publisher_avatar = $customerUser->user->avatarImageSources(48, 48);
}


return [
'slug' => $snapshot->slug,
'published_at' => $snapshot->published_at,
'published_until' => $snapshot->published_until,
'layout' => $snapshot->layout,
'state' => match ($snapshot->state) {
'slug' => $snapshot->slug,
'published_at' => $snapshot->published_at,
'published_until' => $snapshot->published_until,
'layout' => $snapshot->layout,
'publisher' => $publisher,
'publisher_avatar' => $publisher_avatar,
'state' => match ($snapshot->state) {
SnapshotStateEnum::LIVE => [
'tooltip' => __('live'),
'icon' => 'fal fa-broadcast-tower',
Expand All @@ -49,7 +60,7 @@ public function toArray(Request $request): array
'icon' => 'fal fa-ghost'
]
},
'comment' => $comment,
'comment' => $comment,
];
}
}
5 changes: 5 additions & 0 deletions app/Models/Helpers/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* @property-read Model|\Eloquent $parent
* @property-read \Illuminate\Database\Eloquent\Collection<int, Slide> $slides
* @property-read int|null $slides_count
* @property-read Model|\Eloquent $user
* @method static Builder|Snapshot newModelQuery()
* @method static Builder|Snapshot newQuery()
* @method static Builder|Snapshot query()
Expand Down Expand Up @@ -116,6 +117,10 @@ public function parent(): MorphTo
return $this->morphTo();
}

public function user(): MorphTo
{
return $this->morphTo();
}

public function slides(): HasMany
{
Expand Down

0 comments on commit 57cb843

Please sign in to comment.