antares/src/renderer/components/ModalNewSchema.vue

150 lines
4.8 KiB
Vue
Raw Normal View History

2020-09-25 12:39:58 +02:00
<template>
<div class="modal active">
<a class="modal-overlay" @click.stop="closeModal" />
<div class="modal-container p-0">
<div class="modal-header pl-2">
<div class="modal-title h6">
<div class="d-flex">
<i class="mdi mdi-24px mdi-database-plus mr-1" />
<span class="cut-text">{{ $t('message.createNewSchema') }}</span>
2020-09-25 12:39:58 +02:00
</div>
</div>
<a class="btn btn-clear c-hand" @click.stop="closeModal" />
</div>
<div class="modal-body pb-0">
<div class="content">
<form class="form-horizontal" @submit.prevent="createSchema">
2020-09-25 12:39:58 +02:00
<div class="form-group">
<div class="col-3">
2021-01-15 19:18:16 +01:00
<label class="form-label">{{ $t('word.name') }}</label>
2020-09-25 12:39:58 +02:00
</div>
<div class="col-9">
<input
ref="firstInput"
2020-09-25 12:39:58 +02:00
v-model="database.name"
class="form-input"
type="text"
required
:placeholder="$t('message.schemaName')"
2020-09-25 12:39:58 +02:00
>
</div>
</div>
<div v-if="customizations.collations" class="form-group">
2020-09-25 12:39:58 +02:00
<div class="col-3">
2021-01-15 19:18:16 +01:00
<label class="form-label">{{ $t('word.collation') }}</label>
2020-09-25 12:39:58 +02:00
</div>
<div class="col-9">
<select v-model="database.collation" class="form-select">
<option
v-for="collation in collations"
:key="collation.id"
:value="collation.collation"
>
{{ collation.collation }}
</option>
</select>
<small>{{ $t('message.serverDefault') }}: {{ defaultCollation }}</small>
</div>
</div>
</form>
</div>
</div>
2021-07-21 17:56:55 +02:00
<div class="modal-footer">
<button
class="btn btn-primary mr-2"
:class="{'loading': isLoading}"
2021-03-17 11:15:14 +01:00
@click.stop="createSchema"
>
2020-09-25 12:39:58 +02:00
{{ $t('word.add') }}
</button>
<button class="btn btn-link" @click.stop="closeModal">
{{ $t('word.close') }}
</button>
</div>
</div>
</div>
</template>
<script>
import { mapGetters, mapActions } from 'vuex';
2021-03-17 11:15:14 +01:00
import Schema from '@/ipc-api/Schema';
2020-09-25 12:39:58 +02:00
export default {
2021-03-17 11:15:14 +01:00
name: 'ModalNewSchema',
2020-09-25 12:39:58 +02:00
data () {
return {
isLoading: false,
2020-09-25 12:39:58 +02:00
database: {
name: '',
collation: ''
}
};
},
computed: {
...mapGetters({
selectedWorkspace: 'workspaces/getSelected',
getWorkspace: 'workspaces/getWorkspace',
getDatabaseVariable: 'workspaces/getDatabaseVariable'
}),
collations () {
return this.getWorkspace(this.selectedWorkspace).collations;
},
customizations () {
return this.getWorkspace(this.selectedWorkspace).customizations;
},
2020-09-25 12:39:58 +02:00
defaultCollation () {
return this.getDatabaseVariable(this.selectedWorkspace, 'collation_server') ? this.getDatabaseVariable(this.selectedWorkspace, 'collation_server').value : '';
2020-09-25 12:39:58 +02:00
}
},
created () {
this.database = { ...this.database, collation: this.defaultCollation };
2020-10-04 17:21:21 +02:00
window.addEventListener('keydown', this.onKey);
setTimeout(() => {
this.$refs.firstInput.focus();
}, 20);
2020-10-04 17:21:21 +02:00
},
2022-04-21 14:39:24 +02:00
beforeUnmount () {
2020-10-04 17:21:21 +02:00
window.removeEventListener('keydown', this.onKey);
2020-09-25 12:39:58 +02:00
},
methods: {
...mapActions({
addNotification: 'notifications/addNotification'
}),
2021-03-17 11:15:14 +01:00
async createSchema () {
this.isLoading = true;
2020-09-25 12:39:58 +02:00
try {
2021-03-17 11:15:14 +01:00
const { status, response } = await Schema.createSchema({
2020-09-25 12:39:58 +02:00
uid: this.selectedWorkspace,
...this.database
});
if (status === 'success') {
this.closeModal();
this.$emit('reload');
}
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
}
this.isLoading = false;
2020-09-25 12:39:58 +02:00
},
closeModal () {
this.$emit('close');
2020-10-04 17:21:21 +02:00
},
onKey (e) {
e.stopPropagation();
if (e.key === 'Escape')
this.closeModal();
2020-09-25 12:39:58 +02:00
}
}
};
</script>
<style scoped>
.modal-container {
max-width: 360px;
}
</style>