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 ebc30e8 + 7010552 commit ecc18fb
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 22 deletions.
2 changes: 1 addition & 1 deletion app/Filament/Resources/AchievementResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static function table(Table $table): Table
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\EditAction::make()->label('Управление'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EditAchievement extends EditRecord
{
public function getHeading(): string
{
return 'Изменить ачивку';
return 'Управление ачивкой';
}

protected static string $resource = AchievementResource::class;
Expand Down
3 changes: 2 additions & 1 deletion app/Filament/Resources/ChallengeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public static function form(Form $form): Form
Forms\Components\Select::make('achievement_id')
->label('Ачивка')
->relationship('achievement', 'name')
->searchable()
->nullable(),
FileUpload::make('image')
->rules(['image'])
Expand Down Expand Up @@ -105,7 +106,7 @@ public static function table(Table $table): Table
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\EditAction::make()->label('Управление'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EditChallenge extends EditRecord
{
public function getHeading(): string
{
return 'Изменить челлендж';
return 'Управление челленджем';
}

protected static string $resource = ChallengeResource::class;
Expand Down
41 changes: 36 additions & 5 deletions app/Filament/Resources/TeamResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Filament\Resources;

use App\Filament\Resources\TeamResource\Pages;
use App\Models\Challenge;
use App\Models\Team;
use Filament\Forms;
use Filament\Forms\Form;
Expand Down Expand Up @@ -39,17 +40,36 @@ public static function form(Form $form): Form
Forms\Components\Textarea::make('description')
->label('Описание')
->rows(5),
Forms\Components\Select::make('captain_id')
->label('Капитан')
->relationship('users', 'name')
->searchable()
->preload(),
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('users')
->label('Участники')
->label('Участники команды')
->relationship('users', 'name')
->preload()
->multiple(),
Forms\Components\Select::make('achievements')
->label('Достижения')
->label('Достижения команды')
->relationship('achievements', 'name')
->preload()
->multiple(),
])->columns(2)
])->columns(2),
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('challenges')
->label('Челленджи команды')
->relationship('challenges', 'name')
->getOptionLabelFromRecordUsing(
function (Challenge $record) {
return $record->name . ' ' . ($record->is_finished ? '(Завершён)' : '');
})
->preload()
->multiple(),
])->columns(1)
])->columns(1);
}

Expand All @@ -70,7 +90,8 @@ public static function table(Table $table): Table
fn($record) => $record->users->count() > 0
? 'success' : 'danger'
)
->label('Участников'),
->label('Участников')
->sortable(),
Tables\Columns\TextColumn::make('achievements_count')
->counts('achievements')
->badge()
Expand All @@ -79,12 +100,22 @@ public static function table(Table $table): Table
? 'success' : 'danger'
)
->label('Достижений')
->sortable(),
Tables\Columns\TextColumn::make('challenges_count')
->counts('challenges')
->badge()
->color(
fn($record) => $record->challenges->count() > 0
? 'success' : 'danger'
)
->label('Челленджей')
->sortable(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\EditAction::make()->label('Управление'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/TeamResource/Pages/EditTeam.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EditTeam extends EditRecord
{
public function getHeading(): string
{
return 'Изменить команду';
return 'Управление командой';
}
protected static string $resource = TeamResource::class;

Expand Down
52 changes: 46 additions & 6 deletions app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource\RelationManagers;
use App\Models\Challenge;
use App\Models\User;
use Filament\Forms;
use Filament\Forms\Form;
Expand Down Expand Up @@ -62,6 +63,31 @@ public static function form(Form $form): Form
Forms\Components\TextInput::make('patronymic')->label('Отчество'),
Forms\Components\Textarea::make('about')->label('О себе')->rows(5),
])->columns(),
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('teams')
->label('Команды, в которых состоит пользователь')
->relationship('teams', 'name')
->preload()
->multiple(),
Forms\Components\Select::make('achievements')
->label('Достижения пользователя')
->relationship('achievements', 'name')
->preload()
->multiple(),
])->columns(2),
Forms\Components\Section::make()
->schema([
Forms\Components\Select::make('challenges')
->label('Челленджи пользователя')
->relationship('challenges', 'name')
->getOptionLabelFromRecordUsing(
function (Challenge $record) {
return $record->name . ' ' . ($record->is_finished ? '(Завершён)' : '');
})
->preload()
->multiple(),
])->columns(1)
]);
}

