antares/src/renderer/components/WorkspaceExploreBar.vue

584 lines
18 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.connection_status === 'connected'" class="workspace-explorebar-tools">
2020-06-02 19:13:57 +02:00
<i
2020-09-25 12:39:58 +02:00
class="mdi mdi-18px mdi-database-plus c-hand mr-2"
:title="$t('message.createNewSchema')"
2020-09-25 12:39:58 +02:00
@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>
2021-02-20 11:55:34 +01:00
<div class="workspace-explorebar-search">
<div v-if="workspace.connection_status === 'connected'" class="has-icon-right">
2021-02-20 11:55:34 +01:00
<input
v-model="searchTerm"
class="form-input input-sm"
type="text"
:placeholder="$t('message.searchForElements')"
>
<i class="form-icon mdi mdi-magnify mdi-18px" />
</div>
</div>
2020-06-05 21:00:15 +02:00
<WorkspaceConnectPanel
v-if="workspace.connection_status !== 'connected'"
2020-06-05 21:00:15 +02:00
class="workspace-explorebar-body"
:connection="connection"
/>
<div v-else class="workspace-explorebar-body">
2021-03-17 11:15:14 +01:00
<WorkspaceExploreBarSchema
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"
@show-schema-context="openSchemaContext"
2020-12-03 13:00:54 +01:00
@show-table-context="openTableContext"
2021-01-02 14:46:27 +01:00
@show-misc-context="openMiscContext"
2020-06-03 20:56:44 +02:00
/>
2020-05-31 17:56:33 +02:00
</div>
</div>
2021-03-17 11:15:14 +01:00
<ModalNewSchema
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-12-27 16:16:48 +01:00
<ModalNewView
v-if="isNewViewModal"
:workspace="workspace"
@close="hideCreateViewModal"
@open-create-view-editor="openCreateViewEditor"
/>
2021-01-02 15:27:02 +01:00
<ModalNewTrigger
v-if="isNewTriggerModal"
:workspace="workspace"
@close="hideCreateTriggerModal"
@open-create-trigger-editor="openCreateTriggerEditor"
/>
2021-01-06 11:57:49 +01:00
<ModalNewRoutine
v-if="isNewRoutineModal"
:workspace="workspace"
@close="hideCreateRoutineModal"
@open-create-routine-editor="openCreateRoutineEditor"
/>
2021-01-11 09:55:13 +01:00
<ModalNewFunction
v-if="isNewFunctionModal"
:workspace="workspace"
@close="hideCreateFunctionModal"
@open-create-function-editor="openCreateFunctionEditor"
/>
<ModalNewTriggerFunction
v-if="isNewTriggerFunctionModal"
:workspace="workspace"
@close="hideCreateTriggerFunctionModal"
@open-create-function-editor="openCreateTriggerFunctionEditor"
/>
2021-01-16 11:32:42 +01:00
<ModalNewScheduler
v-if="isNewSchedulerModal"
:workspace="workspace"
@close="hideCreateSchedulerModal"
@open-create-scheduler-editor="openCreateSchedulerEditor"
/>
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-12-27 16:16:48 +01:00
@show-create-view-modal="showCreateViewModal"
2021-01-02 15:27:02 +01:00
@show-create-trigger-modal="showCreateTriggerModal"
2021-01-06 11:57:49 +01:00
@show-create-routine-modal="showCreateRoutineModal"
2021-01-11 09:55:13 +01:00
@show-create-function-modal="showCreateFunctionModal"
@show-create-trigger-function-modal="showCreateTriggerFunctionModal"
2021-01-16 11:32:42 +01:00
@show-create-scheduler-modal="showCreateSchedulerModal"
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"
/>
2021-01-02 14:46:27 +01:00
<MiscContext
v-if="isMiscContext"
:selected-misc="selectedMisc"
:context-event="miscContextEvent"
@close-context="closeMiscContext"
@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';
2021-01-06 11:57:49 +01:00
2020-12-03 13:00:54 +01:00
import Tables from '@/ipc-api/Tables';
2020-12-27 16:16:48 +01:00
import Views from '@/ipc-api/Views';
2021-01-02 15:27:02 +01:00
import Triggers from '@/ipc-api/Triggers';
2021-01-06 11:57:49 +01:00
import Routines from '@/ipc-api/Routines';
2021-01-11 09:55:13 +01:00
import Functions from '@/ipc-api/Functions';
2021-01-16 11:32:42 +01:00
import Schedulers from '@/ipc-api/Schedulers';
2021-01-06 11:57:49 +01:00
2020-06-03 20:56:44 +02:00
import WorkspaceConnectPanel from '@/components/WorkspaceConnectPanel';
2021-03-17 11:15:14 +01:00
import WorkspaceExploreBarSchema from '@/components/WorkspaceExploreBarSchema';
import DatabaseContext from '@/components/WorkspaceExploreBarSchemaContext';
2020-12-03 16:15:10 +01:00
import TableContext from '@/components/WorkspaceExploreBarTableContext';
2021-01-02 14:46:27 +01:00
import MiscContext from '@/components/WorkspaceExploreBarMiscContext';
2021-03-17 11:15:14 +01:00
import ModalNewSchema from '@/components/ModalNewSchema';
2020-12-03 13:00:54 +01:00
import ModalNewTable from '@/components/ModalNewTable';
2020-12-27 16:16:48 +01:00
import ModalNewView from '@/components/ModalNewView';
2021-01-02 15:27:02 +01:00
import ModalNewTrigger from '@/components/ModalNewTrigger';
2021-01-06 11:57:49 +01:00
import ModalNewRoutine from '@/components/ModalNewRoutine';
2021-01-11 09:55:13 +01:00
import ModalNewFunction from '@/components/ModalNewFunction';
import ModalNewTriggerFunction from '@/components/ModalNewTriggerFunction';
2021-01-16 11:32:42 +01:00
import ModalNewScheduler from '@/components/ModalNewScheduler';
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,
2021-03-17 11:15:14 +01:00
WorkspaceExploreBarSchema,
2020-10-01 15:08:35 +02:00
DatabaseContext,
2020-12-03 16:15:10 +01:00
TableContext,
2021-01-02 14:46:27 +01:00
MiscContext,
2021-03-17 11:15:14 +01:00
ModalNewSchema,
2020-12-27 16:16:48 +01:00
ModalNewTable,
2021-01-02 15:27:02 +01:00
ModalNewView,
2021-01-06 11:57:49 +01:00
ModalNewTrigger,
2021-01-11 09:55:13 +01:00
ModalNewRoutine,
2021-01-16 11:32:42 +01:00
ModalNewFunction,
ModalNewTriggerFunction,
2021-01-16 11:32:42 +01:00
ModalNewScheduler
},
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,
2021-01-02 15:27:02 +01:00
2020-09-25 12:39:58 +02:00
isNewDBModal: false,
2020-12-03 13:00:54 +01:00
isNewTableModal: false,
2020-12-27 16:16:48 +01:00
isNewViewModal: false,
2021-01-02 15:27:02 +01:00
isNewTriggerModal: false,
2021-01-06 11:57:49 +01:00
isNewRoutineModal: false,
2021-01-11 09:55:13 +01:00
isNewFunctionModal: false,
isNewTriggerFunctionModal: false,
2021-01-16 11:32:42 +01:00
isNewSchedulerModal: false,
2021-01-02 15:27:02 +01:00
2020-10-01 15:08:35 +02:00
localWidth: null,
2021-02-20 11:55:34 +01:00
explorebarWidthInterval: null,
searchTermInterval: null,
2020-10-01 15:08:35 +02:00
isDatabaseContext: false,
isTableContext: false,
2021-01-02 14:46:27 +01:00
isMiscContext: false,
2021-01-02 15:27:02 +01:00
2020-10-01 15:08:35 +02:00
databaseContextEvent: null,
tableContextEvent: null,
2021-01-02 14:46:27 +01:00
miscContextEvent: null,
2021-01-02 15:27:02 +01:00
2020-10-01 15:08:35 +02:00
selectedDatabase: '',
2021-01-02 14:46:27 +01:00
selectedTable: null,
2021-02-20 11:55:34 +01:00
selectedMisc: null,
searchTerm: ''
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);
2021-06-26 16:36:05 +02:00
},
customizations () {
return this.workspace.customizations;
2020-05-18 18:06:32 +02:00
}
},
2020-06-02 19:13:57 +02:00
watch: {
2021-02-19 17:41:33 +01:00
localWidth (val) {
2021-02-20 11:55:34 +01:00
clearTimeout(this.explorebarWidthInterval);
2021-02-19 17:41:33 +01:00
2021-02-20 11:55:34 +01:00
this.explorebarWidthInterval = setTimeout(() => {
2021-02-19 17:41:33 +01:00
this.changeExplorebarSize(val);
}, 500);
},
2020-06-02 19:13:57 +02:00
isSelected (val) {
if (val) this.localWidth = this.explorebarSize;
2021-02-20 11:55:34 +01:00
},
searchTerm () {
clearTimeout(this.searchTermInterval);
this.searchTermInterval = setTimeout(() => {
this.setSearchTerm(this.searchTerm);
}, 200);
2020-06-02 19:13:57 +02:00
}
},
created () {
this.localWidth = this.explorebarSize;
},
mounted () {
const resizer = this.$refs.resizer;
2021-01-31 13:03:25 +01:00
resizer.addEventListener('mousedown', e => {
2020-06-02 19:13:57 +02:00
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',
2021-02-20 11:55:34 +01:00
setSearchTerm: 'workspaces/setSearchTerm',
2020-12-03 13:00:54 +01:00
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 });
},
openSchemaContext (payload) {
this.selectedDatabase = payload.schema;
2020-10-01 15:08:35 +02:00
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-12-27 16:16:48 +01:00
},
2021-01-02 14:46:27 +01:00
openMiscContext (payload) {
this.selectedMisc = payload.misc;
this.miscContextEvent = payload.event;
this.isMiscContext = true;
},
closeMiscContext () {
this.isMiscContext = false;
},
2020-12-27 16:16:48 +01:00
showCreateViewModal () {
this.closeDatabaseContext();
this.isNewViewModal = true;
},
hideCreateViewModal () {
this.isNewViewModal = false;
},
async openCreateViewEditor (payload) {
const params = {
uid: this.connection.uid,
...payload
};
const { status, response } = await Views.createView(params);
if (status === 'success') {
await this.refresh();
this.changeBreadcrumbs({ schema: this.selectedDatabase, view: payload.name });
this.selectTab({ uid: this.workspace.uid, tab: 'prop' });
}
else
this.addNotification({ status: 'error', message: response });
2021-01-02 15:27:02 +01:00
},
showCreateTriggerModal () {
this.closeDatabaseContext();
this.isNewTriggerModal = true;
},
hideCreateTriggerModal () {
this.isNewTriggerModal = false;
},
async openCreateTriggerEditor (payload) {
const params = {
uid: this.connection.uid,
...payload
};
const { status, response } = await Triggers.createTrigger(params);
if (status === 'success') {
await this.refresh();
2021-06-26 16:36:05 +02:00
const triggerName = this.customizations.triggerTableInName ? `${payload.table}.${payload.name}` : payload.name;
this.changeBreadcrumbs({ schema: this.selectedDatabase, trigger: triggerName });
2021-01-02 15:27:02 +01:00
this.selectTab({ uid: this.workspace.uid, tab: 'prop' });
}
else
this.addNotification({ status: 'error', message: response });
2021-01-06 11:57:49 +01:00
},
showCreateRoutineModal () {
this.closeDatabaseContext();
this.isNewRoutineModal = true;
},
hideCreateRoutineModal () {
this.isNewRoutineModal = false;
},
async openCreateRoutineEditor (payload) {
const params = {
uid: this.connection.uid,
...payload
};
const { status, response } = await Routines.createRoutine(params);
if (status === 'success') {
await this.refresh();
this.changeBreadcrumbs({ schema: this.selectedDatabase, procedure: payload.name });
this.selectTab({ uid: this.workspace.uid, tab: 'prop' });
}
else
this.addNotification({ status: 'error', message: response });
2021-01-11 09:55:13 +01:00
},
showCreateFunctionModal () {
this.closeDatabaseContext();
this.isNewFunctionModal = true;
},
hideCreateFunctionModal () {
this.isNewFunctionModal = false;
},
showCreateTriggerFunctionModal () {
this.closeDatabaseContext();
this.isNewTriggerFunctionModal = true;
},
hideCreateTriggerFunctionModal () {
this.isNewTriggerFunctionModal = false;
},
2021-01-16 11:32:42 +01:00
showCreateSchedulerModal () {
this.closeDatabaseContext();
this.isNewSchedulerModal = true;
},
hideCreateSchedulerModal () {
this.isNewSchedulerModal = false;
},
2021-01-11 09:55:13 +01:00
async openCreateFunctionEditor (payload) {
const params = {
uid: this.connection.uid,
...payload
};
const { status, response } = await Functions.createFunction(params);
if (status === 'success') {
await this.refresh();
this.changeBreadcrumbs({ schema: this.selectedDatabase, function: payload.name });
this.selectTab({ uid: this.workspace.uid, tab: 'prop' });
}
else
this.addNotification({ status: 'error', message: response });
2021-01-16 11:32:42 +01:00
},
async openCreateTriggerFunctionEditor (payload) {
const params = {
uid: this.connection.uid,
...payload
};
const { status, response } = await Functions.createTriggerFunction(params);
if (status === 'success') {
await this.refresh();
this.changeBreadcrumbs({ schema: this.selectedDatabase, triggerFunction: payload.name });
this.selectTab({ uid: this.workspace.uid, tab: 'prop' });
}
else
this.addNotification({ status: 'error', message: response });
},
2021-01-16 11:32:42 +01:00
async openCreateSchedulerEditor (payload) {
const params = {
uid: this.connection.uid,
...payload
};
const { status, response } = await Schedulers.createScheduler(params);
if (status === 'success') {
await this.refresh();
this.changeBreadcrumbs({ schema: this.selectedDatabase, scheduler: payload.name });
this.selectTab({ uid: this.workspace.uid, tab: 'prop' });
}
else
this.addNotification({ status: 'error', message: response });
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;
transition: background 0.2s;
&:hover {
background: rgba($primary-color, 50%);
}
2020-07-31 18:16:28 +02:00
}
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;
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
2021-02-20 11:55:34 +01:00
.workspace-explorebar-search {
width: 100%;
display: flex;
justify-content: space-between;
font-size: 0.6rem;
height: 28px;
.has-icon-right {
width: 100%;
padding: 0.1rem;
.form-icon {
opacity: 0.5;
transition: opacity 0.2s;
}
.form-input {
height: 1.2rem;
padding-left: 0.2rem;
&:focus + .form-icon {
opacity: 0.9;
}
&::placeholder {
opacity: 0.6;
}
}
}
}
2020-07-31 18:16:28 +02:00
.workspace-explorebar-body {
width: 100%;
2021-02-20 11:55:34 +01:00
height: calc((100vh - 58px) - #{$excluding-size});
2020-07-31 18:16:28 +02:00
overflow: overlay;
padding: 0 0.1rem;
}
}
2020-05-08 18:02:18 +02:00
</style>