Skip to content

Commit

Permalink
add rename sample
Browse files Browse the repository at this point in the history
  • Loading branch information
khansadaoudi committed Oct 14, 2024
1 parent 899bc2e commit 3e1088e
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/api/backend-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ export default {
deleteSamples(projectName: string, data: any) {
return API.patch(`/projects/${projectName}/samples`, data);
},
renameSample(projectName: string, sampleName: string, data: any) {
return API.post(`/projects/${projectName}/samples/${sampleName}/sample-name`, data);
},
tokenizeSample(projectName: string, data: any) {
return API.post(`/projects/${projectName}/samples/tokenize`, data, { timeout: 400000 });
},
Expand Down
34 changes: 30 additions & 4 deletions src/components/project/ProjectTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@
no-caps
>
{{ props.row.sampleName }}
<q-menu
context-menu
touch-position
>
<q-list>
<q-item v-close-popup clickable @click="showRenameSampleDial(props.row.sampleName)">
<q-item-section>Rename sample</q-item-section>
<q-item-section side>
<q-icon name="edit" />
</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
</q-td>
<q-td key="sentences" :props="props">{{ props.row.sentences }}</q-td>
Expand Down Expand Up @@ -79,19 +92,26 @@
</q-tr>
</template>
</q-table>
<q-dialog v-model="isShowRenameDial">
<RenameSample :sample-name="selectedSample" />
</q-dialog>
</template>
<script lang="ts">
import api from 'src/api/backend-api';
import { sample_t } from 'src/api/backend-types';
import { table_t } from 'src/types/main_types';
import RenameSample from 'src/components/project/RenameSample.vue';
import { mapState } from 'pinia';
import { useProjectStore } from 'src/pinia/modules/project';
import { notifyError, notifyMessage } from 'src/utils/notify';
import { PropType, defineComponent } from 'vue';
import api from '../../api/backend-api';
import { sample_t } from '../../api/backend-types';
import { table_t } from '../../types/main_types';
export default defineComponent({
name: 'ProjectTable',
components: {
RenameSample,
},
emits: ['selected-samples'],
props: {
samples: {
Expand Down Expand Up @@ -170,6 +190,8 @@ export default defineComponent({
value: 4,
},
],
isShowRenameDial: false,
selectedSample: '',
};
},
computed: {
Expand Down Expand Up @@ -203,6 +225,10 @@ export default defineComponent({
});
}, 0);
},
showRenameSampleDial(sampleName: string) {
this.isShowRenameDial = true;
this.selectedSample = sampleName;
}
},
});
</script>
Expand Down
72 changes: 72 additions & 0 deletions src/components/project/RenameSample.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<template>
<q-card style="min-width: 50vw">
<q-bar class="bg-primary text-white">
<q-space />
<q-btn v-close-popup flat dense icon="close" />
</q-bar>
<q-card-section>
<div class="text-h6 text-left">Rename Sample</div>
</q-card-section>
<q-separator />
<q-card-section>
<q-input
outlined
v-model="newSampleName"
label="Rename sample"
lazy-rules
:rules="[
(val) => (val && val.length > 0) || 'Sample name must not be empty',
(val) => (val && !val.endsWith(' ')) || 'Sample must not end with white space',
]"
/>
<div class="flex flex-center">
<q-btn v-close-popup :disable="disableBtn" color="primary" label="Rename sample" @click="renameSample()" />
</div>
</q-card-section>
</q-card>
</template>
<script lang="ts">
import { api } from 'src/boot/axios';
import { mapWritableState, mapState } from 'pinia';
import { useProjectStore } from 'src/pinia/modules/project';
import { notifyError, notifyMessage } from 'src/utils/notify';
import { defineComponent, PropType } from 'vue';
export default defineComponent({
name: 'RenameSample',
props: {
sampleName: {
type: String as PropType<string>,
required: true,
}
},
data() {
return {
newSampleName: '',
}
},
computed: {
...mapState(useProjectStore, ['name']),
...mapWritableState(useProjectStore, ['reloadSamples']),
disableBtn() {
return this.newSampleName === '' && this.newSampleName.endsWith(' ');
}
},
methods: {
renameSample() {
const data = { newSampleName: this.newSampleName };
api
.renameSample(this.name, this.sampleName, data)
.then(() => {
notifyMessage({ message: 'The sample name is modified' });
this.reloadSamples = true;
})
.catch((error) => {
notifyError({ error: error });
});
},
}
});
</script>
2 changes: 1 addition & 1 deletion src/pages/Project.vue
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export default defineComponent({
if (newVal > 0) this.loadProjectData();
},
reloadSamples(newVal) {
if (newVal > 0) this.loadProjectData();
if (newVal) this.loadProjectData();
}
},
methods: {
Expand Down

0 comments on commit 3e1088e

Please sign in to comment.