Replace recipe active time with cook time

This commit is contained in:
Christopher C. Wells 2021-03-13 13:51:37 -08:00
parent 9952803368
commit be9c45a414
7 changed files with 52 additions and 16 deletions

View File

@ -167,7 +167,7 @@ class RecipeController extends Controller
'remove_image' => ['nullable', 'boolean'],
'servings' => ['required', 'numeric'],
'time_prep' => ['nullable', 'numeric'],
'time_active' => ['nullable', 'numeric'],
'time_cook' => ['nullable', 'numeric'],
'weight' => ['nullable', 'numeric'],
'source' => ['nullable', 'string'],
'ingredients.amount' => ['required', 'array', new ArrayNotEmpty],
@ -201,7 +201,7 @@ class RecipeController extends Controller
'servings' => (int) $input['servings'],
'weight' => $input['weight'],
'time_prep' => (int) $input['time_prep'],
'time_active' => (int) $input['time_active'],
'time_cook' => (int) $input['time_cook'],
'source' => $input['source'],
]);

View File

@ -30,7 +30,7 @@ class RecipeSchema extends SchemaProvider
'name' => $resource->name,
'description' => $resource->description,
'time_prep' => $resource->time_prep,
'time_active' => $resource->time_active,
'time_cook' => $resource->time_cook,
'time_total' => $resource->time_total,
'source' => $resource->source,
'servings' => $resource->servings,

View File

@ -60,7 +60,7 @@ use Spatie\Tags\HasTags;
* @method static \Illuminate\Database\Eloquent\Builder|Recipe withAnyTagsOfAnyType($tags)
* @mixin \Eloquent
* @property int|null $time_prep
* @property int|null $time_active
* @property int|null $time_cook
* @property-read int $time_total
* @method static \Illuminate\Database\Eloquent\Builder|Recipe whereTimeActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|Recipe whereTimePrep($value)
@ -90,7 +90,7 @@ final class Recipe extends Model implements HasMedia
'description',
'description_delta',
'time_prep',
'time_active',
'time_cook',
'source',
'servings',
'weight',
@ -102,7 +102,7 @@ final class Recipe extends Model implements HasMedia
protected $casts = [
'servings' => 'int',
'time_prep' => 'int',
'time_active' => 'int',
'time_cook' => 'int',
'weight' => 'float',
];
@ -145,7 +145,7 @@ final class Recipe extends Model implements HasMedia
* Get total recipe time.
*/
public function getTimeTotalAttribute(): int {
return $this->time_prep + $this->time_active;
return $this->time_prep + $this->time_cook;
}
/**

View File

@ -20,7 +20,7 @@ class CreateRecipesTable extends Migration
$table->longText('description')->nullable();
$table->longText('description_delta')->nullable();
$table->integer('time_prep')->nullable();
$table->integer('time_active')->nullable();
$table->integer('time_cook')->nullable();
$table->string('source')->nullable();
$table->unsignedInteger('servings');
$table->unsignedFloat('weight')->nullable();

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class ReplaceActiveTimeWithCookTimeInRecipes extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('recipes', function (Blueprint $table) {
$table->integer('time_cook')->nullable()->after('time_prep');
});
DB::update("UPDATE `recipes` SET `time_cook` = `time_active`;");
Schema::table('recipes', function (Blueprint $table) {
$table->dropColumn(['time_active']);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('recipes', function (Blueprint $table) {
$table->dropColumn(['time_cook']);
});
}
}

View File

@ -51,19 +51,19 @@
step="1"
min="0"
class="block mt-1 w-full"
:value="old('name', $recipe->time_prep)"/>
:value="old('time_prep', $recipe->time_prep)"/>
</div>
<!-- Active Time -->
<!-- Cooke Time -->
<div class="flex-auto">
<x-inputs.label for="time_active" value="Active time (minutes)" />
<x-inputs.label for="time_cook" value="Cook time (minutes)" />
<x-inputs.input name="time_active"
<x-inputs.input name="time_cook"
type="number"
step="1"
min="0"
class="block mt-1 w-full"
:value="old('servings', $recipe->time_active)"/>
:value="old('time_cook', $recipe->time_cook)"/>
</div>
</div>
<div class="flex flex-col space-y-4 mt-4">

View File

@ -22,7 +22,7 @@
</h1>
</x-slot>
<div class="flex flex-col justify-between pb-4 md:flex-row md:space-x-4">
<div x-data="{showNutrientsSummary: false}">
<div class="flex-1" x-data="{showNutrientsSummary: false}">
@if($recipe->time_total > 0)
<section class="flex justify-between mb-2 p-2 bg-gray-100 rounded">
<div>
@ -30,8 +30,8 @@
<p class="text-gray-800 text-sm">{{ $recipe->time_prep }} minutes</p>
</div>
<div>
<h1 class="mb-1 font-bold">Active time</h1>
<p class="text-gray-800 text-sm">{{ $recipe->time_active }} minutes</p>
<h1 class="mb-1 font-bold">Cook time</h1>
<p class="text-gray-800 text-sm">{{ $recipe->time_cook }} minutes</p>
</div>
<div>
<h1 class="mb-1 font-bold">Total time</h1>