Add goal change form base (WIP)

This commit is contained in:
Christopher C. Wells 2021-05-22 06:06:16 -07:00
parent d81ef9952f
commit a310540733
4 changed files with 50 additions and 4 deletions

View File

@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers;
use App\Models\JournalDate;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
class JournalDateController extends Controller
{
/**
* Change the goals for a journal date.
*/
public function updateGoal(Request $request, JournalDate $journalDate): RedirectResponse
{
// @todo Implement goal up behavior.
return redirect()->route('journal-entries.show');
}
}

View File

@ -8,6 +8,7 @@ namespace App\Http\Controllers;
use App\Http\Requests\StoreFromNutrientsJournalEntryRequest; use App\Http\Requests\StoreFromNutrientsJournalEntryRequest;
use App\Http\Requests\StoreJournalEntryRequest; use App\Http\Requests\StoreJournalEntryRequest;
use App\Models\Food; use App\Models\Food;
use App\Models\Goal;
use App\Models\JournalEntry; use App\Models\JournalEntry;
use App\Models\Recipe; use App\Models\Recipe;
use App\Support\ArrayFormat; use App\Support\ArrayFormat;
@ -53,11 +54,20 @@ class JournalEntryController extends Controller
} }
} }
// Get all goals as options to change for the date.
$goalOptions = Goal::whereUserId(Auth::user()->id)
->orderBy('name')
->get()
->map(function (Goal $goal) {
return ['value' => $goal->id, 'label' => $goal->name];
});
return view('journal-entries.index') return view('journal-entries.index')
->with('entries', $entries) ->with('entries', $entries)
->with('sums', $sums) ->with('sums', $sums)
->with('goal', $goal) ->with('currentGoal', $goal)
->with('goalProgress', $goalProgress) ->with('goalProgress', $goalProgress)
->with('goalOptions', $goalOptions)
->with('date', $date); ->with('date', $date);
} }

View File

@ -100,14 +100,25 @@
</div> </div>
</div> </div>
<h4 class="font-semibold text-lg pt-2">Goal</h4> <h4 class="font-semibold text-lg pt-2">Goal</h4>
@empty($goal) @empty($currentGoal)
<div class="italic">No goal.</div> <div class="italic">No goal.</div>
@else @else
<a class="text-gray-500 hover:text-gray-700 hover:border-gray-300" <a class="text-gray-500 hover:text-gray-700 hover:border-gray-300"
href="{{ route('goals.show', $goal) }}"> href="{{ route('goals.show', $currentGoal) }}">
{{ $goal->name }} {{ $currentGoal->name }}
</a> </a>
@endempty @endempty
<form method="POST" action="{{ route('journal-dates.update.goal') }}">
@csrf
<x-inputs.select name="goal"
class="block w-full"
:options="$goalOptions ?? []"
:selectedValue="$currentGoal?->id ?? null">
</x-inputs.select>
<div class="flex items-center justify-start mt-4">
<x-inputs.button>Change Goal</x-inputs.button>
</div>
</form>
</div> </div>
<div class="w-full sm:w-3/5 md:w-2/3 lg:w-3/4 flex flex-col space-y-4"> <div class="w-full sm:w-3/5 md:w-2/3 lg:w-3/4 flex flex-col space-y-4">
@foreach(['breakfast', 'lunch', 'dinner', 'snacks'] as $meal) @foreach(['breakfast', 'lunch', 'dinner', 'snacks'] as $meal)

View File

@ -3,6 +3,7 @@
use App\Http\Controllers\FoodController; use App\Http\Controllers\FoodController;
use App\Http\Controllers\GoalController; use App\Http\Controllers\GoalController;
use App\Http\Controllers\IngredientPickerController; use App\Http\Controllers\IngredientPickerController;
use App\Http\Controllers\JournalDateController;
use App\Http\Controllers\JournalEntryController; use App\Http\Controllers\JournalEntryController;
use App\Http\Controllers\ProfileController; use App\Http\Controllers\ProfileController;
use App\Http\Controllers\RecipeController; use App\Http\Controllers\RecipeController;
@ -30,6 +31,9 @@ Route::middleware(['auth'])->group(function () {
// Ingredient picker. // Ingredient picker.
Route::get('/ingredient-picker/search', [IngredientPickerController::class, 'search'])->name('ingredient-picker.search'); Route::get('/ingredient-picker/search', [IngredientPickerController::class, 'search'])->name('ingredient-picker.search');
// Journal dates.
Route::post('/journal-dates/update/goal', [JournalDateController::class, 'updateGoal'])->name('journal-dates.update.goal');
// Journal entries. // Journal entries.
Route::get('/journal-entries/create/from-nutrients', [JournalEntryController::class, 'createFromNutrients'])->name('journal-entries.create.from-nutrients'); Route::get('/journal-entries/create/from-nutrients', [JournalEntryController::class, 'createFromNutrients'])->name('journal-entries.create.from-nutrients');
Route::post('/journal-entries/create/from-nutrients', [JournalEntryController::class, 'storeFromNutrients'])->name('journal-entries.store.from-nutrients'); Route::post('/journal-entries/create/from-nutrients', [JournalEntryController::class, 'storeFromNutrients'])->name('journal-entries.store.from-nutrients');