Updated success screen

This commit is contained in:
Chris Smith
2025-02-23 14:14:41 +01:00
parent 5ec2680f27
commit 27395cc408
2 changed files with 23 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ namespace frontend\controllers;
use common\models\Meal;
use common\models\MealForm;
use common\models\search\MealSearch;
use DateTime;
use Yii;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
@@ -63,9 +64,10 @@ class MealController extends Controller
$model = new MealForm();
if (Yii::$app->request->isPost) {
$model->load(Yii::$app->request->post());
$model->picture = UploadedFile::getInstance($model, 'picture');
if ($model->upload()) {
$id = \Yii::$app->gemini->mealInquiry($model->filepath);
$id = \Yii::$app->gemini->mealInquiry($model);
return Yii::$app->response->redirect(['meal/success', 'id' => $id]);
}
}
@@ -78,9 +80,7 @@ class MealController extends Controller
public function actionSuccess($id)
{
$model = $this->findModel($id);
$startOfDay = strtotime('today midnight');
$endOfDay = strtotime('tomorrow midnight') - 1;
$today = Meal::find()
$sum = Meal::find()
->select([
'SUM(calories) AS calories',
'SUM(protein) AS protein',
@@ -88,13 +88,22 @@ class MealController extends Controller
'SUM(carbohydrates) AS carbohydrates',
'SUM(fiber) AS fiber'
])
->where(['user_id' => Yii::$app->user->id])
->andWhere(['between', 'created_at', $startOfDay, $endOfDay])
->where(['user_id' => Yii::$app->user->id, 'date' => $model->date])
->asArray()
->one();
$today = array_merge(['calories' => 0, 'protein' => 0, 'fat' => 0, 'carbohydrates' => 0, 'fiber' => 0], $today);
$sum = array_merge(['calories' => 0, 'protein' => 0, 'fat' => 0, 'carbohydrates' => 0, 'fiber' => 0], $sum);
return $this->render('success', ['model' => $model, 'today' => $today]);
$today = new DateTime();
$modelDate = new DateTime($model->date); // @todo should be a date object
$diff = $today->diff($modelDate);
$sum['title'] = match ($diff->days) {
0 => 'Today So Far',
1 => 'Yesterday\'s Sum',
default => $modelDate->format('M jS'),
};
return $this->render('success', ['model' => $model, 'sum' => $sum]);
}
/**

View File

@@ -83,7 +83,7 @@ var isMobile = window.innerWidth < 768; // Adjust as needed for tablets
<!-- Daily Totals Section -->
<div class="col-md-6 d-flex mt-3 mt-md-0">
<div class="card p-3 w-100 h-100 d-flex flex-column" style="max-width: 400px; border-radius: 12px; box-shadow: 0 4px 10px rgba(0,0,0,0.1); z-index: 200;">
<h4 class="card-title text-center">📊 <strong>Today So Far</strong></h4>
<h4 class="card-title text-center">📊 <strong><?=$sum['title']?></strong></h4>
<div class="row flex-grow-1">
<div class="col-6 text-end">
<p class="mb-0"><strong>🔥 Calories</strong></p>
@@ -93,11 +93,11 @@ var isMobile = window.innerWidth < 768; // Adjust as needed for tablets
<p class="mb-0"><strong>🌾 Fiber</strong></p>
</div>
<div class="col-6 text-start">
<p class="mb-0"><?= $today['calories']; ?> kcal</p>
<p class="mb-0"><?= $today['protein']; ?> g</p>
<p class="mb-0"><?= $today['fat']; ?> g</p>
<p class="mb-0"><?= $today['carbohydrates']; ?> g</p>
<p class="mb-0"><?= $today['fiber']; ?> g</p>
<p class="mb-0"><?= $sum['calories']; ?> kcal</p>
<p class="mb-0"><?= $sum['protein']; ?> g</p>
<p class="mb-0"><?= $sum['fat']; ?> g</p>
<p class="mb-0"><?= $sum['carbohydrates']; ?> g</p>
<p class="mb-0"><?= $sum['fiber']; ?> g</p>
</div>
</div>
</div>