antares/src/renderer/components/WorkspaceExploreBar.vue

291 lines
8.4 KiB
Vue
Raw Normal View History

2020-05-08 18:02:18 +02:00
<template>
2020-06-06 16:27:42 +02:00
<div class="column col-auto p-relative">
2020-06-02 19:13:57 +02:00
<div ref="resizer" class="workspace-explorebar-resizer" />
<div
ref="explorebar"
class="workspace-explorebar column"
:style="{width: localWidth ? localWidth+'px' : ''}"
>
<div class="workspace-explorebar-header">
<span class="workspace-explorebar-title">{{ connectionName }}</span>
<span v-if="workspace.connected" class="workspace-explorebar-tools">
<i
2020-09-25 12:39:58 +02:00
class="mdi mdi-18px mdi-database-plus c-hand mr-2"
:title="$t('message.createNewDatabase')"
@click="showNewDBModal"
/>
<i
class="mdi mdi-18px mdi-refresh c-hand mr-2"
2020-06-02 19:13:57 +02:00
:class="{'rotate':isRefreshing}"
:title="$t('word.refresh')"
@click="refresh"
/>
2020-06-02 19:13:57 +02:00
<i
2020-09-25 12:39:58 +02:00
class="mdi mdi-18px mdi-power-plug-off c-hand"
2020-06-02 19:13:57 +02:00
:title="$t('word.disconnect')"
@click="disconnectWorkspace(connection.uid)"
/>
2020-06-02 19:13:57 +02:00
</span>
</div>
2020-06-05 21:00:15 +02:00
<WorkspaceConnectPanel
v-if="!workspace.connected"
class="workspace-explorebar-body"
:connection="connection"
/>
<div v-else class="workspace-explorebar-body">
2020-06-03 20:56:44 +02:00
<WorkspaceExploreBarDatabase
2020-06-02 19:13:57 +02:00
v-for="db of workspace.structure"
2020-06-05 21:00:15 +02:00
:key="db.name"
2020-06-03 20:56:44 +02:00
:database="db"
2020-06-05 21:00:15 +02:00
:connection="connection"
2020-10-01 15:08:35 +02:00
@show-database-context="openDatabaseContext"
2020-12-03 13:00:54 +01:00
@show-table-context="openTableContext"
2020-06-03 20:56:44 +02:00
/>
2020-05-31 17:56:33 +02:00
</div>
</div>
2020-10-03 12:11:42 +02:00
<ModalNewDatabase
2020-09-25 12:39:58 +02:00
v-if="isNewDBModal"
@close="hideNewDBModal"
@reload="refresh"
/>
2020-12-03 13:00:54 +01:00
<ModalNewTable
v-if="isNewTableModal"
:workspace="workspace"
@close="hideCreateTableModal"
@open-create-table-editor="openCreateTableEditor"
/>
2020-10-01 15:08:35 +02:00
<DatabaseContext
v-if="isDatabaseContext"
:selected-database="selectedDatabase"
:context-event="databaseContextEvent"
@close-context="closeDatabaseContext"
2020-12-03 13:00:54 +01:00
@show-create-table-modal="showCreateTableModal"
2020-10-01 15:08:35 +02:00
@reload="refresh"
/>
2020-12-03 16:15:10 +01:00
<TableContext
v-if="isTableContext"
:selected-table="selectedTable"
:context-event="tableContextEvent"
@close-context="closeTableContext"
@reload="refresh"
/>
2020-05-08 18:02:18 +02:00
</div>
</template>
<script>
2020-05-18 18:06:32 +02:00
import { mapGetters, mapActions } from 'vuex';
2020-06-02 19:13:57 +02:00
import _ from 'lodash';
2020-12-03 13:00:54 +01:00
import Tables from '@/ipc-api/Tables';
2020-06-03 20:56:44 +02:00
import WorkspaceConnectPanel from '@/components/WorkspaceConnectPanel';
import WorkspaceExploreBarDatabase from '@/components/WorkspaceExploreBarDatabase';
2020-10-01 15:08:35 +02:00
import DatabaseContext from '@/components/WorkspaceExploreBarDatabaseContext';
2020-12-03 16:15:10 +01:00
import TableContext from '@/components/WorkspaceExploreBarTableContext';
2020-10-03 12:11:42 +02:00
import ModalNewDatabase from '@/components/ModalNewDatabase';
2020-12-03 13:00:54 +01:00
import ModalNewTable from '@/components/ModalNewTable';
2020-05-15 17:52:59 +02:00
2020-05-08 18:02:18 +02:00
export default {
2020-06-03 20:56:44 +02:00
name: 'WorkspaceExploreBar',
components: {
2020-06-03 20:56:44 +02:00
WorkspaceConnectPanel,
2020-09-25 12:39:58 +02:00
WorkspaceExploreBarDatabase,
2020-10-01 15:08:35 +02:00
DatabaseContext,
2020-12-03 16:15:10 +01:00
TableContext,
2020-12-03 13:00:54 +01:00
ModalNewDatabase,
ModalNewTable
},
2020-05-14 15:21:57 +02:00
props: {
2020-06-02 19:13:57 +02:00
connection: Object,
isSelected: Boolean
2020-05-18 18:06:32 +02:00
},
2020-05-20 18:00:14 +02:00
data () {
return {
2020-06-02 19:13:57 +02:00
isRefreshing: false,
2020-09-25 12:39:58 +02:00
isNewDBModal: false,
2020-12-03 13:00:54 +01:00
isNewTableModal: false,
2020-10-01 15:08:35 +02:00
localWidth: null,
isDatabaseContext: false,
isTableContext: false,
databaseContextEvent: null,
tableContextEvent: null,
selectedDatabase: '',
2020-12-26 14:47:15 +01:00
selectedTable: null
2020-05-20 18:00:14 +02:00
};
},
2020-05-18 18:06:32 +02:00
computed: {
...mapGetters({
2020-05-31 17:56:33 +02:00
getWorkspace: 'workspaces/getWorkspace',
2020-06-02 19:13:57 +02:00
explorebarSize: 'settings/getExplorebarSize',
2020-05-31 17:56:33 +02:00
getConnectionName: 'connections/getConnectionName'
2020-05-18 18:06:32 +02:00
}),
2020-05-20 18:00:14 +02:00
workspace () {
return this.getWorkspace(this.connection.uid);
2020-05-31 17:56:33 +02:00
},
connectionName () {
return this.getConnectionName(this.connection.uid);
2020-05-18 18:06:32 +02:00
}
},
2020-06-02 19:13:57 +02:00
watch: {
localWidth: _.debounce(function (val) {
this.changeExplorebarSize(val);
}, 500),
isSelected (val) {
if (val) this.localWidth = this.explorebarSize;
}
},
created () {
this.localWidth = this.explorebarSize;
},
mounted () {
const resizer = this.$refs.resizer;
resizer.addEventListener('mousedown', (e) => {
e.preventDefault();
window.addEventListener('mousemove', this.resize);
window.addEventListener('mouseup', this.stopResize);
});
},
2020-05-18 18:06:32 +02:00
methods: {
...mapActions({
2020-05-20 18:00:14 +02:00
disconnectWorkspace: 'workspaces/removeConnected',
2020-06-02 19:13:57 +02:00
refreshStructure: 'workspaces/refreshStructure',
2020-12-03 13:00:54 +01:00
changeBreadcrumbs: 'workspaces/changeBreadcrumbs',
selectTab: 'workspaces/selectTab',
addNotification: 'notifications/addNotification',
2020-06-02 19:13:57 +02:00
changeExplorebarSize: 'settings/changeExplorebarSize'
2020-05-20 18:00:14 +02:00
}),
async refresh () {
2020-06-10 19:29:10 +02:00
if (!this.isRefreshing) {
this.isRefreshing = true;
await this.refreshStructure(this.connection.uid);
this.isRefreshing = false;
}
2020-06-02 19:13:57 +02:00
},
resize (e) {
const el = this.$refs.explorebar;
let explorebarWidth = e.pageX - el.getBoundingClientRect().left;
if (explorebarWidth > 500) explorebarWidth = 500;
if (explorebarWidth < 150) explorebarWidth = 150;
this.localWidth = explorebarWidth;
},
stopResize () {
window.removeEventListener('mousemove', this.resize);
2020-09-25 12:39:58 +02:00
},
showNewDBModal () {
this.isNewDBModal = true;
},
hideNewDBModal () {
this.isNewDBModal = false;
2020-10-01 15:08:35 +02:00
},
2020-12-03 13:00:54 +01:00
showCreateTableModal () {
this.closeDatabaseContext();
this.isNewTableModal = true;
},
hideCreateTableModal () {
this.isNewTableModal = false;
},
async openCreateTableEditor (payload) {
const params = {
uid: this.connection.uid,
...payload
};
const { status, response } = await Tables.createTable(params);
if (status === 'success') {
await this.refresh();
this.changeBreadcrumbs({ schema: this.selectedDatabase, table: payload.name });
this.selectTab({ uid: this.workspace.uid, tab: 'prop' });
}
else
this.addNotification({ status: 'error', message: response });
},
2020-10-01 15:08:35 +02:00
openDatabaseContext (payload) {
this.selectedDatabase = payload.database;
this.databaseContextEvent = payload.event;
this.isDatabaseContext = true;
},
closeDatabaseContext () {
this.isDatabaseContext = false;
2020-12-03 13:00:54 +01:00
},
openTableContext (payload) {
this.selectedTable = payload.table;
this.tableContextEvent = payload.event;
this.isTableContext = true;
},
closeTableContext () {
2020-12-03 16:15:10 +01:00
this.isTableContext = false;
2020-05-20 18:00:14 +02:00
}
2020-05-14 15:21:57 +02:00
}
2020-05-08 18:02:18 +02:00
};
</script>
<style lang="scss">
2020-07-31 18:16:28 +02:00
.workspace-explorebar-resizer {
position: absolute;
width: 4px;
right: -2px;
top: 0;
height: calc(100vh - #{$excluding-size});
cursor: ew-resize;
z-index: 99;
}
2020-06-02 19:13:57 +02:00
2020-07-31 18:16:28 +02:00
.workspace-explorebar {
width: $explorebar-width;
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: center;
text-align: left;
background: $bg-color-gray;
box-shadow: 0 0 1px 0 #000;
z-index: 8;
flex: initial;
position: relative;
padding: 0;
2020-05-15 17:52:59 +02:00
2020-07-31 18:16:28 +02:00
.workspace-explorebar-header {
width: 100%;
padding: 0.3rem;
display: flex;
justify-content: space-between;
font-size: 0.6rem;
font-weight: 700;
text-transform: uppercase;
2020-05-18 18:06:32 +02:00
2020-07-31 18:16:28 +02:00
.workspace-explorebar-title {
width: 80%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
align-items: center;
}
2020-05-18 18:06:32 +02:00
2020-07-31 18:16:28 +02:00
.workspace-explorebar-tools {
display: flex;
align-items: center;
2020-05-20 18:00:14 +02:00
2020-07-31 18:16:28 +02:00
> i {
opacity: 0.6;
transition: opacity 0.2s;
display: flex;
align-items: center;
2020-05-18 18:06:32 +02:00
2020-07-31 18:16:28 +02:00
&:hover {
opacity: 1;
}
}
2020-05-15 17:52:59 +02:00
}
2020-07-31 18:16:28 +02:00
}
2020-05-31 17:56:33 +02:00
2020-07-31 18:16:28 +02:00
.workspace-explorebar-body {
width: 100%;
height: calc((100vh - 30px) - #{$excluding-size});
overflow: overlay;
padding: 0 0.1rem;
}
}
2020-05-08 18:02:18 +02:00
</style>