Editable datetime fields

This commit is contained in:
Fabio 2020-07-02 19:17:25 +02:00
parent 8a4c628128
commit 50cd852d01
3 changed files with 23 additions and 13 deletions

5
package-lock.json generated
View File

@ -12793,6 +12793,11 @@
"integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==", "integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==",
"dev": true "dev": true
}, },
"vue-the-mask": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/vue-the-mask/-/vue-the-mask-0.11.1.tgz",
"integrity": "sha512-UquSfnSWejD0zAfcD+3jJ1chUAkOAyoxya9Lxh9acCRtrlmGcAIvd0cQYraWqKenbuZJUdum+S174atv2AuEHQ=="
},
"vuedraggable": { "vuedraggable": {
"version": "2.23.2", "version": "2.23.2",
"resolved": "https://registry.npmjs.org/vuedraggable/-/vuedraggable-2.23.2.tgz", "resolved": "https://registry.npmjs.org/vuedraggable/-/vuedraggable-2.23.2.tgz",

View File

@ -42,6 +42,7 @@
"spectre.css": "^0.5.8", "spectre.css": "^0.5.8",
"vue-click-outside": "^1.1.0", "vue-click-outside": "^1.1.0",
"vue-i18n": "^8.18.2", "vue-i18n": "^8.18.2",
"vue-the-mask": "^0.11.1",
"vuedraggable": "^2.23.2", "vuedraggable": "^2.23.2",
"vuex": "^3.5.1", "vuex": "^3.5.1",
"vuex-persist": "^2.2.0" "vuex-persist": "^2.2.0"

View File

@ -16,7 +16,8 @@
v-else v-else
ref="editField" ref="editField"
v-model="localContent" v-model="localContent"
:type="inputType" v-mask="inputProps.mask"
:type="inputProps.type"
autofocus autofocus
class="editable-field px-2" class="editable-field px-2"
@blur="editOFF" @blur="editOFF"
@ -28,6 +29,7 @@
import moment from 'moment'; import moment from 'moment';
import { mimeFromHex, formatBytes } from 'common/libs/utilities'; import { mimeFromHex, formatBytes } from 'common/libs/utilities';
import hexToBinary from 'common/libs/hexToBinary'; import hexToBinary from 'common/libs/hexToBinary';
import { mask } from 'vue-the-mask';
export default { export default {
name: 'WorkspaceQueryTableCell', name: 'WorkspaceQueryTableCell',
@ -41,11 +43,13 @@ export default {
case 'text': case 'text':
case 'mediumtext': case 'mediumtext':
return val.substring(0, 128); return val.substring(0, 128);
case 'date': case 'date': {
return moment(val).format('YYYY-MM-DD'); return moment(val).isValid() ? moment(val).format('YYYY-MM-DD') : val;
}
case 'datetime': case 'datetime':
case 'timestamp': case 'timestamp': {
return moment(val).format('YYYY-MM-DD HH:mm:ss.SSS'); return moment(val).isValid() ? moment(val).format('YYYY-MM-DD HH:mm:ss.SSS') : val;
}
case 'blob': case 'blob':
case 'mediumblob': case 'mediumblob':
case 'longblob': { case 'longblob': {
@ -64,6 +68,9 @@ export default {
} }
} }
}, },
directives: {
mask
},
props: { props: {
type: String, type: String,
field: String, field: String,
@ -76,24 +83,23 @@ export default {
}; };
}, },
computed: { computed: {
inputType () { inputProps () {
switch (this.type) { switch (this.type) {
case 'char': case 'char':
case 'varchar': case 'varchar':
case 'text': case 'text':
case 'mediumtext': case 'mediumtext':
return 'text'; return { type: 'text', mask: false };
case 'int': case 'int':
case 'tinyint': case 'tinyint':
case 'smallint': case 'smallint':
case 'mediumint': case 'mediumint':
return 'number'; return { type: 'number', mask: false };
case 'date': case 'date':
return 'date'; return { type: 'text', mask: '####-##-##' };
case 'datetime': case 'datetime':
case 'timestamp': case 'timestamp':
return 'datetime-local'; return { type: 'text', mask: '####-##-## ##:##:##.###' };// TODO: field length
// TODO: file uploader/viewer or bit field
case 'blob': case 'blob':
case 'mediumblob': case 'mediumblob':
case 'longblob': case 'longblob':
@ -108,8 +114,6 @@ export default {
return value === null ? ' is-null' : ''; return value === null ? ' is-null' : '';
}, },
editON () { editON () {
if (!['number', 'text'].includes(this.inputType)) return;// TODO: remove temporary block
this.$nextTick(() => { this.$nextTick(() => {
this.$refs.cell.blur(); this.$refs.cell.blur();