Archived
1
0
Fork 0

Formatting fixes.

This commit is contained in:
Henrik Hautakoski 2023-02-19 13:56:09 +01:00
parent 0437947c82
commit 86b9f3d2f0
7 changed files with 161 additions and 161 deletions

View file

@ -29,25 +29,25 @@ class AccountForm extends Component
'password' => 'new password', 'password' => 'new password',
]; ];
public function mount(Request $request) public function mount(Request $request)
{ {
$this->record = $request->user(); $this->record = $request->user();
$this->username = $this->record->username; $this->username = $this->record->username;
} }
/** /**
* Validation rules * Validation rules
*/ */
protected function rules() protected function rules()
{ {
return [ return [
'password_current' => [ 'required', 'password' ], 'password_current' => ['required', 'password'],
'password' => [ Password::min(8)->letters()->mixedCase()->numbers(), 'confirmed' ] 'password' => [Password::min(8)->letters()->mixedCase()->numbers(), 'confirmed']
]; ];
} }
public function updated($property, $value) public function updated($property, $value)
{ {
if ($property == 'password_confirmation') { if ($property == 'password_confirmation') {
$property = 'password'; $property = 'password';
@ -64,12 +64,12 @@ class AccountForm extends Component
$this->record->save(); $this->record->save();
return redirect()->route('admin') return redirect()->route('admin')
->with('info', __('Password was successfully updated.')); ->with('info', __('Password was successfully updated.'));
} }
public function render() public function render()
{ {
return view('form.account') return view('form.account')
->layout('layouts.admin'); ->layout('layouts.admin');
} }
} }

View file

@ -9,62 +9,62 @@ use App\Models\Wow;
class CardForm extends ModelForm class CardForm extends ModelForm
{ {
/** /**
* Array of available characters * Array of available characters
*/ */
public $characters; public $characters;
/** /**
* Array of available raids * Array of available raids
*/ */
public $raids; public $raids;
/** /**
* Redirect after this route after record was created. * Redirect after this route after record was created.
*/ */
public string $redirect_route = 'admin.card.index'; public string $redirect_route = 'admin.card.index';
public function mount(Card $card) public function mount(Card $card)
{
$this->record = $card;
$this->characters = Character::all()->pluck('name', 'id');
$this->raids = Raid::all()->pluck('name', 'id');
$this->classes = Wow::$classes;
$this->exist = $card->exists;
}
/**
* Validation rules
*/
protected function rules()
{
return [
'record.body' => 'required|string|min:3|max:200',
'record.character_id' => 'exists:' . Character::class . ',id|nullable',
'record.raid_id' => 'exists:' . Raid::class . ',id|nullable',
'record.class' => 'in:' . collect($this->classes)->keys() . '|nullable',
];
}
public function updated($property, $value)
{ {
// Hack to force empty value to null. $this->record = $card;
if (in_array($property, ['record.character_id', 'record.raid_id', 'record.class'])) { $this->characters = Character::all()->pluck('name', 'id');
if (empty($value)) { $this->raids = Raid::all()->pluck('name', 'id');
$this->{$property} = null; $this->classes = Wow::$classes;
} $this->exist = $card->exists;
} }
/**
* Validation rules
*/
protected function rules()
{
return [
'record.body' => 'required|string|min:3|max:200',
'record.character_id' => 'exists:' . Character::class . ',id|nullable',
'record.raid_id' => 'exists:' . Raid::class . ',id|nullable',
'record.class' => 'in:' . collect($this->classes)->keys() . '|nullable',
];
}
public function updated($property, $value)
{
// Hack to force empty value to null.
if (in_array($property, ['record.character_id', 'record.raid_id', 'record.class'])) {
if (empty($value)) {
$this->{$property} = null;
}
}
$this->validateOnly($property); $this->validateOnly($property);
} }
public function getSubjectProperty() public function getSubjectProperty()
{ {
if ($this->record->character_id) { if ($this->record->character_id) {
return $this->characters[$this->record->character_id]; return $this->characters[$this->record->character_id];
} else if ($this->record->class) { } else if ($this->record->class) {
return $this->classes[$this->record->class]; return $this->classes[$this->record->class];
} }
return "Somebody"; return "Somebody";
} }
} }

View file

