Skip to content

Commit

Permalink
fix: #336
Browse files Browse the repository at this point in the history
  • Loading branch information
khansadaoudi committed Jul 24, 2024
1 parent c434daf commit 1e5f769
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
3 changes: 3 additions & 0 deletions src/api/backend-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ export default {
mergeTrees(projectName: string, sampleName: string, data: any) {
return API.post(`/projects/${projectName}/samples/${sampleName}/trees/merge`, data);
},
saveAllTrees(projectName: string, sampleName: string, data: any) {
return API.post(`/projects/${projectName}/samples/${sampleName}/trees/all`, data);
},
// ----------------------------------------------------- //
// --------------- Grew --------------- //
// ----------------------------------------------------- //
Expand Down
41 changes: 34 additions & 7 deletions src/components/sample/AdvancedFilter.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<template>
<div class="row q-pa-md">
<div class="col-8">
<div class="row q-pa-md q-gutter-x-md">
<div class="col-6">
<q-input
v-model="textFilter"
:label="$t('advancedFilter.textFilter')"
outlined
dense
color="primary"
@keyup.enter="applyAdvancedFilter()"
></q-input>
></q-input>
</div>
<div class="col-3 q-px-md q-gutter-md">
<q-select
Expand All @@ -31,9 +31,13 @@
</template>
</q-select>
</div>
<div>
<q-btn @click="applyAdvancedFilter" color="primary">{{ $t('advancedFilter.applyFilter') }}</q-btn>
</div>
<q-btn @click="applyAdvancedFilter" color="primary">{{ $t('advancedFilter.applyFilter') }}</q-btn>
<q-separator vertical />
<q-btn outline :disable="pendingModifications.size === 0" color="primary" label="Save pending trees" @click="saveAllTrees()">
<q-badge v-if="pendingModifications.size > 0" color="red" floating>
{{ pendingModifications.size }}
</q-badge>
</q-btn>
</div>
<div class="q-pa-md">
<div class="row text-h6">
Expand Down Expand Up @@ -101,8 +105,11 @@ import { mapActions, mapState, mapWritableState } from 'pinia';
import { useProjectStore } from 'src/pinia/modules/project';
import { useTagsStore } from 'src/pinia/modules/tags';
import { useTreesStore } from 'src/pinia/modules/trees';
import { useGrewSearchStore } from 'src/pinia/modules/grewSearch';
import { notifyError, notifyMessage } from 'src/utils/notify';
import { defineComponent } from 'vue';
import { api } from 'src/boot/axios';
interface filter_t {
setUsers: string[];
Expand All @@ -117,6 +124,7 @@ interface element_t {
export default defineComponent({
name: 'AdvancedFilter',
emits: ['trees-saved'],
data() {
const filterOperators: element_t[] = [
{ val: 'have', label: this.$t('advancedFilter.filterOperators[0]') },
Expand All @@ -135,7 +143,7 @@ export default defineComponent({
};
},
computed: {
...mapState(useProjectStore, ['featuresSet']),
...mapState(useProjectStore, ['featuresSet', 'name']),
...mapState(useTreesStore, ['trees', 'filteredTrees', 'numberOfTreesPerUser', 'numberOfTrees', 'userIds']),
...mapState(useTagsStore, ['userTags']),
...mapWritableState(useTreesStore, [
Expand All @@ -148,12 +156,14 @@ export default defineComponent({
'featuresSetForNotDiffs',
'selectedTags',
]),
...mapState(useGrewSearchStore, ['pendingModifications']),
},
mounted() {
this.clearAll();
},
methods: {
...mapActions(useTreesStore, ['applyFilterTrees', 'getUsersTags']),
...mapActions(useGrewSearchStore, ['emptyPendingModification']),
applyAdvancedFilter() {
this.initializeFilters();
for (const filter of this.listFilters) {
Expand Down Expand Up @@ -200,6 +210,23 @@ export default defineComponent({
this.featuresSetForDiffs = [];
this.featuresSetForNotDiffs = [];
},
saveAllTrees() {
const data = {
conllGraph: [...this.pendingModifications.values()].join('\n\n')
};
const sampleName = this.$route.params.samplename as string;
api
.saveAllTrees(this.name, sampleName, data)
.then(() => {
notifyMessage({ position: 'top', message: 'Saved on the server', icon: 'save' });
this.emptyPendingModification();
console.log(this.pendingModifications.size)
this.$emit('trees-saved');
})
.catch((error) => {
notifyError({ error: `Error happened while saving trees ${error}` });
});
}
},
});
</script>
17 changes: 15 additions & 2 deletions src/components/sentence/VueDepTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export default defineComponent({
computed: {
...mapState(useProjectStore, ['diffUserId', 'shownFeatures', 'isStudent']),
...mapState(useUserStore, ['username', 'isLoggedIn']),
...mapState(useGrewSearchStore, ['pendingModifications']),
},
watch: {
diffMode() {
Expand All @@ -100,6 +101,15 @@ export default defineComponent({
diffUserId() {
this.handleDiffPlugging();
},
'pendingModifications.size': {
handler: function (newVal) {
if (newVal === 0) {
this.history_saveIndex = this.sentenceCaretaker.currentStateIndex;
this.statusChangeHandler();
}
},
deep: true,
}
},
mounted() {
// attach so this vue comp become an observer of the reactive sent
Expand Down Expand Up @@ -270,7 +280,10 @@ export default defineComponent({
const statusObj = statusStr ? JSON.parse(statusStr as string) : {};
let card = statusObj[this.cardId];
this.hasPendingChanges[this.treeUserId] = needSave;
if (needSave) this.addPendingModification(this.reactiveSentencesObj[this.treeUserId].state.metaJson.sent_id);
if (needSave) this.addPendingModification(
`${ this.reactiveSentencesObj[this.treeUserId].state.metaJson.sent_id }_${this.reactiveSentencesObj[this.treeUserId].state.metaJson.user_id }`,
this.reactiveSentencesObj[this.treeUserId].exportConll()
);
this.$emit('statusChanged', {
canUndo,
Expand All @@ -296,7 +309,7 @@ export default defineComponent({
if (card[userIds[j]] === true) {
window.onbeforeunload = function () {
return `You have some unsaved changes left,
please save them before you leave this page`;
please save them before you leave this page`;
};
return;
}
Expand Down
4 changes: 1 addition & 3 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 />
<AdvancedFilter @trees-saved="getTrees()" />
</template>
<template v-slot:after>
<div class="custom-frame1">
Expand Down Expand Up @@ -32,9 +32,7 @@
<q-circular-progress indeterminate size="70px" :thickness="0.22" color="primary" track-color="grey-3" />
</div>
</div>

<GrewSearch :sentence-count="numberOfTrees" :search-scope="samplename" :sample-names="[samplename]" :trees-from="userIds" />

<RelationTableMain :sample-names="[samplename]" :treesFrom="userIds" />
</div>
</template>
Expand Down
6 changes: 3 additions & 3 deletions src/pinia/modules/grewSearch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const useGrewSearchStore = defineStore('grewSearch', {
return {
grewDialog: false,
lastQuery: null as null | { text: string; type: 'REWRITE' | 'SEARCH'; userType: string },
pendingModifications: new Set(), // set of sentence ids
pendingModifications: new Map(), // set of sentence ids
treeTypes: ['user', 'user_recent', 'recent', 'validated', 'pending', 'base_tree', 'all', 'others'],
};
},
Expand Down Expand Up @@ -41,8 +41,8 @@ export const useGrewSearchStore = defineStore('grewSearch', {
changeLastGrewQuery(query: null | { text: string; type: 'REWRITE' | 'SEARCH'; userType: string }) {
this.lastQuery = query;
},
addPendingModification(pendingModification: any) {
this.pendingModifications.add(pendingModification);
addPendingModification(sentId: string, conll: string) {
this.pendingModifications.set(sentId, conll);
},
removePendingModification(pendingModification: any) {
this.pendingModifications.delete(pendingModification);
Expand Down

0 comments on commit 1e5f769

Please sign in to comment.