@@ -26,7 +26,18 @@ class PaperModal extends Component
2626
2727 public $ currentProject ;
2828 public $ projectId ;
29- public $ paper = null ;
29+ public $ paper = [
30+ 'id_paper ' => null ,
31+ 'title ' => '' ,
32+ 'author ' => '' ,
33+ 'year ' => '' ,
34+ 'doi ' => '' ,
35+ 'url ' => '' ,
36+ 'data_base ' => null ,
37+ 'database_name ' => '' ,
38+ 'status_selection ' => null ,
39+ 'status_description ' => 'None ' ,
40+ ];
3041 public $ canEdit = false ;
3142
3243 public $ criterias ;
@@ -41,6 +52,7 @@ public function mount()
4152 {
4253 $ this ->projectId = request ()->segment (2 );
4354 $ this ->currentProject = Project::findOrFail ($ this ->projectId );
55+
4456 }
4557 #[On('showPaper ' )]
4658 public function showPaper ($ paper , $ criterias )
@@ -58,13 +70,22 @@ public function showPaper($paper, $criterias)
5870 ->values ()
5971 ->toArray ();
6072
61- $ this ->paper = $ paper ;
73+ // Se showPaper for chamado com o ID do paper, carrega o objeto e converte para array
74+ // Se o paper for passado como um array de dados, usa o id_paper
75+ $ paperId = is_array ($ paper ) ? $ paper ['id_paper ' ] : $ paper ;
76+
77+ if (!$ paperId ) {
78+ Log::error ('showPaper called without a valid paper ID or data. ' );
79+ return ;
80+ }
81+
82+ $ this ->paper = Papers::where ('id_paper ' , $ paperId )->first ()->toArray ();
6283
6384 $ databaseName = DB ::table ('data_base ' )
6485 ->where ('id_database ' , $ this ->paper ['data_base ' ])
6586 ->value ('name ' );
6687
67- $ this ->paper ['database_name ' ] = $ databaseName ;
88+ $ this ->paper ['database_name ' ] = $ databaseName ?? ' Unknown ' ;
6889
6990 // Buscar o membro específico para o projeto atual
7091 $ member = Member::where ('id_user ' , auth ()->user ()->id )
@@ -80,7 +101,7 @@ public function showPaper($paper, $criterias)
80101 $ this ->temp_selected_criterias = $ this ->selected_criterias ;
81102
82103 //status selecionado com base no status salvo no banco de dados
83- $ this ->selected_status = $ this ->paper ['status_description ' ] ;
104+ $ this ->selected_status = $ this ->getPaperStatusDescription ( $ this -> paper ['status_selection ' ]) ;
84105
85106 // Carregar a nota existente
86107 $ paperSelection = PapersSelection::where ('id_paper ' , $ this ->paper ['id_paper ' ])
@@ -200,24 +221,15 @@ public function saveSelectedCriterias()
200221 $ this ->selected_criterias = $ this ->temp_selected_criterias ;
201222
202223 // Atualizar o status do paper
203-
204- $ criteria = Criteria::find (reset ($ addedCriterias ));
205- if ($ criteria ) {
224+ $ criterias = Criteria::whereIn ('id_criteria ' , $ this ->selected_criterias )->get ();
225+ foreach ($ criterias as $ criteria ) {
206226 $ this ->updatePaperStatus ($ criteria ->type );
207227 }
208- /*
209- $criteria = null;
210- if (!empty($addedCriterias)) {
211- $criteria = Criteria::find(reset($addedCriterias));
212- }
213-
214- if ($criteria) {
215- $this->updatePaperStatus($criteria->type);
216- }*/
217228
218229 session ()->flash ('successMessage ' , 'Critérios salvos com sucesso ' );
219230 $ this ->dispatch ('show-success ' );
220231 $ this ->dispatch ('refreshPaperStatus ' );
232+
221233 }
222234
223235 // Método auxiliar para obter a descrição do status
@@ -284,6 +296,12 @@ private function updatePaperStatus($type)
284296 if ($ member ->level == 1 ) {
285297 Papers::where ('id_paper ' , $ id_paper )->update (['status_selection ' => $ new_status ]);
286298 }
299+ // 🔥 Recarrega o paper atualizado
300+ $ this ->paper = Papers::where ('id_paper ' , $ id_paper )->first ()->toArray ();
301+ $ this ->paper ['database_name ' ] = DB ::table ('data_base ' )
302+ ->where ('id_database ' , $ this ->paper ['data_base ' ])
303+ ->value ('name ' ) ?? '' ;
304+
287305 session ()->forget ('successMessage ' );
288306 session ()->flash ('successMessage ' , "Status updated successfully. " );
289307 }
0 commit comments