diff --git a/laravel_app/app/Console/Commands/BuildReports.php b/laravel_app/app/Console/Commands/BuildReports.php index c7ed7af..0ea2f24 100644 --- a/laravel_app/app/Console/Commands/BuildReports.php +++ b/laravel_app/app/Console/Commands/BuildReports.php @@ -19,15 +19,16 @@ class BuildReports extends Command * * @var string */ - protected $description = 'Command description'; + protected $description = 'Builds reports for all the projects'; /** * Execute the console command. */ public function handle() { - // TODO schedule all the project if mail - Project::find(1)->schedule(); + Project::all()->each(function (Project $project) { + $project->schedule(); + }); } } diff --git a/laravel_app/app/Livewire/Projects/ReportManager.php b/laravel_app/app/Livewire/Projects/ReportManager.php index 31e1129..d6cb7b8 100644 --- a/laravel_app/app/Livewire/Projects/ReportManager.php +++ b/laravel_app/app/Livewire/Projects/ReportManager.php @@ -6,6 +6,7 @@ use App\Models\Project; use App\Models\ProjectReport; use App\Rules\AllMosaicsPresentRule; +use Illuminate\Database\Query\Builder; use Livewire\Attributes\Lazy; use Livewire\Component; use Livewire\WithPagination; @@ -85,14 +86,13 @@ public function deleteReport(ProjectReport $report) $this->dispatch('refresh'); } - private function applySearch($query) + private function applySearch(Builder $query) { - if ($this->search) { - $query->where('name', 'like', '%'.$this->search.'%'); - $query->orWhere('year', 'like', '%'.$this->search.'%'); - $query->orWhere('week', 'like', '%'.$this->search.'%'); - } - return $query; + return $query->when($this->search !== '', function ($q){ + $q->where('name', 'like', '%'.$this->search.'%') + ->orWhere('year', 'like', '%'.$this->search.'%') + ->orWhere('week', 'like', '%'.$this->search.'%'); + }); } public function placeholder() diff --git a/laravel_app/app/Livewire/Projects/Tabs/Download.php b/laravel_app/app/Livewire/Projects/Tabs/Download.php index 8ed6328..4819310 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Download.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Download.php @@ -71,15 +71,9 @@ public function saveDownloads() private function applySearch($query) { - if ($this->search) { - $query->where('name', 'like', '%' . $this->search . '%'); - } - return $query; - } - - public function placeholder() - { - return view('livewire.projects.download-manager-placeholder'); + return $query->when($this->search !== '', function ($q){ + $q->where('name', 'like', '%'.$this->search.'%'); + }); } diff --git a/laravel_app/app/Livewire/Projects/Tabs/Mailings.php b/laravel_app/app/Livewire/Projects/Tabs/Mailings.php index ff4cb87..76dabe0 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Mailings.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Mailings.php @@ -11,7 +11,7 @@ class Mailings extends Component { use WithPagination; - public $project; + public Project $project; public $mailingDetailsModal = false; public $formData = [ @@ -57,15 +57,9 @@ private function resetFormData() private function applySearch($query) { - if ($this->search) { - $query->where('subject', 'like', '%'.$this->search.'%'); - } - return $query; - } - - public function placeholder() - { - return view('livewire.projects.mailing-manager-placeholder'); + return $query->when($this->search !== '', function ($q){ + $q->where('subject', 'like', '%'.$this->search.'%'); + }); } public function render() diff --git a/laravel_app/app/Livewire/Projects/Tabs/Mosaic.php b/laravel_app/app/Livewire/Projects/Tabs/Mosaic.php index 36591ee..9a3c77e 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Mosaic.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Mosaic.php @@ -11,7 +11,7 @@ class Mosaic extends Component { use WithPagination; - public $project; + public Project $project; public $formData = [ 'week' => '', @@ -66,12 +66,11 @@ public function getDateRangeProperty() private function applySearch($query) { - if ($this->search) { - $query->where('name', 'like', '%' . $this->search . '%'); - $query->orWhere('year', 'like', '%' . $this->search . '%'); - $query->orWhere('week', 'like', '%' . $this->search . '%'); - } - return $query; + return $query->when($this->search !== '', function ($q){ + $q->where('name', 'like', '%'.$this->search.'%') + ->orWhere('year', 'like', '%' . $this->search . '%') + ->orWhere('week', 'like', '%' . $this->search . '%'); + }); } public function update($property) @@ -80,10 +79,6 @@ public function update($property) $this->resetPage('mosaicPage'); } } - public function placeholder() - { - return view('livewire.projects.mosaic-manager-placeholder'); - } public function render() { diff --git a/laravel_app/app/Livewire/Projects/Tabs/Report.php b/laravel_app/app/Livewire/Projects/Tabs/Report.php index f820ff5..661ac1c 100644 --- a/laravel_app/app/Livewire/Projects/Tabs/Report.php +++ b/laravel_app/app/Livewire/Projects/Tabs/Report.php @@ -14,7 +14,7 @@ class Report extends Component use WithPagination; public $formData = []; - public $project_id; + public Project $project; public $search = ""; @@ -38,10 +38,10 @@ public function saveProjectReport() $this->validate([ 'formData.week' => ['required', 'integer', 'min:1', 'max:53'], 'formData.year' => 'required|integer|min:2020|max:'.now()->addYear()->year, - 'formData' => [new AllMosaicsPresentRule($this->project_id)], + 'formData' => [new AllMosaicsPresentRule($this->project->id)], ]); - $newReport = Project::find($this->project_id) + $newReport = Project::find($this->project->id) ->reports()->create([ 'name' => 'Report for week '.$this->formData['week'].' of '.$this->formData['year'], 'week' => $this->formData['week'], @@ -79,22 +79,23 @@ public function deleteReport(ProjectReport $report) private function applySearch($query) { - if ($this->search) { - $query->where('name', 'like', '%'.$this->search.'%'); - $query->orWhere('year', 'like', '%'.$this->search.'%'); - $query->orWhere('week', 'like', '%'.$this->search.'%'); - } - return $query; + return $query->when($this->search !== '', function ($q){ + $q->where('name', 'like', '%'.$this->search.'%') + ->orWhere('year', 'like', '%'.$this->search.'%') + ->orWhere('week', 'like', '%'.$this->search.'%'); + }); +// if ($this->search) { +// $query->where('name', 'like', '%'.$this->search.'%'); +// $query->orWhere('year', 'like', '%'.$this->search.'%'); +// $query->orWhere('week', 'like', '%'.$this->search.'%'); +// } +// return $query; } - public function placeholder() - { - return view('livewire.projects.report-manager-placeholder'); - } public function render() { - $query = Project::find($this->project_id) + $query = Project::find($this->project->id) ->reports() ->orderBy('year', 'desc') ->orderBy('week', 'desc'); diff --git a/laravel_app/app/Models/Project.php b/laravel_app/app/Models/Project.php index dc29c13..e0cf06f 100644 --- a/laravel_app/app/Models/Project.php +++ b/laravel_app/app/Models/Project.php @@ -230,6 +230,10 @@ public function hasPendingDownload(): bool { return $this->downloads()->statusPending()->count() > 0; } + public function hasPendingReport(): bool + { + return $this->reports()->statusPending()->count() > 0; + } public function hasPendingMosaic(): bool { diff --git a/laravel_app/resources/views/livewire/projects/report-row.blade.php b/laravel_app/resources/views/livewire/projects/report-row.blade.php new file mode 100644 index 0000000..144fd1e --- /dev/null +++ b/laravel_app/resources/views/livewire/projects/report-row.blade.php @@ -0,0 +1,168 @@ +
Pending reports for this project: {{ $project->reports()->statusPending()->count() }}
+ @endif