-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApps.vue
More file actions
269 lines (242 loc) · 6.93 KB
/
Copy pathApps.vue
File metadata and controls
269 lines (242 loc) · 6.93 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<template>
<form
class="card mb-4"
@submit.prevent="saveExternalAppConfiguration"
>
<div class="card-body border-bottom">
<h3 class="card-title mb-3">
External Apps
</h3>
<b-alert
v-if="!isLead"
variant="info"
show
class="mb-3"
>
<app-icon variant="info" />
Only workspace owners can change external app settings.
</b-alert>
<div class="form-check form-switch">
<label class="form-check-label">
<input
v-model="workspace.externalAppAccess"
type="checkbox"
class="form-check-input"
:true-value="1"
:false-value="0"
:disabled="!isLead"
>
Publish this workspace for external apps
</label>
</div>
<hr>
<h4 class="h5">
AVIV ScoutRoute Long Form Quest Definitions
</h4>
<div class="form-check">
<label class="form-check-label">
Define quests in Workspaces
<input
v-model="longFormQuestType"
class="form-check-input"
type="radio"
name="longFormQuestType"
value="JSON"
:disabled="appControlsDisabled"
>
</label>
</div>
<div class="form-check">
<label class="form-check-label">
Load quest definitions from an external URL
<input
v-model="longFormQuestType"
class="form-check-input"
type="radio"
name="longFormQuestType"
value="URL"
:disabled="appControlsDisabled"
>
</label>
</div>
<template v-if="longFormQuestType === 'JSON'">
<label class="d-block form-label mt-3">
JSON Quest Definition
<textarea
v-model.trim="longFormQuestDef"
class="form-control"
:class="{ 'drag-over': isDraggingQuest }"
rows="5"
placeholder="Optional"
:disabled="appControlsDisabled"
@dragover.prevent="isDraggingQuest = true"
@dragleave.prevent="isDraggingQuest = false"
@drop.prevent="onQuestFileDrop"
/>
</label>
<div
id="imagery-help"
class="form-text"
>
Paste the JSON content directly or drag and drop a JSON file.
See the
<a
:href="longFormQuestSchemaUrl"
target="_blank"
>
JSON Schema
</a>
for the required format and an
<a
:href="longFormQuestExampleUrl"
target="_blank"
>
example
</a>.
</div>
</template>
<template v-else-if="longFormQuestType === 'URL'">
<label class="d-block form-label mt-3">
Quest Definition URL
<input
v-model.trim="longFormQuestUrl"
type="text"
class="form-control"
placeholder="https://..."
:disabled="appControlsDisabled"
>
</label>
<div
id="imagery-help"
class="form-text"
>
Enter the address of a quest definition JSON document
See the
<a
:href="longFormQuestSchemaUrl"
target="_blank"
>
JSON Schema
</a>
for the required format and an
<a
:href="longFormQuestExampleUrl"
target="_blank"
>
example
</a>.
</div>
</template>
<div
v-if="longFormQuestError"
class="form-text text-danger"
>
{{ longFormQuestError }}
</div>
<hr>
<button
type="submit"
class="btn btn-primary"
:disabled="!isLead"
>
Save
</button>
</div><!-- .card-body -->
</form><!-- .card -->
</template>
<script setup lang="ts">
import { workspacesClient } from '~/services/index';
import { handleFileDrop, validateJson } from '~/util/schema';
import { isHttpUrl, normalizeUrl } from '~/util/url';
import { toast } from 'vue3-toastify';
import 'vue3-toastify/dist/index.css';
import type { Workspace } from '~/types/workspaces';
const longFormQuestSchemaUrl = import.meta.env.VITE_LONG_FORM_QUEST_SCHEMA;
const longFormQuestExampleUrl = import.meta.env.VITE_LONG_FORM_QUEST_EXAMPLE_URL;
const workspace = inject<Workspace>('workspace')!;
const { isLead } = useWorkspaceRole();
// The quest-definition controls only apply when the workspace is published for
// external apps, so they're disabled when "Publish" is off (or for non-leads).
const appControlsDisabled = computed(() => !isLead.value || !workspace.externalAppAccess);
const [longFormQuestSettings] = await Promise.all([
workspacesClient.getLongFormQuestSettings(workspace.id),
]);
const longFormQuestSchema = ref<object | undefined>();
const longFormQuestType = ref(longFormQuestSettings.type);
const longFormQuestDef = ref(longFormQuestSettings.definition);
const longFormQuestUrl = ref(longFormQuestSettings.url);
const longFormQuestError = ref<string | null>(null);
const isDraggingQuest = ref(false);
watch(
[
longFormQuestType,
longFormQuestDef,
longFormQuestUrl,
() => workspace.externalAppAccess,
],
() => { clearExternalAppMessages(); },
);
function clearExternalAppMessages() {
longFormQuestError.value = null;
}
function onQuestFileDrop(event: DragEvent) {
handleFileDrop(event, longFormQuestDef, isDraggingQuest);
}
async function saveExternalAppConfiguration() {
clearExternalAppMessages();
let type = longFormQuestType.value;
let definition = longFormQuestDef.value;
let url = longFormQuestUrl.value;
if (type === 'JSON') {
url = undefined;
if (!definition) {
type = 'NONE';
}
else {
const validationResult = await validateJson(
definition,
longFormQuestSchemaUrl,
longFormQuestSchema,
'Long form quest definition',
);
if (validationResult.error) {
longFormQuestError.value = validationResult.error;
return;
}
}
}
else if (type === 'URL') {
definition = undefined;
if (!url) {
type = 'NONE';
}
else if (!isHttpUrl(url)) {
longFormQuestError.value = 'The URL is not valid.';
return;
}
else {
url = normalizeUrl(url);
}
}
try {
await Promise.all([
workspacesClient.updateWorkspace(workspace.id, {
externalAppAccess: workspace.externalAppAccess,
}),
workspacesClient.saveLongFormQuestSettings(workspace.id, {
type,
definition,
url,
}),
]);
toast.success('Changes saved.');
longFormQuestType.value = type;
longFormQuestDef.value = definition;
longFormQuestUrl.value = url;
}
catch (e) {
const errorMessage = e instanceof Error ? e.message : 'unexpected error';
toast.error('Failed to save changes: ' + errorMessage);
}
}
</script>