From 430e926d2f11d10368c67013104e23d2cbf303d1 Mon Sep 17 00:00:00 2001 From: elvus Date: Fri, 1 Jul 2022 18:56:45 -0400 Subject: [PATCH] Add date format option to DatePickerCell --- .../spreadsheet/components/EditColumn.vue | 15 +++++++- .../spreadsheet/components/EditableCell.vue | 1 + .../components/editColumn/DateOptions.vue | 38 +++++++++++++++++++ .../editableCell/DatePickerCell.vue | 11 +++++- packages/nc-gui/helpers/dateFormatHelper.js | 9 +++++ 5 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 packages/nc-gui/components/project/spreadsheet/components/editColumn/DateOptions.vue create mode 100644 packages/nc-gui/helpers/dateFormatHelper.js diff --git a/packages/nc-gui/components/project/spreadsheet/components/EditColumn.vue b/packages/nc-gui/components/project/spreadsheet/components/EditColumn.vue index 03d75d602c..a6f1577f9c 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/EditColumn.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/EditColumn.vue @@ -145,7 +145,13 @@ there are multiple values associated with a cell - + + + diff --git a/packages/nc-gui/components/project/spreadsheet/components/editColumn/DateOptions.vue b/packages/nc-gui/components/project/spreadsheet/components/editColumn/DateOptions.vue new file mode 100644 index 0000000000..3be16ef191 --- /dev/null +++ b/packages/nc-gui/components/project/spreadsheet/components/editColumn/DateOptions.vue @@ -0,0 +1,38 @@ + + diff --git a/packages/nc-gui/components/project/spreadsheet/components/editableCell/DatePickerCell.vue b/packages/nc-gui/components/project/spreadsheet/components/editableCell/DatePickerCell.vue index 03fbac7738..d98187ac9f 100644 --- a/packages/nc-gui/components/project/spreadsheet/components/editableCell/DatePickerCell.vue +++ b/packages/nc-gui/components/project/spreadsheet/components/editableCell/DatePickerCell.vue @@ -18,6 +18,7 @@ import dayjs from 'dayjs' export default { name: 'DatePickerCell', props: { + column: Object, value: [String, Date] }, computed: { @@ -35,10 +36,18 @@ export default { }, date() { if (!this.value || this.localState) { - return this.localState + return this.localState ? dayjs(this.localState).format(this.datepickerMeta.date_format || 'YYYY-MM-DD') : this.localState } return 'Invalid Date' }, + datepickerMeta() { + return { + date_format: 'YYYY-MM-DD', + ...(this.column && this.column.meta + ? this.column.meta + : {}) + } + }, parentListeners() { const $listeners = {} diff --git a/packages/nc-gui/helpers/dateFormatHelper.js b/packages/nc-gui/helpers/dateFormatHelper.js new file mode 100644 index 0000000000..032e44f829 --- /dev/null +++ b/packages/nc-gui/helpers/dateFormatHelper.js @@ -0,0 +1,9 @@ +export const dateFormat = [ + 'DD-MM-YYYY', 'MM-DD-YYYY', 'YYYY-MM-DD', + 'DD/MM/YYYY', 'MM/DD/YYYY', 'YYYY/MM/DD', + 'DD MM YYYY', 'MM DD YYYY', 'YYYY MM DD' +] + +export function validateDateFormat(v) { + return dateFormat.includes(v) +} \ No newline at end of file