Skip to content

Commit

Permalink
fix statue activity log (#395)
Browse files Browse the repository at this point in the history
* fix: video url type error (#393)

* fix: video url type error

* fix: add video repeater validation rules

* Translations update from translate.commit (#351)

* Added translation using Weblate (English)

* Translated using Weblate (English)

Currently translated at 0.4% (2 of 482 strings)

Translation: Bursa Binelui/Core
Translate-URL: https://translate.commitglobal.org/projects/bursa-binelui/core/en/

* Translated using Weblate (English)

Currently translated at 0.6% (3 of 488 strings)

Translation: Bursa Binelui/Core
Translate-URL: https://translate.commitglobal.org/projects/bursa-binelui/core/en/

---------

Co-authored-by: Tudor Amariei <[email protected]>
Co-authored-by: Miruna Muscan <[email protected]>
Co-authored-by: Andrei Ioniță <[email protected]>

* fix: project description validation (#394)

* fix statue activity log

---------

Co-authored-by: Andrei Ioniță <[email protected]>
Co-authored-by: code4ro-github-bot <[email protected]>
Co-authored-by: Tudor Amariei <[email protected]>
Co-authored-by: Miruna Muscan <[email protected]>
  • Loading branch information
5 people authored Sep 2, 2024
1 parent 98db7f1 commit 045dfe0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Filament\Forms\Components\Value;
use App\Models\Activity;
use Filament\Tables\Actions\ViewAction as BaseAction;
use Illuminate\Support\HtmlString;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

class ViewActivityAction extends BaseAction
{
Expand Down Expand Up @@ -41,6 +43,26 @@ protected function setUp(): void

Value::make('changed_field_new_value')
->label(__('activity.value.new'))
->content(
function (Activity $record) {
if ($record->changed_field === 'statute') {
$media = Media::find($record->changed_field_new_value);
if (! $media) {
return '-';
}

return new HtmlString(
sprintf(
'<a href="%s" target="_blank">%s</a>',
$media->getTemporaryUrl(now()->addMinutes(30)),
$media->file_name
)
);
}

return $record->changed_field_new_value;
}
)
->inlineLabel(),
]);

Expand Down
9 changes: 6 additions & 3 deletions app/Filament/Resources/ProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ function (callable $get) {
->image()
->multiple()
->maxFiles(20),
Forms\Components\Repeater::make('videos')->schema([
TextInput::make('url'),
]),
Forms\Components\Repeater::make('videos')
->schema([
TextInput::make('url')
->url()
->required(),
]),
Forms\Components\Repeater::make('external_links')->schema([
TextInput::make('title')
->required(),
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/Project/EditRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function rules(): array
'end' => ['date', 'nullable', 'after:tomorrow'],
'counties' => ['array', 'nullable'],
'counties.*' => ['exists:counties,id', 'nullable'],
'description' => ['string', 'nullable', 'max:800'],
'description' => ['string', 'nullable', 'max:1000'],
'scope' => ['string', 'nullable'],
'reason_to_donate' => ['string', 'nullable'],
'beneficiaries' => ['nullable', 'string'],
Expand Down
4 changes: 0 additions & 4 deletions app/Models/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ public function reject(?string $reason): void
*/
public function getModifiedField(mixed $value): ?string
{
if ($this->description === 'statute') {
$value = Media::find($value)?->getTemporaryUrl(now()->addMinutes(5));
}

if (\gettype($value) == 'boolean') {
$value = $value ? __('field.boolean.true') : __('field.boolean.false');
}
Expand Down
6 changes: 4 additions & 2 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Vite;
use Illuminate\Support\Str;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Image\Manipulations;
Expand Down Expand Up @@ -241,7 +242,7 @@ public function getVisibleStatusAttribute(): string

public function markAsApproved(): bool
{
$slug = \Str::slug($this->name);
$slug = Str::slug($this->name);

$count = self::whereRaw("slug RLIKE '^{$this->slug}(-[0-9]+)?$'")->count();
if ($count > 0) {
Expand Down Expand Up @@ -275,11 +276,12 @@ public function getEmbeddedVideosAttribute(): array
{
return collect($this->videos)
->pluck('url')
->filter()
->map(
fn (string $videoUrl) => Cache::remember(
'video-' . hash('sha256', $videoUrl),
MONTH_IN_SECONDS,
fn () => rescue(fn () => (new Embed)->get($videoUrl)->code, '', false)
fn () => rescue(fn () => (new Embed)->get($videoUrl)->code, report: false)
)
)
->filter()
Expand Down
5 changes: 5 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"change_password": "Change password",
"current_password": "Current password",
"password": "Password"
}

0 comments on commit 045dfe0

Please sign in to comment.