Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
deniskorbakov committed Oct 26, 2024
2 parents c61cf87 + db86d4e commit f828a13
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_LOCALE=en
APP_LOCALE=ru

# Hostname without http
APP_HOST=localhost
Expand Down
33 changes: 32 additions & 1 deletion app/Filament/Resources/ChallengeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Filament\Resources;

use App\Enums\ChallengeType;
use App\Filament\Resources\ChallengeResource\Pages;
use App\Models\Challenge;
use Filament\Forms;
Expand Down Expand Up @@ -33,12 +34,27 @@ class ChallengeResource extends Resource

public static function form(Form $form): Form
{
$record = $form->getRecord();

return $form
->schema([
Forms\Components\TextInput::make('name')
->label('Название')
->required()
->maxWidth('sm'),
Forms\Components\Select::make('type')
->label('Тип')
->options([
'personal' => 'Персональный',
'team' => 'Командный',
])
->disabled(
function ($record) {
return $record->teams->count() > 0 || $record->users->count() > 0;
}
)
->required()
->maxWidth('sm'),
Forms\Components\Textarea::make('description')
->label('Описание')
->rows(5),
Expand Down Expand Up @@ -67,7 +83,20 @@ public static function form(Form $form): Form
->directory('achievements')
->visibility('public')
->maxWidth('xs')
->label('Изображение')
->label('Изображение'),
Forms\Components\Section::make()
->schema([
$record->type === ChallengeType::PERSONAL->value ? Forms\Components\Select::make( 'users')
->label('Участники челленджа')
->relationship('users', 'name')
->preload()
->multiple() :
Forms\Components\Select::make('teams')
->label('Команды челленджа')
->relationship('teams', 'name')
->preload()
->multiple(),
])->columns(2),
])->columns(1);
}

Expand All @@ -81,6 +110,8 @@ public static function table(Table $table): Table
Tables\Columns\TextColumn::make('description')
->label('Описание')
->limit(30),
Tables\Columns\TextColumn::make('type_name')
->label('Тип'),
Tables\Columns\TextColumn::make('start_date')
->dateTime('d F')
->label('Дата начала'),
Expand Down
1 change: 1 addition & 0 deletions app/Filament/Resources/TeamResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function (Challenge $record) {
return $record->name . ' ' . ($record->is_finished ? '(Завершён)' : '');
})
->preload()
->disabled()
->multiple(),
])->columns(1)
])->columns(1);
Expand Down
1 change: 1 addition & 0 deletions app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public static function form(Form $form): Form
function (Challenge $record) {
return $record->name . ' ' . ($record->is_finished ? '(Завершён)' : '');
})
->disabled()
->preload()
->multiple(),
])->columns(1)
Expand Down
17 changes: 17 additions & 0 deletions app/Models/Challenge.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Enums\ChallengeType;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -25,6 +26,12 @@ class Challenge extends Model
'type'
];

protected $appends = [
'is_finished',
'is_in_progress',
'type_name'
];

public function users(): belongsToMany
{
return $this->belongsToMany(User::class, 'users_challenges');
Expand All @@ -44,4 +51,14 @@ public function getIsFinishedAttribute(): bool
{
return $this->end_date < Carbon::now();
}

public function getIsInProgressAttribute(): bool
{
return $this->start_date < Carbon::now() && $this->end_date > Carbon::now();
}

public function getTypeNameAttribute()
{
return $this->type == ChallengeType::PERSONAL->value ? 'Персональный' : 'Командный';
}
}
8 changes: 6 additions & 2 deletions database/seeders/ChallengesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ public function run(): void
{
$challenges = config('base.challenges');

foreach ($challenges as $challenge) {
Challenge::factory()->create($challenge);
if (env('APP_DEBUG')) {
Challenge::factory(10)->create();
} else {
foreach ($challenges as $challenge) {
Challenge::factory()->create($challenge);
}
}
}
}
9 changes: 5 additions & 4 deletions database/seeders/TeamsChallengesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

namespace Database\Seeders;

use App\Models\Achievement;
use App\Enums\ChallengeType;
use App\Models\Challenge;
use App\Models\Team;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\User;

class TeamsChallengesSeeder extends Seeder
{
Expand All @@ -19,7 +17,10 @@ class TeamsChallengesSeeder extends Seeder
public function run(): void
{
$teams = Team::query()->limit(5)->get();
$challenges = Challenge::query()->limit(5)->get();
$challenges = Challenge::query()
->where('type', ChallengeType::TEAM)
->limit(5)
->get();

foreach ($teams as $team) {
foreach ($challenges as $challenge) {
Expand Down
7 changes: 5 additions & 2 deletions database/seeders/UserChallengesSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Database\Seeders;

use App\Enums\ChallengeType;
use App\Models\Challenge;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\User;

Expand All @@ -17,7 +17,10 @@ class UserChallengesSeeder extends Seeder
public function run(): void
{
$users = User::query()->limit(5)->get();
$challenges = Challenge::query()->limit(5)->get();
$challenges = Challenge::query()
->where('type', ChallengeType::PERSONAL)
->limit(5)
->get();

foreach ($users as $user) {
foreach ($challenges as $challenge) {
Expand Down

0 comments on commit f828a13

Please sign in to comment.