Skip to content

Commit

Permalink
minor improvemento avoid exporting empty files
Browse files Browse the repository at this point in the history
  • Loading branch information
khansadaoudi committed Jul 23, 2024
1 parent dcaae9a commit d66f056
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions src/components/project/ExportDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
</q-card-section>
<q-card-section class="q-gutter-md">
<q-list bordered>
<q-item v-if="canSeeOtherUsersTrees" tag="label" v-ripple>
<q-item v-if="canSeeOtherUsersTrees && usersTreesFrom.includes('validated')" tag="label" v-ripple>
<q-item-section side top>
<q-checkbox v-model="validated" />
</q-item-section>
<q-item-section>
<q-item-label>{{ $t('exportSamples.exportValidatedTrees') }}</q-item-label>
</q-item-section>
</q-item>
<q-item v-if="canSaveTreeInProject" tag="label" v-ripple>
<q-item v-if="canSaveTreeInProject && usersTreesFrom.includes(username)" tag="label" v-ripple>
<q-item-section side top>
<q-checkbox v-model="user" />
</q-item-section>
Expand All @@ -35,7 +35,11 @@
<q-item-label>{{ $t('exportSamples.exportRecentTrees') }}</q-item-label>
</q-item-section>
</q-item>
<q-item v-if="otherUsers.length > 0 && canSeeOtherUsersTrees" tag="label" v-ripple>
<q-item
v-if="usersTreesFrom.filter((user) => user !== username && user !== 'validated').length > 0 && canSeeOtherUsersTrees"
tag="label"
v-ripple
>
<q-item-section side top>
<q-checkbox v-model="other" />
</q-item-section>
Expand All @@ -55,13 +59,15 @@
</template>

<script lang="ts">
import { notifyError, notifyMessage } from 'src/utils/notify';
import api from '../../api/backend-api';
import { defineComponent, PropType } from 'vue';
import { sample_t } from 'src/api/backend-types';
import { mapState } from 'pinia';
import { useUserStore } from 'src/pinia/modules/user';
import { useProjectStore } from 'src/pinia/modules/project';
import { notifyError } from 'src/utils/notify';
import { defineComponent, PropType } from 'vue';
export default defineComponent({
name: 'ExportDialog',
Expand All @@ -84,17 +90,8 @@ export default defineComponent({
computed: {
...mapState(useUserStore, ['username']),
...mapState(useProjectStore, ['canSaveTreeInProject', 'canSeeOtherUsersTrees']),
otherUsers() {
let otherUsers: String[] = [];
for (const sample of this.samples) {
const sampleTreesFrom = sample.treesFrom;
for (const userId of sampleTreesFrom) {
if (!otherUsers.includes(userId) && userId !== 'validated') {
otherUsers.push(userId);
}
}
}
return otherUsers.filter((user) => user != this.username);
usersTreesFrom() {
return [...new Set(this.samples.map((sample) => sample.treesFrom).reduce((a: string[], b: string[]) => [...a, ...b], []))];
},
projectName() {
return this.$route.params.projectname;
Expand All @@ -105,8 +102,7 @@ export default defineComponent({
},
methods: {
exportSamplesZip() {
const sampleNames: string[] = [];
var usersToExport: string[] = [];
let usersToExport: string[] = [];
if (this.user) {
usersToExport.push(this.username);
}
Expand All @@ -119,11 +115,7 @@ export default defineComponent({
if (this.validated) {
usersToExport.push('validated');
}
for (const sample of this.samples) {
sampleNames.push(sample.sample_name);
}
const data = { sampleNames: sampleNames, users: usersToExport };
const data = { sampleNames: this.samples.map(sample => sample.sample_name), users: usersToExport };
api
.exportSamplesZip(this.projectName as string, data)
.then((response) => {
Expand All @@ -134,7 +126,6 @@ export default defineComponent({
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
notifyMessage({ message: 'Files downloaded' });
return [];
})
.catch((error) => {
Expand All @@ -146,4 +137,3 @@ export default defineComponent({
});
</script>

<style></style>

0 comments on commit d66f056

Please sign in to comment.