ChengLei Shao a7df0e3fd3
refactor: datetime field (#5084)
* refactor: date field support timezone, defaultToCurrentTime, and onUpdateToCurrentTime

* refactor: availableTypes unixTimestamp

* chore: defaultToCurrentTime

* chore: unix timestamp field

* fix: bug

* chore: field type map

* refactor: local improve

* fix: bug

* fix: bug

* chore: timezone test

* chore: test

* fix: test

* fix: test

* chore: field setter

* chore: test

* chore: date only field

* chore: test

* chore: test

* fix: bug

* fix: unixTimestamp

* fix: unixTimestamp

* chore: accuracy

* fix: bug

* fix: bug

* fix: unixTimestamp

* fix: unixTimestamp

* fix: date & datetime

* refactor:  add DateFieldInterface

* fix: bug

* chore: test

* chore: test

* chore: test

* refactor: locale improve

* refactor: local improve

* fix: bug

* refactor: unixTimestamp not support default value

* refactor: timezone

* refactor: datetimeNoTzFieldInterface

* refactor: locale improve

* refactor: locale improve

* fix: test

* fix: bug

* chore: datetime no tz field

* refactor: datetimeNoTz

* refactor: datetime

* fix: bug

* refactor: timeFormat

* style: collection fields style improve

* refactor: defaultToCurrentTime

* fix: datetime no tz

* chore: field type map

* fix: bug

* fix: bug

* refactor: createAt & updateAt

* fix: bug

* fix: no tz field with timezone

* refactor: dateonly

* fix: test

* chore: data type map

* fix: dateonly

* fix: dateonly

* fix: datetime

* refactor: locale improve

* refactor: unixtimestamp

* fix: merge bug

* fix: bug

* fix: datetime

* fix: datetime no tz

* fix: datetime no tz

* chore: mysql datetime map

* chore: test

* chore: test

* chore: test

* chore: datetimeTz field

* fix: no interface option

* refactor: update type

* refactor: update type

* fix: pg no tz field

* chore: save iso8601 format to no tz field

* fix: test

* fix: test

* refactor: gannt & calender startTime & endTime

* refactor: unixTimestamp

* chore: filter of datetime field

* chore: test

* chore: test

* fix: test

* fix: datetime no tz filter

* chore: test

* chore: test

* fix: datetime default value in mysql

* fix: sqlite test

* chore: test

* fix: test

* fix: test

* fix: $dateOn

* fix: bug

* fix: bug

* refactor: datepicker

* fix: test

* refactor: datePicker

* refactor: gantt setting

---------

Co-authored-by: katherinehhh <katherine_15995@163.com>
2024-09-10 15:25:20 +08:00

192 lines
4.9 KiB
TypeScript

/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import { Plugin } from '../application/Plugin';
import { InheritanceCollectionMixin } from './mixins/InheritanceCollectionMixin';
import {
CheckboxFieldInterface,
CheckboxGroupFieldInterface,
ChinaRegionFieldInterface,
CollectionSelectFieldInterface,
ColorFieldInterface,
CreatedAtFieldInterface,
CreatedByFieldInterface,
DatetimeFieldInterface,
EmailFieldInterface,
IconFieldInterface,
IdFieldInterface,
InputFieldInterface,
IntegerFieldInterface,
JsonFieldInterface,
LinkToFieldInterface,
M2MFieldInterface,
M2OFieldInterface,
MarkdownFieldInterface,
MultipleSelectFieldInterface,
NumberFieldInterface,
O2MFieldInterface,
O2OFieldInterface,
OHOFieldInterface,
OBOFieldInterface,
PasswordFieldInterface,
PercentFieldInterface,
PhoneFieldInterface,
RadioGroupFieldInterface,
RichTextFieldInterface,
SelectFieldInterface,
SubTableFieldInterface,
TableoidFieldInterface,
TextareaFieldInterface,
TimeFieldInterface,
UpdatedAtFieldInterface,
UpdatedByFieldInterface,
UrlFieldInterface,
SortFieldInterface,
UUIDFieldInterface,
NanoidFieldInterface,
UnixTimestampFieldInterface,
DateFieldInterface,
DatetimeNoTzFieldInterface,
} from './interfaces';
import {
GeneralCollectionTemplate,
SqlCollectionTemplate,
TreeCollectionTemplate,
ViewCollectionTemplate,
} from './templates';
import { DEFAULT_DATA_SOURCE_KEY, DEFAULT_DATA_SOURCE_TITLE } from '../data-source/data-source/DataSourceManager';
import { DataSource } from '../data-source/data-source/DataSource';
class MainDataSource extends DataSource {
async getDataSource() {
const service = await this.app.apiClient.request({
resource: 'collections',
action: 'list',
params: {
paginate: false,
appends: ['fields', 'category'],
filter: {
// inherit: false,
},
sort: ['sort'],
},
});
const collections = service?.data?.data || [];
return {
collections,
};
}
}
export class CollectionPlugin extends Plugin {
async load() {
this.dataSourceManager.addCollectionMixins([InheritanceCollectionMixin]);
this.addFieldInterfaces();
this.addCollectionTemplates();
this.addFieldInterfaces();
this.addFieldInterfaceGroups();
this.addMainDataSource();
}
addMainDataSource() {
if (this.options?.config?.enableRemoteDataSource === false) return;
this.dataSourceManager.addDataSource(MainDataSource, {
key: DEFAULT_DATA_SOURCE_KEY,
displayName: DEFAULT_DATA_SOURCE_TITLE,
});
}
addFieldInterfaceGroups() {
this.dataSourceManager.addFieldInterfaceGroups({
basic: {
label: '{{t("Basic")}}',
},
choices: {
label: '{{t("Choices")}}',
},
media: {
label: '{{t("Media")}}',
},
datetime: {
label: '{{t("Date & Time")}}',
},
relation: {
label: '{{t("Relation")}}',
},
advanced: {
label: '{{t("Advanced type")}}',
},
systemInfo: {
label: '{{t("System info")}}',
},
others: {
label: '{{t("Others")}}',
},
});
}
addFieldInterfaces() {
this.dataSourceManager.addFieldInterfaces([
CheckboxFieldInterface,
CheckboxGroupFieldInterface,
ChinaRegionFieldInterface,
CollectionSelectFieldInterface,
ColorFieldInterface,
CreatedAtFieldInterface,
CreatedByFieldInterface,
DatetimeFieldInterface,
EmailFieldInterface,
IconFieldInterface,
IdFieldInterface,
InputFieldInterface,
IntegerFieldInterface,
JsonFieldInterface,
LinkToFieldInterface,
M2MFieldInterface,
M2OFieldInterface,
MarkdownFieldInterface,
MultipleSelectFieldInterface,
NumberFieldInterface,
O2MFieldInterface,
O2OFieldInterface,
OHOFieldInterface,
OBOFieldInterface,
PasswordFieldInterface,
PercentFieldInterface,
PhoneFieldInterface,
RadioGroupFieldInterface,
RichTextFieldInterface,
SelectFieldInterface,
SubTableFieldInterface,
TableoidFieldInterface,
TextareaFieldInterface,
TimeFieldInterface,
UpdatedAtFieldInterface,
UpdatedByFieldInterface,
UrlFieldInterface,
SortFieldInterface,
UUIDFieldInterface,
NanoidFieldInterface,
UnixTimestampFieldInterface,
DateFieldInterface,
DatetimeNoTzFieldInterface,
]);
}
addCollectionTemplates() {
this.dataSourceManager.addCollectionTemplates([
GeneralCollectionTemplate,
SqlCollectionTemplate,
TreeCollectionTemplate,
ViewCollectionTemplate,
]);
}
}