Datetime fields precision

This commit is contained in:
Fabio 2020-07-05 16:06:56 +02:00
parent 262a476f50
commit 187b4f50f9
6 changed files with 53 additions and 19 deletions

View File

@ -7,7 +7,7 @@ import Generic from '../models/Generic';
export default (connections) => { export default (connections) => {
ipcMain.handle('getTableColumns', async (event, { uid, schema, table }) => { ipcMain.handle('getTableColumns', async (event, { uid, schema, table }) => {
try { 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 }; return { status: 'success', response: result };
} }
catch (err) { catch (err) {

View File

@ -77,7 +77,8 @@ export default {
return { return {
name: field.COLUMN_NAME, name: field.COLUMN_NAME,
key: field.COLUMN_KEY.toLowerCase(), key: field.COLUMN_KEY.toLowerCase(),
type: field.DATA_TYPE type: field.DATA_TYPE,
precision: field.DATETIME_PRECISION
}; };
}).filter(field => { }).filter(field => {
if (this.results.fields) { if (this.results.fields) {

View File

@ -39,6 +39,7 @@
:key="cKey" :key="cKey"
:content="col" :content="col"
:field="cKey" :field="cKey"
:precision="fieldPrecision(cKey)"
:type="fieldType(cKey)" :type="fieldType(cKey)"
@updateField="updateField($event, row[primaryField.name])" @updateField="updateField($event, row[primaryField.name])"
/> />
@ -105,6 +106,14 @@ export default {
return type; 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) { keyName (key) {
switch (key) { switch (key) {
case 'pri': case 'pri':

View File

@ -11,17 +11,28 @@
class="cell-content px-2" class="cell-content px-2"
:class="isNull(content)" :class="isNull(content)"
@dblclick="editON" @dblclick="editON"
>{{ content | typeFormat(type) }}</span> >{{ content | typeFormat(type, precision) }}</span>
<input <template v-else>
v-else <input
ref="editField" v-if="inputProps.mask"
v-model="localContent" ref="editField"
v-mask="inputProps.mask" v-model="localContent"
:type="inputProps.type" v-mask="inputProps.mask"
autofocus :type="inputProps.type"
class="editable-field px-2" autofocus
@blur="editOFF" class="editable-field px-2"
> @blur="editOFF"
>
<input
v-else
ref="editField"
v-model="localContent"
:type="inputProps.type"
autofocus
class="editable-field px-2"
@blur="editOFF"
>
</template>
</div> </div>
</template> </template>
@ -34,7 +45,7 @@ import { mask } from 'vue-the-mask';
export default { export default {
name: 'WorkspaceQueryTableCell', name: 'WorkspaceQueryTableCell',
filters: { filters: {
typeFormat (val, type) { typeFormat (val, type, precision) {
if (!val) return val; if (!val) return val;
switch (type) { switch (type) {
@ -48,7 +59,11 @@ export default {
} }
case 'datetime': case 'datetime':
case 'timestamp': { 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 'blob':
case 'mediumblob': case 'mediumblob':
@ -74,6 +89,7 @@ export default {
props: { props: {
type: String, type: String,
field: String, field: String,
precision: [Number, null],
content: [String, Number, Object, Date, Uint8Array] content: [String, Number, Object, Date, Uint8Array]
}, },
data () { data () {
@ -98,12 +114,17 @@ export default {
case 'date': case 'date':
return { type: 'text', mask: '####-##-##' }; return { type: 'text', mask: '####-##-##' };
case 'datetime': case 'datetime':
case 'timestamp': case 'timestamp': {
return { type: 'text', mask: '####-##-## ##:##:##.###' };// TODO: field length let datetimeMask = '####-##-## ##:##:##';
for (let i = 0; i < this.precision; i++)
datetimeMask += i === 0 ? '.#' : '#';
return { type: 'text', mask: datetimeMask };
}
case 'blob': case 'blob':
case 'mediumblob': case 'mediumblob':
case 'longblob': case 'longblob':
case 'bit': case 'bit':
return { type: 'file', mask: false };
default: default:
return 'hidden'; return 'hidden';
} }
@ -114,6 +135,8 @@ export default {
return value === null ? ' is-null' : ''; return value === null ? ' is-null' : '';
}, },
editON () { editON () {
if (['file'].includes(this.inputProps.type)) return;// TODO: remove temporary file block
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.cell.blur(); this.$refs.cell.blur();

View File

@ -75,7 +75,8 @@ export default {
return { return {
name: field.COLUMN_NAME, name: field.COLUMN_NAME,
key: field.COLUMN_KEY.toLowerCase(), key: field.COLUMN_KEY.toLowerCase(),
type: field.DATA_TYPE type: field.DATA_TYPE,
precision: field.DATETIME_PRECISION
}; };
}); });
} }

View File

@ -17,7 +17,7 @@ module.exports = {
{ {
loader: 'sass-loader', loader: 'sass-loader',
options: { options: {
prependData: '@import "@/scss/_variables.scss";' additionalData: '@import "@/scss/_variables.scss";'
} }
} }
] ]