From 187b4f50f966b57e7a4eef9056c379e3c635aa06 Mon Sep 17 00:00:00 2001 From: Fabio Date: Sun, 5 Jul 2020 16:06:56 +0200 Subject: [PATCH] Datetime fields precision --- src/main/ipc-handlers/structure.js | 2 +- src/renderer/components/WorkspaceQueryTab.vue | 3 +- .../components/WorkspaceQueryTable.vue | 9 ++++ .../components/WorkspaceQueryTableCell.vue | 53 +++++++++++++------ src/renderer/components/WorkspaceTableTab.vue | 3 +- webpack.config.js | 2 +- 6 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/main/ipc-handlers/structure.js b/src/main/ipc-handlers/structure.js index fc7f4078..6d20c243 100644 --- a/src/main/ipc-handlers/structure.js +++ b/src/main/ipc-handlers/structure.js @@ -7,7 +7,7 @@ import Generic from '../models/Generic'; export default (connections) => { ipcMain.handle('getTableColumns', async (event, { uid, schema, table }) => { try { - const result = await InformationSchema.getTableColumns(connections[uid], schema, table); + const result = await InformationSchema.getTableColumns(connections[uid], schema, table);// TODO: uniform column properties return { status: 'success', response: result }; } catch (err) { diff --git a/src/renderer/components/WorkspaceQueryTab.vue b/src/renderer/components/WorkspaceQueryTab.vue index 5be875c4..f1a4ec27 100644 --- a/src/renderer/components/WorkspaceQueryTab.vue +++ b/src/renderer/components/WorkspaceQueryTab.vue @@ -77,7 +77,8 @@ export default { return { name: field.COLUMN_NAME, key: field.COLUMN_KEY.toLowerCase(), - type: field.DATA_TYPE + type: field.DATA_TYPE, + precision: field.DATETIME_PRECISION }; }).filter(field => { if (this.results.fields) { diff --git a/src/renderer/components/WorkspaceQueryTable.vue b/src/renderer/components/WorkspaceQueryTable.vue index 0486f2b8..45c62f5e 100644 --- a/src/renderer/components/WorkspaceQueryTable.vue +++ b/src/renderer/components/WorkspaceQueryTable.vue @@ -39,6 +39,7 @@ :key="cKey" :content="col" :field="cKey" + :precision="fieldPrecision(cKey)" :type="fieldType(cKey)" @updateField="updateField($event, row[primaryField.name])" /> @@ -105,6 +106,14 @@ export default { return type; }, + fieldPrecision (cKey) { + let length = 0; + const field = this.fields.filter(field => field.name === cKey)[0]; + if (field) + length = field.precision; + + return length; + }, keyName (key) { switch (key) { case 'pri': diff --git a/src/renderer/components/WorkspaceQueryTableCell.vue b/src/renderer/components/WorkspaceQueryTableCell.vue index 2a4c2077..6b6e6676 100644 --- a/src/renderer/components/WorkspaceQueryTableCell.vue +++ b/src/renderer/components/WorkspaceQueryTableCell.vue @@ -11,17 +11,28 @@ class="cell-content px-2" :class="isNull(content)" @dblclick="editON" - >{{ content | typeFormat(type) }} - + >{{ content | typeFormat(type, precision) }} + @@ -34,7 +45,7 @@ import { mask } from 'vue-the-mask'; export default { name: 'WorkspaceQueryTableCell', filters: { - typeFormat (val, type) { + typeFormat (val, type, precision) { if (!val) return val; switch (type) { @@ -48,7 +59,11 @@ export default { } case 'datetime': case 'timestamp': { - return moment(val).isValid() ? moment(val).format('YYYY-MM-DD HH:mm:ss.SSS') : val; + let datePrecision = ''; + for (let i = 0; i < precision; i++) + datePrecision += i === 0 ? '.S' : 'S'; + + return moment(val).isValid() ? moment(val).format(`YYYY-MM-DD HH:mm:ss${datePrecision}`) : val; } case 'blob': case 'mediumblob': @@ -74,6 +89,7 @@ export default { props: { type: String, field: String, + precision: [Number, null], content: [String, Number, Object, Date, Uint8Array] }, data () { @@ -98,12 +114,17 @@ export default { case 'date': return { type: 'text', mask: '####-##-##' }; case 'datetime': - case 'timestamp': - return { type: 'text', mask: '####-##-## ##:##:##.###' };// TODO: field length + case 'timestamp': { + let datetimeMask = '####-##-## ##:##:##'; + for (let i = 0; i < this.precision; i++) + datetimeMask += i === 0 ? '.#' : '#'; + return { type: 'text', mask: datetimeMask }; + } case 'blob': case 'mediumblob': case 'longblob': case 'bit': + return { type: 'file', mask: false }; default: return 'hidden'; } @@ -114,6 +135,8 @@ export default { return value === null ? ' is-null' : ''; }, editON () { + if (['file'].includes(this.inputProps.type)) return;// TODO: remove temporary file block + this.$nextTick(() => { this.$refs.cell.blur(); diff --git a/src/renderer/components/WorkspaceTableTab.vue b/src/renderer/components/WorkspaceTableTab.vue index 3aa0184e..f9ee5012 100644 --- a/src/renderer/components/WorkspaceTableTab.vue +++ b/src/renderer/components/WorkspaceTableTab.vue @@ -75,7 +75,8 @@ export default { return { name: field.COLUMN_NAME, key: field.COLUMN_KEY.toLowerCase(), - type: field.DATA_TYPE + type: field.DATA_TYPE, + precision: field.DATETIME_PRECISION }; }); } diff --git a/webpack.config.js b/webpack.config.js index 3d192093..c1ea21cf 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -17,7 +17,7 @@ module.exports = { { loader: 'sass-loader', options: { - prependData: '@import "@/scss/_variables.scss";' + additionalData: '@import "@/scss/_variables.scss";' } } ]