antares/src/renderer/components/WorkspaceTabPropsTableFIeld...

264 lines
7.8 KiB
Vue
Raw Normal View History

2020-10-24 14:47:35 +02:00
<template>
<div
ref="tableWrapper"
class="vscroll"
:style="{'height': resultsSize+'px'}"
>
<TableContext
v-if="isContext"
:context-event="contextEvent"
2020-11-13 16:19:59 +01:00
:selected-field="selectedField"
2020-12-01 16:48:20 +01:00
:index-types="indexTypes"
:indexes="indexes"
2020-11-13 16:19:59 +01:00
@delete-selected="removeField"
@duplicate-selected="duplicateField"
2020-10-24 14:47:35 +02:00
@close-context="isContext = false"
2020-12-01 16:48:20 +01:00
@add-new-index="$emit('add-new-index', $event)"
@add-to-index="$emit('add-to-index', $event)"
2020-10-24 14:47:35 +02:00
/>
<div ref="propTable" class="table table-hover">
<div class="thead">
<div class="tr">
<div class="th">
<div class="text-right">
{{ $t('word.order') }}
</div>
</div>
<div class="th">
<div class="table-column-title">
{{ $tc('word.key', 2) }}
</div>
</div>
<div class="th">
2020-12-11 15:55:18 +01:00
<div class="column-resizable min-100">
2020-10-24 14:47:35 +02:00
<div class="table-column-title">
{{ $t('word.name') }}
</div>
</div>
</div>
<div class="th">
2020-12-11 15:55:18 +01:00
<div class="column-resizable min-100">
2020-10-24 14:47:35 +02:00
<div class="table-column-title">
{{ $t('word.type') }}
</div>
</div>
</div>
<div v-if="customizations.tableArray" class="th">
<div class="column-resizable">
<div class="table-column-title">
{{ $t('word.array') }}
</div>
</div>
</div>
2020-10-24 14:47:35 +02:00
<div class="th">
<div class="column-resizable">
<div class="table-column-title">
{{ $t('word.length') }}
</div>
</div>
</div>
2021-03-25 18:33:29 +01:00
<div v-if="customizations.unsigned" class="th">
2020-10-24 14:47:35 +02:00
<div class="column-resizable">
<div class="table-column-title">
{{ $t('word.unsigned') }}
</div>
</div>
</div>
2021-03-25 18:33:29 +01:00
<div v-if="customizations.nullable" class="th">
2020-10-24 14:47:35 +02:00
<div class="column-resizable">
<div class="table-column-title">
{{ $t('message.allowNull') }}
</div>
</div>
</div>
2021-03-25 18:33:29 +01:00
<div v-if="customizations.zerofill" class="th">
2020-10-24 14:47:35 +02:00
<div class="column-resizable">
<div class="table-column-title">
{{ $t('message.zeroFill') }}
</div>
</div>
</div>
<div class="th">
<div class="column-resizable">
<div class="table-column-title">
{{ $t('word.default') }}
</div>
</div>
</div>
2021-03-25 18:33:29 +01:00
<div v-if="customizations.comment" class="th">
2020-10-24 14:47:35 +02:00
<div class="column-resizable">
<div class="table-column-title">
{{ $t('word.comment') }}
</div>
</div>
</div>
2021-03-25 18:33:29 +01:00
<div v-if="customizations.collation" class="th">
2020-12-15 17:08:36 +01:00
<div class="column-resizable min-100">
2020-10-24 14:47:35 +02:00
<div class="table-column-title">
{{ $t('word.collation') }}
</div>
</div>
</div>
</div>
</div>
2021-07-14 20:30:54 +02:00
<Draggable
2020-11-13 12:39:40 +01:00
ref="resultTable"
:list="fields"
class="tbody"
handle=".row-draggable"
>
<TableRow
v-for="row in fields"
:key="row._id"
:row="row"
:indexes="getIndexes(row.name)"
2020-12-15 17:08:36 +01:00
:foreigns="getForeigns(row.name)"
2020-11-13 12:39:40 +01:00
:data-types="dataTypes"
2021-03-25 18:33:29 +01:00
:customizations="customizations"
2020-11-13 16:19:59 +01:00
@contextmenu="contextMenu"
@rename-field="$emit('rename-field', $event)"
2020-11-13 12:39:40 +01:00
/>
2021-07-14 20:30:54 +02:00
</Draggable>
2020-10-24 14:47:35 +02:00
</div>
</div>
</template>
<script>
import { mapActions, mapGetters } from 'vuex';
2021-07-14 20:30:54 +02:00
import Draggable from 'vuedraggable';
2021-08-12 09:54:13 +02:00
import TableRow from '@/components/WorkspaceTabPropsTableRow';
import TableContext from '@/components/WorkspaceTabPropsTableContext';
2020-10-24 14:47:35 +02:00
export default {
2021-08-12 09:54:13 +02:00
name: 'WorkspaceTabPropsTableFIelds',
2020-10-24 14:47:35 +02:00
components: {
2020-11-13 12:39:40 +01:00
TableRow,
2020-11-13 16:19:59 +01:00
TableContext,
2021-07-14 20:30:54 +02:00
Draggable
2020-10-24 14:47:35 +02:00
},
props: {
2020-11-13 12:39:40 +01:00
fields: Array,
indexes: Array,
2020-12-15 17:08:36 +01:00
foreigns: Array,
2020-12-01 16:48:20 +01:00
indexTypes: Array,
2020-10-24 14:47:35 +02:00
tabUid: [String, Number],
connUid: String,
table: String,
schema: String,
mode: String
},
data () {
return {
resultsSize: 1000,
isContext: false,
contextEvent: null,
2020-11-13 16:19:59 +01:00
selectedField: null,
2020-10-24 14:47:35 +02:00
scrollElement: null
};
},
computed: {
...mapGetters({
getWorkspaceTab: 'workspaces/getWorkspaceTab',
getWorkspace: 'workspaces/getWorkspace'
}),
workspaceSchema () {
return this.getWorkspace(this.connUid).breadcrumbs.schema;
},
2021-03-25 18:33:29 +01:00
customizations () {
return this.getWorkspace(this.connUid).customizations;
},
2020-11-13 12:39:40 +01:00
dataTypes () {
return this.getWorkspace(this.connUid).dataTypes;
},
2020-10-24 14:47:35 +02:00
primaryField () {
2020-11-13 12:39:40 +01:00
return this.fields.filter(field => ['pri', 'uni'].includes(field.key))[0] || false;
2020-10-24 14:47:35 +02:00
},
tabProperties () {
return this.getWorkspaceTab(this.tabUid);
2020-12-01 16:48:20 +01:00
},
fieldsLength () {
return this.fields.length;
}
},
watch: {
fieldsLength () {
this.refreshScroller();
2020-10-24 14:47:35 +02:00
}
},
updated () {
if (this.$refs.propTable)
this.refreshScroller();
if (this.$refs.tableWrapper)
this.scrollElement = this.$refs.tableWrapper;
},
mounted () {
window.addEventListener('resize', this.resizeResults);
},
destroyed () {
window.removeEventListener('resize', this.resizeResults);
},
methods: {
...mapActions({
addNotification: 'notifications/addNotification'
}),
resizeResults () {
if (this.$refs.resultTable) {
const el = this.$refs.tableWrapper;
if (el) {
const footer = document.getElementById('footer');
const size = window.innerHeight - el.getBoundingClientRect().top - footer.offsetHeight;
this.resultsSize = size;
}
}
},
refreshScroller () {
this.resizeResults();
},
2020-11-13 16:19:59 +01:00
contextMenu (event, uid) {
2020-12-01 16:48:20 +01:00
this.selectedField = this.fields.find(field => field._id === uid);
2020-10-24 14:47:35 +02:00
this.contextEvent = event;
this.isContext = true;
2020-11-13 16:19:59 +01:00
},
duplicateField () {
this.$emit('duplicate-field', this.selectedField._id);
},
2020-11-13 16:19:59 +01:00
removeField () {
2020-12-01 16:48:20 +01:00
this.$emit('remove-field', this.selectedField._id);
},
getIndexes (field) {
2020-12-01 16:48:20 +01:00
return this.indexes.reduce((acc, curr) => {
acc.push(...curr.fields.map(f => ({ name: f, type: curr.type })));
return acc;
}, []).filter(f => f.name === field);
2020-12-15 17:08:36 +01:00
},
getForeigns (field) {
return this.foreigns.reduce((acc, curr) => {
if (curr.field === field)
acc.push(`${curr.refTable}.${curr.refField}`);
return acc;
}, []);
2020-10-24 14:47:35 +02:00
}
}
};
</script>
<style lang="scss" scoped>
.column-resizable {
&:hover,
&:active {
resize: horizontal;
overflow: hidden;
}
}
2020-12-01 16:48:20 +01:00
.vscroll {
overflow: auto;
}
2020-12-11 15:55:18 +01:00
.min-100 {
min-width: 100px !important;
}
2020-10-24 14:47:35 +02:00
</style>