forked from eatvio/eatvio-infra
live charts update added
This commit is contained in:
110
app/Http/Controllers/ConsultantRequestFormController.php
Normal file
110
app/Http/Controllers/ConsultantRequestFormController.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class ConsultantRequestFormController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('consultant.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$user = Auth::user();
|
||||
$state = $user->consultant_state;
|
||||
if ($state !== 'incomplete') {
|
||||
return redirect()->route('consultant_request.show', [$user]);
|
||||
}
|
||||
return view(
|
||||
'consultant.registration',
|
||||
[
|
||||
'user' => $user,
|
||||
'currentConsultantRegistrationState' => $state,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(User $user)
|
||||
{
|
||||
$requestData = $user->consultant_request;
|
||||
$medicalEducations = $requestData ? json_decode($requestData->completed_courses, true) : [];
|
||||
$certs = $user->attachments()->certs()->get();
|
||||
return view(
|
||||
'consultant.show',
|
||||
[
|
||||
'user' => $user,
|
||||
'currentConsultantRegistrationState' => $user->consultant_state,
|
||||
'medicalEducations' => $medicalEducations,
|
||||
'certPhotos' => $certs,
|
||||
'requestData' => $requestData,
|
||||
]
|
||||
);
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(User $user)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, User $user)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(User $user)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,6 @@ class DiaryController extends Controller
|
||||
/* $curDiary = Diary::find($id); */
|
||||
$daysCount = Diary::where('user_id', auth()->id())->count();
|
||||
return view('diary.show', ['curDiary' => $diary, 'daysCount' => $daysCount]);
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,8 +6,6 @@ use App\Models\UserDetailz;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Asantibanez\LivewireCharts\Models\LineChartModel;
|
||||
use Asantibanez\LivewireCharts\Models\AreaChartModel;
|
||||
|
||||
class ProfileController extends Controller
|
||||
{
|
||||
@@ -18,59 +16,7 @@ class ProfileController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$user = Auth::user();
|
||||
$lastFourMisures = $user
|
||||
->circumference_measures()
|
||||
->orderBy('created_at', 'desc')
|
||||
->limit(4)
|
||||
->get()
|
||||
->sortBy('id');
|
||||
|
||||
$lastOneMisure = $user->circumference_measures()->get()->last();
|
||||
|
||||
$lineChartModel =
|
||||
(new LineChartModel())
|
||||
->setSmoothCurve()
|
||||
->multiLine()
|
||||
->setColors(['#b2df8a', '#1f78b4', '#e3a6a6']);
|
||||
|
||||
$lastFourMisures->each(
|
||||
function ($item, $key) use ($lineChartModel) {
|
||||
$createdAt = \Carbon\Carbon::parse($item['created_at'])->format('d.m.y');
|
||||
$lineChartModel->addSeriesPoint(__('chest'), $createdAt, $item['chest_circumference']);
|
||||
$lineChartModel->addSeriesPoint(__('waist'), $createdAt, $item['waist_circumference']);
|
||||
$lineChartModel->addSeriesPoint(__('hip'), $createdAt, $item['hip_circumference']);
|
||||
});
|
||||
|
||||
$areaChartModel =
|
||||
(new AreaChartModel())
|
||||
->setSmoothCurve()
|
||||
->setColors(['#b7d7e8']);
|
||||
|
||||
$lastFourWeightMisures = $user
|
||||
->weight_measures()
|
||||
->orderBy('created_at', 'desc')
|
||||
->limit(4)
|
||||
->get()
|
||||
->sortBy('id');
|
||||
|
||||
$lastFourWeightMisures->each(
|
||||
function ($item, $key) use ($areaChartModel) {
|
||||
$createdAt = \Carbon\Carbon::parse($item['created_at'])->format('d.m.y');
|
||||
$areaChartModel->addPoint($createdAt, $item['weight']);
|
||||
}
|
||||
);
|
||||
|
||||
return view(
|
||||
'profile.index',
|
||||
[
|
||||
'user' => $user,
|
||||
'lastFourMisures' => $lastFourMisures,
|
||||
'lastOneMisure' => $lastOneMisure,
|
||||
'lineChartModel' => $lineChartModel,
|
||||
'areaChartModel' => $areaChartModel,
|
||||
]
|
||||
);
|
||||
return view('profile.index', ['user' => Auth::user()]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -181,4 +181,5 @@ class UserDetailzController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
17
app/Http/Livewire/Consultant/ListConsultants.php
Normal file
17
app/Http/Livewire/Consultant/ListConsultants.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Consultant;
|
||||
|
||||
use App\Models\ConsultantEducation;
|
||||
use Livewire\Component;
|
||||
|
||||
class ListConsultants extends Component
|
||||
{
|
||||
public function render()
|
||||
{
|
||||
return view(
|
||||
'livewire.consultant.list-consultants',
|
||||
['consultantRequests' => ConsultantEducation::all()]
|
||||
);
|
||||
}
|
||||
}
|
||||
158
app/Http/Livewire/Consultant/RegistrationForm.php
Normal file
158
app/Http/Livewire/Consultant/RegistrationForm.php
Normal file
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Consultant;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\ConsultantEducation;
|
||||
use App\Models\UserAttachment;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
|
||||
class RegistrationForm extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public User $user;
|
||||
public $medicalEducations = [];
|
||||
public $vkLink = "";
|
||||
public $instagramLink = "";
|
||||
public $facebookLink = "";
|
||||
public $telegramLink = "";
|
||||
public $hasMedicalEducation = false;
|
||||
public $certPhotos = [];
|
||||
public $tmpCertPhotos = [];
|
||||
|
||||
protected $rules = [
|
||||
'medicalEducations.*.title' => 'required|string|min:6',
|
||||
'medicalEducations.*.date' => 'required|date',
|
||||
'vkLink' => 'required|url',
|
||||
'instagramLink' => 'required|url',
|
||||
'facebookLink' => 'required|url',
|
||||
'telegramLink' => 'required|url',
|
||||
'hasMedicalEducation' => 'required|boolean',
|
||||
'tmpCertPhotos.*' => 'image|max:4024'
|
||||
];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->user = Auth::user();
|
||||
$consultant_request = $this->user->consultant_request;
|
||||
if ($consultant_request) {
|
||||
$this->medicalEducations = json_decode($consultant_request->completed_courses, true);
|
||||
$this->vkLink = $consultant_request->vk_link;
|
||||
$this->instagramLink = $consultant_request->insta_link;
|
||||
$this->facebookLink= $consultant_request->fb_link;
|
||||
$this->telegramLink = $consultant_request->tg_link;
|
||||
$this->hasMedicalEducation = $consultant_request->has_medical_education;
|
||||
}
|
||||
|
||||
$photos = $this->user->attachments()->certs()->get();
|
||||
|
||||
if ($photos) {
|
||||
$this->certPhotos = collect($photos);
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.consultant.registration-form');
|
||||
}
|
||||
|
||||
public function addEducation()
|
||||
{
|
||||
$this->validate();
|
||||
$medicalEducations = $this->medicalEducations;
|
||||
$this->resetExcept(
|
||||
[
|
||||
'user',
|
||||
'vkLink',
|
||||
'instagramLink',
|
||||
'facebookLink',
|
||||
'telegramLink',
|
||||
'hasMedicalEducation',
|
||||
'certPhotos',
|
||||
'tmpCertPhotos'
|
||||
]
|
||||
);
|
||||
|
||||
$this->medicalEducations = $medicalEducations;
|
||||
}
|
||||
|
||||
public function remove($index)
|
||||
{
|
||||
$filteredEducations = array_filter(
|
||||
$this->medicalEducations,
|
||||
function($val, $key) use ($index) {
|
||||
return $key != $index;
|
||||
},
|
||||
ARRAY_FILTER_USE_BOTH
|
||||
);
|
||||
|
||||
$this->medicalEducations = array_values($filteredEducations);
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$data = [
|
||||
'user_id' => $this->user->id,
|
||||
'completed_courses' => json_encode($this->medicalEducations),
|
||||
'vk_link' => $this->vkLink,
|
||||
'insta_link' => $this->instagramLink,
|
||||
'fb_link' => $this->facebookLink,
|
||||
'tg_link' => $this->telegramLink,
|
||||
'has_medical_education' => $this->hasMedicalEducation,
|
||||
'request_state' => 'created',
|
||||
];
|
||||
|
||||
$this->validate();
|
||||
|
||||
ConsultantEducation::updateOrCreate(
|
||||
[
|
||||
'user_id' => $this->user->id
|
||||
],
|
||||
$data
|
||||
);
|
||||
|
||||
/* $newConsultantRequest->save(); */
|
||||
|
||||
$attachmentGroup = "user_certs";
|
||||
|
||||
foreach($this->tmpCertPhotos as $photo) {
|
||||
$curCert = $photo->storePublicly("public/" . $attachmentGroup . "/" . $this->user->id);
|
||||
$fileData = [
|
||||
'user_id' => $this->user->id,
|
||||
'group' => $attachmentGroup,
|
||||
'original_name' => $photo->getClientOriginalName(),
|
||||
'size' => $photo->getSize(),
|
||||
];
|
||||
|
||||
$newFile = UserAttachment::updateOrCreate(
|
||||
$fileData,
|
||||
[
|
||||
'path' => preg_replace("/public\//xi", "/storage/", $curCert),
|
||||
'specs' => json_encode(
|
||||
[
|
||||
'ext' => $photo->extension(),
|
||||
'original_path' => $curCert,
|
||||
]
|
||||
)
|
||||
]
|
||||
);
|
||||
$newFile->save();
|
||||
$this->certPhotos = collect($this->user->attachments()->certs()->get());
|
||||
$this->reset('tmpCertPhotos');
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteImg($id)
|
||||
{
|
||||
$file = UserAttachment::find($id);
|
||||
$fileSpecs = json_decode($file->specs, true);
|
||||
Storage::delete($fileSpecs['original_path']);
|
||||
$file->delete();
|
||||
|
||||
$this->certPhotos = $this->certPhotos->whereNotIn('id', [$id]);
|
||||
}
|
||||
}
|
||||
66
app/Http/Livewire/Diary/MealPhotos.php
Normal file
66
app/Http/Livewire/Diary/MealPhotos.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Diary;
|
||||
|
||||
use App\Models\Meal;
|
||||
use App\Models\UserAttachment;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithFileUploads;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class MealPhotos extends Component
|
||||
{
|
||||
use WithFileUploads;
|
||||
|
||||
public Meal $meal;
|
||||
public $tmpMealPhotos = [];
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view(
|
||||
'livewire.diary.meal-photos',
|
||||
[
|
||||
'curMealPhotos' => $this->meal->photos
|
||||
],
|
||||
);
|
||||
}
|
||||
public function updatedTmpMealPhotos($values)
|
||||
{
|
||||
/* dd($values); */
|
||||
$newPhotos = collect($values)->take(3);
|
||||
$attachmentGroup = "meal_photos";
|
||||
$userId = Auth::user()->id;
|
||||
|
||||
$filePath = $attachmentGroup . "/" . $userId . "/" . $this->meal->id;
|
||||
$publicFilePath = "public/" . $filePath;
|
||||
|
||||
foreach($newPhotos as $photo) {
|
||||
|
||||
$curPhoto = $photo
|
||||
->storePublicly($publicFilePath);
|
||||
|
||||
$fileData = [
|
||||
'user_id' => $userId,
|
||||
'group' => $attachmentGroup,
|
||||
'original_name' => $photo->getClientOriginalName(),
|
||||
'size' => $photo->getSize(),
|
||||
];
|
||||
|
||||
$newFile = UserAttachment::updateOrCreate(
|
||||
$fileData,
|
||||
[
|
||||
'path' => preg_replace("/public\//xi", "/storage/", $curPhoto),
|
||||
'specs' => json_encode(
|
||||
[
|
||||
'ext' => $photo->extension(),
|
||||
'original_path' => $curPhoto,
|
||||
]
|
||||
)
|
||||
]
|
||||
);
|
||||
$newFile->save();
|
||||
$this->meal->photos()->attach($newFile->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,8 @@ class MealForm extends Component
|
||||
'portion' => 'required|min:1'
|
||||
];
|
||||
|
||||
protected $listeners = ['food-intake-updated' => '$refresh'];
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->diary = Diary::find($this->diaryId);
|
||||
@@ -63,7 +65,23 @@ class MealForm extends Component
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.meal-form');
|
||||
$types = [0, 1, 2, 3, 4];
|
||||
$typeNames = ['Завтрак', 'Обед', 'Ужин', 'Ланч', 'Перекусы'];
|
||||
$typeCssIds = ['breakfast', 'dinner', 'supper', 'lunch', 'snacks'];
|
||||
|
||||
return view(
|
||||
'livewire.meal-form',
|
||||
[
|
||||
'types' => $types,
|
||||
'typeNames' => $typeNames,
|
||||
'typeCssIds' => $typeCssIds,
|
||||
'curMeal' => $this
|
||||
->diary
|
||||
->meals
|
||||
->where('type', $this->type)
|
||||
->first(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function setType(int $type): void
|
||||
@@ -113,6 +131,8 @@ class MealForm extends Component
|
||||
}
|
||||
}
|
||||
}
|
||||
/* $this->emit('food-intake-updated'); */
|
||||
$this->emitSelf('food-intake-updated');
|
||||
}
|
||||
|
||||
public function addPortion()
|
||||
@@ -142,12 +162,14 @@ class MealForm extends Component
|
||||
$this->delPortion($key, $item);
|
||||
$this->fill($filed);
|
||||
}
|
||||
|
||||
private function addPortionIfItFilled()
|
||||
{
|
||||
if (mb_strlen($this->product_name) && $this->quantity && mb_strlen($this->portion)) {
|
||||
$this->addPortion();
|
||||
}
|
||||
}
|
||||
|
||||
public function delPortion($key, $item)
|
||||
{
|
||||
if (isset($item['id'])) {
|
||||
|
||||
55
app/Http/Livewire/Profile/CircumferenceChart.php
Normal file
55
app/Http/Livewire/Profile/CircumferenceChart.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Profile;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\User;
|
||||
use Asantibanez\LivewireCharts\Models\LineChartModel;
|
||||
|
||||
class CircumferenceChart extends Component
|
||||
{
|
||||
public User $user;
|
||||
|
||||
protected $listeners = ['circumference-chart-updated' => '$refresh'];
|
||||
|
||||
public function render()
|
||||
{
|
||||
|
||||
$lastOneMisure = $this
|
||||
->user
|
||||
->circumference_measures()
|
||||
->get()
|
||||
->last();
|
||||
|
||||
$lastFourMisures = $this
|
||||
->user
|
||||
->circumference_measures()
|
||||
->orderBy('created_at', 'desc')
|
||||
->limit(4)
|
||||
->get()
|
||||
->sortBy('id');
|
||||
|
||||
$lineChartModel =
|
||||
(new LineChartModel())
|
||||
->setSmoothCurve()
|
||||
->multiLine()
|
||||
->setColors(['#b2df8a', '#1f78b4', '#e3a6a6']);
|
||||
|
||||
$lastFourMisures->each(
|
||||
function ($item, $key) use ($lineChartModel) {
|
||||
$createdAt = \Carbon\Carbon::parse($item['created_at'])->format('d.m.y');
|
||||
$lineChartModel->addSeriesPoint(__('chest'), $createdAt, $item['chest_circumference']);
|
||||
$lineChartModel->addSeriesPoint(__('waist'), $createdAt, $item['waist_circumference']);
|
||||
$lineChartModel->addSeriesPoint(__('hip'), $createdAt, $item['hip_circumference']);
|
||||
});
|
||||
|
||||
return view(
|
||||
'livewire.profile.circumference-chart',
|
||||
[
|
||||
'user' => $this->user,
|
||||
'lineChartModel' => $lineChartModel,
|
||||
'lastOneMisure' => $lastOneMisure,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
44
app/Http/Livewire/Profile/WeightChart.php
Normal file
44
app/Http/Livewire/Profile/WeightChart.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Profile;
|
||||
|
||||
use Livewire\Component;
|
||||
use App\Models\User;
|
||||
use Asantibanez\LivewireCharts\Models\AreaChartModel;
|
||||
|
||||
class WeightChart extends Component
|
||||
{
|
||||
public User $user;
|
||||
|
||||
protected $listeners = ['weight-chart-updated' => '$refresh'];
|
||||
|
||||
public function render()
|
||||
{
|
||||
$areaChartModel =
|
||||
(new AreaChartModel())
|
||||
->setSmoothCurve()
|
||||
->setColors(['#b7d7e8']);
|
||||
|
||||
$lastFourWeightMisures = $this->user
|
||||
->weight_measures()
|
||||
->orderBy('created_at', 'desc')
|
||||
->limit(4)
|
||||
->get()
|
||||
->sortBy('id');
|
||||
|
||||
$lastFourWeightMisures->each(
|
||||
function ($item, $key) use ($areaChartModel) {
|
||||
$createdAt = \Carbon\Carbon::parse($item['created_at'])->format('d.m.y');
|
||||
$areaChartModel->addPoint($createdAt, $item['weight']);
|
||||
}
|
||||
);
|
||||
|
||||
return view(
|
||||
'livewire.profile.weight-chart',
|
||||
[
|
||||
'user' => $this->user,
|
||||
'areaChartModel' => $areaChartModel,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class AddCircumference extends ModalComponent
|
||||
]);
|
||||
$newMeasure->save();
|
||||
$this->reset(['chest_circumference', 'waist_circumference', 'hip_circumference']);
|
||||
$this->emitTo('profile.circumference-chart', 'circumference-chart-updated');
|
||||
$this->closeModal();
|
||||
/* dd($newMeasure); */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,9 @@ class AddWeight extends ModalComponent
|
||||
]);
|
||||
$newMeasure->save();
|
||||
$this->reset(['weight']);
|
||||
|
||||
$this->emitTo('profile.weight-chart', 'weight-chart-updated');
|
||||
$this->closeModal();
|
||||
/* dd($newMeasure); */
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user