Skip to content

Commit

Permalink
feat: aliases support
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Sep 1, 2020
1 parent 8390f8a commit 264de9c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
9 changes: 8 additions & 1 deletion src/renderer/components/WorkspaceQueryTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,15 @@ export default {
};
const { status, response } = await Tables.getTableColumns(params);
if (status === 'success') {
const fields = response.filter(field => this.selectedFields.includes(field.name));
let fields = response.filter(field => this.selectedFields.includes(field.name));
if (this.selectedFields.length) {
fields = fields.map((field, index) => {
return { ...field, alias: this.results.fields[index].name };
});
}
this.setTabFields({ cUid: this.connection.uid, tUid: this.tabUid, fields });
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/WorkspaceQueryTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
class="tr"
:class="{'selected': selectedRows.includes(row._id)}"
@select-row="selectRow($event, row._id)"
@update-field="updateField($event, row[primaryField.name])"
@update-field="updateField($event, row[primaryField.alias || primaryField.name])"
@contextmenu="contextMenu"
/>
</template>
Expand Down
29 changes: 14 additions & 15 deletions src/renderer/components/WorkspaceQueryTableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
class="td p-0"
tabindex="0"
@contextmenu.prevent="$emit('contextmenu', $event, {id: row._id, field: cKey})"
@update-field="updateField($event, row[primaryField.name])"
>
<template v-if="cKey !== '_id'">
<span
v-if="!isInlineEditor[cKey]"
class="cell-content px-2"
:class="`${isNull(col)} type-${fieldType(cKey)}`"
:class="`${isNull(col)} type-${getFieldType(cKey)}`"
@dblclick="editON($event, col, cKey)"
>{{ col | typeFormat(fieldType(cKey), fieldPrecision(cKey)) | cutText }}</span>
>{{ col | typeFormat(getFieldType(cKey), getFieldPrecision(cKey)) | cutText }}</span>
<ForeignKeySelect
v-else-if="foreignKeys.includes(cKey)"
class="editable-field"
Expand Down Expand Up @@ -218,7 +217,7 @@ export default {
if (TIME.includes(this.editingType)) {
let timeMask = '##:##:##';
const precision = this.fieldPrecision(this.editingField);
const precision = this.getFieldPrecision(this.editingField);
for (let i = 0; i < precision; i++)
timeMask += i === 0 ? '.#' : '#';
Expand All @@ -231,7 +230,7 @@ export default {
if (DATETIME.includes(this.editingType)) {
let datetimeMask = '####-##-## ##:##:##';
const precision = this.fieldPrecision(this.editingField);
const precision = this.getFieldPrecision(this.editingField);
for (let i = 0; i < precision; i++)
datetimeMask += i === 0 ? '.#' : '#';
Expand Down Expand Up @@ -260,30 +259,33 @@ export default {
});
},
methods: {
fieldType (cKey) {
getFieldType (cKey) {
let type = 'unknown';
const field = this.fields.filter(field => field.name === cKey)[0];
const field = this.getFieldObj(cKey);
if (field)
type = field.type;
return type;
},
fieldPrecision (cKey) {
getFieldPrecision (cKey) {
let length = 0;
const field = this.fields.filter(field => field.name === cKey)[0];
const field = this.getFieldObj(cKey);
if (field)
length = field.datePrecision;
return length;
},
getFieldObj (cKey) {
return this.fields.filter(field => field.name === cKey || field.alias === cKey)[0];
},
isNull (value) {
return value === null ? ' is-null' : '';
},
bufferToBase64 (val) {
return bufferToBase64(val);
},
editON (event, content, field) {
const type = this.fieldType(field);
const type = this.getFieldType(field);
this.originalContent = content;
this.editingType = type;
this.editingField = field;
Expand Down Expand Up @@ -316,7 +318,7 @@ export default {
}
// Inline editable fields
this.editingContent = this.$options.filters.typeFormat(this.originalContent, type, this.fieldPrecision(field));
this.editingContent = this.$options.filters.typeFormat(this.originalContent, type, this.getFieldPrecision(field));
this.$nextTick(() => { // Focus on input
event.target.blur();
Expand Down Expand Up @@ -347,7 +349,7 @@ export default {
}
this.$emit('update-field', {
field: this.editingField,
field: this.getFieldObj(this.editingField).name,
type: this.editingType,
content
});
Expand Down Expand Up @@ -385,9 +387,6 @@ export default {
};
this.willBeDeleted = true;
},
updateField (event, id) {
this.$emit('update-field', event, id);
},
contextMenu (event, cell) {
this.$emit('update-field', event, cell);
},
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ body {
}

.form-select,
.form-select:not([multiple]):not([size]),
.form-input,
.form-select:not([multiple]):not([size]),
.form-checkbox .form-icon,
.form-radio .form-icon {
border-color: $bg-color-light;
background: $bg-color-gray;
background-color: $bg-color-gray;
}

.form-input:not(:placeholder-shown):invalid:focus {
Expand Down

0 comments on commit 264de9c

Please sign in to comment.