mirror of https://github.com/kcal-app/kcal.git
Refactor Goal attribute names
This commit is contained in:
parent
eee1cfaaf1
commit
755ef60561
|
|
@ -51,7 +51,7 @@ class GoalController extends Controller
|
||||||
{
|
{
|
||||||
return view('goals.edit')
|
return view('goals.edit')
|
||||||
->with('goal', $goal)
|
->with('goal', $goal)
|
||||||
->with('attributeOptions', Goal::getAttributeOptions());
|
->with('goalOptions', Goal::getGoalOptions());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -62,8 +62,8 @@ class GoalController extends Controller
|
||||||
$attributes = $request->validate([
|
$attributes = $request->validate([
|
||||||
'from' => ['nullable', 'date'],
|
'from' => ['nullable', 'date'],
|
||||||
'to' => ['nullable', 'date'],
|
'to' => ['nullable', 'date'],
|
||||||
'attribute' => ['required', 'string'],
|
'goal' => ['required', 'string'],
|
||||||
'goal' => ['required', 'numeric'],
|
'amount' => ['required', 'numeric'],
|
||||||
]);
|
]);
|
||||||
$goal->fill(array_filter($attributes))
|
$goal->fill(array_filter($attributes))
|
||||||
->user()->associate(Auth::user());
|
->user()->associate(Auth::user());
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ use App\Support\Nutrients;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* App\Models\Goal
|
* App\Models\Goal
|
||||||
|
|
@ -15,15 +14,15 @@ use Illuminate\Support\Str;
|
||||||
* @property int $user_id
|
* @property int $user_id
|
||||||
* @property \datetime|null $from
|
* @property \datetime|null $from
|
||||||
* @property \datetime|null $to
|
* @property \datetime|null $to
|
||||||
* @property string $attribute
|
* @property string $goal
|
||||||
* @property float $goal
|
* @property float $amount
|
||||||
* @property \Illuminate\Support\Carbon|null $created_at
|
* @property \Illuminate\Support\Carbon|null $created_at
|
||||||
* @property \Illuminate\Support\Carbon|null $updated_at
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||||
* @property-read \App\Models\User $user
|
* @property-read \App\Models\User $user
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Goal newModelQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal newModelQuery()
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Goal newQuery()
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal newQuery()
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Goal query()
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal query()
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereAttribute($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereAmount($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereCreatedAt($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereCreatedAt($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereFrom($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereFrom($value)
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereGoal($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereGoal($value)
|
||||||
|
|
@ -33,7 +32,7 @@ use Illuminate\Support\Str;
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereUserId($value)
|
* @method static \Illuminate\Database\Eloquent\Builder|Goal whereUserId($value)
|
||||||
* @mixin \Eloquent
|
* @mixin \Eloquent
|
||||||
*/
|
*/
|
||||||
class Goal extends Model
|
final class Goal extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
|
|
@ -43,8 +42,8 @@ class Goal extends Model
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'from',
|
'from',
|
||||||
'to',
|
'to',
|
||||||
'attribute',
|
|
||||||
'goal',
|
'goal',
|
||||||
|
'amount',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -53,7 +52,7 @@ class Goal extends Model
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'from' => 'datetime:Y-m-d',
|
'from' => 'datetime:Y-m-d',
|
||||||
'to' => 'datetime:Y-m-d',
|
'to' => 'datetime:Y-m-d',
|
||||||
'goal' => 'float',
|
'amount' => 'float',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -64,21 +63,19 @@ class Goal extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get options for the "attribute" column.
|
* Get options for the "goal" column.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function getAttributeOptions(): array {
|
public static function getGoalOptions(): array {
|
||||||
$options = [];
|
$options = [];
|
||||||
foreach (Nutrients::$all as $nutrient) {
|
foreach (Nutrients::$all as $nutrient) {
|
||||||
foreach (['daily', 'weekly', 'monthly', 'yearly'] as $frequency) {
|
$key = "{$nutrient['value']}_per_day";
|
||||||
$key = "{$nutrient['value']}_{$frequency}";
|
|
||||||
$options[$key] = [
|
$options[$key] = [
|
||||||
'value' => $key,
|
'value' => $key,
|
||||||
'label' => Str::ucfirst("{$frequency} {$nutrient['value']}")
|
'label' => "{$nutrient['value']} per day",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return $options;
|
return $options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ class CreateGoalsTable extends Migration
|
||||||
$table->foreignIdFor(User::class)->constrained()->cascadeOnUpdate()->cascadeOnDelete();
|
$table->foreignIdFor(User::class)->constrained()->cascadeOnUpdate()->cascadeOnDelete();
|
||||||
$table->date('from')->nullable();
|
$table->date('from')->nullable();
|
||||||
$table->date('to')->nullable();
|
$table->date('to')->nullable();
|
||||||
$table->string('attribute');
|
$table->string('goal');
|
||||||
$table->unsignedFloat('goal');
|
$table->unsignedFloat('amount');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
$table->index('user_id');
|
$table->index('user_id');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<x-app-layout>
|
<x-app-layout>
|
||||||
<x-slot name="header">
|
<x-slot name="header">
|
||||||
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
|
||||||
Delete {{ $goal->attribute }} Goal?
|
Delete {{ $goal->goal }} goal?
|
||||||
</h2>
|
</h2>
|
||||||
</x-slot>
|
</x-slot>
|
||||||
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
@method('delete')
|
@method('delete')
|
||||||
@csrf
|
@csrf
|
||||||
<div class="text-lg pb-3">
|
<div class="text-lg pb-3">
|
||||||
Are you sure what to delete your <span class="font-extrabold">{{ $goal->attribute }}</span> goal?
|
Are you sure what to delete your <span class="font-extrabold">{{ $goal->goal }}</span> goal?
|
||||||
</div>
|
</div>
|
||||||
<x-inputs.button class="bg-red-800 hover:bg-red-700">
|
<x-inputs.button class="bg-red-800 hover:bg-red-700">
|
||||||
Yes, delete
|
Yes, delete
|
||||||
|
|
|
||||||
|
|
@ -32,27 +32,24 @@
|
||||||
:value="old('to', $goal->to)" />
|
:value="old('to', $goal->to)" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Attribute -->
|
<!-- Amount -->
|
||||||
<div class="flex-auto">
|
<div class="flex-auto">
|
||||||
<x-inputs.label for="attribute" value="Attribute"/>
|
<x-inputs.label for="amount" value="Amount" />
|
||||||
|
<x-inputs.input name="amount"
|
||||||
<x-inputs.select name="attribute"
|
type="number"
|
||||||
class="block mt-1 w-full"
|
step="any"
|
||||||
:options="$attributeOptions"
|
class="block w-full"
|
||||||
:selectedValue="old('attribute', $goal->attribute)">
|
:value="old('amount', $goal->amount)"/>
|
||||||
<option value=""></option>
|
|
||||||
</x-inputs.select>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Goal -->
|
<!-- Goal -->
|
||||||
<div class="flex-auto">
|
<div class="flex-auto">
|
||||||
<x-inputs.label for="goal" value="Goal"/>
|
<x-inputs.label for="goal" value="Goal" />
|
||||||
|
<x-inputs.select name="goal"
|
||||||
<x-inputs.input name="goal"
|
class="block w-full"
|
||||||
type="number"
|
:options="$goalOptions"
|
||||||
step="any"
|
:selectedValue="old('goal', $goal->goal)">
|
||||||
class="block mt-1 w-full"
|
</x-inputs.select>
|
||||||
:value="old('goal', $goal->goal)"/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<x-app-layout>
|
<x-app-layout>
|
||||||
<x-slot name="header">
|
<x-slot name="header">
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<h2 class="font-semibold text-2xl text-gray-800 leading-tight">Goals</h2>
|
<h2 class="font-semibold text-2xl text-gray-800 leading-tight">{{ Auth::user()->name }}'s Goals</h2>
|
||||||
<a href="{{ route('goals.create') }}" class="inline-flex items-center rounded-md font-semibold text-white p-2 bg-green-500 tracking-widest hover:bg-green-700 active:bg-green-900 focus:outline-none focus:border-green-900 focus:ring ring-green-600 disabled:opacity-25 transition ease-in-out duration-150">
|
<a href="{{ route('goals.create') }}" class="inline-flex items-center rounded-md font-semibold text-white p-2 bg-green-500 tracking-widest hover:bg-green-700 active:bg-green-900 focus:outline-none focus:border-green-900 focus:ring ring-green-600 disabled:opacity-25 transition ease-in-out duration-150">
|
||||||
<svg class="w-6 h-6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
<svg class="w-6 h-6" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
|
||||||
<path fill-rule="evenodd" d="M10 5a1 1 0 011 1v3h3a1 1 0 110 2h-3v3a1 1 0 11-2 0v-3H6a1 1 0 110-2h3V6a1 1 0 011-1z" clip-rule="evenodd" />
|
<path fill-rule="evenodd" d="M10 5a1 1 0 011 1v3h3a1 1 0 110 2h-3v3a1 1 0 11-2 0v-3H6a1 1 0 110-2h3V6a1 1 0 011-1z" clip-rule="evenodd" />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue