-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathSelectPreferredStore.vue
More file actions
163 lines (143 loc) · 5.3 KB
/
Copy pathSelectPreferredStore.vue
File metadata and controls
163 lines (143 loc) · 5.3 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<script setup lang="ts">
import axios from "axios";
import { computed, type PropType, ref } from "vue";
import { getPermissions, isHistoryPrivate, makePrivate, type PermissionsResponse } from "@/components/History/services";
import { useConfirmDialog } from "@/composables/confirmDialog";
import { useStorageLocationConfiguration } from "@/composables/storageLocation";
import { prependPath } from "@/utils/redirect";
import { errorMessageAsString } from "@/utils/simple-error";
import GModal from "@/components/BaseComponents/GModal.vue";
import SelectObjectStore from "@/components/ObjectStore/SelectObjectStore.vue";
const props = defineProps({
userPreferredObjectStoreId: {
type: String as PropType<string | null>,
default: null,
},
preferredObjectStoreId: {
type: String as PropType<string | null>,
default: null,
},
history: {
type: Object,
required: true,
},
showSubSetting: {
type: Boolean,
default: false,
},
showModal: {
type: Boolean,
default: false,
},
});
const { confirm } = useConfirmDialog();
const error = ref();
const newDatasetsDescription = "New dataset outputs from tools and workflows executed in this history";
const galaxySelectionDefaultTitle = "Use Galaxy Defaults";
const galaxySelectionDefaultDescription =
"Selecting this will reset Galaxy to default behaviors configured by your Galaxy administrator.";
const userSelectionDefaultTitle = "Use Your User Preference Defaults";
const userSelectionDefaultDescription =
"Selecting this will cause the history to not set a default and to fallback to your user preference defined default.";
const defaultOptionTitle = computed(() => {
if (props.userPreferredObjectStoreId) {
return userSelectionDefaultTitle;
} else {
return galaxySelectionDefaultTitle;
}
});
const defaultOptionDescription = computed(() => {
if (props.userPreferredObjectStoreId) {
return userSelectionDefaultDescription;
} else {
return galaxySelectionDefaultDescription;
}
});
const emit = defineEmits<{
(e: "close"): void;
(e: "updated", id: string | null): void;
}>();
async function handleSubmit(preferredObjectStoreId: string | null, isPrivate: boolean) {
if (isPrivate) {
const { data } = await getPermissions(props.history.id);
const permissionResponse = data as PermissionsResponse;
const historyPrivate = await isHistoryPrivate(permissionResponse);
if (!historyPrivate) {
const confirmed = await confirm(
"Your history is set to create sharable datasets, but the target storage location is private. Change the history configuration so new datasets are private by default?",
{
okText: "Private new datasets",
cancelText: "Keep datasets public",
},
);
if (confirmed) {
try {
await makePrivate(props.history.id, permissionResponse);
} catch {
error.value = "Failed to update default permissions for history.";
throw new Error();
}
}
}
}
const payload = { preferred_object_store_id: preferredObjectStoreId };
const url = prependPath(`api/histories/${props.history.id}`);
try {
await axios.put(url, payload);
emit("updated", preferredObjectStoreId);
} catch (e) {
error.value = errorMessageAsString(e);
throw new Error();
}
}
const { isOnlyPreference } = useStorageLocationConfiguration();
const storageLocationTitle = computed(() => {
if (isOnlyPreference.value) {
return "History Preferred Storage Location";
} else {
return "History Storage Location";
}
});
const currentSelectedStoreId = ref<string | null>(props.preferredObjectStoreId);
const currentSelectedStorePrivate = ref(false);
function selectionChanged(preferredObjectStoreId: string | null, isPrivate: boolean) {
currentSelectedStoreId.value = preferredObjectStoreId;
currentSelectedStorePrivate.value = isPrivate;
}
async function modalOk() {
try {
await handleSubmit(currentSelectedStoreId.value, currentSelectedStorePrivate.value);
reset();
} catch (_e) {
// pass
}
}
function reset() {
currentSelectedStoreId.value = props.preferredObjectStoreId;
currentSelectedStorePrivate.value = false;
error.value = null;
}
</script>
<template>
<GModal
id="modal-select-history-storage-location"
:show="props.showModal"
size="small"
:title="storageLocationTitle"
ok-text="Change Storage Location"
class="modal-select-history-storage-location"
:ok-disabled="currentSelectedStoreId === props.preferredObjectStoreId"
confirm
@cancel="reset"
@close="emit('close')"
@ok="modalOk">
<SelectObjectStore
:show-sub-setting="props.showSubSetting"
:parent-error="error"
:for-what="newDatasetsDescription"
:selected-object-store-id="currentSelectedStoreId"
:default-option-title="defaultOptionTitle"
:default-option-description="defaultOptionDescription"
@onSubmit="selectionChanged" />
</GModal>
</template>