initial release
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace frontend\controllers;
|
||||
|
||||
use common\models\Meal;
|
||||
use common\models\search\MealSearch;
|
||||
use frontend\models\MealForm;
|
||||
use Yii;
|
||||
use yii\data\ActiveDataProvider;
|
||||
@@ -51,22 +52,10 @@ class MealController extends Controller
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => Meal::find(),
|
||||
/*
|
||||
'pagination' => [
|
||||
'pageSize' => 50
|
||||
],
|
||||
'sort' => [
|
||||
'defaultOrder' => [
|
||||
'id' => SORT_DESC,
|
||||
]
|
||||
],
|
||||
*/
|
||||
]);
|
||||
$searchModel = new MealSearch();
|
||||
|
||||
return $this->render('index', [
|
||||
'dataProvider' => $dataProvider,
|
||||
'dataProvider' => $searchModel->search($this->request->queryParams),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -77,8 +66,8 @@ class MealController extends Controller
|
||||
if (Yii::$app->request->isPost) {
|
||||
$model->picture = UploadedFile::getInstance($model, 'picture');
|
||||
if ($model->upload()) {
|
||||
$meal = \Yii::$app->gemini->mealInquiry($model->filepath);
|
||||
return $this->render('success', ['model' => $meal]);
|
||||
$id = \Yii::$app->gemini->mealInquiry($model->filepath);
|
||||
return Yii::$app->response->redirect(['meal/success', 'id' => $id]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,9 +76,11 @@ class MealController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionSuccess()
|
||||
public function actionSuccess($id)
|
||||
{
|
||||
return $this->render('success');
|
||||
$model = $this->findModel($id);
|
||||
|
||||
return $this->render('success', ['model' => $model]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,7 +161,7 @@ class MealController extends Controller
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = Meal::findOne(['id' => $id])) !== null) {
|
||||
if (($model = MealSearch::findOne(['id' => $id, 'user_id' => Yii::$app->user->id])) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
@@ -144,8 +144,8 @@ class SiteController extends Controller
|
||||
{
|
||||
$model = new SignupForm();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->signup()) {
|
||||
Yii::$app->session->setFlash('success', 'Thank you for registration! Snap your first meal.');
|
||||
return $this->response->redirect(['meal/create']);
|
||||
Yii::$app->session->setFlash('success', 'Thank you for registering! Sign in and snap your first meal!');
|
||||
return $this->response->redirect(['meal/upload']);
|
||||
}
|
||||
|
||||
return $this->render('signup', [
|
||||
@@ -170,11 +170,6 @@ class SiteController extends Controller
|
||||
}
|
||||
|
||||
|
||||
// @todo
|
||||
// fix deployment script
|
||||
// save local .env variables for deployment
|
||||
// verify email is working
|
||||
// fix user sales agent issue
|
||||
/**
|
||||
* Requests password reset.
|
||||
*
|
||||
|
||||
@@ -55,8 +55,8 @@ class SignupForm extends Model
|
||||
|
||||
// the following three lines were added:
|
||||
$auth = \Yii::$app->authManager;
|
||||
$salesAgentRole = $auth->getRole('user');
|
||||
$auth->assign($salesAgentRole, $user->getId());
|
||||
$userRole = $auth->getRole('user');
|
||||
$auth->assign($userRole, $user->getId());
|
||||
|
||||
return $this->sendEmail($user);
|
||||
}
|
||||
|
||||
@@ -48,13 +48,9 @@ $this->beginPage() ?>
|
||||
'label' => 'Capture Meal',
|
||||
'url' => [Url::to(['meal/upload'])],
|
||||
];
|
||||
$menuItems[] = [
|
||||
'label' => 'List Meals',
|
||||
'url' => [Url::to(['meal/index'])],
|
||||
];
|
||||
$menuItems[] = [
|
||||
'label' => 'Summary',
|
||||
'url' => [Url::to(['summary'])],
|
||||
'url' => [Url::to(['meal/index'])],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -25,19 +25,15 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
'dataProvider' => $dataProvider,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
'id',
|
||||
'file_name',
|
||||
'food_name',
|
||||
'calories',
|
||||
'protein',
|
||||
'fat',
|
||||
//'carbohydrates',
|
||||
//'fiber',
|
||||
//'meal',
|
||||
//'created_at',
|
||||
//'updated_at',
|
||||
'carbohydrates',
|
||||
'fiber',
|
||||
'created_at:datetime',
|
||||
[
|
||||
'class' => ActionColumn::className(),
|
||||
'class' => ActionColumn::class,
|
||||
'urlCreator' => function ($action, Meal $model, $key, $index, $column) {
|
||||
return Url::toRoute([$action, 'id' => $model->id]);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ $this->registerJS("
|
||||
<?= $form->field($model, 'picture')
|
||||
->fileInput([
|
||||
'class' => 'form-control',
|
||||
//'capture' => 'environment',
|
||||
'capture' => 'environment',
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
||||
@@ -16,7 +16,7 @@ $this->title = 'Calorie Thingy';
|
||||
<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/upload']) ?>">Capture a meal</a>
|
||||
<a class="btn btn-lg btn-primary" href="<?= Yii::$app->getUrlManager()->createUrl(['summary']) ?>">View Summary</a></p>
|
||||
<a class="btn btn-lg btn-primary" href="<?= Yii::$app->getUrlManager()->createUrl(['meal/index']) ?>">View Summary</a></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="body-content">
|
||||
|
||||
@@ -41,8 +41,6 @@ $this->params['breadcrumbs'][] = $this->title;
|
||||
|
||||
<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">
|
||||
|
||||
Reference in New Issue
Block a user