From: Adam Dullage Date: Wed, 25 Aug 2021 20:33:16 +0000 (+0100) Subject: Note Creation/Rename Functionality X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=b9d682dd119e7fe28b97f8a30e5ebb4d51a83423;p=flatnotes.git Note Creation/Rename Functionality --- diff --git a/README.md b/README.md index 435d578..8a82143 100644 --- a/README.md +++ b/README.md @@ -26,22 +26,17 @@ This is what flatnotes aims to achieve. ## To Do -* [x] Proof of Concept - Stage 1 - * [x] Notes List - * [x] Full Text Searching -* [x] Proof of Concept - Stage 2 - * [x] View Note Content - * [x] Edit Note Content - * [x] Docker Deployment - * [x] Password Authentication -* [ ] Proof of Concept - Stage 3 - * [ ] Public URL Sharing -* [ ] Proof of Concept - Stage 4 - * [ ] Image Embedding - * [ ] Attachment Upload -* [ ] First Release - * [ ] Clean & Responsive UI - * [ ] Ability to Create a Note - * [ ] Ability to Rename a Note - * [ ] Ability to Delete a Note - * [ ] Error Handling +* [x] Notes List +* [x] Full Text Searching +* [x] View Note Content +* [x] Edit Note Content +* [x] Docker Deployment +* [x] Password Authentication +* [x] Ability to Create a Note +* [x] Ability to Rename a Note +* [ ] Clean & Responsive UI +* [ ] Public URL Sharing +* [ ] Image Embedding +* [ ] Attachment Upload +* [ ] Ability to Delete a Note +* [ ] Error Handling diff --git a/flatnotes/main.py b/flatnotes/main.py index 1258bf7..4123faa 100644 --- a/flatnotes/main.py +++ b/flatnotes/main.py @@ -63,13 +63,11 @@ async def get_notes( @app.post("/api/notes", response_model=NoteModel) -async def post_note( - filename: str, content: str, _: str = Depends(validate_token) -): +async def post_note(data: NoteModel, _: str = Depends(validate_token)): """Create a new note.""" try: - note = Note(flatnotes, filename, new=True) - note.content = content + note = Note(flatnotes, data.filename, new=True) + note.content = data.content return NoteModel.dump(note, include_content=True) except FilenameContainsPathError: return filename_contains_path_response diff --git a/flatnotes/models.py b/flatnotes/models.py index e71b090..969dd9b 100644 --- a/flatnotes/models.py +++ b/flatnotes/models.py @@ -12,7 +12,7 @@ class LoginModel(CamelCaseBaseModel): class NoteModel(CamelCaseBaseModel): filename: str - last_modified: int + last_modified: Optional[int] content: Optional[str] @classmethod diff --git a/flatnotes/src/components/App.js b/flatnotes/src/components/App.js index e40dbeb..93264b4 100644 --- a/flatnotes/src/components/App.js +++ b/flatnotes/src/components/App.js @@ -24,6 +24,7 @@ export default { searchTimeout: null, searchResults: null, currentNote: null, + newFilename: null, editMode: false, }; }, @@ -146,27 +147,59 @@ export default { let parent = this; api.get(`/api/notes/${filename}`).then(function(response) { parent.currentNote = response.data; + parent.newFilename = parent.currentNote.filename; }); }, + newNote: function() { + this.currentNote = new Note(); + this.editMode = true; + }, + unloadNote: function() { this.currentNote = null; + this.newFilename = null; this.editMode = false; + this.getNotes(); }, saveNote: function() { let parent = this; let newContent = this.$refs.toastUiEditor.invoke("getMarkdown"); - if (newContent != this.currentNote.content) { + + // New Note + if (this.currentNote.lastModified == null) { + api + .post(`/api/notes`, { + filename: this.newFilename, + content: newContent, + }) + .then(function(response) { + parent.currentNote = response.data; + parent.newFilename = parent.currentNote.filename; + parent.editMode = false; + }); + } + + // Modified Note + else if ( + newContent != this.currentNote.content || + this.newFilename != this.currentNote.filename + ) { api .patch(`/api/notes/${this.currentNote.filename}`, { + newFilename: this.newFilename, newContent: newContent, }) .then(function(response) { parent.currentNote = response.data; + parent.newFilename = parent.currentNote.filename; parent.editMode = false; }); - } else { + } + + // No Change + else { this.editMode = false; } }, diff --git a/flatnotes/src/components/App.vue b/flatnotes/src/components/App.vue index 03e8080..58fce64 100644 --- a/flatnotes/src/components/App.vue +++ b/flatnotes/src/components/App.vue @@ -18,6 +18,16 @@ Logout + + +