-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathSaveSegmentGroupDialog.vue
More file actions
103 lines (91 loc) · 2.42 KB
/
SaveSegmentGroupDialog.vue
File metadata and controls
103 lines (91 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<template>
<v-card>
<v-card-title class="d-flex flex-row align-center">
Save Segment Group
</v-card-title>
<v-card-text>
<v-form v-model="valid" @submit.prevent="saveSegmentGroup">
<v-text-field
v-model="fileName"
hint="Filename that will appear in downloads."
label="Filename"
:rules="[validFileName]"
required
id="filename"
/>
<v-select
label="Format"
v-model="fileFormat"
:items="EXTENSIONS"
></v-select>
</v-form>
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn
:loading="saving"
color="secondary"
@click="saveSegmentGroup"
:disabled="!valid"
>
<v-icon class="mr-2">mdi-content-save</v-icon>
<span data-testid="save-confirm-button">Save</span>
</v-btn>
</v-card-actions>
</v-card>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { onKeyDown } from '@vueuse/core';
import { saveAs } from 'file-saver';
import { useSegmentGroupStore } from '@/src/store/segmentGroups';
import { writeSegmentation } from '@/src/io/readWriteImage';
import { useErrorMessage } from '@/src/composables/useErrorMessage';
const EXTENSIONS = [
'seg.nrrd',
'nrrd',
'nii',
'nii.gz',
'dcm',
'hdf5',
'tif',
'mha',
'vtk',
'iwi.cbor',
];
const props = defineProps<{
id: string;
}>();
const emit = defineEmits(['done']);
const fileName = ref('');
const valid = ref(true);
const saving = ref(false);
const fileFormat = ref(EXTENSIONS[0]);
const segmentGroupStore = useSegmentGroupStore();
async function saveSegmentGroup() {
if (fileName.value.trim().length === 0) {
return;
}
saving.value = true;
await useErrorMessage('Failed to save segment group', async () => {
const serialized = await writeSegmentation(
fileFormat.value,
segmentGroupStore.dataIndex[props.id],
segmentGroupStore.metadataByID[props.id]
);
saveAs(new Blob([serialized]), `${fileName.value}.${fileFormat.value}`);
});
saving.value = false;
emit('done');
}
onMounted(() => {
// trigger form validation check so can immediately save with default value
fileName.value = segmentGroupStore.metadataByID[props.id].name;
});
onKeyDown('Enter', () => {
saveSegmentGroup();
});
function validFileName(name: string) {
return name.trim().length > 0 || 'Required';
}
</script>