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
|
<script setup lang="ts">
import { useSessionStore, type EditorQuest } from '@/stores/session';
import { computed, ref } from 'vue';
const props = defineProps<{
taskId: string;
quest: EditorQuest;
}>();
const sessionStore = useSessionStore();
const taskType = computed(() => props.quest.tasks[props.taskId].config.type);
const taskDefintion = computed(() => sessionStore.getTaskDefinitionByTaskType(taskType.value));
const taskConfig = computed(() => {
return Object.keys(props.quest.tasks[props.taskId].config).filter((fieldName) => fieldName !== 'type').reduce((acc, fieldName) => {
acc[fieldName] = props.quest.tasks[props.taskId].config[fieldName];
return acc;
}, {} as { [key: string]: any });
});
const requiredFields = computed(() => {
return Object.keys(taskDefintion.value.configuration).filter((fieldName) => taskDefintion.value.configuration[fieldName].required);
});
const givenRequiredFields = computed(() => {
return requiredFields.value.filter((fieldName) => taskConfig.value[fieldName]);
});
const missingFields = computed(() => {
return requiredFields.value.filter((fieldName) => !props.quest.tasks[props.taskId].config[fieldName]);
});
const remainingGivenFields = computed(() => {
return Object.keys(taskConfig.value).filter((fieldName) => !requiredFields.value.includes(fieldName));
});
const configKeysOptions = computed(() => Object.keys(taskDefintion.value.configuration).filter((key) => !Object.keys(taskConfig.value).some((fieldName) => fieldName === key)));
// const configKeysOptions = computed(() => {
// const keys = Object.keys(taskDefintion.value.configuration).filter((key) => !Object.keys(taskConfig.value).some((fieldName) => fieldName === key));
//
// return keys.map((key) => {
// return {
// value: key,
// description: taskDefintion.value.configuration[key].description,
// note: taskDefintion.value.configuration[key].note,
// };
// });
// });
const onAddOption = (option: any) => {
sessionStore.getQuestById(props.quest.id)!.tasks[props.taskId].config[option] = taskDefintion.value.configuration[option].default || null;
};
const updateValue = (fieldName: string, value: any) => {
sessionStore.getQuestById(props.quest.id)!.tasks[props.taskId].config[fieldName] = value;
};
const deleteValue = (fieldName: string) => {
delete sessionStore.getQuestById(props.quest.id)!.tasks[props.taskId].config[fieldName];
};
const showChangeModal = ref(false);
const updateTaskType = (newType: string) => {
sessionStore.getQuestById(props.quest.id)!.tasks[props.taskId].config = {
type: newType
};
showChangeModal.value = false;
}
const deleteTaskType = (taskId: string) => {
delete sessionStore.getQuestById(props.quest.id)!.tasks[taskId];
}
</script>
<template>
<div id="task-configuration-table">
<div id="task-header">
<p id="task-id">
<span id="task-name">
{{ props.taskId }}
</span>
<code>
({{ taskType }})
</code>
</p>
<div id="task-controls" class="control-group">
<Button :icon="['fas', 'fa-pen']" :label="'Change'" @click="showChangeModal = true"></Button>
<Button :icon="['fas', 'fa-trash']" :label="'Delete'" @click="deleteTaskType(props.taskId)"></Button>
</div>
</div>
<div id="task-configuration">
<div v-if="!taskDefintion" class="error">
<font-awesome-icon id="error-icon" :icon="['fas', 'fa-triangle-exclamation']" />
<p id="error-message">
Unable to edit task <code>{{ props.taskId }}</code>.
</p>
<p id="error-description">
The quests web editor does not know how to configure task
type <code>{{ taskType }}</code> as it has no task definition.
</p>
</div>
<div v-if="taskDefintion">
<EditorTaskConfigurationRow
v-for="fieldName in [...givenRequiredFields, ...missingFields, ...remainingGivenFields]"
:key="`${quest.id}-${props.taskId}-${taskType}-${fieldName}`" :required="requiredFields.includes(fieldName)"
:configKey="fieldName" :initialValue="taskConfig[fieldName]" :taskType="taskType"
:type="(taskDefintion.configuration[fieldName].type as string)"
@update="(newValue: any) => updateValue(fieldName, newValue)" @delete="() => deleteValue(fieldName)" />
<div id="add-option">
<multiselect class="multiselect" :options="configKeysOptions" :searchable="true" @select="onAddOption"
placeholder="Add option...">
</multiselect>
</div>
</div>
</div>
</div>
<EditorTaskModalChange v-model="showChangeModal" :taskId="props.taskId" :currentTaskType="taskType"
:key="`change-task-${props.taskId}`" @update="updateTaskType" />
</template>
<style scoped>
.error {
padding: 0.5rem 0.5rem 0.5rem calc(0.5rem + 20px);
#error-icon {
float: left;
margin: 5px 0 0 -20px;
}
#error-message {
font-weight: 700;
}
}
#task-configuration-table {
display: flex;
flex-direction: column;
border: 1px solid var(--color-border);
#task-header {
display: flex;
justify-content: space-between;
border-bottom: 1px solid var(--color-border);
background-color: var(--color-background-soft);
padding: 0.5rem;
#task-id {
font-size: 1.2em;
#task-name {
font-weight: 700;
}
code {
font-size: 0.8em;
color: var(--color-text-mute);
}
}
}
}
#add-option {
width: 100%;
border-right: 1px solid var(--color-border);
border-top: 1px solid var(--color-border);
}
.multiselect::v-deep .multiselect__tags {
border: none !important;
border-radius: 0px !important;
background: transparent !important;
}
.multiselect::v-deep .multiselect__select {
background: transparent !important;
}
</style>
|