Skip to content

Commit

Permalink
add the possibility to validate all trees in sample view
Browse files Browse the repository at this point in the history
  • Loading branch information
khansadaoudi committed Sep 18, 2024
1 parent 1354204 commit 66d1eec
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 20 deletions.
9 changes: 6 additions & 3 deletions src/api/backend-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ export default {
getProjectImage(projectName: string) {
return API.get(`projects/${projectName}/image`);
},
checkProjectLanguageDetected(projectName: string) {
return API.get(`projects/${projectName}/language-detected`);
},
getProjectFeatures(projectName: string) {
return API.get<getProjectFeatures_RV>(`projects/${projectName}/features`);
},
Expand Down Expand Up @@ -161,6 +164,9 @@ export default {
saveAllTrees(projectName: string, sampleName: string, data: any) {
return API.post(`/projects/${projectName}/samples/${sampleName}/trees/all`, data);
},
validateAllTrees(projectName: string, sampleName: string) {
return API.post(`/projects/${projectName}/samples/${sampleName}/validate`);
},
validateTree(projectName: string, data: any) {
return API.post(`/projects/${projectName}/tree/validate`, data);
},
Expand Down Expand Up @@ -379,7 +385,4 @@ export default {
getStats(projectName: string) {
return API.get<getStatProject_RV>(`projects/${projectName}/statistics`);
},
getProjectTags(projectName: string, data: any) {
return API.post(`projects/${projectName}/tags`, data);
}
};
38 changes: 31 additions & 7 deletions src/components/sample/AdvancedFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,24 @@
dense
v-model="order"
:options="orderOptions"
label="Order sentences by length"
:label="$t('advancedFilter.orderLength')"
@update:model-value="orderFilteredTrees(order)"
/>
</div>
<q-separator vertical />
<q-btn v-if="isLoggedIn" outline :disable="pendingModifications.size === 0" color="primary" label="Save pending trees" @click="saveAllTrees()">
<q-btn no-caps v-if="config === 'ud' && !blindAnnotationMode" color="primary" :label="$t('advancedFilter.validateAllTrees')" @click="validateAllTrees()">
<q-tooltip>
{{ $t('advancedFilter.validateAllTreesTooltip') }}
</q-tooltip>
</q-btn>
<q-btn
v-if="isLoggedIn"
outline
:disable="pendingModifications.size === 0"
color="primary"
:label="$t('advancedFilter.savePendingTrees')"
@click="saveAllTrees()"
>
<q-badge v-if="pendingModifications.size > 0" color="red" floating>
{{ pendingModifications.size }}
</q-badge>
Expand Down Expand Up @@ -121,7 +133,7 @@ import { useTreesStore } from 'src/pinia/modules/trees';
import { useUserStore } from 'src/pinia/modules/user';
import { notifyError, notifyMessage } from 'src/utils/notify';
import { defineComponent } from 'vue';
import { defineComponent, PropType } from 'vue';
import { api } from 'src/boot/axios';
import Breadcrumbs from 'src/layouts/Breadcrumbs.vue';
Expand All @@ -142,6 +154,12 @@ export default defineComponent({
components: {
Breadcrumbs,
},
props: {
parentOnValidate: {
type: Function as PropType<CallableFunction>,
required: true,
}
},
data() {
const filterOperators: element_t[] = [
{ val: 'have', label: this.$t('advancedFilter.filterOperators[0]') },
Expand All @@ -152,6 +170,7 @@ export default defineComponent({
{ val: 'diff', label: this.$t('advancedFilter.filterChoices[1]') },
];
const listFilters: filter_t[] = [];
return {
selectedUsers: [],
filterChoices,
Expand All @@ -162,8 +181,8 @@ export default defineComponent({
};
},
computed: {
...mapState(useProjectStore, ['featuresSet', 'name']),
...mapState(useTreesStore, ['trees', 'filteredTrees', 'numberOfTreesPerUser', 'numberOfTrees', 'userIds']),
...mapState(useProjectStore, ['featuresSet', 'name', 'config', 'blindAnnotationMode']),
...mapState(useTreesStore, ['trees', 'filteredTrees', 'numberOfTreesPerUser', 'numberOfTrees', 'userIds', 'sortedSentIds']),
...mapState(useTagsStore, ['userTags']),
...mapWritableState(useTreesStore, [
'textFilter',
Expand All @@ -177,6 +196,9 @@ export default defineComponent({
'pendingModifications'
]),
...mapState(useUserStore, ['isLoggedIn']),
sampleName() {
return this.$route.params.samplename as string;
},
},
mounted() {
this.clearAll();
Expand Down Expand Up @@ -233,9 +255,8 @@ export default defineComponent({
const data = {
conllGraph: [...this.pendingModifications.values()].map((sentence) => sentence.conll).join('\n\n')
};
const sampleName = this.$route.params.samplename as string;
api
.saveAllTrees(this.name, sampleName, data)
.saveAllTrees(this.name, this.sampleName, data)
.then(() => {
notifyMessage({ position: 'top', message: 'Saved on the server', icon: 'save' });
this.emptyPendingModification();
Expand All @@ -244,6 +265,9 @@ export default defineComponent({
.catch((error) => {
notifyError({ error: `Error happened while saving trees ${error}` });
});
},
validateAllTrees() {
this.parentOnValidate();
}
},
});
Expand Down
27 changes: 23 additions & 4 deletions src/components/sentence/SentenceCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ export default defineComponent({
default: () => [] as matches_t[],
type: Object as PropType<matches_t>,
},
udValidation: {
type: Object as PropType<any>,
required: false,
},
},
data() {
const hasPendingChanges: { [key: string]: boolean } = {};
Expand All @@ -255,14 +259,13 @@ export default defineComponent({
udValidationPassed,
udValidationMsg,
udValidationStatut,
languageDetected: false,
showUdValidation,
};
},
computed: {
...mapWritableState(useProjectStore, ['diffMode', 'diffUserId', 'name']),
...mapWritableState(useGithubStore, ['reloadCommits']),
...mapState(useProjectStore, ['isValidator', 'blindAnnotationMode', 'shownMeta']),
...mapState(useProjectStore, ['isValidator', 'blindAnnotationMode', 'shownMeta', 'languageDetected']),
...mapState(useUserStore, ['username']),
...mapState(useTagsStore, ['defaultTags']),
lastModifiedTime() {
Expand Down Expand Up @@ -314,6 +317,23 @@ export default defineComponent({
}
this.diffMode = !!this.diffMode;
},
watch: {
'udValidation': {
handler: function (newVal) {
for (const user of Object.keys(this.sentence.conlls)) {
if(newVal[user]) {
this.udValidationMsg[user] = newVal[user].message;
this.udValidationStatut[user] = 'negative'
}
else {
this.udValidationMsg[user] = '';
this.udValidationStatut[user] = 'positive';
}
}
},
deep: true,
},
},
methods: {
...mapActions(useTagsStore, ['removeTag']),
...mapActions(useTreesStore, ['removePendingModification']),
Expand Down Expand Up @@ -392,12 +412,11 @@ export default defineComponent({
}
this.udValidationMsg[this.openTabUser] = response.data.message;
this.udValidationPassed[this.openTabUser] = response.data.passed;
this.languageDetected = response.data.detected;
}
})
.catch((error) => {
notifyError({ error: `Error happened while validating ${error}` });
})
});
},
transitioned() {
if (this.exportedConll) {
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/en-us/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,10 @@ export default {
usersSelect: 'Select set of users',
filterOperators: ['Have', 'Not Have'],
filterChoices: ['Trees', 'Differences'],
orderLength: 'Ordonner les phrases par taille',
validateAllTrees: 'Validate all trees',
validateAllTreesTooltip: "Appliquer le script de validation d'UD sur l'ensemble des arbres d'échantillon",
savePendingTrees: 'Save pending trees',
},
tokenReplaceDialog: {
merge: 'Merge',
Expand Down
4 changes: 4 additions & 0 deletions src/i18n/fr-fra/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,10 @@ export default {
usersSelect: 'Sélectionner la liste des utilisateurs',
filterOperators: ['ont', "n'ont pas"],
filterChoices: ['Arbres', 'Differences'],
orderLength: 'Ordonner les phrases par taille',
validateAllTrees: 'Valider tous les arbres',
validateAllTreesTooltip: "Appliquer le script de validation d'UD sur l'ensemble des arbres d'échantillon",
savePendingTrees: 'Sauvegarder tous les arbres',
},
tokenReplaceDialog: {
merge: 'Fusionner',
Expand Down
43 changes: 37 additions & 6 deletions src/pages/Sample.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<q-splitter v-model="splitterModel" horizontal :limits="[0, 100]" :style="{ height: `${splitterHeight}px` }" emit-immediately>
<template v-slot:before>
<AdvancedFilter @trees-saved="getTrees()" />
<AdvancedFilter @trees-saved="getTrees()" :parent-on-validate="validateAllTrees" />
</template>
<template v-slot:after>
<div class="custom-frame1">
Expand All @@ -20,6 +20,7 @@
:sentence="item"
:index="index"
:blind-annotation-level="blindAnnotationLevel"
:ud-validation="udValidationPassed[item.sent_id] || {}"
>
</SentenceCard>
</template>
Expand All @@ -36,14 +37,17 @@
</template>

<script lang="ts">
import { mapActions, mapState, mapWritableState } from 'pinia';
import { QVirtualScroll } from 'quasar';
import api from 'src/api/backend-api';
import AdvancedFilter from 'src/components/sample/AdvancedFilter.vue';
import SentenceCard from '../components/sentence/SentenceCard.vue';
import { QVirtualScroll } from 'quasar';
import { mapActions, mapState, mapWritableState } from 'pinia';
import { notifyError } from 'src/utils/notify';
import { useTreesStore } from 'src/pinia/modules/trees';
import { useProjectStore } from 'src/pinia/modules/project';
import { PropType, defineComponent } from 'vue';
import SentenceCard from '../components/sentence/SentenceCard.vue';
export default defineComponent({
components: {
SentenceCard,
Expand Down Expand Up @@ -75,9 +79,12 @@ export default defineComponent({
data() {
const splitterModel: number = 12;
const splitterHeight: number = 0;
const udValidationPassed: { [sentId: string]: { [userId: string]: { message: string, passed: boolean } } } = {};
return {
splitterModel,
splitterHeight,
udValidationPassed,
languageDetected: false,
};
},
computed: {
Expand All @@ -88,9 +95,14 @@ export default defineComponent({
'numberOfTrees',
'userIds',
'blindAnnotationLevel',
'pendingModifications'
'pendingModifications',
'sortedSentIds'
]),
...mapState(useProjectStore, ['name']),
...mapWritableState(useTreesStore, ['reloadTrees']),
sampleName() {
return this.$route.params.samplename as string;
}
},
created() {
window.addEventListener('resize', this.calculateHeight);
Expand Down Expand Up @@ -136,6 +148,25 @@ export default defineComponent({
this.splitterHeight = window.innerHeight - 35;
}
},
validateAllTrees() {
api
.validateAllTrees(this.name, this.sampleName)
.then((response) => {
const validationResults = response.data.message;
for (const userId of Object.keys(validationResults)) {
for (const sentId of Object.keys(validationResults[userId])) {
if (!Object.keys(this.udValidationPassed).includes(sentId)) {
this.udValidationPassed[sentId] = {};
}
let userTreeValidation = { message: validationResults[userId][sentId], passed: false };
this.udValidationPassed[sentId][userId] = userTreeValidation;
}
}
})
.catch((error) => {
notifyError({ error: error });
});
}
},
});
</script>
2 changes: 2 additions & 0 deletions src/pinia/modules/project/defaultState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface configState {
freezed: boolean;
config: string;
language: string;
languageDetected: boolean;
diffMode: boolean;
diffUserId: string;
collaborativeMode: boolean;
Expand Down Expand Up @@ -47,6 +48,7 @@ export default function defaultState(): configState {
freezed: false,
config: '',
language: '',
languageDetected: false,
diffMode: false,
diffUserId: '',
collaborativeMode: true,
Expand Down
3 changes: 3 additions & 0 deletions src/pinia/modules/project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ export const useProjectStore = defineStore('project', {
this.shownMeta = response.data.shownMeta;
this.shownFeatures = response.data.shownFeatures;
});
api.checkProjectLanguageDetected(projectName).then((response) => {
this.languageDetected = response.data;
});
api
.getProjectConlluSchema(projectName)
.then((response) => {
Expand Down

0 comments on commit 66d1eec

Please sign in to comment.