1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-06-05 21:59:22 +02:00

feat: databases deletion

This commit is contained in:
2020-10-01 15:08:35 +02:00
parent 52449e0420
commit 4288a1fd33
15 changed files with 168 additions and 16 deletions

View File

@ -19,7 +19,7 @@ My target is to support as many databases as possible, and all major operating s
Why am I developing an SQL client when there are a lot of them on the market? Why am I developing an SQL client when there are a lot of them on the market?
The main goal is to develop a totally free, cross platform and open source alternative, empowered by JavaScript's ecosystem. The main goal is to develop a totally free, cross platform and open source alternative, empowered by JavaScript's ecosystem.
An application created with minimalism and semplicity in mind, with features in the righ places, not hundreds of tiny buttons or submenu. An application created with minimalism and semplicity in mind, with features in the right places, not hundreds of tiny buttons or submenu.
## How to contribute ## How to contribute

View File

@ -39,7 +39,8 @@ export default connections => {
port: +conn.port, port: +conn.port,
user: conn.user, user: conn.user,
password: conn.password password: conn.password
} },
poolSize: 1
}); });
try { try {

View File

@ -14,6 +14,18 @@ export default connections => {
} }
}); });
ipcMain.handle('delete-database', async (event, params) => {
try {
const query = `DROP DATABASE \`${params.database}\``;
await connections[params.uid].raw(query);
return { status: 'success' };
}
catch (err) {
return { status: 'error', response: err.toString() };
}
});
ipcMain.handle('get-structure', async (event, uid) => { ipcMain.handle('get-structure', async (event, uid) => {
try { try {
const structure = await connections[uid].getStructure(); const structure = await connections[uid].getStructure();

View File

@ -27,7 +27,7 @@
<div class="modal-footer"> <div class="modal-footer">
<button <button
class="btn btn-primary mr-2" class="btn btn-primary mr-2"
@click="confirmModal" @click.stop="confirmModal"
> >
{{ confirmText || $t('word.confirm') }} {{ confirmText || $t('word.confirm') }}
</button> </button>

View File

@ -72,6 +72,7 @@ export default {
align-items: center; align-items: center;
padding: 0.1rem 0.3rem; padding: 0.1rem 0.3rem;
cursor: pointer; cursor: pointer;
justify-content: space-between;
&:hover { &:hover {
background: $primary-color; background: $primary-color;

View File

@ -4,10 +4,10 @@
@close-context="$emit('close-context')" @close-context="$emit('close-context')"
> >
<div class="context-element" @click="showEditModal(contextConnection)"> <div class="context-element" @click="showEditModal(contextConnection)">
<i class="mdi mdi-18px mdi-pencil text-light pr-1" /> {{ $t('word.edit') }} <span class="d-flex"><i class="mdi mdi-18px mdi-pencil text-light pr-1" /> {{ $t('word.edit') }}</span>
</div> </div>
<div class="context-element" @click="showConfirmModal"> <div class="context-element" @click="showConfirmModal">
<i class="mdi mdi-18px mdi-delete text-light pr-1" /> {{ $t('word.delete') }} <span class="d-flex"><i class="mdi mdi-18px mdi-delete text-light pr-1" /> {{ $t('word.delete') }}</span>
</div> </div>
<ConfirmModal <ConfirmModal
@ -22,7 +22,7 @@
</template> </template>
<div :slot="'body'"> <div :slot="'body'">
<div class="mb-2"> <div class="mb-2">
{{ $t('message.deleteConnectionCorfirm') }} <b>{{ connectionName }}</b>? {{ $t('message.deleteCorfirm') }} <b>{{ connectionName }}</b>?
</div> </div>
</div> </div>
</ConfirmModal> </ConfirmModal>

View File

@ -38,6 +38,7 @@
:key="db.name" :key="db.name"
:database="db" :database="db"
:connection="connection" :connection="connection"
@show-database-context="openDatabaseContext"
/> />
</div> </div>
</div> </div>
@ -46,6 +47,13 @@
@close="hideNewDBModal" @close="hideNewDBModal"
@reload="refresh" @reload="refresh"
/> />
<DatabaseContext
v-if="isDatabaseContext"
:selected-database="selectedDatabase"
:context-event="databaseContextEvent"
@close-context="closeDatabaseContext"
@reload="refresh"
/>
</div> </div>
</template> </template>
@ -54,6 +62,7 @@ import { mapGetters, mapActions } from 'vuex';
import _ from 'lodash'; import _ from 'lodash';
import WorkspaceConnectPanel from '@/components/WorkspaceConnectPanel'; import WorkspaceConnectPanel from '@/components/WorkspaceConnectPanel';
import WorkspaceExploreBarDatabase from '@/components/WorkspaceExploreBarDatabase'; import WorkspaceExploreBarDatabase from '@/components/WorkspaceExploreBarDatabase';
import DatabaseContext from '@/components/WorkspaceExploreBarDatabaseContext';
import ModalNewDB from '@/components/ModalNewDB'; import ModalNewDB from '@/components/ModalNewDB';
export default { export default {
@ -61,6 +70,7 @@ export default {
components: { components: {
WorkspaceConnectPanel, WorkspaceConnectPanel,
WorkspaceExploreBarDatabase, WorkspaceExploreBarDatabase,
DatabaseContext,
ModalNewDB ModalNewDB
}, },
props: { props: {
@ -71,7 +81,13 @@ export default {
return { return {
isRefreshing: false, isRefreshing: false,
isNewDBModal: false, isNewDBModal: false,
localWidth: null localWidth: null,
isDatabaseContext: false,
isTableContext: false,
databaseContextEvent: null,
tableContextEvent: null,
selectedDatabase: '',
selectedTable: ''
}; };
}, },
computed: { computed: {
@ -115,6 +131,7 @@ export default {
changeExplorebarSize: 'settings/changeExplorebarSize' changeExplorebarSize: 'settings/changeExplorebarSize'
}), }),
async refresh () { async refresh () {
console.log('refresh');
if (!this.isRefreshing) { if (!this.isRefreshing) {
this.isRefreshing = true; this.isRefreshing = true;
await this.refreshStructure(this.connection.uid); await this.refreshStructure(this.connection.uid);
@ -136,6 +153,16 @@ export default {
}, },
hideNewDBModal () { hideNewDBModal () {
this.isNewDBModal = false; this.isNewDBModal = false;
},
openDatabaseContext (payload) {
this.isTableContext = false;
this.selectedDatabase = payload.database;
this.databaseContextEvent = payload.event;
this.isDatabaseContext = true;
},
closeDatabaseContext () {
this.isDatabaseContext = false;
this.selectedDatabase = '';
} }
} }
}; };

View File

@ -4,6 +4,7 @@
class="accordion-header database-name pb-0" class="accordion-header database-name pb-0"
:class="{'text-bold': breadcrumbs.schema === database.name}" :class="{'text-bold': breadcrumbs.schema === database.name}"
@click="changeBreadcrumbs({schema: database.name, table:null})" @click="changeBreadcrumbs({schema: database.name, table:null})"
@contextmenu.prevent="showDatabaseContext($event, database.name)"
> >
<i class="icon mdi mdi-18px mdi-chevron-right" /> <i class="icon mdi mdi-18px mdi-chevron-right" />
<i class="database-icon mdi mdi-18px mdi-database mr-1" /> <i class="database-icon mdi mdi-18px mdi-database mr-1" />
@ -18,6 +19,7 @@
class="menu-item" class="menu-item"
:class="{'text-bold': breadcrumbs.schema === database.name && breadcrumbs.table === table.TABLE_NAME}" :class="{'text-bold': breadcrumbs.schema === database.name && breadcrumbs.table === table.TABLE_NAME}"
@click="changeBreadcrumbs({schema: database.name, table: table.TABLE_NAME})" @click="changeBreadcrumbs({schema: database.name, table: table.TABLE_NAME})"
@contextmenu.prevent="showTableContext($event, table.TABLE_NAME)"
> >
<a class="table-name"> <a class="table-name">
<i class="table-icon mdi mdi-18px mdi-table mr-1" /> <i class="table-icon mdi mdi-18px mdi-table mr-1" />
@ -50,7 +52,13 @@ export default {
methods: { methods: {
...mapActions({ ...mapActions({
changeBreadcrumbs: 'workspaces/changeBreadcrumbs' changeBreadcrumbs: 'workspaces/changeBreadcrumbs'
}) }),
showDatabaseContext (event, database) {
this.$emit('show-database-context', { event, database });
},
showTableContext (table) {
this.$emit('show-table-context', table);
}
} }
}; };
</script> </script>

View File

@ -0,0 +1,97 @@
<template>
<BaseContextMenu
:context-event="contextEvent"
@close-context="closeContext"
>
<!-- <div class="context-element">
<span class="d-flex"><i class="mdi mdi-18px mdi-plus text-light pr-1" /> {{ $t('word.add') }}</span>
<i class="mdi mdi-18px mdi-chevron-right text-light pl-1" />
</div> -->
<div class="context-element">
<span class="d-flex"><i class="mdi mdi-18px mdi-pencil text-light pr-1" /> {{ $t('word.edit') }}</span>
</div>
<div class="context-element" @click="showConfirmModal">
<span class="d-flex"><i class="mdi mdi-18px mdi-delete text-light pr-1" /> {{ $t('word.delete') }}</span>
</div>
<ConfirmModal
v-if="isConfirmModal"
@confirm="deleteDatabase"
@hide="hideConfirmModal"
>
<template slot="header">
<div class="d-flex">
<i class="mdi mdi-24px mdi-database-remove mr-1" /> {{ $t('message.deleteDatabase') }}
</div>
</template>
<div slot="body">
<div class="mb-2">
{{ $t('message.deleteCorfirm') }} "<b>{{ selectedDatabase }}</b>"?
</div>
</div>
</ConfirmModal>
</BaseContextMenu>
</template>
<script>
import { mapGetters, mapActions } from 'vuex';
import BaseContextMenu from '@/components/BaseContextMenu';
import ConfirmModal from '@/components/BaseConfirmModal';
import Database from '@/ipc-api/Database';
export default {
name: 'WorkspaceExploreBarDatabaseContext',
components: {
BaseContextMenu,
ConfirmModal
},
props: {
contextEvent: MouseEvent,
selectedDatabase: String
},
data () {
return {
isConfirmModal: false
};
},
computed: {
...mapGetters({
selectedWorkspace: 'workspaces/getSelected'
})
},
methods: {
...mapActions({
deleteConnection: 'connections/deleteConnection',
showEditModal: 'application/showEditConnModal',
addNotification: 'notifications/addNotification'
}),
showConfirmModal () {
this.isConfirmModal = true;
},
hideConfirmModal () {
this.isConfirmModal = false;
},
closeContext () {
this.$emit('close-context');
},
async deleteDatabase () {
try {
const { status, response } = await Database.deleteDatabase({
uid: this.selectedWorkspace,
database: this.selectedDatabase
});
if (status === 'success') {
this.closeContext();
this.$emit('reload');
}
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
}
}
}
};
</script>

View File

@ -4,7 +4,7 @@
@close-context="closeContext" @close-context="closeContext"
> >
<div class="context-element" @click="showConfirmModal"> <div class="context-element" @click="showConfirmModal">
<i class="mdi mdi-18px mdi-delete text-light pr-1" /> {{ $tc('message.deleteRows', selectedRows.length) }} <span class="d-flex"><i class="mdi mdi-18px mdi-delete text-light pr-1" /> {{ $tc('message.deleteRows', selectedRows.length) }}</span>
</div> </div>
<ConfirmModal <ConfirmModal

View File

@ -50,7 +50,7 @@ module.exports = {
testConnection: 'إختبر الإتصال', testConnection: 'إختبر الإتصال',
editConnection: 'عدل الإتصال', editConnection: 'عدل الإتصال',
deleteConnection: 'إحذف الإتصال', deleteConnection: 'إحذف الإتصال',
deleteConnectionCorfirm: 'هل أنت متأكد من حذف الإتصال؟', deleteCorfirm: 'هل أنت متأكد من حذف الإتصال؟',
connectionSuccessfullyMade: 'تم الإتصال بنجاح!', connectionSuccessfullyMade: 'تم الإتصال بنجاح!',
madeWithJS: 'بني بـ 💛 و جافاسكربت!', madeWithJS: 'بني بـ 💛 و جافاسكربت!',
checkForUpdates: 'تأكد من التحديثات', checkForUpdates: 'تأكد من التحديثات',

View File

@ -53,7 +53,7 @@ module.exports = {
testConnection: 'Test connection', testConnection: 'Test connection',
editConnection: 'Edit connection', editConnection: 'Edit connection',
deleteConnection: 'Delete connection', deleteConnection: 'Delete connection',
deleteConnectionCorfirm: 'Do you confirm the cancellation of', deleteCorfirm: 'Do you confirm the cancellation of',
connectionSuccessfullyMade: 'Connection successfully made!', connectionSuccessfullyMade: 'Connection successfully made!',
madeWithJS: 'Made with 💛 and JavaScript!', madeWithJS: 'Made with 💛 and JavaScript!',
checkForUpdates: 'Check for updates', checkForUpdates: 'Check for updates',
@ -76,7 +76,9 @@ module.exports = {
affectedRows: 'Affected rows', affectedRows: 'Affected rows',
createNewDatabase: 'Create new Database', createNewDatabase: 'Create new Database',
databaseName: 'Database name', databaseName: 'Database name',
serverDefault: 'Server default' serverDefault: 'Server default',
deleteDatabase: 'Delete database',
editDatabase: 'Edit database'
}, },
// Date and Time // Date and Time
short: { short: {

View File

@ -51,7 +51,7 @@ module.exports = {
testConnection: 'Comprobar conexión', testConnection: 'Comprobar conexión',
editConnection: 'Editar conexión', editConnection: 'Editar conexión',
deleteConnection: 'Eliminar conexión', deleteConnection: 'Eliminar conexión',
deleteConnectionCorfirm: 'Confirmas la cancelación de', deleteCorfirm: 'Confirmas la cancelación de',
connectionSuccessfullyMade: 'Conexión realizada correctamente!', connectionSuccessfullyMade: 'Conexión realizada correctamente!',
madeWithJS: 'Hecho con 💛 y JavaScript!', madeWithJS: 'Hecho con 💛 y JavaScript!',
checkForUpdates: 'Comprobar actualizaciones', checkForUpdates: 'Comprobar actualizaciones',

View File

@ -29,10 +29,10 @@ module.exports = {
donate: 'Dona', donate: 'Dona',
run: 'Esegui', run: 'Esegui',
schema: 'Schema', schema: 'Schema',
results: 'Results', results: 'Risultati',
size: 'Dimensioni', size: 'Dimensioni',
seconds: 'Secondi', seconds: 'Secondi',
type: 'tipologia', type: 'Tipo',
mimeType: 'Mime-Type', mimeType: 'Mime-Type',
download: 'Scarica', download: 'Scarica',
add: 'Aggiungi', add: 'Aggiungi',
@ -51,7 +51,7 @@ module.exports = {
testConnection: 'Testa connessione', testConnection: 'Testa connessione',
editConnection: 'Modifica connessione', editConnection: 'Modifica connessione',
deleteConnection: 'Elimina connessione', deleteConnection: 'Elimina connessione',
deleteConnectionCorfirm: 'Confermi l\'eliminazione di', deleteCorfirm: 'Confermi l\'eliminazione di',
connectionSuccessfullyMade: 'Connessione avvenuta con successo!', connectionSuccessfullyMade: 'Connessione avvenuta con successo!',
madeWithJS: 'Fatto con 💛 e JavaScript!', madeWithJS: 'Fatto con 💛 e JavaScript!',
checkForUpdates: 'Cerca aggiornamenti', checkForUpdates: 'Cerca aggiornamenti',

View File

@ -6,6 +6,10 @@ export default class {
return ipcRenderer.invoke('create-database', params); return ipcRenderer.invoke('create-database', params);
} }
static deleteDatabase (params) {
return ipcRenderer.invoke('delete-database', params);
}
static getStructure (uid) { static getStructure (uid) {
return ipcRenderer.invoke('get-structure', uid); return ipcRenderer.invoke('get-structure', uid);
} }