save and load configs

This commit is contained in:
Tako 2023-05-30 10:42:17 +00:00
parent 0c4c4b7fc6
commit 2c65c37caa
2 changed files with 47 additions and 36 deletions

View File

@ -32,37 +32,38 @@
</b-list-group>
</b-col>
<b-col>
<b-row>
<b-col>
<b-row>
<b-col>
<b-form-select v-model="pairlistStore.config" :options="configsSelectOptions" />
</b-col>
<b-col
><b-form-input
v-model="pairlistStore.config.name"
class="mb-2"
placeholder="Configuration name..."
></b-form-input
></b-col>
</b-row>
</b-col>
<b-col cols="auto">
<b-button>New</b-button>
<b-button @click="pairlistStore.saveConfig()">Save</b-button>
</b-col>
</b-row>
<b-button
:disabled="pairlistStore.evaluating || !pairlistStore.pairlistValid"
variant="primary"
size="lg"
squared
class="mb-2 evaluate"
@click="evaluateClick"
>
<b-spinner v-if="pairlistStore.evaluating" small></b-spinner>
<span>{{ pairlistStore.evaluating ? 'Evaluating...' : 'Evaluate' }}</span>
</b-button>
<b-input-group class="mb-2">
<template #prepend>
<b-dropdown text="Configs">
<b-dropdown-item
v-for="config in pairlistStore.savedConfigs"
:key="config.name"
@click="pairlistStore.selectConfig(config)"
>{{ config.name }}</b-dropdown-item
>
</b-dropdown>
</template>
<b-form-input v-model="pairlistStore.config.name" placeholder="Configuration name..." />
<template #append>
<b-button @click="pairlistStore.saveConfig()"
><i-mdi-content-save class="fs-4"
/></b-button>
<b-button @click="pairlistStore.newConfig()"><i-mdi-plus class="fs-4" /></b-button>
<b-button
:disabled="pairlistStore.evaluating || !pairlistStore.pairlistValid"
variant="primary"
size="lg"
squared
class="evaluate"
@click="evaluateClick"
>
<b-spinner v-if="pairlistStore.evaluating" small></b-spinner>
<span>{{ pairlistStore.evaluating ? 'Evaluating...' : 'Evaluate' }}</span>
</b-button>
</template>
</b-input-group>
<b-alert
:model-value="
pairlistStore.config.pairlists.length > 0 && !pairlistStore.firstPairlistIsGenerator
@ -94,7 +95,7 @@ import { computed, onMounted, ref } from 'vue';
import { useBotStore } from '@/stores/ftbotwrapper';
import { usePairlistConfigStore } from '@/stores/pairlistConfig';
import PairlistConfigItem from './PairlistConfigItem.vue';
import { Pairlist, PairlistParamType, PairlistPayloadItem } from '@/types';
import { Pairlist, PairlistConfig, PairlistParamType, PairlistPayloadItem } from '@/types';
import { useSortable, moveArrayElement } from '@vueuse/integrations/useSortable';
import CopyableTextfield from '@/components/general/CopyableTextfield.vue';

View File

@ -60,15 +60,23 @@ export const usePairlistConfigStore = defineStore(
config.value.pairlists.splice(index, 1);
}
const saveConfig = () => {
function saveConfig() {
const i = savedConfigs.value.findIndex((c) => c.name === config.value.name);
if (i > -1) {
savedConfigs.value[i] = structuredClone(toRaw(config.value));
savedConfigs.value[i] = config.value;
} else {
savedConfigs.value.push(structuredClone(toRaw(config.value)));
savedConfigs.value.push(config.value);
}
};
}
function newConfig() {
config.value = { name: '', pairlists: [] };
}
function selectConfig(selected: PairlistConfig) {
config.value = structuredClone(toRaw(selected));
}
return {
evaluating,
@ -79,6 +87,8 @@ export const usePairlistConfigStore = defineStore(
addToConfig,
removeFromConfig,
saveConfig,
selectConfig,
newConfig,
firstPairlistIsGenerator,
pairlistValid,
};