mirror of
https://github.com/freqtrade/frequi.git
synced 2024-11-27 05:25:17 +00:00
Merge pull request #697 from xxRockOnxx/feat/rename-bot
feat: rename bot
This commit is contained in:
commit
50a8858035
|
@ -16,9 +16,10 @@
|
||||||
R
|
R
|
||||||
</b-form-checkbox>
|
</b-form-checkbox>
|
||||||
<div v-if="!noButtons" class="d-flex flex-align-cent">
|
<div v-if="!noButtons" class="d-flex flex-align-cent">
|
||||||
<!-- <b-button class="ml-1" size="sm" title="Edit bot">
|
<b-button class="ml-1" size="sm" title="Delete bot" @click="$emit('edit')">
|
||||||
<EditIcon :size="16" title="Edit Button" />
|
<EditIcon :size="16" />
|
||||||
</b-button> -->
|
</b-button>
|
||||||
|
|
||||||
<b-button class="ml-1" size="sm" title="Delete bot" @click.prevent="clickRemoveBot(bot)">
|
<b-button class="ml-1" size="sm" title="Delete bot" @click.prevent="clickRemoveBot(bot)">
|
||||||
<DeleteIcon :size="16" title="Delete Bot" />
|
<DeleteIcon :size="16" title="Delete Bot" />
|
||||||
</b-button>
|
</b-button>
|
||||||
|
@ -31,15 +32,19 @@
|
||||||
import { Component, Prop, Vue } from 'vue-property-decorator';
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
||||||
import { namespace } from 'vuex-class';
|
import { namespace } from 'vuex-class';
|
||||||
import { MultiBotStoreGetters } from '@/store/modules/botStoreWrapper';
|
import { MultiBotStoreGetters } from '@/store/modules/botStoreWrapper';
|
||||||
import LoginModal from '@/views/LoginModal.vue';
|
import EditIcon from 'vue-material-design-icons/Pencil.vue';
|
||||||
import EditIcon from 'vue-material-design-icons/Cog.vue';
|
|
||||||
import DeleteIcon from 'vue-material-design-icons/Delete.vue';
|
import DeleteIcon from 'vue-material-design-icons/Delete.vue';
|
||||||
import { BotDescriptor, BotDescriptors } from '@/types';
|
import { BotDescriptor, BotDescriptors } from '@/types';
|
||||||
import StoreModules from '@/store/storeSubModules';
|
import StoreModules from '@/store/storeSubModules';
|
||||||
|
|
||||||
const ftbot = namespace(StoreModules.ftbot);
|
const ftbot = namespace(StoreModules.ftbot);
|
||||||
|
|
||||||
@Component({ components: { LoginModal, DeleteIcon, EditIcon } })
|
@Component({
|
||||||
|
components: {
|
||||||
|
DeleteIcon,
|
||||||
|
EditIcon,
|
||||||
|
},
|
||||||
|
})
|
||||||
export default class BotList extends Vue {
|
export default class BotList extends Vue {
|
||||||
@Prop({ default: false, type: Object }) bot!: BotDescriptor;
|
@Prop({ default: false, type: Object }) bot!: BotDescriptor;
|
||||||
|
|
||||||
|
@ -79,5 +84,3 @@ export default class BotList extends Vue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
|
|
|
@ -10,7 +10,14 @@
|
||||||
:title="`${bot.botId} - ${bot.botName} - ${bot.botUrl}`"
|
:title="`${bot.botId} - ${bot.botName} - ${bot.botUrl}`"
|
||||||
@click="selectBot(bot.botId)"
|
@click="selectBot(bot.botId)"
|
||||||
>
|
>
|
||||||
<bot-entry :bot="bot" :no-buttons="small" />
|
<bot-rename
|
||||||
|
v-if="editingBots.includes(bot.botId)"
|
||||||
|
:bot="bot"
|
||||||
|
@saved="stopEditBot(bot.botId)"
|
||||||
|
@cancelled="stopEditBot(bot.botId)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<bot-entry v-else :bot="bot" :no-buttons="small" @edit="editBot(bot.botId)" />
|
||||||
</b-list-group-item>
|
</b-list-group-item>
|
||||||
</b-list-group>
|
</b-list-group>
|
||||||
<LoginModal v-if="!small" class="mt-2" login-text="Add new bot" />
|
<LoginModal v-if="!small" class="mt-2" login-text="Add new bot" />
|
||||||
|
@ -23,12 +30,19 @@ import { namespace } from 'vuex-class';
|
||||||
import { MultiBotStoreGetters } from '@/store/modules/botStoreWrapper';
|
import { MultiBotStoreGetters } from '@/store/modules/botStoreWrapper';
|
||||||
import LoginModal from '@/views/LoginModal.vue';
|
import LoginModal from '@/views/LoginModal.vue';
|
||||||
import BotEntry from '@/components/BotEntry.vue';
|
import BotEntry from '@/components/BotEntry.vue';
|
||||||
|
import BotRename from '@/components/BotRename.vue';
|
||||||
import { BotDescriptors } from '@/types';
|
import { BotDescriptors } from '@/types';
|
||||||
import StoreModules from '@/store/storeSubModules';
|
import StoreModules from '@/store/storeSubModules';
|
||||||
|
|
||||||
const ftbot = namespace(StoreModules.ftbot);
|
const ftbot = namespace(StoreModules.ftbot);
|
||||||
|
|
||||||
@Component({ components: { LoginModal, BotEntry } })
|
@Component({
|
||||||
|
components: {
|
||||||
|
LoginModal,
|
||||||
|
BotEntry,
|
||||||
|
BotRename,
|
||||||
|
},
|
||||||
|
})
|
||||||
export default class BotList extends Vue {
|
export default class BotList extends Vue {
|
||||||
@Prop({ default: false, type: Boolean }) small!: boolean;
|
@Prop({ default: false, type: Boolean }) small!: boolean;
|
||||||
|
|
||||||
|
@ -41,7 +55,21 @@ export default class BotList extends Vue {
|
||||||
@ftbot.Getter [MultiBotStoreGetters.allAvailableBots]: BotDescriptors;
|
@ftbot.Getter [MultiBotStoreGetters.allAvailableBots]: BotDescriptors;
|
||||||
|
|
||||||
@ftbot.Action selectBot;
|
@ftbot.Action selectBot;
|
||||||
|
|
||||||
|
editingBots: string[] = [];
|
||||||
|
|
||||||
|
editBot(botId: string) {
|
||||||
|
if (!this.editingBots.includes(botId)) {
|
||||||
|
this.editingBots.push(botId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stopEditBot(botId: string) {
|
||||||
|
if (!this.editingBots.includes(botId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.editingBots.splice(this.editingBots.indexOf(botId), 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
|
|
57
src/components/BotRename.vue
Normal file
57
src/components/BotRename.vue
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
<template>
|
||||||
|
<form class="d-flex" @submit.prevent="save">
|
||||||
|
<b-form-input
|
||||||
|
v-model="newName"
|
||||||
|
size="sm"
|
||||||
|
class="w-100"
|
||||||
|
placeholder="Bot name"
|
||||||
|
style="border-style: solid; border-width: 1px"
|
||||||
|
autofocus
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="d-flex ml-2">
|
||||||
|
<b-button type="submit" size="sm" title="Save">
|
||||||
|
<CheckIcon :size="16" />
|
||||||
|
</b-button>
|
||||||
|
|
||||||
|
<b-button class="ml-1" size="sm" title="Cancel" @click="$emit('cancelled')">
|
||||||
|
<CloseIcon :size="16" />
|
||||||
|
</b-button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { Component, Prop, Vue } from 'vue-property-decorator';
|
||||||
|
import { namespace } from 'vuex-class';
|
||||||
|
import CheckIcon from 'vue-material-design-icons/Check.vue';
|
||||||
|
import CloseIcon from 'vue-material-design-icons/Close.vue';
|
||||||
|
import { BotDescriptor, RenameBotPayload } from '@/types';
|
||||||
|
import StoreModules from '@/store/storeSubModules';
|
||||||
|
|
||||||
|
const ftbot = namespace(StoreModules.ftbot);
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
components: {
|
||||||
|
CheckIcon,
|
||||||
|
CloseIcon,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
export default class BotList extends Vue {
|
||||||
|
@Prop({ required: true, type: Object }) bot!: BotDescriptor;
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
|
@ftbot.Action renameBot!: (payload: RenameBotPayload) => Promise<void>;
|
||||||
|
|
||||||
|
newName: string = this.bot.botName;
|
||||||
|
|
||||||
|
save() {
|
||||||
|
this.renameBot({
|
||||||
|
botId: this.bot.botId,
|
||||||
|
botName: this.newName,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$emit('saved');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -13,6 +13,12 @@ export class UserService {
|
||||||
this.botId = botId;
|
this.botId = botId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public renameBot(newName: string): void {
|
||||||
|
const newInfo = this.getLoginInfo();
|
||||||
|
newInfo.botName = newName;
|
||||||
|
this.storeLoginInfo(newInfo);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores info for current botId in the object of all bots.
|
* Stores info for current botId in the object of all bots.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {
|
||||||
DailyReturnValue,
|
DailyReturnValue,
|
||||||
MultiDeletePayload,
|
MultiDeletePayload,
|
||||||
MultiForcesellPayload,
|
MultiForcesellPayload,
|
||||||
|
RenameBotPayload,
|
||||||
Trade,
|
Trade,
|
||||||
} from '@/types';
|
} from '@/types';
|
||||||
import { AxiosInstance } from 'axios';
|
import { AxiosInstance } from 'axios';
|
||||||
|
@ -182,7 +183,15 @@ export default function createBotStore(store) {
|
||||||
state.refreshing = refreshing;
|
state.refreshing = refreshing;
|
||||||
},
|
},
|
||||||
addBot(state: FTMultiBotState, bot: BotDescriptor) {
|
addBot(state: FTMultiBotState, bot: BotDescriptor) {
|
||||||
state.availableBots[bot.botId] = bot;
|
// When Vue gets initialized, only existing objects will be added with reactivity.
|
||||||
|
// To add reactivity to new property, we need to mutate the already reactive object.
|
||||||
|
state.availableBots = {
|
||||||
|
...state.availableBots,
|
||||||
|
[bot.botId]: bot,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
renameBot(state: FTMultiBotState, bot: RenameBotPayload) {
|
||||||
|
state.availableBots[bot.botId].botName = bot.botName;
|
||||||
},
|
},
|
||||||
removeBot(state: FTMultiBotState, botId: string) {
|
removeBot(state: FTMultiBotState, botId: string) {
|
||||||
if (botId in state.availableBots) {
|
if (botId in state.availableBots) {
|
||||||
|
@ -214,6 +223,17 @@ export default function createBotStore(store) {
|
||||||
dispatch(`${bot.botId}/botAdded`);
|
dispatch(`${bot.botId}/botAdded`);
|
||||||
commit('addBot', bot);
|
commit('addBot', bot);
|
||||||
},
|
},
|
||||||
|
renameBot({ dispatch, getters, commit }, bot: RenameBotPayload) {
|
||||||
|
if (!Object.keys(getters.allAvailableBots).includes(bot.botId)) {
|
||||||
|
// TODO: handle error!
|
||||||
|
console.error('Bot not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(`${bot.botId}/rename`, bot.botName).then(() => {
|
||||||
|
commit('renameBot', bot);
|
||||||
|
});
|
||||||
|
},
|
||||||
removeBot({ commit, getters, dispatch }, botId: string) {
|
removeBot({ commit, getters, dispatch }, botId: string) {
|
||||||
if (Object.keys(getters.allAvailableBots).includes(botId)) {
|
if (Object.keys(getters.allAvailableBots).includes(botId)) {
|
||||||
dispatch(`${botId}/logout`);
|
dispatch(`${botId}/logout`);
|
||||||
|
|
|
@ -155,6 +155,7 @@ export enum BotStoreActions {
|
||||||
setBacktestResultKey = 'setBacktestResultKey',
|
setBacktestResultKey = 'setBacktestResultKey',
|
||||||
sysInfo = 'sysInfo',
|
sysInfo = 'sysInfo',
|
||||||
logout = 'logout',
|
logout = 'logout',
|
||||||
|
rename = 'rename',
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createBotSubStore(botId: string, botName: string) {
|
export function createBotSubStore(botId: string, botName: string) {
|
||||||
|
@ -488,6 +489,9 @@ export function createBotSubStore(botId: string, botName: string) {
|
||||||
[BotStoreActions.logout]() {
|
[BotStoreActions.logout]() {
|
||||||
userService.logout();
|
userService.logout();
|
||||||
},
|
},
|
||||||
|
[BotStoreActions.rename](ctx, name) {
|
||||||
|
userService.renameBot(name);
|
||||||
|
},
|
||||||
[BotStoreActions.setRefreshRequired]({ commit }, refreshRequired: boolean) {
|
[BotStoreActions.setRefreshRequired]({ commit }, refreshRequired: boolean) {
|
||||||
commit('updateRefreshRequired', refreshRequired);
|
commit('updateRefreshRequired', refreshRequired);
|
||||||
},
|
},
|
||||||
|
|
|
@ -31,3 +31,8 @@ export interface BotDescriptor {
|
||||||
export interface BotDescriptors {
|
export interface BotDescriptors {
|
||||||
[key: string]: BotDescriptor;
|
[key: string]: BotDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface RenameBotPayload {
|
||||||
|
botId: string;
|
||||||
|
botName: string;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user