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 @@ + + + {{ $report->created_at->diffForHumans() }} + + + {{ $report->name }} + + @if($report->status == \App\Enums\Status::Pending) + + @else + + @endif + + + + + + + + + + + + + + + + + Download + + + + + + + + + + + + Create Mail + + + + + +
+

@lang('Create report email')

+ +
+ + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + Delete + + + + + +
+

Are you sure you?

+

This operation is permanent and can not be reversed.

+ + + + + + + + + +
+
+
+
+
+ + + + diff --git a/laravel_app/resources/views/livewire/projects/tabs/download.blade.php b/laravel_app/resources/views/livewire/projects/tabs/download.blade.php index 55e87c5..4276dc2 100644 --- a/laravel_app/resources/views/livewire/projects/tabs/download.blade.php +++ b/laravel_app/resources/views/livewire/projects/tabs/download.blade.php @@ -24,7 +24,7 @@ class="rounded-md bg-indigo-600 px-3 py-2 justify-center text-center text-sm fon
-
+
@@ -67,7 +67,6 @@ class="px-3 py-3.5 text-right pr-4 sm:pr-8 lg:pr-8 text-sm font-semibold text-gr {{ $downloads->links('livewire.pagination') }} - {{--
--}} diff --git a/laravel_app/resources/views/livewire/projects/tabs/mailings.blade.php b/laravel_app/resources/views/livewire/projects/tabs/mailings.blade.php index 9caf6b9..2df5ac9 100644 --- a/laravel_app/resources/views/livewire/projects/tabs/mailings.blade.php +++ b/laravel_app/resources/views/livewire/projects/tabs/mailings.blade.php @@ -10,7 +10,7 @@
-
+
@@ -52,7 +52,6 @@ class="text-indigo-600 hover:text-indigo-900">Show @endforeach
-
@@ -62,75 +61,73 @@ class="text-indigo-600 hover:text-indigo-900">Show {{ $mailings->links('livewire.pagination') }}
- - - - - - {{ __('Mailing') }} - - - - - - - - -
- - @foreach($formData['recipients'] as $key => $recipient) -
- - -
- @endforeach -
-
- - -
-
- - -
- @empty($formData['attachments']) -
- - -
- @else - @foreach($formData['attachments'] as $key => $attachment) -
- -
- @endforeach - @endempty -
- - - {{ __('Close') }} - - -
-
+ + + + {{ __('Mailing') }} + + + + + + + + +
+ + @foreach($formData['recipients'] as $key => $recipient) +
+ + +
+ @endforeach +
+
+ + +
+
+ + +
+ @empty($formData['attachments']) +
+ + +
+ @else + @foreach($formData['attachments'] as $key => $attachment) +
+ +
+ @endforeach + @endempty +
+ + + {{ __('Close') }} + + +
+
diff --git a/laravel_app/resources/views/livewire/projects/tabs/mosaic.blade.php b/laravel_app/resources/views/livewire/projects/tabs/mosaic.blade.php index 4303247..d903bab 100644 --- a/laravel_app/resources/views/livewire/projects/tabs/mosaic.blade.php +++ b/laravel_app/resources/views/livewire/projects/tabs/mosaic.blade.php @@ -63,7 +63,6 @@ class="px-3 py-3.5 text-right text-sm font-semibold text-gray-900 sm:pr-8 lg:pr- {{ $mosaics->links('livewire.pagination') }} -
diff --git a/laravel_app/resources/views/livewire/projects/tabs/report.blade.php b/laravel_app/resources/views/livewire/projects/tabs/report.blade.php index 2062ab9..473e067 100644 --- a/laravel_app/resources/views/livewire/projects/tabs/report.blade.php +++ b/laravel_app/resources/views/livewire/projects/tabs/report.blade.php @@ -1,9 +1,11 @@ -
+

Reports

-

+ @if($project->hasPendingReport()) +

Pending reports for this project: {{ $project->reports()->statusPending()->count() }}

+ @endif
@@ -14,7 +16,7 @@ class="flex justify-center rounded-md bg-indigo-600 px-3 py-2 text-center text-s
-
+
@@ -46,10 +48,8 @@ class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6 lg
Results: {{ \Illuminate\Support\Number::format($reports->total()) }}
- {{ $reports->links('livewire.pagination') }} -
diff --git a/laravel_app/resources/views/projects/show.blade.php b/laravel_app/resources/views/projects/show.blade.php index ad225ff..aa1c110 100644 --- a/laravel_app/resources/views/projects/show.blade.php +++ b/laravel_app/resources/views/projects/show.blade.php @@ -16,7 +16,7 @@ @break @case('reports') - + @break @case('mailings')