feat: contextual menu option to duplicate table fields

This commit is contained in:
Fabio Di Stasio 2021-08-04 09:59:50 +02:00
parent 70354aa828
commit 3abff36136
8 changed files with 50 additions and 26 deletions

View File

@ -87,17 +87,17 @@
}
},
"dependencies": {
"@electron/remote": "^1.2.0",
"@electron/remote": "^1.2.1",
"@mdi/font": "^5.9.55",
"ace-builds": "^1.4.12",
"electron-log": "^4.3.5",
"electron-log": "^4.4.1",
"electron-store": "^8.0.0",
"electron-updater": "^4.3.9",
"faker": "^5.5.3",
"marked": "^2.1.1",
"moment": "^2.29.1",
"mysql2": "^2.2.5",
"pg": "^8.5.1",
"pg": "^8.7.1",
"pgsql-ast-parser": "^7.2.1",
"source-map-support": "^0.5.16",
"spectre.css": "^0.5.9",
@ -109,22 +109,22 @@
"vuex": "^3.6.2"
},
"devDependencies": {
"@babel/eslint-parser": "^7.14.5",
"@babel/eslint-parser": "^7.14.9",
"cross-env": "^7.0.2",
"electron": "^13.1.2",
"electron": "^13.1.8",
"electron-builder": "^22.11.7",
"electron-devtools-installer": "^3.2.0",
"electron-webpack": "^2.8.2",
"electron-webpack-vue": "^2.4.0",
"eslint": "^7.29.0",
"eslint": "^7.32.0",
"eslint-config-standard": "^16.0.3",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-vue": "^7.11.1",
"sass": "^1.35.1",
"eslint-plugin-vue": "^7.15.1",
"sass": "^1.37.5",
"sass-loader": "^10.2.0",
"standard-version": "^9.3.0",
"standard-version": "^9.3.1",
"stylelint": "^13.13.1",
"stylelint-config-standard": "^22.0.0",
"stylelint-scss": "^3.20.1",

View File

@ -29,18 +29,23 @@ export default {
},
computed: {
position () {
const { clientY, clientX } = this.contextEvent;
let topCord = `${clientY + 2}px`;
let leftCord = `${clientX + 5}px`;
let topCord = 0;
let leftCord = 0;
if (this.contextSize) {
if (clientY + (this.contextSize.height < 200 ? 200 : this.contextSize.height) + 5 >= window.innerHeight) {
topCord = `${clientY + 3 - this.contextSize.height}px`;
this.isBottom = true;
if (this.contextEvent) {
const { clientY, clientX } = this.contextEvent;
topCord = `${clientY + 2}px`;
leftCord = `${clientX + 5}px`;
if (this.contextSize) {
if (clientY + (this.contextSize.height < 200 ? 200 : this.contextSize.height) + 5 >= window.innerHeight) {
topCord = `${clientY + 3 - this.contextSize.height}px`;
this.isBottom = true;
}
if (clientX + this.contextSize.width + 5 >= window.innerWidth)
leftCord = `${clientX - this.contextSize.width}px`;
}
if (clientX + this.contextSize.width + 5 >= window.innerWidth)
leftCord = `${clientX - this.contextSize.width}px`;
}
return {
@ -53,7 +58,8 @@ export default {
window.addEventListener('keydown', this.onKey);
},
mounted () {
this.contextSize = this.$refs.contextContent.getBoundingClientRect();
if (this.$refs.contextContent)
this.contextSize = this.$refs.contextContent.getBoundingClientRect();
},
beforeDestroy () {
window.removeEventListener('keydown', this.onKey);

View File

@ -318,7 +318,7 @@ export default {
localTimeout: null,
localEditorTheme: null,
selectedTab: 'general',
pageSizes: [40, 100, 250, 500, 1000],
pageSizes: [30, 40, 100, 250, 500, 1000],
editorThemes: [
{
group: this.$t('word.light'),

View File

@ -4,28 +4,28 @@
@close-context="closeContext"
>
<div
v-if="selectedTable.type === 'table' && customizations.tableSettings"
v-if="selectedTable && selectedTable.type === 'table' && customizations.tableSettings"
class="context-element"
@click="openTableSettingTab"
>
<span class="d-flex"><i class="mdi mdi-18px mdi-tune-vertical-variant text-light pr-1" /> {{ $t('word.settings') }}</span>
</div>
<div
v-if="selectedTable.type === 'view' && customizations.viewSettings"
v-if="selectedTable && selectedTable.type === 'view' && customizations.viewSettings"
class="context-element"
@click="openViewSettingTab"
>
<span class="d-flex"><i class="mdi mdi-18px mdi-tune-vertical-variant text-light pr-1" /> {{ $t('word.settings') }}</span>
</div>
<div
v-if="selectedTable.type === 'table'"
v-if="selectedTable && selectedTable.type === 'table'"
class="context-element"
@click="duplicateTable"
>
<span class="d-flex"><i class="mdi mdi-18px mdi-table-multiple text-light pr-1" /> {{ $t('message.duplicateTable') }}</span>
</div>
<div
v-if="selectedTable.type === 'table'"
v-if="selectedTable && selectedTable.type === 'table'"
class="context-element"
@click="showEmptyModal"
>

View File

@ -81,6 +81,7 @@
:table="table"
:schema="schema"
mode="table"
@duplicate-field="duplicateField"
@remove-field="removeField"
@add-new-index="addNewIndex"
@add-to-index="addToIndex"
@ -527,6 +528,13 @@ export default {
return key;
});
},
duplicateField (uid) {
const fieldToClone = Object.assign({}, this.localFields.find(field => field._id === uid));
fieldToClone._id = uidGen();
fieldToClone.name = `${fieldToClone.name}_copy`;
fieldToClone.order = this.localFields.length + 1;
this.localFields = [...this.localFields, fieldToClone];
},
removeField (uid) {
this.localFields = this.localFields.filter(field => field._id !== uid);
},

View File

@ -11,6 +11,7 @@
:index-types="indexTypes"
:indexes="indexes"
@delete-selected="removeField"
@duplicate-selected="duplicateField"
@close-context="isContext = false"
@add-new-index="$emit('add-new-index', $event)"
@add-to-index="$emit('add-to-index', $event)"
@ -220,6 +221,9 @@ export default {
this.contextEvent = event;
this.isContext = true;
},
duplicateField () {
this.$emit('duplicate-field', this.selectedField._id);
},
removeField () {
this.$emit('remove-field', this.selectedField._id);
},

View File

@ -33,6 +33,9 @@
</div>
</div>
</div>
<div class="context-element" @click="duplicateField">
<span class="d-flex"><i class="mdi mdi-18px mdi-content-duplicate text-light pr-1" /> {{ $t('word.duplicate') }}</span>
</div>
<div class="context-element" @click="deleteField">
<span class="d-flex"><i class="mdi mdi-18px mdi-delete text-light pr-1" /> {{ $t('message.deleteField') }}</span>
</div>
@ -62,6 +65,10 @@ export default {
closeContext () {
this.$emit('close-context');
},
duplicateField () {
this.$emit('duplicate-selected');
this.closeContext();
},
deleteField () {
this.$emit('delete-selected');
this.closeContext();

View File

@ -459,7 +459,6 @@ export default {
: '';
}
else if (this.defaultValue.type === 'expression') {
console.log(this.localRow.default);
if (this.localRow.default.toUpperCase().includes('ON UPDATE'))
this.defaultValue.expression = this.localRow.default.replace(/ on update.*$/i, '');
else