Expand All @@ -76,15 +102,29 @@ public static function table(Table $table): Table
->label('Фамилия')
->default('-')
->searchable(),
Tables\Columns\TextColumn::make('patronymic')
->label('Отчество')
->default('-')
->searchable(),
Tables\Columns\TextColumn::make('email')
->label('Почта')
->searchable(),
CheckboxColumn::make('is_confirmed')
->label('Верифицирован'),
->label('Проверен'),
Tables\Columns\TextColumn::make('challenges_count')
->counts('challenges')
->badge()
->color(
fn($record) => $record->challenges->count() > 0
? 'success' : 'danger'
)
->label('Челленджей')
->sortable(),
Tables\Columns\TextColumn::make('achievements_count')
->counts('achievements')
->badge()
->color(
fn($record) => $record->achievements->count() > 0
? 'success' : 'danger'
)
->label('Достижений')
->sortable()
])
->defaultSort('created_at', 'desc')
->filters([
Expand All @@ -94,7 +134,7 @@ public static function table(Table $table): Table
->label('Не верифицированные'),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\EditAction::make()->label('Управление'),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/UserResource/Pages/EditUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class EditUser extends EditRecord
{
public function getHeading(): string
{
return 'Изменить пользователя';
return 'Управление пользователем';
}

protected static string $resource = UserResource::class;
Expand Down
6 changes: 6 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 Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
Expand Down Expand Up @@ -38,4 +39,9 @@ public function teams(): belongsToMany
{
return $this->belongsToMany(Team::class, 'teams_challenges');
}

public function getIsFinishedAttribute(): bool
{
return $this->end_date < Carbon::now();
}
}
33 changes: 32 additions & 1 deletion app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasOne;

class Team extends Model
{
use HasFactory;

public $timestamps = true;

protected $fillable = [
'name',
'description',
'image'
'captain_id'
];

protected $appends = [
'active_challenges',
'completed_challenges'
];

public function captain(): HasOne
{
return $this->hasOne(User::class, 'captain_id');
}

public function users(): belongsToMany
{
return $this->belongsToMany(User::class, 'users_teams', 'team_id', 'user_id');
Expand All @@ -30,4 +45,20 @@ public function achievements(): belongsToMany
{
return $this->belongsToMany(Achievement::class, 'teams_achievements');
}

public function getActiveChallengesAttribute(): Collection
{
return $this->challenges()
->where('start_date', '<=', Carbon::now())
->where('end_date', '>=', Carbon::now())
->get();
}

public function getCompletedChallengesAttribute(): Collection
{
return $this->challenges()
->where('end_date', '<', Carbon::now())
->get();
}

}
6 changes: 3 additions & 3 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@
|
*/

'locale' => env('APP_LOCALE', 'en'),
'locale' => env('APP_LOCALE', 'ru'),

'fallback_locale' => env('APP_FALLBACK_LOCALE', 'en'),
'fallback_locale' => env('APP_FALLBACK_LOCALE', 'ru'),

'faker_locale' => env('APP_FAKER_LOCALE', 'en_US'),
'faker_locale' => env('APP_FAKER_LOCALE', 'ru_RU'),

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions database/factories/TeamFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Database\Factories;

use App\Models\Team;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
Expand All @@ -24,6 +25,7 @@ public function definition(): array
return [
'name' => $this->faker->company,
'description' => $this->faker->sentence,
'captain_id' => User::query()->first()->id,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function up(): void
$table->string('name');
$table->string('image')->nullable();
$table->text('description');
$table->foreignId('captain_id')->constrained('users')->onDelete('cascade');
$table->timestamps();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public function up(): void
$table->id();
$table->foreignId('user_id')->constrained('users')->onDelete('cascade');
$table->foreignId('team_id')->constrained('teams')->onDelete('cascade');
$table->boolean('is_captain')->default(false);
$table->timestamps();
});
}
Expand Down

0 comments on commit ecc18fb

Please sign in to comment.