Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to open a new file. #72

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/components/menubar/MenuBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@
</div>
-->

<div class="q-ml-md cursor-pointer non-selectable">
<span>
File
</span>
<q-menu>
<q-list dense style="min-width: 100px">
<q-item clickable v-close-popup @click="$refs.file.click()">
<q-item-section>Open File</q-item-section>
<input
@change="openFile"
type="file"
ref="file"
accept=".txt"
style="display: none"
/>
</q-item>
</q-list>
</q-menu>
</div>

<div class="q-ml-md cursor-pointer non-selectable">
<span>
Annotations
Expand Down Expand Up @@ -183,7 +203,7 @@ export default {
...mapState(["annotations", "classes"]),
},
methods: {
...mapMutations(["loadClasses", "loadAnnotations"]),
...mapMutations(["loadClasses", "loadAnnotations", "setInputSentences", "clearAllAnnotations", "resetIndex"]),
// Funtion that exports the tags to a JSON file
exportTags: async function() {
await exportFile(JSON.stringify(this.classes), "tags.json");
Expand All @@ -205,6 +225,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();
},
importAnnotations: function(e) {
let file = e.target.files[0];
let filereader = new FileReader();
Expand Down
4 changes: 4 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down