@ -6,24 +6,24 @@ use App\Models\Character;
class CharacterForm extends ModelForm class CharacterForm extends ModelForm
{ {
/** /**
* Redirect after this route after record was created. * Redirect after this route after record was created.
*/ */
public string $redirect_route = 'admin.character.index'; public string $redirect_route = 'admin.character.index';
public function mount(Character $character) public function mount(Character $character)
{ {
$this->record = $character; $this->record = $character;
$this->exist = $character->exists; $this->exist = $character->exists;
} }
/** /**
* Validation rules * Validation rules
*/ */
protected function rules() protected function rules()
{ {
return [ return [
'record.name' => 'required|string|min:3|max:14', 'record.name' => 'required|string|min:3|max:14',
]; ];
} }
} }

View file

@ -7,31 +7,31 @@ use Illuminate\Support\Facades\Auth;
class LoginForm extends Component class LoginForm extends Component
{ {
public $username; public $username;
public $password; public $password;
protected $rules = [ protected $rules = [
'username' => 'required|string|min:3', 'username' => 'required|string|min:3',
'password' => 'required|string', 'password' => 'required|string',
]; ];
public function submit() public function submit()
{ {
$this->validate(); $this->validate();
$cred = [ $cred = [
'username' => $this->username, 'username' => $this->username,
'password' => $this->password 'password' => $this->password
]; ];
if (!Auth::attempt($cred)) { if (!Auth::attempt($cred)) {
session()->flash('message', __('auth.failed')); session()->flash('message', __('auth.failed'));
return; return;
} }
return redirect()->intended('/admin'); return redirect()->intended('/admin');
} }
/** /**
* Render the setup page * Render the setup page

View file

@ -9,68 +9,68 @@ use Illuminate\Support\Str;
abstract class ModelForm extends Component abstract class ModelForm extends Component
{ {
use Alert; use Alert;
/** /**
* The model record * The model record
*/ */
public $record; public $record;
/** /**
* True if the record already exists in the database. * True if the record already exists in the database.
*/ */
public bool $exist; public bool $exist;
/** /**
* Redirect after this route after record was created. * Redirect after this route after record was created.
*/ */
public string $redirect_route; public string $redirect_route;
/** /**
* Get the name of the model * Get the name of the model
*/ */
public function getModelName() : string public function getModelName(): string
{ {
return Str::afterLast(get_class($this->record), '\\'); return Str::afterLast(get_class($this->record), '\\');
} }
public function updated($property, $value) public function updated($property, $value)
{ {
$this->validateOnly($property); $this->validateOnly($property);
} }
/** /**
* Returns true if this record has not been stored in the database. * Returns true if this record has not been stored in the database.
*/ */
public function isNew() : bool public function isNew(): bool
{ {
return !$this->exist; return !$this->exist;
} }
/** /**
* Submit the form, create/update record. * Submit the form, create/update record.
*/ */
public function submit() public function submit()
{ {
$this->validate(); $this->validate();
$this->record->save(); $this->record->save();
if ($this->isNew()) { if ($this->isNew()) {
return redirect()->route($this->redirect_route) return redirect()->route($this->redirect_route)
->with('info', __("{$this->getModelName()} was successfully created.")); ->with('info', __("{$this->getModelName()} was successfully created."));
} }
$this->info(__("{$this->getModelName()} was successfully updated.")); $this->info(__("{$this->getModelName()} was successfully updated."));
} }
/** /**
* Render the setup page * Render the setup page
*/ */
public function render() public function render()
{ {
$script = Str::lower($this->getModelName()); $script = Str::lower($this->getModelName());
return view("form.$script") return view("form.$script")
->layout('layouts.admin'); ->layout('layouts.admin');
} }
} }

View file

@ -6,24 +6,24 @@ use App\Models\Raid;
class RaidForm extends ModelForm class RaidForm extends ModelForm
{ {
/** /**
* Redirect after this route after record was created. * Redirect after this route after record was created.
*/ */
public string $redirect_route = 'admin.raid.index'; public string $redirect_route = 'admin.raid.index';
public function mount(Raid $raid) public function mount(Raid $raid)
{ {
$this->record = $raid; $this->record = $raid;
$this->exist = $raid->exists; $this->exist = $raid->exists;
} }
/** /**
* Validation rules * Validation rules
*/ */
protected function rules() protected function rules()
{ {
return [ return [
'record.name' => 'required|string|min:2|max:20', 'record.name' => 'required|string|min:2|max:20',
]; ];
} }
} }

View file

@ -11,7 +11,7 @@ abstract class GameComponent extends Component
/** /**
* Get the game service object * Get the game service object
*/ */
public function getServiceProperty() : GameService public function getServiceProperty(): GameService
{ {
return app()->make(GameService::class); return app()->make(GameService::class);
} }