Initial commit

This commit is contained in:
Chris Smith
2025-02-19 14:51:16 +01:00
commit d82a6cad96
198 changed files with 13819 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
<?php
/** @var \yii\web\View $this */
/** @var string $content */
use common\widgets\Alert;
use frontend\assets\AppAsset;
use yii\bootstrap5\Breadcrumbs;
use yii\bootstrap5\Html;
use yii\bootstrap5\Nav;
use yii\bootstrap5\NavBar;
use yii\helpers\Url;
AppAsset::register($this);
?>
<?php
$this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>" class="h-100">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<?php
$this->registerCsrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body class="d-flex flex-column h-100">
<?php
$this->beginBody() ?>
<header>
<?php
NavBar::begin([
'brandLabel' => Yii::$app->name,
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar navbar-expand-xxl navbar-dark bg-dark fixed-top navbar-fixed-50',
],
]);
$menuItems = [];
if (!Yii::$app->user->isGuest) {
$menuItems[] = [
'label' => 'Meals',
'url' => [Url::to(['meal/index'])],
];
$menuItems[] = [
'label' => 'Summary',
'url' => [Url::to(['summary'])],
];
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav me-auto'],
'items' => $menuItems,
]);
if (Yii::$app->user->isGuest) {
echo
Html::a(
'Signup',
['/site/signup'],
[
'class' => ['btn btn-link login text-decoration-none'],
]
);
echo
Html::a(
'Login',
['/site/login'],
[
'class' => ['btn btn-link login text-decoration-none'],
]
);
} else {
echo Html::beginForm(['/site/logout'], 'post', ['class' => 'd-flex'])
. Html::submitButton(
'Logout (' . Yii::$app->user->identity->email . ')',
['class' => 'btn btn-link logout text-decoration-none']
)
. Html::endForm();
}
NavBar::end();
?>
</header>
<main role="main" class="flex-shrink-0">
<div class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
</main>
<footer class="footer mt-auto py-3 text-muted">
<div class="container">
<p class="float-start">&copy; <?= Html::encode(Yii::$app->name) ?> <?= date('Y') ?></p>
</div>
</footer>
<?php
$this->endBody() ?>
</body>
</html>
<?php
$this->endPage();

View File

@@ -0,0 +1,39 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/** @var yii\web\View $this */
/** @var common\models\Meal $model */
/** @var yii\widgets\ActiveForm $form */
?>
<div class="meal-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'file_name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'calories')->textInput() ?>
<?= $form->field($model, 'protein')->textInput() ?>
<?= $form->field($model, 'fat')->textInput() ?>
<?= $form->field($model, 'carbohydrates')->textInput() ?>
<?= $form->field($model, 'fiber')->textInput() ?>
<?= $form->field($model, 'meal')->textInput() ?>
<?= $form->field($model, 'created_at')->textInput() ?>
<?= $form->field($model, 'updated_at')->textInput() ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@@ -0,0 +1,20 @@
<?php
use yii\helpers\Html;
/** @var yii\web\View $this */
/** @var common\models\Meal $model */
$this->title = 'Create Meal';
$this->params['breadcrumbs'][] = ['label' => 'Meals', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="meal-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@@ -0,0 +1,49 @@
<?php
use common\models\Meal;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\ActionColumn;
use yii\grid\GridView;
/** @var yii\web\View $this */
/** @var yii\data\ActiveDataProvider $dataProvider */
$this->title = 'Meals';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="meal-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Create Meal', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'file_name',
'calories',
'protein',
'fat',
//'carbohydrates',
//'fiber',
//'meal',
//'created_at',
//'updated_at',
[
'class' => ActionColumn::className(),
'urlCreator' => function ($action, Meal $model, $key, $index, $column) {
return Url::toRoute([$action, 'id' => $model->id]);
}
],
],
]); ?>
</div>

View File

