2023-05-23 18:27:33 +00:00
|
|
|
<template>
|
2023-05-24 18:19:46 +00:00
|
|
|
<b-container fluid>
|
|
|
|
<b-row align-v="stretch">
|
2023-05-29 10:28:24 +00:00
|
|
|
<b-col cols="12" md="3" class="overflow-auto">
|
2023-05-28 16:17:40 +00:00
|
|
|
<b-list-group ref="availablePairlistsEl" class="available-pairlists">
|
|
|
|
<b-list-group-item
|
2023-05-24 18:19:46 +00:00
|
|
|
v-for="pairlist in availablePairlists"
|
|
|
|
:key="pairlist.name"
|
|
|
|
align-v="center"
|
2023-05-29 21:36:23 +00:00
|
|
|
:class="{
|
|
|
|
'no-drag':
|
|
|
|
pairlistStore.config.pairlists.length == 0 && !pairlist.is_pairlist_generator,
|
|
|
|
}"
|
2023-05-29 10:04:11 +00:00
|
|
|
class="pairlist d-flex text-start align-items-center py-2 px-3"
|
2023-05-24 18:19:46 +00:00
|
|
|
>
|
2023-05-28 16:17:40 +00:00
|
|
|
<div class="d-flex flex-grow-1 align-items-start flex-column">
|
|
|
|
<span class="fw-bold fd-italic">{{ pairlist.name }}</span>
|
|
|
|
<span class="fw-lighter">{{ pairlist.description }}</span>
|
|
|
|
</div>
|
|
|
|
<b-button
|
|
|
|
class="p-0"
|
|
|
|
style="border: none"
|
|
|
|
variant="outline-light"
|
2023-05-29 21:36:23 +00:00
|
|
|
:disabled="
|
|
|
|
pairlistStore.config.pairlists.length == 0 && !pairlist.is_pairlist_generator
|
|
|
|
"
|
|
|
|
@click="pairlistStore.addToConfig(pairlist, pairlistStore.config.pairlists.length)"
|
2023-05-29 06:29:30 +00:00
|
|
|
>
|
|
|
|
<i-mdi-arrow-right-bold-box-outline class="fs-4" />
|
|
|
|
</b-button>
|
2023-05-28 16:17:40 +00:00
|
|
|
</b-list-group-item>
|
|
|
|
</b-list-group>
|
2023-05-24 18:19:46 +00:00
|
|
|
</b-col>
|
|
|
|
<b-col>
|
2023-05-30 15:45:03 +00:00
|
|
|
<PairlistConfigActions />
|
2023-05-30 11:28:55 +00:00
|
|
|
<PairlistConfigBlacklist />
|
2023-05-29 10:28:24 +00:00
|
|
|
<b-alert
|
2023-05-29 21:36:23 +00:00
|
|
|
:model-value="
|
|
|
|
pairlistStore.config.pairlists.length > 0 && !pairlistStore.firstPairlistIsGenerator
|
|
|
|
"
|
2023-05-29 10:28:24 +00:00
|
|
|
variant="warning"
|
|
|
|
>
|
|
|
|
First entry in the pairlist must be a Generating pairlist, like StaticPairList or
|
|
|
|
VolumePairList.
|
|
|
|
</b-alert>
|
2023-05-28 16:41:18 +00:00
|
|
|
<div ref="pairlistConfigsEl" class="h-100">
|
2023-05-24 18:19:46 +00:00
|
|
|
<PairlistConfigItem
|
2023-05-26 11:12:40 +00:00
|
|
|
v-for="(pairlist, i) in pairlistsComp"
|
2023-05-24 18:19:46 +00:00
|
|
|
:key="pairlist.id"
|
2023-05-29 21:36:23 +00:00
|
|
|
v-model="pairlistStore.config.pairlists[i]"
|
2023-05-24 18:19:46 +00:00
|
|
|
:index="i"
|
2023-05-29 21:36:23 +00:00
|
|
|
@remove="pairlistStore.removeFromConfig"
|
2023-05-24 18:19:46 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</b-col>
|
2023-05-26 11:12:40 +00:00
|
|
|
<b-col cols="12" md="3">
|
2023-05-30 11:41:37 +00:00
|
|
|
<CopyableTextfield
|
|
|
|
:content="pairlistStore.configJSON"
|
|
|
|
:is-valid="pairlistStore.pairlistValid"
|
|
|
|
/>
|
2023-05-26 11:12:40 +00:00
|
|
|
</b-col>
|
2023-05-24 18:19:46 +00:00
|
|
|
</b-row>
|
|
|
|
</b-container>
|
2023-05-23 18:27:33 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2023-05-29 21:36:23 +00:00
|
|
|
import { computed, onMounted, ref } from 'vue';
|
2023-05-23 18:27:33 +00:00
|
|
|
import { useBotStore } from '@/stores/ftbotwrapper';
|
2023-05-29 21:36:23 +00:00
|
|
|
import { usePairlistConfigStore } from '@/stores/pairlistConfig';
|
2023-05-23 18:27:33 +00:00
|
|
|
import PairlistConfigItem from './PairlistConfigItem.vue';
|
2023-05-30 11:28:55 +00:00
|
|
|
import PairlistConfigBlacklist from './PairlistConfigBlacklist.vue';
|
2023-05-30 15:45:03 +00:00
|
|
|
import PairlistConfigActions from './PairlistConfigActions.vue';
|
2023-05-30 11:41:37 +00:00
|
|
|
import { Pairlist } from '@/types';
|
2023-05-23 18:27:33 +00:00
|
|
|
import { useSortable, moveArrayElement } from '@vueuse/integrations/useSortable';
|
2023-05-29 12:55:15 +00:00
|
|
|
import CopyableTextfield from '@/components/general/CopyableTextfield.vue';
|
2023-05-23 18:27:33 +00:00
|
|
|
|
|
|
|
const botStore = useBotStore();
|
2023-05-29 21:36:23 +00:00
|
|
|
const pairlistStore = usePairlistConfigStore();
|
2023-05-23 18:27:33 +00:00
|
|
|
|
|
|
|
const availablePairlists = ref<Pairlist[]>([]);
|
|
|
|
const pairlistConfigsEl = ref<HTMLElement | null>(null);
|
2023-05-24 18:19:46 +00:00
|
|
|
const availablePairlistsEl = ref<HTMLElement | null>(null);
|
2023-05-29 06:40:24 +00:00
|
|
|
|
2023-05-23 18:27:33 +00:00
|
|
|
// v-for updates with sorting, deleting and adding items seem to get wonky without unique keys for every item
|
2023-05-26 11:12:40 +00:00
|
|
|
const pairlistsComp = computed(() =>
|
2023-05-29 21:36:23 +00:00
|
|
|
pairlistStore.config.pairlists.map((p) => {
|
2023-05-23 18:27:33 +00:00
|
|
|
if (p.id) {
|
|
|
|
return p;
|
|
|
|
} else {
|
|
|
|
return { id: Date.now().toString(36) + Math.random().toString(36).substring(2), ...p };
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
2023-05-24 18:19:46 +00:00
|
|
|
useSortable(availablePairlistsEl, availablePairlists.value, {
|
|
|
|
group: {
|
|
|
|
name: 'configurator',
|
|
|
|
pull: 'clone',
|
|
|
|
put: false,
|
|
|
|
},
|
|
|
|
sort: false,
|
2023-05-29 09:57:37 +00:00
|
|
|
filter: '.no-drag',
|
2023-05-23 18:27:33 +00:00
|
|
|
});
|
|
|
|
|
2023-05-29 21:36:23 +00:00
|
|
|
useSortable(pairlistConfigsEl, pairlistStore.config.pairlists, {
|
2023-05-23 18:27:33 +00:00
|
|
|
handle: '.handle',
|
2023-05-24 18:19:46 +00:00
|
|
|
group: 'configurator',
|
2023-05-23 18:27:33 +00:00
|
|
|
onUpdate: async (e) => {
|
2023-05-29 21:36:23 +00:00
|
|
|
moveArrayElement(pairlistStore.config.pairlists, e.oldIndex, e.newIndex);
|
2023-05-23 18:27:33 +00:00
|
|
|
},
|
2023-05-24 18:19:46 +00:00
|
|
|
onAdd: (e) => {
|
|
|
|
const pairlist = availablePairlists.value[e.oldIndex];
|
2023-05-29 21:36:23 +00:00
|
|
|
pairlistStore.addToConfig(pairlist, e.newIndex);
|
2023-05-24 21:53:10 +00:00
|
|
|
// quick fix from: https://github.com/SortableJS/Sortable/issues/1515
|
|
|
|
e.clone.replaceWith(e.item);
|
|
|
|
e.clone.remove();
|
2023-05-24 18:19:46 +00:00
|
|
|
},
|
2023-05-23 18:27:33 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
onMounted(async () => {
|
2023-05-28 17:39:06 +00:00
|
|
|
availablePairlists.value = (await botStore.activeBot.getPairlists()).pairlists.sort((a, b) =>
|
|
|
|
// Sort by is_pairlist_generator (by name), then by name.
|
|
|
|
// TODO: this might need to be improved
|
|
|
|
a.is_pairlist_generator === b.is_pairlist_generator
|
|
|
|
? a.name.localeCompare(b.name)
|
|
|
|
: a.is_pairlist_generator
|
|
|
|
? -1
|
|
|
|
: 1,
|
|
|
|
);
|
2023-05-23 18:27:33 +00:00
|
|
|
});
|
|
|
|
</script>
|
2023-05-24 18:19:46 +00:00
|
|
|
|
2023-05-29 09:57:37 +00:00
|
|
|
<style lang="scss" scoped>
|
2023-05-24 18:19:46 +00:00
|
|
|
.pairlist {
|
|
|
|
border: 1px solid white;
|
|
|
|
}
|
|
|
|
|
2023-05-29 09:57:37 +00:00
|
|
|
.pairlist.no-drag {
|
|
|
|
color: gray;
|
|
|
|
}
|
|
|
|
|
|
|
|
.pairlist.no-drag:hover {
|
|
|
|
cursor: default;
|
|
|
|
}
|
|
|
|
|
2023-05-24 18:19:46 +00:00
|
|
|
.pairlist:hover {
|
|
|
|
cursor: grab;
|
|
|
|
}
|
|
|
|
|
|
|
|
[data-theme='light'] .pairlist {
|
|
|
|
border-color: black;
|
|
|
|
}
|
|
|
|
</style>
|