From 407a89e1eb4bf376cd3b2ea5d2203de94ec034a1 Mon Sep 17 00:00:00 2001 From: Matheus Martins Ciocca Date: Sun, 6 Apr 2025 13:07:45 -0300 Subject: [PATCH] fix: crash na exportacao consertada com verificacoes de 'papers' vazio e reset dos campos de opcao de pergunta de extracao de dados --- .../Conducting/DataExtraction/Buttons.php | 62 ++++++++++++++++--- .../Conducting/QualityAssessment/Buttons.php | 62 ++++++++++++++++--- .../Conducting/Snowballing/Buttons.php | 46 ++++++++++++++ .../Conducting/StudySelection/Buttons.php | 41 ++++++++++++ .../Planning/DataExtraction/Option.php | 3 +- lang/en/project/conducting.php | 2 + lang/pt_BR/project/conducting.php | 3 + 7 files changed, 203 insertions(+), 16 deletions(-) diff --git a/app/Livewire/Conducting/DataExtraction/Buttons.php b/app/Livewire/Conducting/DataExtraction/Buttons.php index fd9c38137..0135faa0f 100644 --- a/app/Livewire/Conducting/DataExtraction/Buttons.php +++ b/app/Livewire/Conducting/DataExtraction/Buttons.php @@ -16,14 +16,39 @@ class Buttons extends Component { + private $translationPath = 'project/conducting.data-extraction.buttons'; + private $toastMessages = 'project/conducting.data-extraction.buttons'; + public $projectId; + protected function messages() + { + return [ + 'no-papers' => __($this->translationPath . '.no-papers'), + ]; + } + + public function toast(string $message, string $type) + { + $this->dispatch('buttons', ToastHelper::dispatch($type, $message)); + } + public function exportCsv() { - $papers = $this->getPapersExport($this->projectId); + $papers = $this->getPapersExport(); + + // Verifica se existem papers para exportar + if ($papers->isEmpty()) { + $this->toast( + message: $this->toastMessages . '.no-papers', + type: 'error' + ); + return; + } + $csvData = $this->formatCsv($papers); - return response()->streamDownload(function() use ($csvData) { + return response()->streamDownload(function () use ($csvData) { echo $csvData; }, 'studies-extraction.csv'); } @@ -31,8 +56,18 @@ public function exportCsv() public function exportXml() { $papers = $this->getPapersExport($this->projectId); + + // Verifica se existem papers para exportar + if ($papers->isEmpty()) { + $this->toast( + message: $this->toastMessages . '.no-papers', + type: 'error' + ); + return; + } + $xmlData = $this->formatXml($papers); - return response()->streamDownload(function() use ($xmlData) { + return response()->streamDownload(function () use ($xmlData) { echo $xmlData; }, 'studies-extraction.xml'); } @@ -41,8 +76,18 @@ public function exportPdf() { $papers = $this->getPapersExport($this->projectId); + + // Verifica se existem papers para exportar + if ($papers->isEmpty()) { + $this->toast( + message: $this->toastMessages . '.no-papers', + type: 'error' + ); + return; + } + $pdfData = $this->formatPdf($papers); - return response()->streamDownload(function() use ($pdfData) { + return response()->streamDownload(function () use ($pdfData) { echo $pdfData; }, 'studies-extraction.pdf'); } @@ -82,13 +127,15 @@ private function getPapersExport() ->where('papers.status_qa', 1) ->where('papers_qa.id_member', $member->id_members) ->distinct() - ->select('papers.id as id_paper', + ->select( + 'papers.id as id_paper', 'papers.title', 'papers.year', 'data_base.name as database_name', 'users.firstname', 'users.lastname', - 'status_extraction.description as status_description') + 'status_extraction.description as status_description' + ) ->get(); } @@ -154,7 +201,8 @@ private function formatPdf($papers) } - public function mount() { + public function mount() + { $this->projectId = request()->segment(2); } diff --git a/app/Livewire/Conducting/QualityAssessment/Buttons.php b/app/Livewire/Conducting/QualityAssessment/Buttons.php index 5925a9dab..58ecf487a 100644 --- a/app/Livewire/Conducting/QualityAssessment/Buttons.php +++ b/app/Livewire/Conducting/QualityAssessment/Buttons.php @@ -17,14 +17,39 @@ class Buttons extends Component { + private $translationPath = 'project/conducting.data-extraction.buttons'; + private $toastMessages = 'project/conducting.data-extraction.buttons'; + public $projectId; + protected function messages() + { + return [ + 'no-papers' => __($this->translationPath . '.no-papers'), + ]; + } + + public function toast(string $message, string $type) + { + $this->dispatch('buttons', ToastHelper::dispatch($type, $message)); + } + public function exportCsv() { $papers = $this->getPapersExport($this->projectId); + + // Verifica se existem papers para exportar + if ($papers->isEmpty()) { + $this->toast( + message: $this->toastMessages . '.no-papers', + type: 'error' + ); + return; + } + $csvData = $this->formatCsv($papers); - return response()->streamDownload(function() use ($csvData) { + return response()->streamDownload(function () use ($csvData) { echo $csvData; }, 'studies-qa.csv'); } @@ -32,8 +57,18 @@ public function exportCsv() public function exportXml() { $papers = $this->getPapersExport($this->projectId); + + // Verifica se existem papers para exportar + if ($papers->isEmpty()) { + $this->toast( + message: $this->toastMessages . '.no-papers', + type: 'error' + ); + return; + } + $xmlData = $this->formatXml($papers); - return response()->streamDownload(function() use ($xmlData) { + return response()->streamDownload(function () use ($xmlData) { echo $xmlData; }, 'studies-qa.xml'); } @@ -42,8 +77,18 @@ public function exportPdf() { $papers = $this->getPapersExport($this->projectId); + + // Verifica se existem papers para exportar + if ($papers->isEmpty()) { + $this->toast( + message: $this->toastMessages . '.no-papers', + type: 'error' + ); + return; + } + $pdfData = $this->formatPdf($papers); - return response()->streamDownload(function() use ($pdfData) { + return response()->streamDownload(function () use ($pdfData) { echo $pdfData; }, 'studies-qa.pdf'); } @@ -70,7 +115,8 @@ private function getPapersExport() ->join('members', 'members.id_members', '=', 'papers_qa.id_member') ->join('users', 'members.id_user', '=', 'users.id') ->join('papers_selection', 'papers_selection.id_paper', '=', 'papers_qa.id_paper') - ->select('papers.*', + ->select( + 'papers.*', 'papers.id as id_paper', 'data_base.name as database_name', 'general_score.description as general_score', @@ -78,9 +124,10 @@ private function getPapersExport() 'users.firstname', 'users.lastname', 'paper_decision_conflicts.new_status_paper', - 'status_qa.status as status_description') + 'status_qa.status as status_description' + ) - ->leftJoin('paper_decision_conflicts', function($join) { + ->leftJoin('paper_decision_conflicts', function ($join) { $join->on('papers.id_paper', '=', 'paper_decision_conflicts.id_paper') ->where('paper_decision_conflicts.phase', '=', 'quality'); // Filtrar pela fase 'quality' }) @@ -173,7 +220,8 @@ private function formatPdf($papers) } - public function mount() { + public function mount() + { $this->projectId = request()->segment(2); } diff --git a/app/Livewire/Conducting/Snowballing/Buttons.php b/app/Livewire/Conducting/Snowballing/Buttons.php index 0c6edd524..36dd60efe 100644 --- a/app/Livewire/Conducting/Snowballing/Buttons.php +++ b/app/Livewire/Conducting/Snowballing/Buttons.php @@ -16,12 +16,38 @@ class Buttons extends Component { + private $translationPath = 'project/conducting.data-extraction.buttons'; + private $toastMessages = 'project/conducting.data-extraction.buttons'; + public $projectId; + protected function messages() + { + return [ + 'no-papers' => __($this->translationPath . '.no-papers'), + ]; + } + + public function toast(string $message, string $type) + { + $this->dispatch('buttons', ToastHelper::dispatch($type, $message)); + } + + public function exportCsv() { $papers = $this->getPapersExport($this->projectId); + + // Verifica se existem papers para exportar + if ($papers->isEmpty()) { + $this->toast( + message: $this->toastMessages . '.no-papers', + type: 'error' + ); + return; + } + $csvData = $this->formatCsv($papers); return response()->streamDownload(function() use ($csvData) { echo $csvData; @@ -31,6 +57,16 @@ public function exportCsv() public function exportXml() { $papers = $this->getPapersExport($this->projectId); + + // Verifica se existem papers para exportar + if ($papers->isEmpty()) { + $this->toast( + message: $this->toastMessages . '.no-papers', + type: 'error' + ); + return; + } + $xmlData = $this->formatXml($papers); return response()->streamDownload(function() use ($xmlData) { echo $xmlData; @@ -41,6 +77,16 @@ public function exportPdf() { $papers = $this->getPapersExport($this->projectId); + + // Verifica se existem papers para exportar + if ($papers->isEmpty()) { + $this->toast( + message: $this->toastMessages . '.no-papers', + type: 'error' + ); + return; + } + $pdfData = $this->formatPdf($papers); return response()->streamDownload(function() use ($pdfData) { echo $pdfData; diff --git a/app/Livewire/Conducting/StudySelection/Buttons.php b/app/Livewire/Conducting/StudySelection/Buttons.php index bdb72b849..8bf2e41e8 100644 --- a/app/Livewire/Conducting/StudySelection/Buttons.php +++ b/app/Livewire/Conducting/StudySelection/Buttons.php @@ -17,6 +17,10 @@ class Buttons extends Component { + + private $translationPath = 'project/conducting.data-extraction.buttons'; + private $toastMessages = 'project/conducting.data-extraction.buttons'; + public $projectId; public $duplicates = []; // Armazena os papers duplicados organizados por título public $uniquePapers = []; @@ -24,6 +28,13 @@ class Buttons extends Component public $totalDuplicates = 0; + protected function messages() + { + return [ + 'no-papers' => __($this->translationPath . '.no-papers'), + ]; + } + private function translate(string $message, string $key = 'duplicates') { return __('project/conducting.study-selection.' . $key . '.' . $message); @@ -295,6 +306,16 @@ public function toast(string $message, string $type) public function exportCsv() { $papers = $this->getPapersExport($this->projectId); + + // Verifica se existem papers para exportar + if ($papers->isEmpty()) { + $this->toast( + message: $this->toastMessages . '.no-papers', + type: 'error' + ); + return; + } + $csvData = $this->formatCsv($papers); return response()->streamDownload(function() use ($csvData) { echo $csvData; @@ -304,6 +325,16 @@ public function exportCsv() public function exportXml() { $papers = $this->getPapersExport($this->projectId); + + // Verifica se existem papers para exportar + if ($papers->isEmpty()) { + $this->toast( + message: $this->toastMessages . '.no-papers', + type: 'error' + ); + return; + } + $xmlData = $this->formatXml($papers); return response()->streamDownload(function() use ($xmlData) { echo $xmlData; @@ -313,6 +344,16 @@ public function exportXml() public function exportPdf() { $papers = $this->getPapersExport($this->projectId); + + // Verifica se existem papers para exportar + if ($papers->isEmpty()) { + $this->toast( + message: $this->toastMessages . '.no-papers', + type: 'error' + ); + return; + } + $pdfData = $this->formatPdf($papers); return response()->streamDownload(function() use ($pdfData) { echo $pdfData; diff --git a/app/Livewire/Planning/DataExtraction/Option.php b/app/Livewire/Planning/DataExtraction/Option.php index c7ce10177..d3fda88bc 100644 --- a/app/Livewire/Planning/DataExtraction/Option.php +++ b/app/Livewire/Planning/DataExtraction/Option.php @@ -85,8 +85,7 @@ private function resetFields() { $this->optionId = null; $this->description = null; - $this->questionId['value'] = $this->currentProject - ->dataExtractionQuestions->first()->id_de ?? null; + $this->questionId = []; $this->form['isEditing'] = false; } diff --git a/lang/en/project/conducting.php b/lang/en/project/conducting.php index a39ae0ee6..ef83ff822 100644 --- a/lang/en/project/conducting.php +++ b/lang/en/project/conducting.php @@ -205,6 +205,7 @@ 'select-database' => 'Show all Databases', 'select-status' => 'Show all Statuses...', 'search-papers' => 'Search papers...', + 'no-papers' => 'No studies available for export.', ], 'modal' => [ 'author' => 'Author', @@ -416,6 +417,7 @@ 'select-database' => 'Show all Databases', 'select-status' => 'Show all Statuses...', 'search-papers' => 'Search papers...', + 'no-papers' => 'No studies available for export.', ], 'modal' => [ 'author' => 'Author', diff --git a/lang/pt_BR/project/conducting.php b/lang/pt_BR/project/conducting.php index afe5f78fd..39fd4ee99 100644 --- a/lang/pt_BR/project/conducting.php +++ b/lang/pt_BR/project/conducting.php @@ -199,6 +199,7 @@ 'select-status' => 'Mostrar todos os Status...', 'select-type' => 'Mostrar todos os Tipos...', 'search-papers' => 'Pesquisar artigos...', + 'no-papers' => 'Não há estudos disponíveis para exportar', ], 'modal' => [ 'author' => 'Autor', @@ -383,6 +384,7 @@ 'select-database' => 'Mostrar todos as Bases', 'select-status' => 'Mostrar todos Status...', 'search-papers' => 'Buscar estudos...', + 'no-papers' => 'Não há estudos disponíveis para exportar', ], 'modal' => [ 'author' => 'Autor', @@ -511,6 +513,7 @@ 'select-database' => 'Mostrar todas as Bases de Dados', 'select-status' => 'Mostrar todos os Status...', 'search-papers' => 'Pesquisar artigos...', + 'no-papers' => 'Não há estudos disponíveis para exportar', ], 'modal' => [ 'author' => 'Autor',