Note Creation/Rename Functionality
authorAdam Dullage <redacted>
Wed, 25 Aug 2021 20:33:16 +0000 (21:33 +0100)
committerAdam Dullage <redacted>
Wed, 25 Aug 2021 20:33:16 +0000 (21:33 +0100)
README.md
flatnotes/main.py
flatnotes/models.py
flatnotes/src/components/App.js
flatnotes/src/components/App.vue

index 435d57860fc59ee6713e2712ff0d0b0aa134c50d..8a82143bcb3004538122740eb6478bae2c51787c 100644 (file)
--- 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
index 1258bf776b96c458e84825c30e6723c725063e5b..4123faab13c74efdc7bb65caba9143c9900bfb5d 100644 (file)
@@ -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
index e71b09089223d3ab4bf8043efd39b8af9a110ba1..969dd9b9fb8f9d2918601f0116b4343e7a5fe9cd 100644 (file)
@@ -12,7 +12,7 @@ class LoginModel(CamelCaseBaseModel):
 
 class NoteModel(CamelCaseBaseModel):
     filename: str
-    last_modified: int
+    last_modified: Optional[int]
     content: Optional[str]
 
     @classmethod
index e40dbebb297ef8e29082cc2a12caace087402bc6..93264b455878bdd8c5d13dfda1d88fab1a37a677 100644 (file)
@@ -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;
       }
     },
index 03e8080ce4e643de2b7ec74c7fc93cb66399e4e6..58fce648cecef1992a0d10408f6e42973dadbe00 100644 (file)
           Logout
         </button>
 
+        <!-- New -->
+        <button
+          v-if="currentView == 0"
+          type="button"
+          class="btn btn-primary mx-1"
+          @click="newNote"
+        >
+          New
+        </button>
+
         <!-- Close -->
         <button
           v-if="currentView == 2"
 
       <!-- Editor -->
       <div v-else-if="currentView == 3">
+        <input type="text" class="form-control" v-model="newFilename" />
         <editor
           :initialValue="currentNote.content"
           previewStyle="tab"
git clone https://git.99rst.org/PROJECT