## 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
@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
class NoteModel(CamelCaseBaseModel):
filename: str
- last_modified: int
+ last_modified: Optional[int]
content: Optional[str]
@classmethod
searchTimeout: null,
searchResults: null,
currentNote: null,
+ newFilename: null,
editMode: false,
};
},
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;
}
},
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"