@@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
/** @var yii\web\View $this */
/** @var common\models\Meal $model */
$this->title = 'Update Meal: ' . $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Meals', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="meal-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@@ -0,0 +1,45 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/** @var yii\web\View $this */
/** @var common\models\Meal $model */
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Meals', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="meal-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'file_name',
'calories',
'protein',
'fat',
'carbohydrates',
'fiber',
'meal',
'created_at',
'updated_at',
],
]) ?>
</div>

View File

@@ -0,0 +1,27 @@
<?php
/** @var yii\web\View $this */
/** @var string $name */
/** @var string $message */
/** @var Exception $exception */
use yii\helpers\Html;
$this->title = $name;
?>
<div class="site-error">
<h1><?= Html::encode($this->title) ?></h1>
<div class="alert alert-danger">
<?= nl2br(Html::encode($message)) ?>
</div>
<p>
The above error occurred while the Web server was processing your request.
</p>
<p>
Please contact us if you think this is a server error. Thank you.
</p>
</div>

View File

@@ -0,0 +1,43 @@
<?php
/** @var yii\web\View $this */
$this->title = 'Sales Agent';
?>
<div class="alert alert-info" role="info">
👋 <i>Please note: This app provides estimated nutritional values. It is not a substitute for professional dietary advice.</i>
</div>
<div class="site-index">
<div class="p-5 mb-4 bg-transparent rounded-3">
<div class="container-fluid py-5 text-center">
<h1 class="display-4">Calorie Ease</h1>
<p class="fs-5 fw-light">Track your food with a picture!</p>
<p>
<a class="btn btn-lg btn-success" href="<?= Yii::$app->getUrlManager()->createUrl(['meal/create']) ?>">Log a meal</a>
<a class="btn btn-lg btn-primary" href="<?= Yii::$app->getUrlManager()->createUrl(['summary']) ?>">View Summary</a></p>
</div>
</div>
<div class="body-content">
<div class="row">
<div class="col-lg-4">
<h2><i class="bi bi-camera-video"></i> Upload Food Photos</h2>
<p>Easily upload photos of your meals and snacks. Our AI analyzes the images to provide estimated nutrition data.</p>
</div>
<div class="col-lg-4">
<h2><i class="bi bi-bar-chart-line"></i> Daily Nutrition Summary</h2>
<p>View a concise summary of your daily calorie, protein, fat, carbohydrate, and fiber intake. This helps track your progress and goals.</p>
</div>
<div class="col-lg-4">
<h2><i class="bi bi-calendar-event"></i> Meal Logging & Tracking</h2>
<p>Effortlessly log your meals and snacks throughout the day. The app will automatically calculate your daily totals.</p>
</div>
</div>
<p></p>
</div>
</div>

View File

