antares/src/renderer/components/SettingBarContext.vue

227 lines
6.7 KiB
Vue
Raw Normal View History

2020-05-23 13:32:14 +02:00
<template>
<BaseContextMenu
:context-event="contextEvent"
2020-08-12 18:11:48 +02:00
@close-context="$emit('close-context')"
2020-05-23 13:32:14 +02:00
>
2022-06-29 19:05:45 +02:00
<div
v-if="isConnected"
class="context-element"
@click="disconnect"
>
<span class="d-flex">
<BaseIcon
class="text-light mt-1 mr-1"
icon-name="mdiPower"
:size="18"
/> {{ t('connection.disconnect') }}</span>
2022-06-29 19:05:45 +02:00
</div>
<div v-if="!contextConnection.isFolder" class="context-element">
<span class="d-flex">
<BaseIcon
class="text-light mt-1 mr-1"
icon-name="mdiFolderMove"
:size="18"
/> {{ t('general.moveTo') }}</span>
<BaseIcon
class="text-light ml-1"
icon-name="mdiChevronRight"
:size="18"
/>
<div class="context-submenu">
<div class="context-element" @click.stop="moveToFolder(null)">
<span class="d-flex">
<BaseIcon
class="text-light mt-1 mr-1"
icon-name="mdiFolderPlus"
:size="18"
/> {{ t('application.newFolder') }}</span>
</div>
<div
v-for="folder in parsedFolders"
:key="folder.uid"
class="context-element"
@click.stop="moveToFolder(folder.uid)"
>
<span class="d-flex">
<BaseIcon
class="text-light mt-1 mr-1"
icon-name="mdiFolder"
:size="18"
:style="`color: ${folder.color}!important`"
/> {{ folder.name || t('general.folder') }}</span>
</div>
</div>
</div>
<div class="context-element" @click.stop="showAppearanceModal">
<span class="d-flex">
<BaseIcon
class="text-light mt-1 mr-1"
icon-name="mdiBrushVariant"
:size="18"
/> {{ t('application.appearance') }}</span>
</div>
2022-11-21 20:19:02 +01:00
<div
v-if="!contextConnection.isFolder"
class="context-element"
@click="duplicateConnection"
>
<span class="d-flex">
<BaseIcon
class="text-light mt-1 mr-1"
icon-name="mdiContentDuplicate"
:size="18"
/> {{ t('general.duplicate') }}</span>
</div>
2020-05-23 13:32:14 +02:00
<div class="context-element" @click="showConfirmModal">
<span class="d-flex">
<BaseIcon
class="text-light mt-1 mr-1"
icon-name="mdiDelete"
:size="18"
/> {{ t('general.delete') }}</span>
2020-05-23 13:32:14 +02:00
</div>
<ConfirmModal
v-if="isConfirmModal"
@confirm="confirmDeleteConnection"
2020-05-23 13:32:14 +02:00
@hide="hideConfirmModal"
>
2021-12-10 17:34:44 +01:00
<template #header>
2020-08-12 18:11:48 +02:00
<div class="d-flex">
<BaseIcon
class="text-light mr-1"
:icon-name="contextConnection.isFolder ? 'mdiFolderRemove' : 'mdiServerRemove'"
:size="24"
/> {{ t(contextConnection.isFolder ? 'application.deleteFolder' : 'connection.deleteConnection') }}
2020-08-12 18:11:48 +02:00
</div>
2020-05-23 13:32:14 +02:00
</template>
2021-12-10 17:34:44 +01:00
<template #body>
2020-05-23 13:32:14 +02:00
<div class="mb-2">
{{ t('general.deleteConfirm') }} <b>{{ connectionName }}</b>?
2020-05-23 13:32:14 +02:00
</div>
2021-12-10 17:34:44 +01:00
</template>
2020-05-23 13:32:14 +02:00
</ConfirmModal>
<ModalFolderAppearance
2022-11-26 11:21:47 +01:00
v-if="isFolderEdit"
:folder="contextConnection"
@close="hideAppearanceModal"
2022-11-26 11:21:47 +01:00
/>
<ModalConnectionAppearance
2022-11-27 17:52:32 +01:00
v-if="isConnectionEdit"
:connection="contextConnection"
@close="hideAppearanceModal"
2022-11-27 17:52:32 +01:00
/>
2020-05-23 13:32:14 +02:00
</BaseContextMenu>
</template>
<script setup lang="ts">
import { uidGen } from 'common/libs/uidGen';
import { storeToRefs } from 'pinia';
import { computed, Prop, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import ConfirmModal from '@/components/BaseConfirmModal.vue';
import BaseContextMenu from '@/components/BaseContextMenu.vue';
import BaseIcon from '@/components/BaseIcon.vue';
import ModalConnectionAppearance from '@/components/ModalConnectionAppearance.vue';
import ModalFolderAppearance from '@/components/ModalFolderAppearance.vue';
import { SidebarElement, useConnectionsStore } from '@/stores/connections';
import { useWorkspacesStore } from '@/stores/workspaces';
const { t } = useI18n();
2022-06-29 19:05:45 +02:00
const connectionsStore = useConnectionsStore();
const {
2022-11-21 20:19:02 +01:00
getConnectionByUid,
getConnectionName,
addConnection,
deleteConnection,
addFolder
2022-06-29 19:05:45 +02:00
} = connectionsStore;
const { getFolders: folders } = storeToRefs(connectionsStore);
const workspacesStore = useWorkspacesStore();
2022-06-29 19:05:45 +02:00
const {
removeConnected: disconnectWorkspace,
getWorkspace
} = workspacesStore;
const props = defineProps({
contextEvent: MouseEvent,
2022-11-21 20:19:02 +01:00
contextConnection: Object as Prop<SidebarElement>
});
const emit = defineEmits(['close-context']);
const isConfirmModal = ref(false);
2022-11-26 11:21:47 +01:00
const isFolderEdit = ref(false);
const isConnectionEdit = ref(false);
2020-05-23 13:32:14 +02:00
const connectionName = computed(() => props.contextConnection.name || getConnectionName(props.contextConnection.uid) || t('general.folder', 1));
2022-11-21 20:19:02 +01:00
const isConnected = computed(() => getWorkspace(props.contextConnection.uid)?.connectionStatus === 'connected');
const parsedFolders = computed(() => folders.value.filter(f => !f.connections.includes(props.contextConnection.uid)));
2022-04-30 00:47:37 +02:00
const confirmDeleteConnection = () => {
if (isConnected.value)
disconnectWorkspace(props.contextConnection.uid);
deleteConnection(props.contextConnection);
closeContext();
};
const moveToFolder = (folderUid?: string) => {
if (!folderUid) {
addFolder({
connections: [props.contextConnection.uid]
});
}
closeContext();
};
const duplicateConnection = () => {
2022-11-21 20:19:02 +01:00
let connectionCopy = getConnectionByUid(props.contextConnection.uid);
connectionCopy = {
...connectionCopy,
uid: uidGen('C'),
name: connectionCopy.name ? `${connectionCopy?.name}_copy` : ''
};
addConnection(connectionCopy);
closeContext();
};
2022-04-30 00:47:37 +02:00
const showAppearanceModal = () => {
2022-11-26 11:21:47 +01:00
if (props.contextConnection.isFolder)
isFolderEdit.value = true;
else
2022-11-27 17:52:32 +01:00
isConnectionEdit.value = true;
2022-11-26 11:21:47 +01:00
};
const hideAppearanceModal = () => {
2022-11-26 11:21:47 +01:00
isConnectionEdit.value = false;
isFolderEdit.value = false;
closeContext();
};
const showConfirmModal = () => {
isConfirmModal.value = true;
};
const hideConfirmModal = () => {
isConfirmModal.value = false;
closeContext();
};
2022-06-29 19:05:45 +02:00
const disconnect = () => {
disconnectWorkspace(props.contextConnection.uid);
closeContext();
};
const closeContext = () => {
emit('close-context');
2020-05-23 13:32:14 +02:00
};
</script>