mirror of https://github.com/gmbrax/Pilgrim.git
				
				
				
			Compare commits
	
		
			No commits in common. "35f37f592684eaff29f974d172be4d04b9d9688e" and "7dbb89b6924000a9adf3c5ab45b8d745288ea71a" have entirely different histories.
		
	
	
		
			35f37f5926
			...
			7dbb89b692
		
	
		| 
						 | 
					@ -206,17 +206,29 @@ class DiaryListScreen(Screen):
 | 
				
			||||||
        """Action to create new diary"""
 | 
					        """Action to create new diary"""
 | 
				
			||||||
        self.app.push_screen(NewDiaryModal(),self._on_new_diary_submitted)
 | 
					        self.app.push_screen(NewDiaryModal(),self._on_new_diary_submitted)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _on_new_diary_submitted(self, result):
 | 
					    def _on_new_diary_submitted(self,result):
 | 
				
			||||||
        """Callback after diary creation"""
 | 
					        self.notify(str(result))
 | 
				
			||||||
        if result:  # Se result não é string vazia, o diário foi criado
 | 
					        if result:
 | 
				
			||||||
            self.notify(f"Returning to diary list...")
 | 
					            self.notify(f"Creating Diary:{result}'...")
 | 
				
			||||||
            # Atualiza a lista de diários
 | 
					            self.call_later(self._async_create_diary,result)
 | 
				
			||||||
            self.refresh_diaries()
 | 
					 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            self.notify(f"Creation canceled...")
 | 
					            self.notify(f"Canceled...")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    async def _async_create_diary(self,name: str):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            service = self.app.service_manager.get_travel_diary_service()
 | 
				
			||||||
 | 
					            created_diary = await service.async_create(name)
 | 
				
			||||||
 | 
					            if created_diary:
 | 
				
			||||||
 | 
					                self.diary_id_map[created_diary.id] = created_diary.id
 | 
				
			||||||
 | 
					                await self.async_refresh_diaries()
 | 
				
			||||||
 | 
					                self.notify(f"Diary: '{name}' created!")
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                self.notify("Error Creating the diary")
 | 
				
			||||||
 | 
					        except Exception as e:
 | 
				
			||||||
 | 
					            self.notify(f"Exception on creating the diary: {str(e)}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _on_screen_resume(self) -> None:
 | 
					 | 
				
			||||||
        self.refresh_diaries()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def action_edit_selected_diary(self):
 | 
					    def action_edit_selected_diary(self):
 | 
				
			||||||
        """Action to edit selected diary"""
 | 
					        """Action to edit selected diary"""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -4,17 +4,14 @@ from textual.containers import Vertical, Horizontal
 | 
				
			||||||
from textual.screen import ModalScreen
 | 
					from textual.screen import ModalScreen
 | 
				
			||||||
from textual.widgets import Label, Input, Button
 | 
					from textual.widgets import Label, Input, Button
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from pilgrim.ui.screens.edit_entry_screen import EditEntryScreen
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
class NewDiaryModal(ModalScreen[str]):
 | 
					class NewDiaryModal(ModalScreen[str]):
 | 
				
			||||||
    BINDINGS = [
 | 
					    BINDINGS = [
 | 
				
			||||||
        Binding("escape", "cancel", "Cancel"),
 | 
					        Binding("escape", "cancel", "Cancel"),
 | 
				
			||||||
        Binding("enter", "create_diary", "Create",priority=True),
 | 
					        Binding("enter", "create_diary", "Create",priority=True),
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
    def __init__(self,autoopen=True):
 | 
					    def __init__(self):
 | 
				
			||||||
        super().__init__()
 | 
					        super().__init__()
 | 
				
			||||||
        self.auto_open = autoopen
 | 
					 | 
				
			||||||
        self.name_input = Input(id="NewDiaryModal-NameInput",classes="NewDiaryModal-NameInput") # This ID is fine, it's specific to the input
 | 
					        self.name_input = Input(id="NewDiaryModal-NameInput",classes="NewDiaryModal-NameInput") # This ID is fine, it's specific to the input
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def compose(self) -> ComposeResult:
 | 
					    def compose(self) -> ComposeResult:
 | 
				
			||||||
| 
						 | 
					@ -37,7 +34,7 @@ class NewDiaryModal(ModalScreen[str]):
 | 
				
			||||||
        if event.button.id == "create_diary_button":
 | 
					        if event.button.id == "create_diary_button":
 | 
				
			||||||
            self.action_create_diary()
 | 
					            self.action_create_diary()
 | 
				
			||||||
        elif event.button.id == "cancel_button":
 | 
					        elif event.button.id == "cancel_button":
 | 
				
			||||||
            self.dismiss()
 | 
					            self.dismiss("")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def action_cancel(self) -> None:
 | 
					    def action_cancel(self) -> None:
 | 
				
			||||||
        """Action to cancel the modal."""
 | 
					        """Action to cancel the modal."""
 | 
				
			||||||
| 
						 | 
					@ -46,9 +43,7 @@ class NewDiaryModal(ModalScreen[str]):
 | 
				
			||||||
    def action_create_diary(self) -> None:
 | 
					    def action_create_diary(self) -> None:
 | 
				
			||||||
        diary_name = self.name_input.value.strip()
 | 
					        diary_name = self.name_input.value.strip()
 | 
				
			||||||
        if diary_name:
 | 
					        if diary_name:
 | 
				
			||||||
 | 
					            self.dismiss(diary_name)
 | 
				
			||||||
            self.call_later(self._async_create_diary, diary_name)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            self.notify("Diary name cannot be empty.", severity="warning")
 | 
					            self.notify("Diary name cannot be empty.", severity="warning")
 | 
				
			||||||
            self.name_input.focus()
 | 
					            self.name_input.focus()
 | 
				
			||||||
| 
						 | 
					@ -57,24 +52,3 @@ class NewDiaryModal(ModalScreen[str]):
 | 
				
			||||||
        if event.input.id == "NewDiaryModal-NameInput":
 | 
					        if event.input.id == "NewDiaryModal-NameInput":
 | 
				
			||||||
            self.action_create_diary()
 | 
					            self.action_create_diary()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def _async_create_diary(self, name: str):
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            service = self.app.service_manager.get_travel_diary_service()
 | 
					 | 
				
			||||||
            created_diary = await service.async_create(name)
 | 
					 | 
				
			||||||
            if created_diary:
 | 
					 | 
				
			||||||
                self.dismiss(name)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                if self.auto_open:
 | 
					 | 
				
			||||||
                    self.app.push_screen(EditEntryScreen(diary_id=created_diary.id))
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                self.notify(f"Diary: '{name}' created!")
 | 
					 | 
				
			||||||
            else:
 | 
					 | 
				
			||||||
                self.notify("Error Creating the diary")
 | 
					 | 
				
			||||||
        except Exception as e:
 | 
					 | 
				
			||||||
            self.notify(f"Exception on creating the diary: {str(e)}")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue