Skip to content

Commit

Permalink
Start adding support for plain Time fields
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarHawk committed Jan 14, 2025
1 parent d0ff099 commit f12d038
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ _%>
<%_ } else if (field.fieldTypeBoolean) { _%>
<input type="<%= fieldInputType %>" class="form-check" name="<%= fieldName %>" id="field_<%= fieldName %>"
data-cy="<%= fieldName %>" formControlName="<%= fieldName %>" <% if (readonly) { %> [readonly]="true"<% } %>/>
<%_ } else if (field.fieldTypeTime) { _%>
<input type="time" class="form-control" name="<%= fieldName %>" id="field_<%= fieldName %>" data-cy="<%= fieldName %>"
formControlName="<%= fieldName %>"<% if (readonly) { %> [readonly]="true"<% } %>/>
<%_ } else { _%>
<input type="<%= fieldInputType %>" class="form-control" name="<%= fieldName %>" id="field_<%= fieldName %>" data-cy="<%= fieldName %>"
formControlName="<%= fieldName %>"<% if (field.id && !field.autoGenerate) { %> [readonly]="editForm.get('<%= primaryKey.name %>')!.disabled"<% } else if (readonly) { %> [readonly]="true"<% } %>/>
Expand Down
2 changes: 2 additions & 0 deletions generators/base-application/support/field-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const {
STRING,
UUID,
ZONED_DATE_TIME,
LOCAL_TIME,
IMAGE_BLOB,
ANY_BLOB,
TEXT_BLOB,
Expand All @@ -50,6 +51,7 @@ export function fieldIsEnum(fieldType) {
LOCAL_DATE,
INSTANT,
ZONED_DATE_TIME,
LOCAL_TIME,
DURATION,
UUID,
BOOLEAN,
Expand Down
3 changes: 2 additions & 1 deletion generators/base-application/support/prepare-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const NO_MAPPER = MapperTypes.NO;

const { CASSANDRA, COUCHBASE, NEO4J, SQL, MONGODB } = databaseTypes;

const { INSTANT, ZONED_DATE_TIME, DURATION, LOCAL_DATE, BIG_DECIMAL } = fieldTypes.CommonDBTypes;
const { INSTANT, ZONED_DATE_TIME, DURATION, LOCAL_DATE, BIG_DECIMAL, LOCAL_TIME } = fieldTypes.CommonDBTypes;

const { BYTES, BYTE_BUFFER } = fieldTypes.RelationalOnlyDBTypes;
const { IMAGE, TEXT } = fieldTypes.BlobTypes;
Expand Down Expand Up @@ -549,6 +549,7 @@ export function preparePostEntityCommonDerivedProperties(entity: Entity) {

entity.anyFieldIsZonedDateTime = fieldsType.includes(ZONED_DATE_TIME);
entity.anyFieldIsInstant = fieldsType.includes(INSTANT);
entity.anyFieldIsTime = fieldsType.includes(LOCAL_TIME);
entity.anyFieldIsDuration = fieldsType.includes(DURATION);
entity.anyFieldIsLocalDate = fieldsType.includes(LOCAL_DATE);
entity.anyFieldIsBigDecimal = fieldsType.includes(BIG_DECIMAL);
Expand Down
2 changes: 2 additions & 0 deletions generators/base-application/support/prepare-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const {
ANY_BLOB,
TEXT_BLOB,
BLOB,
LOCAL_TIME,
} = CommonDBTypes;
const { BYTES, BYTE_BUFFER } = RelationalOnlyDBTypes;

Expand Down Expand Up @@ -262,6 +263,7 @@ function _derivedProperties(field) {
fieldTypeTimed: fieldType === ZONED_DATE_TIME || fieldType === INSTANT,
fieldTypeCharSequence: fieldType === STRING || fieldType === UUID || fieldType === TEXT_BLOB,
fieldTypeTemporal: fieldType === ZONED_DATE_TIME || fieldType === INSTANT || fieldType === LOCAL_DATE,
fieldTypeTime: fieldType === LOCAL_TIME,
fieldValidationRequired: validationRules.includes(REQUIRED),
fieldValidationMin: validationRules.includes(MIN),
fieldValidationMinLength: validationRules.includes(MINLENGTH),
Expand Down
13 changes: 13 additions & 0 deletions generators/bootstrap-application/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ describe(`generator - ${generator}`, () => {
"anyFieldIsDuration": false,
"anyFieldIsInstant": false,
"anyFieldIsLocalDate": false,
"anyFieldIsTime": false,
"anyFieldIsTimeDerived": false,
"anyFieldIsUUID": true,
"anyFieldIsZonedDateTime": false,
Expand Down Expand Up @@ -305,6 +306,7 @@ describe(`generator - ${generator}`, () => {
"fieldTypeString": false,
"fieldTypeTemporal": false,
"fieldTypeTextBlob": false,
"fieldTypeTime": false,
"fieldTypeTimed": false,
"fieldTypeUUID": true,
"fieldTypeZonedDateTime": false,
Expand Down Expand Up @@ -403,6 +405,7 @@ describe(`generator - ${generator}`, () => {
"fieldTypeString": true,
"fieldTypeTemporal": false,
"fieldTypeTextBlob": false,
"fieldTypeTime": false,
"fieldTypeTimed": false,
"fieldTypeUUID": false,
"fieldTypeZonedDateTime": false,
Expand Down Expand Up @@ -503,6 +506,7 @@ describe(`generator - ${generator}`, () => {
"fieldTypeString": true,
"fieldTypeTemporal": false,
"fieldTypeTextBlob": false,
"fieldTypeTime": false,
"fieldTypeTimed": false,
"fieldTypeUUID": false,
"fieldTypeZonedDateTime": false,
Expand Down Expand Up @@ -593,6 +597,7 @@ describe(`generator - ${generator}`, () => {
"fieldTypeString": true,
"fieldTypeTemporal": false,
"fieldTypeTextBlob": false,
"fieldTypeTime": false,
"fieldTypeTimed": false,
"fieldTypeUUID": false,
"fieldTypeZonedDateTime": false,
Expand Down Expand Up @@ -683,6 +688,7 @@ describe(`generator - ${generator}`, () => {
"fieldTypeString": true,
"fieldTypeTemporal": false,
"fieldTypeTextBlob": false,
"fieldTypeTime": false,
"fieldTypeTimed": false,
"fieldTypeUUID": false,
"fieldTypeZonedDateTime": false,
Expand Down Expand Up @@ -778,6 +784,7 @@ describe(`generator - ${generator}`, () => {
"fieldTypeString": true,
"fieldTypeTemporal": false,
"fieldTypeTextBlob": false,
"fieldTypeTime": false,
"fieldTypeTimed": false,
"fieldTypeUUID": false,
"fieldTypeZonedDateTime": false,
Expand Down Expand Up @@ -869,6 +876,7 @@ describe(`generator - ${generator}`, () => {
"fieldTypeString": false,
"fieldTypeTemporal": false,
"fieldTypeTextBlob": false,
"fieldTypeTime": false,
"fieldTypeTimed": false,
"fieldTypeUUID": false,
"fieldTypeZonedDateTime": false,
Expand Down Expand Up @@ -951,6 +959,7 @@ describe(`generator - ${generator}`, () => {
"fieldTypeString": true,
"fieldTypeTemporal": false,
"fieldTypeTextBlob": false,
"fieldTypeTime": false,
"fieldTypeTimed": false,
"fieldTypeUUID": false,
"fieldTypeZonedDateTime": false,
Expand Down Expand Up @@ -1161,6 +1170,7 @@ describe(`generator - ${generator}`, () => {
"anyFieldIsDuration": false,
"anyFieldIsInstant": false,
"anyFieldIsLocalDate": false,
"anyFieldIsTime": false,
"anyFieldIsTimeDerived": false,
"anyFieldIsUUID": true,
"anyFieldIsZonedDateTime": false,
Expand Down Expand Up @@ -1272,6 +1282,7 @@ describe(`generator - ${generator}`, () => {
"fieldTypeString": false,
"fieldTypeTemporal": false,
"fieldTypeTextBlob": false,
"fieldTypeTime": false,
"fieldTypeTimed": false,
"fieldTypeUUID": true,
"fieldTypeZonedDateTime": false,
Expand Down Expand Up @@ -1536,6 +1547,7 @@ describe(`generator - ${generator}`, () => {
"anyFieldIsDuration": false,
"anyFieldIsInstant": false,
"anyFieldIsLocalDate": false,
"anyFieldIsTime": false,
"anyFieldIsTimeDerived": false,
"anyFieldIsUUID": true,
"anyFieldIsZonedDateTime": false,
Expand Down Expand Up @@ -1647,6 +1659,7 @@ describe(`generator - ${generator}`, () => {
"fieldTypeString": false,
"fieldTypeTemporal": false,
"fieldTypeTextBlob": false,
"fieldTypeTime": false,
"fieldTypeTimed": false,
"fieldTypeUUID": true,
"fieldTypeZonedDateTime": false,
Expand Down
3 changes: 2 additions & 1 deletion generators/client/support/entity-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const {
ZONED_DATE_TIME: TYPE_ZONED_DATE_TIME,
INSTANT: TYPE_INSTANT,
DURATION: TYPE_DURATION,
LOCAL_TIME: TYPE_TIME,
} = dbTypes.CommonDBTypes;

const TYPE_BYTES = dbTypes.RelationalOnlyDBTypes.BYTES;
Expand Down Expand Up @@ -85,7 +86,7 @@ const generateEntityClientFields = (
tsType = 'boolean';
} else if ([TYPE_INTEGER, TYPE_LONG, TYPE_FLOAT, TYPE_DOUBLE, TYPE_BIG_DECIMAL].includes(fieldType)) {
tsType = 'number';
} else if ([TYPE_STRING, TYPE_UUID, TYPE_DURATION, TYPE_BYTES, TYPE_BYTE_BUFFER].includes(fieldType)) {
} else if ([TYPE_STRING, TYPE_UUID, TYPE_DURATION, TYPE_BYTES, TYPE_BYTE_BUFFER, TYPE_TIME].includes(fieldType)) {
tsType = 'string';
if ([TYPE_BYTES, TYPE_BYTE_BUFFER].includes(fieldType) && field.fieldTypeBlobContent !== 'text') {
variablesWithTypes.push(`${fieldName}ContentType?: ${nullable ? 'string | null' : 'string'}`);
Expand Down
1 change: 1 addition & 0 deletions generators/client/support/types-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('generator - client - support - type-utils', () => {
"Instant": "dayjs.Dayjs",
"Integer": "number",
"LocalDate": "dayjs.Dayjs",
"LocalTime": "string",
"Long": "number",
"String": "string",
"TextBlob": "string",
Expand Down
20 changes: 17 additions & 3 deletions generators/entity/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,22 @@ const { NO: NO_MAPPER, MAPSTRUCT } = MapperTypes;

const { CommonDBTypes, RelationalOnlyDBTypes, BlobTypes } = fieldTypes;

const { BIG_DECIMAL, BOOLEAN, DOUBLE, DURATION, ENUM, FLOAT, INTEGER, INSTANT, LOCAL_DATE, LONG, STRING, UUID, ZONED_DATE_TIME } =
CommonDBTypes;
const {
BIG_DECIMAL,
BOOLEAN,
DOUBLE,
DURATION,
ENUM,
FLOAT,
INTEGER,
INSTANT,
LOCAL_DATE,
LONG,
STRING,
UUID,
ZONED_DATE_TIME,
LOCAL_TIME,
} = CommonDBTypes;
const { BYTES, BYTE_BUFFER } = RelationalOnlyDBTypes;
const { ANY, IMAGE, TEXT } = BlobTypes;

Expand Down Expand Up @@ -485,7 +499,7 @@ async function askForField(this: EntityGenerator) {
{ value: BOOLEAN, name: 'Boolean' },
{ value: ENUM, name: 'Enumeration (Java enum type)' },
{ value: UUID, name: 'UUID' },
{ value: UUID, name: 'UUID' },
{ value: LOCAL_TIME, name: 'LocalTime' },
...(databaseType === CASSANDRA ? [{ value: BYTE_BUFFER, name: '[BETA] Blob' }] : [{ value: BYTES, name: '[BETA] Blob' }]),
],
default: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import java.time.Instant;
import java.time.LocalDate;
<%_ } if (anyFieldIsZonedDateTime) { _%>
import java.time.ZonedDateTime;
<%_ } if (anyFieldIsTime) { _%>
import java.time.LocalTime;
<%_ } if (anyFieldIsDuration) { _%>
import java.time.Duration;
<%_ } if (entityContainsCollectionField) { _%>
Expand Down
7 changes: 6 additions & 1 deletion generators/liquibase/support/prepare-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import type { ApplicationType } from '../../../lib/types/application/application
const { MYSQL, MARIADB } = databaseTypes;
const { CommonDBTypes, RelationalOnlyDBTypes, BlobTypes } = fieldTypes;

const { STRING, INTEGER, LONG, BIG_DECIMAL, FLOAT, DOUBLE, UUID, BOOLEAN, LOCAL_DATE, ZONED_DATE_TIME, INSTANT, DURATION } = CommonDBTypes;
const { STRING, INTEGER, LONG, BIG_DECIMAL, FLOAT, DOUBLE, UUID, BOOLEAN, LOCAL_DATE, ZONED_DATE_TIME, INSTANT, DURATION, LOCAL_TIME } =
CommonDBTypes;
const { BYTES } = RelationalOnlyDBTypes;
const { TEXT } = BlobTypes;

Expand Down Expand Up @@ -74,6 +75,10 @@ function parseLiquibaseColumnType(field: Field) {
return 'bigint';
}

if (fieldType === LOCAL_TIME) {
return 'time';
}

if (fieldType === UUID) {
// eslint-disable-next-line no-template-curly-in-string
return '${uuidType}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ _%>
type="date"
<%- include('react_validators'); %>
/>
<%_ } else if (field.fieldTypeTime) { _%>
type="time"
placeholder="HH:mm"
<%- include('react_validators'); %>
<%_ } else if (field.fieldIsEnum) {_%>
type="select"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
fieldInputType = 'date';
} else if (field.fieldTypeTimed) {
fieldInputType = 'datetime-local';
} else if (field.fieldTypeTime) {
fieldInputType = 'time';
} else if (field.fieldTypeBoolean) {
fieldInputType = 'checkbox';
fieldInputClass = 'form-check';
Expand Down
1 change: 1 addition & 0 deletions lib/application/field-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const fieldTypes = {
ZONED_DATE_TIME: 'ZonedDateTime',
INSTANT: 'Instant',
DURATION: 'Duration',
TIME: 'LocalTime',
BYTES: 'byte[]', // Supported by mongodb at CI samples
BYTE_BUFFER: 'ByteBuffer',
...blobFieldTypes,
Expand Down
2 changes: 2 additions & 0 deletions lib/jhipster/field-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const CommonDBTypes = {
DURATION: 'Duration',
BYTES: 'byte[]', // Supported by mongodb at CI samples
BYTE_BUFFER: 'ByteBuffer', // Supported by cassandra at CI samples
LOCAL_TIME: 'LocalTime',
};

export const RelationalOnlyDBTypes = {
Expand Down Expand Up @@ -78,6 +79,7 @@ const CommonDBValidations = {
UUID: new Set([REQUIRED, UNIQUE]),
Instant: new Set([REQUIRED, UNIQUE]),
Duration: new Set([REQUIRED, UNIQUE]),
LocalTime: new Set([REQUIRED, UNIQUE]),
};

export default {
Expand Down
1 change: 1 addition & 0 deletions lib/types/application/entity.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export interface Entity<F extends BaseField = Field, R extends BaseRelationship
anyFieldIsDuration: boolean;
anyFieldIsInstant: boolean;
anyFieldIsLocalDate: boolean;
anyFieldIsTime: boolean;
/**
* Any field is of type ZonedDateTime or Instant
*/
Expand Down
1 change: 1 addition & 0 deletions lib/types/application/field.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export interface Field extends Property, BaseField {
fieldTypeTimed?: boolean;
fieldTypeLocalDate?: boolean;
fieldTypeDateTime?: boolean;
fieldTypeTime?: boolean;
/** @deprecated */
fieldTypeTemporal: boolean;
/** @deprecated */
Expand Down

0 comments on commit f12d038

Please sign in to comment.