Skip to content

Commit 8ec6622

Browse files
committed
feat: disable menu options on start page
1 parent 62cadad commit 8ec6622

File tree

6 files changed

+56
-24
lines changed

6 files changed

+56
-24
lines changed

src/App.vue

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,12 @@ export default {
8686
},
8787
data() {
8888
return {
89-
currentPage: "start",
9089
overlayActive: false,
9190
pendingFileDrop: null,
9291
};
9392
},
9493
computed: {
95-
...mapState(["annotations", "classes"]),
94+
...mapState(["annotations", "classes", "currentPage"]),
9695
},
9796
methods: {
9897
...mapMutations([
@@ -101,10 +100,8 @@ export default {
101100
"setInputSentences",
102101
"clearAllAnnotations",
103102
"resetIndex",
103+
"switchToPage",
104104
]),
105-
switchToPage(page) {
106-
this.currentPage = page;
107-
},
108105
onDragEnter() {
109106
this.overlayActive = true;
110107
},

src/components/AnnotationPage.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ export default {
131131
event.stopPropagation();
132132
},
133133
tokenizeCurrentSentence() {
134+
if (this.currentIndex == this.inputSentences.length) {
135+
// last sentence done
136+
return;
137+
}
138+
134139
this.currentSentence = this.inputSentences[this.currentIndex];
135140
this.currentAnnotation = this.annotations[this.currentIndex];
136141

src/components/StartPage.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
filled
1515
label="Load a text file"
1616
:color="highlightTextFileInput ? 'red-8' : 'primary'"
17-
:bg-color="highlightTextFileInput && 'red-1'"
17+
:bg-color="highlightTextFileInput ? 'red-1' : 'grey-3'"
1818
@rejected="
1919
fileSelectionError(
2020
'Only text files (.txt) can be used for creating annotations.'

src/components/menubar/ExportAnnotations.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
v-close-popup
44
clickable
55
@click="generateJSONExport()"
6+
:disable="!annotations.length"
67
>
78
<q-item-section>Export</q-item-section>
89
</q-item>
@@ -21,10 +22,10 @@ export default {
2122
async generateJSONExport() {
2223
const output = {
2324
classes: this.classes.map((c) => c.name),
24-
annotations: this.annotations.map((a) => ([
25+
annotations: this.annotations.map((a) => [
2526
a.text,
26-
{entities: a.entities}
27-
])),
27+
{ entities: a.entities },
28+
]),
2829
};
2930
const jsonStr = JSON.stringify(output);
3031
await exportFile(jsonStr, "annotations.json");

src/components/menubar/MenuBar.vue

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333
<q-menu>
3434
<q-list dense style="min-width: 100px">
3535
<export-annotations />
36-
<q-item v-close-popup clickable @click="pendingClick = $refs.file">
36+
<q-item
37+
v-close-popup
38+
clickable
39+
@click="pendingClick = $refs.file"
40+
:disable="currentPage === 'start'"
41+
>
3742
<q-item-section>Import</q-item-section>
3843
<input
3944
ref="file"
@@ -51,10 +56,20 @@
5156
<span> Tags </span>
5257
<q-menu>
5358
<q-list dense style="min-width: 100px">
54-
<q-item v-close-popup clickable @click="exportTags()">
59+
<q-item
60+
v-close-popup
61+
clickable
62+
@click="exportTags()"
63+
:disable="currentPage == 'start'"
64+
>
5565
<q-item-section>Export</q-item-section>
5666
</q-item>
57-
<q-item v-close-popup clickable @click="$refs.file.click()">
67+
<q-item
68+
v-close-popup
69+
clickable
70+
@click="$refs.file.click()"
71+
:disable="currentPage == 'start'"
72+
>
5873
<q-item-section>Import</q-item-section>
5974
<input
6075
ref="file"
@@ -187,7 +202,7 @@ export default {
187202
};
188203
},
189204
computed: {
190-
...mapState(["annotations", "classes"]),
205+
...mapState(["annotations", "classes", "currentPage"]),
191206
},
192207
methods: {
193208
...mapMutations([
@@ -196,6 +211,7 @@ export default {
196211
"setInputSentences",
197212
"clearAllAnnotations",
198213
"resetIndex",
214+
"switchToPage",
199215
]),
200216
// Funtion that exports the tags to a JSON file
201217
exportTags: async function () {
@@ -227,6 +243,9 @@ export default {
227243
};
228244
filereader.readAsText(file);
229245
this.resetIndex();
246+
if (this.currentPage != "annotate") {
247+
this.switchToPage("annotate");
248+
}
230249
},
231250
importAnnotations: function (e) {
232251
let file = e.target.files[0];

src/store/index.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const mutations = {
4242
id: lastIndex + 1,
4343
name: payload,
4444
color: niceColors[lastIndex % niceColors.length],
45-
}
45+
};
4646
state.classes = [...state.classes, newClass];
4747
if (state.classes.length === 1) {
4848
state.currentClass = state.classes[0];
@@ -81,6 +81,10 @@ export const mutations = {
8181
state.currentIndex += 1;
8282
state.currentAnnotation = state.annotations[state.currentIndex] || {};
8383
} else {
84+
if (state.currentIndex == state.inputSentences.length - 1) {
85+
// last sentence
86+
state.currentIndex += 1;
87+
}
8488
alert("You have completed all the sentences");
8589
}
8690
},
@@ -116,9 +120,10 @@ export const mutations = {
116120
LocalStorage.set("tags", state.classes);
117121
},
118122
loadAnnotations(state, payload) {
119-
let isValid = typeof payload === "object" &&
120-
"annotations" in payload &&
121-
"classes" in payload;
123+
let isValid =
124+
typeof payload === "object" &&
125+
"annotations" in payload &&
126+
"classes" in payload;
122127

123128
if (!isValid) {
124129
throw new Error("loadAnnotations: payload has invalid schema");
@@ -139,19 +144,22 @@ export const mutations = {
139144
for (var i = 0; i < annotations.length; i++) {
140145
if (annotations[i] == null) continue;
141146
let annotation = {
142-
'text': annotations[i][0],
143-
'entities': annotations[i][1].entities,
144-
}
147+
text: annotations[i][0],
148+
entities: annotations[i][1].entities,
149+
};
145150
newAnnotations[i] = annotation;
146151
}
147152
state.annotations = newAnnotations;
148153
state.currentAnnotation = state.annotations[state.currentIndex];
149154

150-
for(let c of classes) {
155+
for (let c of classes) {
151156
this.commit("addClass", c);
152157
}
153158
LocalStorage.set("tags", state.classes);
154159
},
160+
switchToPage(state, payload) {
161+
state.currentPage = payload;
162+
},
155163
};
156164

157165
export const getters = {};
@@ -174,8 +182,9 @@ const actions = {
174182
},
175183
};
176184

177-
window.addEventListener('beforeunload', async (event) => {
178-
event.returnValue = "Please make sure you export annotations before closing the file.";
185+
window.addEventListener("beforeunload", async (event) => {
186+
event.returnValue =
187+
"Please make sure you export annotations before closing the file.";
179188
});
180189

181190
export default {
@@ -191,9 +200,10 @@ export default {
191200
annotationPrecision: "word",
192201
// current state
193202
currentAnnotation: {},
194-
currentClass: tags && tags[0] || {},
203+
currentClass: (tags && tags[0]) || {},
195204
currentIndex: 0,
196205
currentSentence: "",
206+
currentPage: "start",
197207
};
198208
},
199209
getters,

0 commit comments

Comments
 (0)