From 3f4bd59ad8d982152ead577f7722b5804fa773d3 Mon Sep 17 00:00:00 2001 From: Alvi Khan <55395950+alvi-khan@users.noreply.github.com> Date: Sun, 22 Jan 2023 17:42:39 +0600 Subject: [PATCH] Added option to open a new file. --- src/components/menubar/MenuBar.vue | 32 +++++++++++++++++++++++++++++- src/store/index.js | 4 ++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/components/menubar/MenuBar.vue b/src/components/menubar/MenuBar.vue index 5721574..16f4ef2 100644 --- a/src/components/menubar/MenuBar.vue +++ b/src/components/menubar/MenuBar.vue @@ -38,6 +38,26 @@ --> +
+ + File + + + + + Open File + + + + +
+
Annotations @@ -173,7 +193,7 @@ export default { ...mapState(["annotations", "classes"]), }, methods: { - ...mapMutations(["loadClasses"]), + ...mapMutations(["loadClasses", "setInputSentences", "clearAllAnnotations", "resetIndex"]), // Funtion that exports the tags to a JSON file exportTags: async function() { await exportFile(JSON.stringify(this.classes), "tags.json"); @@ -195,6 +215,16 @@ export default { }; filereader.readAsText(file); }, + openFile: function(e) { + let file = e.target.files[0]; + let filereader = new FileReader(); + filereader.onload = (ev) => { + this.setInputSentences(ev.target.result); + this.clearAllAnnotations(); + }; + filereader.readAsText(file); + this.resetIndex(); + }, }, }; diff --git a/src/store/index.js b/src/store/index.js index 132177a..4c6fc63 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -60,6 +60,10 @@ export const mutations = { state.annotations[state.currentIndex] = payload; state.currentAnnotation = payload; }, + clearAllAnnotations(state) { + state.annotations = []; + state.currentAnnotation = {}; + }, setSeparator(state, payload) { state.separator = payload; const sentences = state.originalText.split(state.separator);