@@ -0,0 +1,55 @@
<?php
/** @var yii\web\View $this */
/** @var yii\bootstrap5\ActiveForm $form */
/** @var \common\models\LoginForm $model */
use yii\bootstrap5\Alert;
use yii\bootstrap5\Html;
use yii\bootstrap5\ActiveForm;
$this->title = 'Login';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-login">
<?php
if (YII_ENV_DEV) {
echo Alert::widget([
'options' => [
'class' => 'alert-success',
],
'body' => '<img src="/images/navi.png"> Hey! Listen! You can login with <strong>admin@example.com</strong> or <strong>user@example.com</strong> - both passwords are <strong>password</strong>',
'closeButton' => false,
]); ?>
<?php
}
?>
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to login:</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
<?= $form->field($model, 'email')->textInput(['autofocus' => true]) ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= $form->field($model, 'rememberMe')->checkbox() ?>
<div class="my-1 mx-0" style="color:#999;">
If you forgot your password you can <?= Html::a('reset it', ['site/request-password-reset']) ?>.
<br>
Need new verification email? <?= Html::a('Resend', ['site/resend-verification-email']) ?>
</div>
<div class="form-group">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,31 @@
<?php
/** @var yii\web\View $this */
/** @var yii\bootstrap5\ActiveForm $form */
/** @var \frontend\models\PasswordResetRequestForm $model */
use yii\bootstrap5\Html;
use yii\bootstrap5\ActiveForm;
$this->title = 'Request password reset';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-request-password-reset">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out your email. A link to reset password will be sent there.</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'request-password-reset-form']); ?>
<?= $form->field($model, 'email')->textInput(['autofocus' => true]) ?>
<div class="form-group">
<?= Html::submitButton('Send', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,31 @@
<?php
/** @var yii\web\View$this */
/** @var yii\bootstrap5\ActiveForm $form */
/** @var \frontend\models\ResetPasswordForm $model */
use yii\bootstrap5\Html;
use yii\bootstrap5\ActiveForm;
$this->title = 'Resend verification email';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-resend-verification-email">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out your email. A verification email will be sent there.</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'resend-verification-email-form']); ?>
<?= $form->field($model, 'email')->textInput(['autofocus' => true, 'data-1p-ignore' => '']) ?>
<div class="form-group">
<?= Html::submitButton('Send', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,31 @@
<?php
/** @var yii\web\View $this */
/** @var yii\bootstrap5\ActiveForm $form */
/** @var \frontend\models\ResetPasswordForm $model */
use yii\bootstrap5\Html;
use yii\bootstrap5\ActiveForm;
$this->title = 'Reset password';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-reset-password">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please choose your new password:</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'reset-password-form']); ?>
<?= $form->field($model, 'password')->passwordInput(['autofocus' => true]) ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,35 @@
<?php
/** @var yii\web\View $this */
/** @var yii\bootstrap5\ActiveForm $form */
/** @var \frontend\models\SignupForm $model */
use yii\bootstrap5\Html;
use yii\bootstrap5\ActiveForm;
$this->title = 'Signup';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-signup">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to signup:</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'form-signup']); ?>
<?= $form->field($model, 'first_name') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<div class="form-group">
<?= Html::submitButton('Signup', ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>

View File

@@ -0,0 +1,41 @@
<?php
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\bootstrap5\ActiveForm;
/** @var yii\web\View $this */
/** @var common\models\User $model */
/** @var array $salesAgents */
/** @var yii\widgets\ActiveForm $form */
?>
<div class="user-form">
<?php
$form = ActiveForm::begin(); ?>
<?= $form->field($model, 'email')->textInput() ?>
<?= $form->field($model, 'status')->dropDownList($model->getStatusName(true)) ?>
<?= $form->field($model, 'role')->dropDownList(
ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name'),
['prompt' => '-- Select role --']
) ?>
<?= $form->field($model, 'sales_agent_id')->label(Yii::t('app', 'Sales Agent'))->dropDownList(
$salesAgents,
['prompt' => '-- Select Sales Agent --']
) ?>
<br/>
<div class="form-group">
<?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success']) ?>
</div>
<?php
ActiveForm::end(); ?>
</div>

View File

@@ -0,0 +1,24 @@
<?php
use yii\helpers\Html;
/** @var yii\web\View $this */
/** @var common\models\User $model */
/** @var array $salesAgents */
$this->title = Yii::t('app', 'Create User');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Users'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-create">
<h1><?= Html::encode($this->title) ?></h1>
<p>A new password will be emailed to the user upon creation. The user will not need to validate their email address.</p>
<p>If you want them to validate their email, have them sign up on the home page.</p>
<?= $this->render('_form', [
'model' => $model,
'salesAgents' => $salesAgents,
]) ?>
</div>

View File

@@ -0,0 +1,97 @@
<?php
use common\models\User;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\ActionColumn;
use yii\grid\GridView;
use common\models\SalesAgent;
/** @var yii\web\View $this */
/** @var yii\data\ActiveDataProvider $dataProvider */
/** @var common\models\search\User $searchModel */
$this->title = Yii::t('app', 'Users');
?>
<div class="user-index container1">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a(Yii::t('app', 'Create User'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'layout' => "{items}\n{summary}{pager}",
'tableOptions' => [
'class' => 'custom-table',
],
'headerRowOptions' => [
'class' => 'table-header',
],
'rowOptions' => [
'class' => 'align-middle',
],
'columns' => [
'email:email',
[
'attribute' => 'status',
'label' => 'Status',
'value' => function ($model) {
return $model->getStatusName();
},
'filter' => [
User::STATUS_ACTIVE => 'Active',
User::STATUS_INACTIVE => 'Inactive',
User::STATUS_UNVERIFIED => 'Unverified',
User::STATUS_VERIFIED => 'Verified (not active)',
],
],
[
'attribute' => 'salesAgentName',
'label' => Yii::t('app', 'Sales Agent'),
'format' => 'raw',
'value' => function ($model) {
return $model->salesAgent
? Html::a($model->salesAgent->name, Url::to(['sales-agent/view', 'id' => $model->salesAgent->id]))
: Yii::t('app', 'None assigned');
},
'filter' => \yii\helpers\ArrayHelper::map(SalesAgent::find()->all(), 'name', 'name'),
],
[
'attribute' => 'role',
'label' => 'Role',
'value' => function ($model) {
$roles = Yii::$app->authManager->getRolesByUser($model->id);
return !empty($roles) ? reset($roles)->name : null;
},
'filter' => \yii\helpers\ArrayHelper::map(
Yii::$app->authManager->getRoles(),
'name',
'name'
),
],
'created_at:datetime',
'updated_at:datetime',
[
'class' => ActionColumn::class,
'urlCreator' => function ($action, User $model, $key, $index, $column) {
return Url::toRoute([$action, 'id' => $model->id]);
},
],
],
'pager' => [
'class' => 'yii\widgets\LinkPager',
'nextPageLabel' => '►',
'prevPageLabel' => '◄',
'firstPageLabel' => 'First',
'lastPageLabel' => 'Last',
'maxButtonCount' => 5,
'options' => ['class' => 'pagination'],
],
]); ?>
</div>

View File

@@ -0,0 +1,22 @@
<?php
use yii\helpers\Html;
/** @var yii\web\View $this */
/** @var common\models\User $model */
/** @var array $salesAgents */
$this->title = Yii::t('app', 'Update User: {name}', [
'name' => $model->email,
]);
?>
<div class="user-update container1">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
'salesAgents' => $salesAgents
]) ?>
</div>

View File

@@ -0,0 +1,51 @@
<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\DetailView;
/** @var yii\web\View $this */
/** @var common\models\User $model */
$this->title = $model->email;
\yii\web\YiiAsset::register($this);
?>
<div class="user-view mt-3">
<div class="card shadow-sm rounded-lg p-4">
<h2 class="mb-3"><?= Html::encode($this->title) ?></h2>
<div class="d-flex gap-2 mb-4">
<?php if (Yii::$app->user->can('updateDelete')): ?>
<?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => Yii::t('app', 'Are you sure you want to delete this user?'),
'method' => 'post',
],
]) ?>
<?php endif; ?>
</div>
<div class="row">
<div class="col-md-6">
<p><strong>ID:</strong> <?= Html::encode($model->id) ?></p>
<p><strong>Email:</strong> <?= Html::encode($model->email) ?></p>
<p><strong>Status:</strong> <?= Html::encode($model->statusName) ?></p>
<p><strong>Role:</strong> <?= Html::encode($model->role) ?></p>
</div>
<div class="col-md-6">
<p><strong>Sales Agent:</strong>
<?php if (!empty($model->salesAgent)): ?>
<?= Html::a(Html::encode($model->salesAgent->name), Url::to(['sales-agent/view', 'id' => $model->salesAgent->id]), ['class' => 'text-decoration-none']) ?>
<?php else: ?>
<?= Yii::t('app', 'None assigned') ?>
<?php endif; ?>
</p>
<p><strong>Created At:</strong> <?= Yii::$app->formatter->asDatetime($model->created_at) ?></p>
<p><strong>Updated At:</strong> <?= Yii::$app->formatter->asDatetime($model->updated_at) ?></p>
</div>
</div>
</div>
</div>