@anglr/datetime 5.0.0-beta.20221019112435 → 5.0.0-beta.20221020045240
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +16 -13
- package/es2015/src/misc/types.js.map +1 -1
- package/es2015/src/misc/utils.js.map +1 -1
- package/es2015/src/misc/validators.js.map +1 -1
- package/es2015/src/modules/dateTime/directives/dateTime/dateTime.directive.js +233 -0
- package/es2015/src/modules/dateTime/directives/dateTime/dateTime.directive.js.map +1 -0
- package/es2015/src/modules/dateTime/directives/dateTimeBase.js +25 -41
- package/es2015/src/modules/dateTime/directives/dateTimeBase.js.map +1 -1
- package/es2015/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.js +16 -17
- package/es2015/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.js.map +1 -1
- package/es2015/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.js +10 -13
- package/es2015/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.js.map +1 -1
- package/es2015/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.js +9 -11
- package/es2015/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.js.map +1 -1
- package/es2015/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.js +6 -8
- package/es2015/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.js.map +1 -1
- package/es2015/src/modules/dateTime/directives/index.js +1 -1
- package/es2015/src/modules/dateTime/directives/index.js.map +1 -1
- package/es2015/src/modules/dateTime/modules/dateTime.module.js +7 -3
- package/es2015/src/modules/dateTime/modules/dateTime.module.js.map +1 -1
- package/es2015/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.js +5 -22
- package/es2015/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.js.map +1 -1
- package/es2020/src/misc/types.js.map +1 -1
- package/es2020/src/misc/utils.js.map +1 -1
- package/es2020/src/misc/validators.js.map +1 -1
- package/es2020/src/modules/dateTime/directives/dateTime/dateTime.directive.js +230 -0
- package/es2020/src/modules/dateTime/directives/dateTime/dateTime.directive.js.map +1 -0
- package/es2020/src/modules/dateTime/directives/dateTimeBase.js +25 -41
- package/es2020/src/modules/dateTime/directives/dateTimeBase.js.map +1 -1
- package/es2020/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.js +16 -17
- package/es2020/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.js.map +1 -1
- package/es2020/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.js +10 -13
- package/es2020/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.js.map +1 -1
- package/es2020/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.js +9 -11
- package/es2020/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.js.map +1 -1
- package/es2020/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.js +6 -8
- package/es2020/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.js.map +1 -1
- package/es2020/src/modules/dateTime/directives/index.js +1 -1
- package/es2020/src/modules/dateTime/directives/index.js.map +1 -1
- package/es2020/src/modules/dateTime/modules/dateTime.module.js +7 -3
- package/es2020/src/modules/dateTime/modules/dateTime.module.js.map +1 -1
- package/es2020/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.js +5 -22
- package/es2020/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.js.map +1 -1
- package/package.json +1 -1
- package/src/misc/types.d.ts +2 -2
- package/src/misc/types.d.ts.map +1 -1
- package/src/misc/utils.d.ts +2 -2
- package/src/misc/utils.d.ts.map +1 -1
- package/src/misc/validators.d.ts +5 -5
- package/src/misc/validators.d.ts.map +1 -1
- package/src/modules/dateTime/directives/dateTime/dateTime.directive.d.ts +128 -0
- package/src/modules/dateTime/directives/dateTime/dateTime.directive.d.ts.map +1 -0
- package/src/modules/dateTime/directives/dateTimeBase.d.ts +19 -27
- package/src/modules/dateTime/directives/dateTimeBase.d.ts.map +1 -1
- package/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.d.ts +3 -2
- package/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.d.ts.map +1 -1
- package/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.d.ts +4 -4
- package/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.d.ts.map +1 -1
- package/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.d.ts +4 -4
- package/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.d.ts.map +1 -1
- package/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.d.ts +2 -2
- package/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.d.ts.map +1 -1
- package/src/modules/dateTime/directives/index.d.ts +1 -1
- package/src/modules/dateTime/directives/index.d.ts.map +1 -1
- package/src/modules/dateTime/modules/dateTime.module.d.ts +7 -6
- package/src/modules/dateTime/modules/dateTime.module.d.ts.map +1 -1
- package/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.d.ts +6 -8
- package/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.d.ts.map +1 -1
- package/version.bak +1 -1
- package/es2015/src/modules/dateTime/directives/dateTimeRestrictedBase.js +0 -152
- package/es2015/src/modules/dateTime/directives/dateTimeRestrictedBase.js.map +0 -1
- package/es2020/src/modules/dateTime/directives/dateTimeRestrictedBase.js +0 -149
- package/es2020/src/modules/dateTime/directives/dateTimeRestrictedBase.js.map +0 -1
- package/src/modules/dateTime/directives/dateTimeRestrictedBase.d.ts +0 -74
- package/src/modules/dateTime/directives/dateTimeRestrictedBase.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/misc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AC,CAAC,EAAE,KAAK,IAAI,IAAI;YAC7B,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,IAAI;SAC9B,CAAC;KACL;IAED,uBAAuB;IACvB,IAAG,cAAc,IAAI,mBAAmB,CAAC,oBAAoB,EAC7D;QACI,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;KACnF;IAED,kBAAkB;IAClB,IAAG,cAAc,IAAI,mBAAmB,CAAC,eAAe,EACxD;QACI,+CAA+C;QAC/C,IAAG,OAAO,CAAC,YAAY,CAAC,EACxB;YACI,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;SAC5E;QAED,OAAO,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;KACrC;IAED,IAAG,cAAc,IAAI,mBAAmB,CAAC,aAAa,EACtD;QACI,KAAK,CAAC,aAAa,EAAE,CAAC;KACzB;IAED,OAAO,KAAK,CAAC,KAAK,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAkB,KAAc;IAE3D,OAAO,UAAU,CAAC,KAAK,CAAC;QACjB,MAAM,CAAgB,MAAM,CAAC,IAAI,KAAK;QACtC,MAAM,CAAgB,IAAI,CAAC,IAAI,KAAK,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAQ,KAAqD;IAE/F,IAAG,eAAe,CAAC,KAAK,CAAC,EACzB;QACI,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;KAC7F;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import {isBlank, isJsObject, isPresent, isString, nameof} from '@jscrpt/common';\n\nimport {DateTimeValue} from '../interfaces';\nimport {DateApi, DateApiObject} from '../services';\nimport {DateTimeValueFormat} from './enums';\nimport {DateTimeInputOutputValue, DateTimeObjectValue} from './types';\n\n/**\n * Parses date time input output value\n * @param value - Value to be parsed\n * @param dateApi - Date api used for obtaining result\n * @param dateTimeFormat - Date time format type, optional, if not specified autodetection of format will be used\n * @param stringFormat - String format for parsing string dates, required only for string dates\n */\nexport function parseDateTime<TDate = unknown>(value: DateTimeInputOutputValue<TDate>|undefined|null,\n dateApi: DateApi<TDate>,\n dateTimeFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): DateTimeObjectValue<TDate>|undefined|null\n{\n if(isBlank(value))\n {\n return value;\n }\n\n //format is specified\n if(isPresent(dateTimeFormat))\n {\n //string format required, but format string was not provided\n if(dateTimeFormat == DateTimeValueFormat.FormattedString && isBlank(stringFormat))\n {\n throw new Error('DateTime: unable to parse string date, because format is missing!');\n }\n\n //value is range\n if(isDateTimeValue(value))\n {\n //requirested format is different\n if(dateTimeFormat != DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: requested datetime format is not range, but value is range!');\n }\n\n return [\n isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n ];\n }\n\n //value should be date instance, or number, or string, but it is not\n if(dateTimeFormat != DateTimeValueFormat.DateInstance &&\n dateTimeFormat != DateTimeValueFormat.FormattedString &&\n dateTimeFormat != DateTimeValueFormat.UnixTimestamp)\n {\n throw new Error('DateTime: unable to get date time value, should be date instance, or string, or number!');\n }\n\n //value is string, instance of date or unix timestamp\n return dateApi.getValue(value, stringFormat ?? undefined);\n }\n\n //value is range\n if(isDateTimeValue(value))\n {\n return [\n isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance , null) as DateApiObject<TDate>,\n ];\n }\n\n //string format, but format string was not provided\n if(isString(value) && isBlank(stringFormat))\n {\n throw new Error('DateTime: unable to parse string date, because format is missing!');\n }\n\n //value is string, instance of date or unix timestamp\n return dateApi.getValue(value, stringFormat ?? undefined);\n}\n\n/**\n * Formats value into specified format of date time\n * @param value - Value that should be converted to input output date time value\n * @param dateTimeFormat - Date time format type\n * @param stringFormat - String format for parsing string dates, required only for string dates\n */\nexport function formatDateTime<TDate = unknown>(value: DateTimeObjectValue<TDate>|undefined|null,\n dateTimeFormat: DateTimeValueFormat,\n stringFormat: string|undefined|null): DateTimeInputOutputValue<TDate>|undefined|null\n{\n if(isBlank(value))\n {\n return value;\n }\n\n //value is range\n if(Array.isArray(value))\n {\n //range is expected\n if(dateTimeFormat != DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: value is array of values, but format is not range!');\n }\n\n return {\n from: value[0]?.value ?? null,\n to: value[1]?.value ?? null,\n };\n }\n\n //range is not expected\n if(dateTimeFormat == DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: value is not array of values, but format is range!');\n }\n\n //string date time\n if(dateTimeFormat == DateTimeValueFormat.FormattedString)\n {\n //string format is missing for string date time\n if(isBlank(stringFormat))\n {\n throw new Error('DateTime: missing string format for string date time!');\n }\n\n return value.format(stringFormat);\n }\n\n if(dateTimeFormat == DateTimeValueFormat.UnixTimestamp)\n {\n value.unixTimestamp();\n }\n\n return value.value;\n}\n\n/**\n * Tests whether value is `DateTimeValue`\n * @param value - Value that is tested\n */\nexport function isDateTimeValue<TDate = unknown>(value: unknown): value is DateTimeValue<TDate>\n{\n return isJsObject(value) &&\n nameof<DateTimeValue>('from') in value &&\n nameof<DateTimeValue>('to') in value;\n}\n\n/**\n * Gets single date time value, use in places where ranged date time can not be used\n * @param value - Value to be examined\n */\nexport function getSingleDateTimeValue<TDate>(value: DateTimeInputOutputValue<TDate>|undefined|null):
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/misc/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,E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AI;SAC9B,CAAC;KACL;IAED,uBAAuB;IACvB,IAAG,cAAc,IAAI,mBAAmB,CAAC,oBAAoB,EAC7D;QACI,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;KACnF;IAED,kBAAkB;IAClB,IAAG,cAAc,IAAI,mBAAmB,CAAC,eAAe,EACxD;QACI,+CAA+C;QAC/C,IAAG,OAAO,CAAC,YAAY,CAAC,EACxB;YACI,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;SAC5E;QAED,OAAO,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;KACrC;IAED,IAAG,cAAc,IAAI,mBAAmB,CAAC,aAAa,EACtD;QACI,KAAK,CAAC,aAAa,EAAE,CAAC;KACzB;IAED,OAAO,KAAK,CAAC,KAAK,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAkB,KAAc;IAE3D,OAAO,UAAU,CAAC,KAAK,CAAC;QACjB,MAAM,CAAgB,MAAM,CAAC,IAAI,KAAK;QACtC,MAAM,CAAgB,IAAI,CAAC,IAAI,KAAK,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAQ,KAAqD;IAE/F,IAAG,eAAe,CAAC,KAAK,CAAC,EACzB;QACI,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;KAC7F;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import {isBlank, isJsObject, isPresent, isString, nameof} from '@jscrpt/common';\n\nimport {DateTimeValue} from '../interfaces';\nimport {DateApi, DateApiObject, DateValue} from '../services';\nimport {DateTimeValueFormat} from './enums';\nimport {DateTimeInputOutputValue, DateTimeObjectValue} from './types';\n\n/**\n * Parses date time input output value\n * @param value - Value to be parsed\n * @param dateApi - Date api used for obtaining result\n * @param dateTimeFormat - Date time format type, optional, if not specified autodetection of format will be used\n * @param stringFormat - String format for parsing string dates, required only for string dates\n */\nexport function parseDateTime<TDate = unknown>(value: DateTimeInputOutputValue<TDate>|undefined|null,\n dateApi: DateApi<TDate>,\n dateTimeFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): DateTimeObjectValue<TDate>|undefined|null\n{\n if(isBlank(value))\n {\n return value;\n }\n\n //format is specified\n if(isPresent(dateTimeFormat))\n {\n //string format required, but format string was not provided\n if(dateTimeFormat == DateTimeValueFormat.FormattedString && isBlank(stringFormat))\n {\n throw new Error('DateTime: unable to parse string date, because format is missing!');\n }\n\n //value is range\n if(isDateTimeValue(value))\n {\n //requirested format is different\n if(dateTimeFormat != DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: requested datetime format is not range, but value is range!');\n }\n\n return [\n isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n ];\n }\n\n //value should be date instance, or number, or string, but it is not\n if(dateTimeFormat != DateTimeValueFormat.DateInstance &&\n dateTimeFormat != DateTimeValueFormat.FormattedString &&\n dateTimeFormat != DateTimeValueFormat.UnixTimestamp)\n {\n throw new Error('DateTime: unable to get date time value, should be date instance, or string, or number!');\n }\n\n //value is string, instance of date or unix timestamp\n return dateApi.getValue(value, stringFormat ?? undefined);\n }\n\n //value is range\n if(isDateTimeValue(value))\n {\n return [\n isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance , null) as DateApiObject<TDate>,\n ];\n }\n\n //string format, but format string was not provided\n if(isString(value) && isBlank(stringFormat))\n {\n throw new Error('DateTime: unable to parse string date, because format is missing!');\n }\n\n //value is string, instance of date or unix timestamp\n return dateApi.getValue(value, stringFormat ?? undefined);\n}\n\n/**\n * Formats value into specified format of date time\n * @param value - Value that should be converted to input output date time value\n * @param dateTimeFormat - Date time format type\n * @param stringFormat - String format for parsing string dates, required only for string dates\n */\nexport function formatDateTime<TDate = unknown>(value: DateTimeObjectValue<TDate>|undefined|null,\n dateTimeFormat: DateTimeValueFormat,\n stringFormat: string|undefined|null): DateTimeInputOutputValue<TDate>|undefined|null\n{\n if(isBlank(value))\n {\n return value;\n }\n\n //value is range\n if(Array.isArray(value))\n {\n //range is expected\n if(dateTimeFormat != DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: value is array of values, but format is not range!');\n }\n\n return {\n from: value[0]?.value ?? null,\n to: value[1]?.value ?? null,\n };\n }\n\n //range is not expected\n if(dateTimeFormat == DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: value is not array of values, but format is range!');\n }\n\n //string date time\n if(dateTimeFormat == DateTimeValueFormat.FormattedString)\n {\n //string format is missing for string date time\n if(isBlank(stringFormat))\n {\n throw new Error('DateTime: missing string format for string date time!');\n }\n\n return value.format(stringFormat);\n }\n\n if(dateTimeFormat == DateTimeValueFormat.UnixTimestamp)\n {\n value.unixTimestamp();\n }\n\n return value.value;\n}\n\n/**\n * Tests whether value is `DateTimeValue`\n * @param value - Value that is tested\n */\nexport function isDateTimeValue<TDate = unknown>(value: unknown): value is DateTimeValue<TDate>\n{\n return isJsObject(value) &&\n nameof<DateTimeValue>('from') in value &&\n nameof<DateTimeValue>('to') in value;\n}\n\n/**\n * Gets single date time value, use in places where ranged date time can not be used\n * @param value - Value to be examined\n */\nexport function getSingleDateTimeValue<TDate>(value: DateTimeInputOutputValue<TDate>|undefined|null): DateValue|TDate|null|undefined\n{\n if(isDateTimeValue(value))\n {\n throw new Error('DateTime: Unable to apply ranged date time input as value restriction!');\n }\n\n return value;\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/misc/validators.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,qBAAqB,EAAE,kBAAkB,EAAC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YAED,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import {AbstractControl, ValidationErrors, ValidatorFn} from '@angular/forms';\nimport {ModelPropertyMetadata, ValidatorFnFactory} from '@anglr/common/forms';\nimport {isBlank, isNumber, isString} from '@jscrpt/common';\n\nimport {DateApi} from '../services';\nimport {DateTimeValueObject} from '../interfaces/dateTime/datetime.interface';\nimport {getSingleDateTimeValue, parseDateTime} from './utils';\nimport {DateTimeValueFormat} from './enums';\nimport {DateTimeInputOutputValue} from './types';\nimport {DateTimeBase} from '../modules/dateTime/directives/dateTimeBase';\nimport {DATE_API} from './tokens';\n\n//TODO: add decorators for min and max date time\n\n/**\n * Validations arguments for date time validators for model based forms\n */\nexport interface DateTimeValidationArgs<TDate = unknown>\n{\n /**\n * Format of validated value\n */\n valueFormat?: DateTimeValueFormat|null;\n\n /**\n * Format of string value\n */\n stringFormat?: string|null;\n\n /**\n * Max allowed value\n */\n maxValue?: string|number|TDate|Date|DateTimeBase<TDate>;\n\n /**\n * Min allowed value\n */\n minValue?: string|number|TDate|Date|DateTimeBase<TDate>;\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime\n * @param dateApi - Date api used for parsing date time\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value))\n {\n return null;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n if(!Array.isArray(parsedValue))\n {\n if(!parsedValue.isValid())\n {\n return {\n 'datetime': stringFormat\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Factory function that creates validator function factory\n * @param args - Static arguments for date time validator\n */\nexport function dateTimeModelValidatorFactory<TDate = unknown>(args: DateTimeValidationArgs<TDate>): ValidatorFnFactory<DateTimeValidationArgs<TDate>>\n{\n return new ValidatorFnFactory<DateTimeValidationArgs<TDate>>(args =>\n {\n const dateApi = args.injector?.get(DATE_API, null);\n\n if(!dateApi)\n {\n throw new Error('DateTime: missing DateApi! Please provide one.');\n }\n\n return datetimeValidator(dateApi, args.valueFormat, args.stringFormat);\n }, args);\n}\n\n/**\n * Sets date time validator, with default formats\n */\nexport function DateTime(): PropertyDecorator\n/**\n * Sets date time validator, with default string format\n * @param valueFormat - Format of validated value\n */\nexport function DateTime(valueFormat: DateTimeValueFormat): PropertyDecorator\n/**\n * Sets date time validator, with default value format\n * @param stringFormat - Format of string value\n */\nexport function DateTime(stringFormat: string|null): PropertyDecorator\n/**\n * Sets date time validator\n * @param valueFormat - Format of validated value\n * @param stringFormat - Format of string value\n */\nexport function DateTime(valueFormat: DateTimeValueFormat, stringFormat: string): PropertyDecorator\n/**\n * Sets date time validator to property on which is used\n */\nexport function DateTime(valueFormatOrStringFormat?: DateTimeValueFormat|string|null, stringFormat?: string|undefined|null): PropertyDecorator\n{\n let valueFormat: DateTimeValueFormat|undefined|null;\n\n if(isNumber(valueFormatOrStringFormat))\n {\n valueFormat = valueFormatOrStringFormat;\n }\n\n if(isString(valueFormatOrStringFormat))\n {\n stringFormat = valueFormatOrStringFormat;\n }\n\n return ModelPropertyMetadata(\n {\n validators: [dateTimeModelValidatorFactory(\n {\n stringFormat,\n valueFormat,\n })]\n });\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime max value\n * @param dateApi - Date api used for parsing date time\n * @param maxValue - Maximal date time value that should be used for validation against\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeMaxValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n maxValue: string|number|TDate|Date|DateTimeBase<TDate>|undefined|null,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value) || isBlank(maxValue))\n {\n return null;\n }\n\n if(maxValue instanceof DateTimeBase<TDate>)\n {\n const value = getSingleDateTimeValue(maxValue.value);\n\n //no validation\n if(isBlank(value))\n {\n return null;\n }\n\n maxValue = value;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n const maxDateTime = dateApi.getValue(maxValue as string|number|TDate, stringFormat ?? undefined);\n\n if(!Array.isArray(parsedValue))\n {\n if(parsedValue.isValid() && !parsedValue.isBefore(maxDateTime.value))\n {\n return {\n 'datetimemax': maxDateTime.value\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime min value\n * @param dateApi - Date api used for parsing date time\n * @param minValue - Minimal date time value that should be used for validation against\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeMinValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n minValue: string|number|TDate|Date|DateTimeBase<TDate>|undefined|null,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value) || isBlank(minValue))\n {\n return null;\n }\n\n if(minValue instanceof DateTimeBase<TDate>)\n {\n const value = getSingleDateTimeValue(minValue.value);\n\n //no validation\n if(isBlank(value))\n {\n return null;\n }\n\n minValue = value;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n const minDateTime = dateApi.getValue(minValue as string|number|TDate, stringFormat ?? undefined);\n\n if(!Array.isArray(parsedValue))\n {\n if(parsedValue.isValid() && !parsedValue.isAfter(minDateTime.value))\n {\n return {\n 'datetimemin': minDateTime.value\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Validations functions for datetime\n */\nexport class Validators\n{\n /**\n * Creates validator function that validates control if its value is valid datetime value\n * @param datetime - Object storing information about datetime value\n */\n public static datetime<TDate = any>(datetime: DateTimeValueObject<TDate>): ValidatorFn\n {\n return (): ValidationErrors|null =>\n {\n if(!datetime.valid)\n {\n return {\n 'datetime': true\n };\n }\n\n return null;\n };\n }\n\n /**\n * Creates validator function that validates control if its value is withing range of minimal datetime value\n * @param datetime - Object storing information about datetime value\n * @param dateApi - Date api object\n */\n public static minDatetime<TDate = any>(datetime: DateTimeValueObject<TDate>, dateApi: DateApi<TDate>): ValidatorFn\n {\n return (control: AbstractControl): ValidationErrors|null =>\n {\n if(!!control.value &&\n datetime.valid &&\n datetime.minValue &&\n dateApi.getValue(control.value).isBefore(datetime.minValue))\n {\n return {\n 'minDatetime': datetime.minValue,\n 'actualValue': control.value\n };\n }\n\n return null;\n };\n }\n\n /**\n * Creates validator function that validates control if its value is withing range of maximal datetime value\n * @param datetime - Object storing information about datetime value\n * @param dateApi - Date api object\n */\n public static maxDatetime<TDate = any>(datetime: DateTimeValueObject<TDate>, dateApi: DateApi<TDate>): ValidatorFn\n {\n return (control: AbstractControl): ValidationErrors|null =>\n {\n if(!!control.value &&\n datetime.valid &&\n datetime.maxValue &&\n dateApi.getValue(control.value).isAfter(datetime.maxValue))\n {\n return {\n 'maxDatetime': datetime.maxValue,\n 'actualValue': control.value\n };\n }\n\n return null;\n };\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/misc/validators.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,qBAAqB,EAAE,kBAAkB,EAAC,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAI3D,OAAO,EAAC,sBAAsB,EAAE,aAA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FnFactory} from '@anglr/common/forms';\nimport {isBlank, isNumber, isString} from '@jscrpt/common';\n\nimport {DateApi, DateValue} from '../services';\nimport {DateTimeValueObject} from '../interfaces/dateTime/datetime.interface';\nimport {getSingleDateTimeValue, parseDateTime} from './utils';\nimport {DateTimeValueFormat} from './enums';\nimport {DateTimeInputOutputValue} from './types';\nimport {DateTimeBase} from '../modules/dateTime/directives/dateTimeBase';\nimport {DATE_API} from './tokens';\n\n//TODO: add decorators for min and max date time\n\n/**\n * Validations arguments for date time validators for model based forms\n */\nexport interface DateTimeValidationArgs<TDate = unknown>\n{\n /**\n * Format of validated value\n */\n valueFormat?: DateTimeValueFormat|null;\n\n /**\n * Format of string value\n */\n stringFormat?: string|null;\n\n /**\n * Max allowed value\n */\n maxValue?: DateValue|TDate|DateTimeBase<TDate>;\n\n /**\n * Min allowed value\n */\n minValue?: DateValue|TDate|DateTimeBase<TDate>;\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime\n * @param dateApi - Date api used for parsing date time\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value))\n {\n return null;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n if(!Array.isArray(parsedValue))\n {\n if(!parsedValue.isValid())\n {\n return {\n 'datetime': stringFormat\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Factory function that creates validator function factory\n * @param args - Static arguments for date time validator\n */\nexport function dateTimeModelValidatorFactory<TDate = unknown>(args: DateTimeValidationArgs<TDate>): ValidatorFnFactory<DateTimeValidationArgs<TDate>>\n{\n return new ValidatorFnFactory<DateTimeValidationArgs<TDate>>(args =>\n {\n const dateApi = args.injector?.get(DATE_API, null);\n\n if(!dateApi)\n {\n throw new Error('DateTime: missing DateApi! Please provide one.');\n }\n\n return datetimeValidator(dateApi, args.valueFormat, args.stringFormat);\n }, args);\n}\n\n/**\n * Sets date time validator, with default formats\n */\nexport function DateTime(): PropertyDecorator\n/**\n * Sets date time validator, with default string format\n * @param valueFormat - Format of validated value\n */\nexport function DateTime(valueFormat: DateTimeValueFormat): PropertyDecorator\n/**\n * Sets date time validator, with default value format\n * @param stringFormat - Format of string value\n */\nexport function DateTime(stringFormat: string|null): PropertyDecorator\n/**\n * Sets date time validator\n * @param valueFormat - Format of validated value\n * @param stringFormat - Format of string value\n */\nexport function DateTime(valueFormat: DateTimeValueFormat, stringFormat: string): PropertyDecorator\n/**\n * Sets date time validator to property on which is used\n */\nexport function DateTime(valueFormatOrStringFormat?: DateTimeValueFormat|string|null, stringFormat?: string|undefined|null): PropertyDecorator\n{\n let valueFormat: DateTimeValueFormat|undefined|null;\n\n if(isNumber(valueFormatOrStringFormat))\n {\n valueFormat = valueFormatOrStringFormat;\n }\n\n if(isString(valueFormatOrStringFormat))\n {\n stringFormat = valueFormatOrStringFormat;\n }\n\n return ModelPropertyMetadata(\n {\n validators: [dateTimeModelValidatorFactory(\n {\n stringFormat,\n valueFormat,\n })]\n });\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime max value\n * @param dateApi - Date api used for parsing date time\n * @param maxValue - Maximal date time value that should be used for validation against\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeMaxValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n maxValue: DateValue|TDate|DateTimeBase<TDate>|undefined|null,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value) || isBlank(maxValue))\n {\n return null;\n }\n\n if(maxValue instanceof DateTimeBase<TDate>)\n {\n const value = getSingleDateTimeValue(maxValue.value);\n\n //no validation\n if(isBlank(value))\n {\n return null;\n }\n\n maxValue = value;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n const maxDateTime = dateApi.getValue(maxValue, stringFormat ?? undefined);\n\n if(!Array.isArray(parsedValue))\n {\n if(parsedValue.isValid() && !parsedValue.isBefore(maxDateTime.value))\n {\n return {\n 'datetimemax': maxDateTime.value\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime min value\n * @param dateApi - Date api used for parsing date time\n * @param minValue - Minimal date time value that should be used for validation against\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeMinValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n minValue: DateValue|TDate|DateTimeBase<TDate>|undefined|null,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value) || isBlank(minValue))\n {\n return null;\n }\n\n if(minValue instanceof DateTimeBase<TDate>)\n {\n const value = getSingleDateTimeValue(minValue.value);\n\n //no validation\n if(isBlank(value))\n {\n return null;\n }\n\n minValue = value;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n const minDateTime = dateApi.getValue(minValue, stringFormat ?? undefined);\n\n if(!Array.isArray(parsedValue))\n {\n if(parsedValue.isValid() && !parsedValue.isAfter(minDateTime.value))\n {\n return {\n 'datetimemin': minDateTime.value\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Validations functions for datetime\n */\nexport class Validators\n{\n /**\n * Creates validator function that validates control if its value is valid datetime value\n * @param datetime - Object storing information about datetime value\n */\n public static datetime<TDate = any>(datetime: DateTimeValueObject<TDate>): ValidatorFn\n {\n return (): ValidationErrors|null =>\n {\n if(!datetime.valid)\n {\n return {\n 'datetime': true\n };\n }\n\n return null;\n };\n }\n\n /**\n * Creates validator function that validates control if its value is withing range of minimal datetime value\n * @param datetime - Object storing information about datetime value\n * @param dateApi - Date api object\n */\n public static minDatetime<TDate = any>(datetime: DateTimeValueObject<TDate>, dateApi: DateApi<TDate>): ValidatorFn\n {\n return (control: AbstractControl): ValidationErrors|null =>\n {\n if(!!control.value &&\n datetime.valid &&\n datetime.minValue &&\n dateApi.getValue(control.value).isBefore(datetime.minValue))\n {\n return {\n 'minDatetime': datetime.minValue,\n 'actualValue': control.value\n };\n }\n\n return null;\n };\n }\n\n /**\n * Creates validator function that validates control if its value is withing range of maximal datetime value\n * @param datetime - Object storing information about datetime value\n * @param dateApi - Date api object\n */\n public static maxDatetime<TDate = any>(datetime: DateTimeValueObject<TDate>, dateApi: DateApi<TDate>): ValidatorFn\n {\n return (control: AbstractControl): ValidationErrors|null =>\n {\n if(!!control.value &&\n datetime.valid &&\n datetime.maxValue &&\n dateApi.getValue(control.value).isAfter(datetime.maxValue))\n {\n return {\n 'maxDatetime': datetime.maxValue,\n 'actualValue': control.value\n };\n }\n\n return null;\n };\n }\n}"]}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { Directive, inject, Input } from '@angular/core';
|
|
3
|
+
import { BindThis, isBlank, isString } from '@jscrpt/common';
|
|
4
|
+
import { Subject } from 'rxjs';
|
|
5
|
+
import { DateTimeValueFormat } from '../../../../misc/enums';
|
|
6
|
+
import { DATE_API, FORMAT_PROVIDER } from '../../../../misc/tokens';
|
|
7
|
+
import { getSingleDateTimeValue } from '../../../../misc/utils';
|
|
8
|
+
import { DateTimeBase } from '../dateTimeBase';
|
|
9
|
+
import * as i0 from "@angular/core";
|
|
10
|
+
/**
|
|
11
|
+
* Directive that holds shared data for date time, like formats, restrictions
|
|
12
|
+
*/
|
|
13
|
+
export class DateTimeDirective {
|
|
14
|
+
constructor() {
|
|
15
|
+
//######################### protected properties #########################
|
|
16
|
+
/**
|
|
17
|
+
* Subject used for emitting changes in max date time value
|
|
18
|
+
*/
|
|
19
|
+
this.maxDateTimeChangesSubject = new Subject();
|
|
20
|
+
/**
|
|
21
|
+
* Subject used for emitting changes in min date time value
|
|
22
|
+
*/
|
|
23
|
+
this.minDateTimeChangesSubject = new Subject();
|
|
24
|
+
/**
|
|
25
|
+
* Date time value format which is being worked with in this date time
|
|
26
|
+
*/
|
|
27
|
+
this.ɵValueFormat = DateTimeValueFormat.DateInstance;
|
|
28
|
+
/**
|
|
29
|
+
* Format of string representation of date
|
|
30
|
+
*/
|
|
31
|
+
this.ɵFormat = 'date';
|
|
32
|
+
/**
|
|
33
|
+
* Date api instance, used for date time manipulation
|
|
34
|
+
*/
|
|
35
|
+
this.dateApi = inject(DATE_API);
|
|
36
|
+
/**
|
|
37
|
+
* Provider for available formats
|
|
38
|
+
*/
|
|
39
|
+
this.formatProvider = inject(FORMAT_PROVIDER);
|
|
40
|
+
/**
|
|
41
|
+
* Custom format string representation of date
|
|
42
|
+
*/
|
|
43
|
+
this.customFormat = this.dateApi.getFormat(this.formatProvider[this.ɵFormat]);
|
|
44
|
+
}
|
|
45
|
+
//######################### public properties #########################
|
|
46
|
+
/**
|
|
47
|
+
* Occurs when there are changes in max date time value
|
|
48
|
+
*/
|
|
49
|
+
get maxDateTimeChanges() {
|
|
50
|
+
return this.maxDateTimeChangesSubject.asObservable();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Occurs when there are changes in min date time value
|
|
54
|
+
*/
|
|
55
|
+
get minDateTimeChanges() {
|
|
56
|
+
return this.minDateTimeChangesSubject.asObservable();
|
|
57
|
+
}
|
|
58
|
+
//######################### public properties - inputs #########################
|
|
59
|
+
/**
|
|
60
|
+
* Gets or sets date time value format which is being worked with in this date time
|
|
61
|
+
*/
|
|
62
|
+
get valueFormat() {
|
|
63
|
+
return this.ɵValueFormat;
|
|
64
|
+
}
|
|
65
|
+
set valueFormat(value) {
|
|
66
|
+
if (isString(value)) {
|
|
67
|
+
this.ɵValueFormat = DateTimeValueFormat[value];
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.ɵValueFormat = value;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Gets or sets format of string representation of date
|
|
74
|
+
*/
|
|
75
|
+
get format() {
|
|
76
|
+
return this.ɵFormat;
|
|
77
|
+
}
|
|
78
|
+
set format(value) {
|
|
79
|
+
this.ɵFormat = value;
|
|
80
|
+
this.customFormat = this.dateApi.getFormat(this.formatProvider[value]);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Gets or sets max allowed date for date time
|
|
84
|
+
*/
|
|
85
|
+
get maxDateTime() {
|
|
86
|
+
return this.ɵMaxDateTime;
|
|
87
|
+
}
|
|
88
|
+
set maxDateTime(value) {
|
|
89
|
+
this.maxDateInstanceChange?.unsubscribe();
|
|
90
|
+
this.maxDateInstanceChange = null;
|
|
91
|
+
if (isBlank(value)) {
|
|
92
|
+
this.maxDateSet(value);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
let val = value;
|
|
96
|
+
if (value instanceof (DateTimeBase)) {
|
|
97
|
+
this.maxDateInstanceChange = value.valueChange.subscribe(() => {
|
|
98
|
+
const val = getSingleDateTimeValue(value.value);
|
|
99
|
+
if (isBlank(val)) {
|
|
100
|
+
this.maxDateSet(null);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
this.setMinMaxValue(val, this.maxDateSet);
|
|
104
|
+
});
|
|
105
|
+
const v = getSingleDateTimeValue(value.value);
|
|
106
|
+
if (isBlank(v)) {
|
|
107
|
+
this.maxDateSet(null);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
val = v;
|
|
111
|
+
}
|
|
112
|
+
this.setMinMaxValue(val, this.maxDateSet);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Gets or sets min allowed date for date time
|
|
116
|
+
*/
|
|
117
|
+
get minDateTime() {
|
|
118
|
+
return this.ɵMinDateTime;
|
|
119
|
+
}
|
|
120
|
+
set minDateTime(value) {
|
|
121
|
+
this.minDateInstanceChange?.unsubscribe();
|
|
122
|
+
this.minDateInstanceChange = null;
|
|
123
|
+
if (isBlank(value)) {
|
|
124
|
+
this.minDateSet(value);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
let val = value;
|
|
128
|
+
if (value instanceof (DateTimeBase)) {
|
|
129
|
+
this.minDateInstanceChange = value.valueChange.subscribe(() => {
|
|
130
|
+
const val = getSingleDateTimeValue(value.value);
|
|
131
|
+
if (isBlank(val)) {
|
|
132
|
+
this.minDateSet(null);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.setMinMaxValue(val, this.minDateSet);
|
|
136
|
+
});
|
|
137
|
+
const v = getSingleDateTimeValue(value.value);
|
|
138
|
+
if (isBlank(v)) {
|
|
139
|
+
this.minDateSet(null);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
val = v;
|
|
143
|
+
}
|
|
144
|
+
this.setMinMaxValue(val, this.minDateSet);
|
|
145
|
+
}
|
|
146
|
+
//######################### public methods - implementation of OnDestroy #########################
|
|
147
|
+
/**
|
|
148
|
+
* Called when component is destroyed
|
|
149
|
+
*/
|
|
150
|
+
ngOnDestroy() {
|
|
151
|
+
this.maxDateInstanceChange?.unsubscribe();
|
|
152
|
+
this.maxDateInstanceChange = null;
|
|
153
|
+
this.minDateInstanceChange?.unsubscribe();
|
|
154
|
+
this.minDateInstanceChange = null;
|
|
155
|
+
}
|
|
156
|
+
//######################### protected methods #########################
|
|
157
|
+
/**
|
|
158
|
+
* Sets min date time and notifies about changes
|
|
159
|
+
* @param value - Value to be set
|
|
160
|
+
*/
|
|
161
|
+
minDateSet(value) {
|
|
162
|
+
this.ɵMinDateTime = value;
|
|
163
|
+
this.minDateTimeChangesSubject.next();
|
|
164
|
+
this.onMinDateTimeChange();
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Sets max date time and notifies about changes
|
|
168
|
+
* @param value - Value to be set
|
|
169
|
+
*/
|
|
170
|
+
maxDateSet(value) {
|
|
171
|
+
this.ɵMaxDateTime = value;
|
|
172
|
+
this.maxDateTimeChangesSubject.next();
|
|
173
|
+
this.onMaxDateTimeChange();
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Sets min or max date time value
|
|
177
|
+
* @param value - Value to be set
|
|
178
|
+
* @param setter - Action used for setting value
|
|
179
|
+
*/
|
|
180
|
+
setMinMaxValue(value, setter) {
|
|
181
|
+
const val = this.dateApi.getValue(value, this.customFormat);
|
|
182
|
+
if (val.isValid()) {
|
|
183
|
+
setter(val.value);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
setter(null);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Called whenever max date time restriction changes
|
|
191
|
+
*/
|
|
192
|
+
onMaxDateTimeChange() {
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Called whenever min date time restriction changes
|
|
196
|
+
*/
|
|
197
|
+
onMinDateTimeChange() {
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
DateTimeDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
201
|
+
DateTimeDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.6", type: DateTimeDirective, selector: "[dateTime]", inputs: { valueFormat: "valueFormat", format: "format", customFormat: "customFormat", maxDateTime: "maxDateTime", minDateTime: "minDateTime" }, ngImport: i0 });
|
|
202
|
+
__decorate([
|
|
203
|
+
BindThis,
|
|
204
|
+
__metadata("design:type", Function),
|
|
205
|
+
__metadata("design:paramtypes", [Object]),
|
|
206
|
+
__metadata("design:returntype", void 0)
|
|
207
|
+
], DateTimeDirective.prototype, "minDateSet", null);
|
|
208
|
+
__decorate([
|
|
209
|
+
BindThis,
|
|
210
|
+
__metadata("design:type", Function),
|
|
211
|
+
__metadata("design:paramtypes", [Object]),
|
|
212
|
+
__metadata("design:returntype", void 0)
|
|
213
|
+
], DateTimeDirective.prototype, "maxDateSet", null);
|
|
214
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeDirective, decorators: [{
|
|
215
|
+
type: Directive,
|
|
216
|
+
args: [{
|
|
217
|
+
selector: '[dateTime]'
|
|
218
|
+
}]
|
|
219
|
+
}], propDecorators: { valueFormat: [{
|
|
220
|
+
type: Input
|
|
221
|
+
}], format: [{
|
|
222
|
+
type: Input
|
|
223
|
+
}], customFormat: [{
|
|
224
|
+
type: Input
|
|
225
|
+
}], maxDateTime: [{
|
|
226
|
+
type: Input
|
|
227
|
+
}], minDateTime: [{
|
|
228
|
+
type: Input
|
|
229
|
+
}], minDateSet: [], maxDateSet: [] } });
|
|
230
|
+
//# sourceMappingURL=dateTime.directive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dateTime.directive.js","sourceRoot":"","sources":["../../../../../../src/modules/dateTime/directives/dateTime/dateTime.directive.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAY,MAAM,eAAe,CAAC;AAClE,OAAO,EAAU,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAa,OAAO,EAAe,MAAM,MAAM,CAAC;AAGvD,OAAO,EAAC,mBAAmB,EAAC,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAC,QAAQ,EAAE,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAElE,OAAO,EAAC,sBAAsB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This, isBlank, isString} from '@jscrpt/common';\nimport {Observable, Subject, Subscription} from 'rxjs';\n\nimport {FormatProvider} from '../../../../interfaces';\nimport {DateTimeValueFormat} from '../../../../misc/enums';\nimport {DATE_API, FORMAT_PROVIDER} from '../../../../misc/tokens';\nimport {DateTimeInputOutputValue} from '../../../../misc/types';\nimport {getSingleDateTimeValue} from '../../../../misc/utils';\nimport {DateApi, DateValue} from '../../../../services';\nimport {DateTimeBase} from '../dateTimeBase';\n\n/**\n * Directive that holds shared data for date time, like formats, restrictions\n */\n@Directive(\n{\n selector: '[dateTime]'\n})\nexport class DateTimeDirective<TDate = unknown> implements OnDestroy\n{\n //######################### protected properties #########################\n\n /**\n * Subject used for emitting changes in max date time value\n */\n protected maxDateTimeChangesSubject: Subject<void> = new Subject<void>();\n\n /**\n * Subject used for emitting changes in min date time value\n */\n protected minDateTimeChangesSubject: Subject<void> = new Subject<void>();\n\n /**\n * Subscription for max date instance value changes\n */\n protected maxDateInstanceChange: Subscription|undefined|null;\n\n /**\n * Subscription for min date instance value changes\n */\n protected minDateInstanceChange: Subscription|undefined|null;\n\n /**\n * Max allowed value of date time\n */\n protected ɵMaxDateTime: TDate|undefined|null;\n\n /**\n * Min allowed value of date time\n */\n protected ɵMinDateTime: TDate|undefined|null;\n\n /**\n * Date time value format which is being worked with in this date time\n */\n protected ɵValueFormat: DateTimeValueFormat = DateTimeValueFormat.DateInstance;\n\n /**\n * Format of string representation of date\n */\n protected ɵFormat: keyof FormatProvider = 'date';\n\n /**\n * Date api instance, used for date time manipulation\n */\n protected dateApi: DateApi<TDate> = inject(DATE_API);\n\n /**\n * Provider for available formats\n */\n protected formatProvider: FormatProvider = inject(FORMAT_PROVIDER);\n\n //######################### public properties #########################\n\n /**\n * Occurs when there are changes in max date time value\n */\n public get maxDateTimeChanges(): Observable<void>\n {\n return this.maxDateTimeChangesSubject.asObservable();\n }\n\n /**\n * Occurs when there are changes in min date time value\n */\n public get minDateTimeChanges(): Observable<void>\n {\n return this.minDateTimeChangesSubject.asObservable();\n }\n\n //######################### public properties - inputs #########################\n\n /**\n * Gets or sets date time value format which is being worked with in this date time\n */\n @Input()\n public get valueFormat(): DateTimeValueFormat\n {\n return this.ɵValueFormat;\n }\n public set valueFormat(value: DateTimeValueFormat)\n {\n if(isString(value))\n {\n this.ɵValueFormat = DateTimeValueFormat[value] as unknown as DateTimeValueFormat;\n\n return;\n }\n\n this.ɵValueFormat = value;\n }\n\n /**\n * Gets or sets format of string representation of date\n */\n @Input()\n public get format(): keyof FormatProvider\n {\n return this.ɵFormat;\n }\n public set format(value: keyof FormatProvider)\n {\n this.ɵFormat = value;\n this.customFormat = this.dateApi.getFormat(this.formatProvider[value]);\n }\n\n /**\n * Custom format string representation of date\n */\n @Input()\n public customFormat: string = this.dateApi.getFormat(this.formatProvider[this.ɵFormat]);\n\n /**\n * Gets or sets max allowed date for date time\n */\n @Input()\n public get maxDateTime(): TDate|undefined|null\n {\n return this.ɵMaxDateTime;\n }\n public set maxDateTime(value: TDate|undefined|null)\n {\n this.maxDateInstanceChange?.unsubscribe();\n this.maxDateInstanceChange = null;\n\n if(isBlank(value))\n {\n this.maxDateSet(value);\n\n return;\n }\n\n let val: DateTimeInputOutputValue<TDate> = value;\n\n if(value instanceof DateTimeBase<TDate>)\n {\n this.maxDateInstanceChange = value.valueChange.subscribe(() =>\n {\n const val = getSingleDateTimeValue<TDate>(value.value);\n\n if(isBlank(val))\n {\n this.maxDateSet(null);\n\n return;\n }\n\n this.setMinMaxValue(val, this.maxDateSet);\n });\n\n const v = getSingleDateTimeValue<TDate>(value.value);\n\n if(isBlank(v))\n {\n this.maxDateSet(null);\n\n return;\n }\n\n val = v;\n }\n \n this.setMinMaxValue(val, this.maxDateSet);\n }\n\n /**\n * Gets or sets min allowed date for date time\n */\n @Input()\n public get minDateTime(): TDate|undefined|null\n {\n return this.ɵMinDateTime;\n }\n public set minDateTime(value: TDate|undefined|null)\n {\n this.minDateInstanceChange?.unsubscribe();\n this.minDateInstanceChange = null;\n\n if(isBlank(value))\n {\n this.minDateSet(value);\n\n return;\n }\n\n let val: DateTimeInputOutputValue<TDate> = value;\n\n if(value instanceof DateTimeBase<TDate>)\n {\n this.minDateInstanceChange = value.valueChange.subscribe(() =>\n {\n const val = getSingleDateTimeValue<TDate>(value.value);\n\n if(isBlank(val))\n {\n this.minDateSet(null);\n\n return;\n }\n\n this.setMinMaxValue(val, this.minDateSet);\n });\n\n const v = getSingleDateTimeValue<TDate>(value.value);\n\n if(isBlank(v))\n {\n this.minDateSet(null);\n\n return;\n }\n\n val = v;\n }\n\n this.setMinMaxValue(val, this.minDateSet);\n }\n\n //######################### public methods - implementation of OnDestroy #########################\n \n /**\n * Called when component is destroyed\n */\n public ngOnDestroy(): void\n {\n this.maxDateInstanceChange?.unsubscribe();\n this.maxDateInstanceChange = null;\n\n this.minDateInstanceChange?.unsubscribe();\n this.minDateInstanceChange = null;\n }\n\n //######################### protected methods #########################\n\n /**\n * Sets min date time and notifies about changes\n * @param value - Value to be set\n */\n @BindThis\n protected minDateSet(value: TDate|undefined|null): void\n {\n this.ɵMinDateTime = value;\n this.minDateTimeChangesSubject.next();\n this.onMinDateTimeChange();\n }\n\n /**\n * Sets max date time and notifies about changes\n * @param value - Value to be set\n */\n @BindThis\n protected maxDateSet(value: TDate|undefined|null): void\n {\n this.ɵMaxDateTime = value;\n this.maxDateTimeChangesSubject.next();\n this.onMaxDateTimeChange();\n }\n\n /**\n * Sets min or max date time value\n * @param value - Value to be set\n * @param setter - Action used for setting value\n */\n protected setMinMaxValue(value: DateValue|TDate, setter: Action1<TDate|undefined|null>): void\n {\n const val = this.dateApi.getValue(value, this.customFormat);\n\n if(val.isValid())\n {\n setter(val.value);\n }\n else\n {\n setter(null);\n }\n }\n\n /**\n * Called whenever max date time restriction changes\n */\n protected onMaxDateTimeChange(): void\n {\n }\n\n /**\n * Called whenever min date time restriction changes\n */\n protected onMinDateTimeChange(): void\n {\n }\n\n //######################### ng language server #########################\n \n /**\n * Custom input type for `valueFormat` input\n */\n public static ngAcceptInputType_valueFormat: keyof typeof DateTimeValueFormat|DateTimeValueFormat;\n\n /**\n * Custom input type for `maxDateTime` input\n */\n public static ngAcceptInputType_maxDateTime: DateValue|DateTimeBase;\n\n /**\n * Custom input type for `minDateTime` input\n */\n public static ngAcceptInputType_minDateTime: DateValue|DateTimeBase;\n}"]}
|
|
@@ -1,32 +1,28 @@
|
|
|
1
|
-
import { Directive, EventEmitter,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Directive, EventEmitter, inject } from '@angular/core';
|
|
2
|
+
import { Subscription } from 'rxjs';
|
|
3
|
+
import { DateTimeDirective } from './dateTime/dateTime.directive';
|
|
4
4
|
import * as i0 from "@angular/core";
|
|
5
5
|
/**
|
|
6
6
|
* Base class for date time directives, contains basic shared data
|
|
7
7
|
*/
|
|
8
8
|
export class DateTimeBase {
|
|
9
|
-
//#########################
|
|
10
|
-
constructor(
|
|
11
|
-
this.dateApi = dateApi;
|
|
12
|
-
this.formatProvider = formatProvider;
|
|
9
|
+
//######################### constructor #########################
|
|
10
|
+
constructor() {
|
|
13
11
|
//######################### protected properties #########################
|
|
14
12
|
/**
|
|
15
|
-
*
|
|
13
|
+
* Subscriptions created during initialization
|
|
16
14
|
*/
|
|
17
|
-
this
|
|
15
|
+
this.initSubscriptions = new Subscription();
|
|
18
16
|
/**
|
|
19
|
-
*
|
|
17
|
+
* Instance of date time shared data, like formats and restrictions
|
|
20
18
|
*/
|
|
21
|
-
this
|
|
19
|
+
this.dateTimeData = inject((DateTimeDirective));
|
|
22
20
|
/**
|
|
23
21
|
* @inheritdoc
|
|
24
22
|
*/
|
|
25
23
|
this.valueChange = new EventEmitter();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
29
|
-
this.customFormat = this.dateApi.getFormat(this.formatProvider[this.ɵFormat]);
|
|
24
|
+
this.initSubscriptions.add(this.dateTimeData.maxDateTimeChanges.subscribe(() => this.onMaxDateTimeChange()));
|
|
25
|
+
this.initSubscriptions.add(this.dateTimeData.minDateTimeChanges.subscribe(() => this.onMinDateTimeChange()));
|
|
30
26
|
}
|
|
31
27
|
//######################### public properties - implementation of DateTimeInputValue #########################
|
|
32
28
|
/**
|
|
@@ -38,40 +34,28 @@ export class DateTimeBase {
|
|
|
38
34
|
set value(value) {
|
|
39
35
|
this.ɵValue = value;
|
|
40
36
|
}
|
|
41
|
-
//######################### public
|
|
37
|
+
//######################### public methods - implementation of OnDestroy #########################
|
|
42
38
|
/**
|
|
43
|
-
*
|
|
39
|
+
* Called when component is destroyed
|
|
44
40
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
set valueFormat(value) {
|
|
49
|
-
if (isString(value)) {
|
|
50
|
-
this.ɵValueFormat = DateTimeValueFormat[value];
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
this.ɵValueFormat = value;
|
|
41
|
+
ngOnDestroy() {
|
|
42
|
+
this.initSubscriptions.unsubscribe();
|
|
54
43
|
}
|
|
44
|
+
//######################### protected methods #########################
|
|
55
45
|
/**
|
|
56
|
-
*
|
|
46
|
+
* Called whenever max date time restriction changes
|
|
57
47
|
*/
|
|
58
|
-
|
|
59
|
-
return this.ɵFormat;
|
|
48
|
+
onMaxDateTimeChange() {
|
|
60
49
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Called whenever min date time restriction changes
|
|
52
|
+
*/
|
|
53
|
+
onMinDateTimeChange() {
|
|
64
54
|
}
|
|
65
55
|
}
|
|
66
|
-
DateTimeBase.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeBase, deps:
|
|
67
|
-
DateTimeBase.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.6", type: DateTimeBase,
|
|
56
|
+
DateTimeBase.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
57
|
+
DateTimeBase.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.6", type: DateTimeBase, ngImport: i0 });
|
|
68
58
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeBase, decorators: [{
|
|
69
59
|
type: Directive
|
|
70
|
-
}], ctorParameters: function () { return [
|
|
71
|
-
type: Input
|
|
72
|
-
}], format: [{
|
|
73
|
-
type: Input
|
|
74
|
-
}], customFormat: [{
|
|
75
|
-
type: Input
|
|
76
|
-
}] } });
|
|
60
|
+
}], ctorParameters: function () { return []; } });
|
|
77
61
|
//# sourceMappingURL=dateTimeBase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateTimeBase.js","sourceRoot":"","sources":["../../../../../src/modules/dateTime/directives/dateTimeBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"dateTimeBase.js","sourceRoot":"","sources":["../../../../../src/modules/dateTime/directives/dateTimeBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,YAAY,EAAE,MAAM,EAAY,MAAM,eAAe,CAAC;AACzE,OAAO,EAAC,YAAY,EAAC,MAAM,MAAM,CAAC;AAIlC,OAAO,EAAC,iBAAiB,EAAC,MAAM,+BAA+B,CAAC;;AAEhE;;GAEG;AAEH,MAAM,OAAO,YAAY;IAsCrB,iEAAiE;IACjE;QArCA,0EAA0E;QAE1E;;WAEG;QACO,sBAAiB,GAAiB,IAAI,YAAY,EAAE,CAAC;QAO/D;;WAEG;QACO,iBAAY,GAA6B,MAAM,CAAC,CAAA,iBAAwB,CAAA,CAAC,CAAC;QAgBpF;;WAEG;QACI,gBAAW,GAAuB,IAAI,YAAY,EAAQ,CAAC;QAK9D,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC;QAC7G,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,SAAS,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC;IACjH,CAAC;IAxBD,8GAA8G;IAE9G;;OAEG;IACH,IAAW,KAAK;QAEZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IACD,IAAW,KAAK,CAAC,KAAqD;QAElE,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;IACxB,CAAC;IAcD,kGAAkG;IAElG;;OAEG;IACI,WAAW;QAEd,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE,CAAC;IACzC,CAAC;IAED,uEAAuE;IAEvE;;OAEG;IACO,mBAAmB;IAE7B,CAAC;IAED;;OAEG;IACO,mBAAmB;IAE7B,CAAC;;yGArEQ,YAAY;6FAAZ,YAAY;2FAAZ,YAAY;kBADxB,SAAS","sourcesContent":["import {Directive, EventEmitter, inject, OnDestroy} from '@angular/core';\nimport {Subscription} from 'rxjs';\n\nimport {DateTimeInputValue} from '../../../interfaces';\nimport {DateTimeInputOutputValue} from '../../../misc/types';\nimport {DateTimeDirective} from './dateTime/dateTime.directive';\n\n/**\n * Base class for date time directives, contains basic shared data\n */\n@Directive()\nexport class DateTimeBase<TDate = unknown> implements DateTimeInputValue<TDate>, OnDestroy\n{\n //######################### protected properties #########################\n\n /**\n * Subscriptions created during initialization\n */\n protected initSubscriptions: Subscription = new Subscription();\n\n /**\n * Current value of date time, could be string, unix timestamp, Date, TDate object, or ranged DateTimeValue\n */\n protected ɵValue: DateTimeInputOutputValue<TDate>|undefined|null;\n\n /**\n * Instance of date time shared data, like formats and restrictions\n */\n protected dateTimeData: DateTimeDirective<TDate> = inject(DateTimeDirective<TDate>);\n\n //######################### public properties - implementation of DateTimeInputValue #########################\n\n /**\n * @inheritdoc\n */\n public get value(): DateTimeInputOutputValue<TDate>|undefined|null\n {\n return this.ɵValue;\n }\n public set value(value: DateTimeInputOutputValue<TDate>|undefined|null)\n {\n this.ɵValue = value;\n }\n\n /**\n * @inheritdoc\n */\n public valueChange: EventEmitter<void> = new EventEmitter<void>();\n\n //######################### constructor #########################\n constructor()\n {\n this.initSubscriptions.add(this.dateTimeData.maxDateTimeChanges.subscribe(() => this.onMaxDateTimeChange()));\n this.initSubscriptions.add(this.dateTimeData.minDateTimeChanges.subscribe(() => this.onMinDateTimeChange()));\n }\n\n //######################### public methods - implementation of OnDestroy #########################\n \n /**\n * Called when component is destroyed\n */\n public ngOnDestroy(): void\n {\n this.initSubscriptions.unsubscribe();\n }\n\n //######################### protected methods #########################\n\n /**\n * Called whenever max date time restriction changes\n */\n protected onMaxDateTimeChange(): void\n {\n }\n\n /**\n * Called whenever min date time restriction changes\n */\n protected onMinDateTimeChange(): void\n {\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Directive, ElementRef, EventEmitter, forwardRef, Inject } from '@angular/core';
|
|
3
3
|
import { BindThis, isBlank } from '@jscrpt/common';
|
|
4
|
-
import { DATE_API, DATE_TIME_INPUT
|
|
4
|
+
import { DATE_API, DATE_TIME_INPUT } from '../../../../misc/tokens';
|
|
5
5
|
import { formatDateTime, parseDateTime } from '../../../../misc/utils';
|
|
6
6
|
import { DateValueProvider } from '../../../../services';
|
|
7
7
|
import { DateTimeBase } from '../dateTimeBase';
|
|
@@ -13,9 +13,10 @@ import * as i1 from "../../../../services";
|
|
|
13
13
|
*/
|
|
14
14
|
export class DateTimeInputDirective extends DateTimeBase {
|
|
15
15
|
//######################### constructors #########################
|
|
16
|
-
constructor(elementRef, dateApi,
|
|
17
|
-
super(
|
|
16
|
+
constructor(elementRef, dateApi, valueProvider) {
|
|
17
|
+
super();
|
|
18
18
|
this.elementRef = elementRef;
|
|
19
|
+
this.dateApi = dateApi;
|
|
19
20
|
this.valueProvider = valueProvider;
|
|
20
21
|
/**
|
|
21
22
|
* @inheritdoc
|
|
@@ -48,10 +49,10 @@ export class DateTimeInputDirective extends DateTimeBase {
|
|
|
48
49
|
set value(value) {
|
|
49
50
|
//accepts all available formats
|
|
50
51
|
this.setInternalValue(value);
|
|
51
|
-
this.ɵValue = formatDateTime(this.internalValue, this.valueFormat, this.customFormat);
|
|
52
|
+
this.ɵValue = formatDateTime(this.internalValue, this.dateTimeData.valueFormat, this.dateTimeData.customFormat);
|
|
52
53
|
//not range value
|
|
53
54
|
if (!Array.isArray(this.internalValue)) {
|
|
54
|
-
this.rawValue = this.internalValue?.format(this.customFormat);
|
|
55
|
+
this.rawValue = this.internalValue?.format(this.dateTimeData.customFormat);
|
|
55
56
|
}
|
|
56
57
|
else {
|
|
57
58
|
//TODO: add support for ranges
|
|
@@ -77,6 +78,7 @@ export class DateTimeInputDirective extends DateTimeBase {
|
|
|
77
78
|
* Called when component is destroyed
|
|
78
79
|
*/
|
|
79
80
|
ngOnDestroy() {
|
|
81
|
+
super.ngOnDestroy();
|
|
80
82
|
this.elementRef.nativeElement.removeEventListener('input', this.handleInput);
|
|
81
83
|
this.elementRef.nativeElement.removeEventListener('focus', this.handleFocus);
|
|
82
84
|
this.elementRef.nativeElement.removeEventListener('blur', this.handleBlur);
|
|
@@ -87,7 +89,7 @@ export class DateTimeInputDirective extends DateTimeBase {
|
|
|
87
89
|
* @param value - Value to be set
|
|
88
90
|
*/
|
|
89
91
|
setInternalValue(value) {
|
|
90
|
-
this.internalValue = parseDateTime(value, this.dateApi, null, this.customFormat);
|
|
92
|
+
this.internalValue = parseDateTime(value, this.dateApi, null, this.dateTimeData.customFormat);
|
|
91
93
|
if (isBlank(this.internalValue)) {
|
|
92
94
|
return;
|
|
93
95
|
}
|
|
@@ -95,22 +97,22 @@ export class DateTimeInputDirective extends DateTimeBase {
|
|
|
95
97
|
if (Array.isArray(this.internalValue)) {
|
|
96
98
|
const [from, to] = this.internalValue;
|
|
97
99
|
if (from) {
|
|
98
|
-
const val = this.valueProvider.getValue(from.value, this.customFormat).from;
|
|
100
|
+
const val = this.valueProvider.getValue(from.value, this.dateTimeData.customFormat).from;
|
|
99
101
|
if (val) {
|
|
100
|
-
this.internalValue[0] = this.dateApi.getValue(val, this.customFormat);
|
|
102
|
+
this.internalValue[0] = this.dateApi.getValue(val, this.dateTimeData.customFormat);
|
|
101
103
|
}
|
|
102
104
|
}
|
|
103
105
|
if (to) {
|
|
104
|
-
const val = this.valueProvider.getValue(to.value, this.customFormat).to;
|
|
106
|
+
const val = this.valueProvider.getValue(to.value, this.dateTimeData.customFormat).to;
|
|
105
107
|
if (val) {
|
|
106
|
-
this.internalValue[1] = this.dateApi.getValue(val, this.customFormat);
|
|
108
|
+
this.internalValue[1] = this.dateApi.getValue(val, this.dateTimeData.customFormat);
|
|
107
109
|
}
|
|
108
110
|
}
|
|
109
111
|
}
|
|
110
112
|
else {
|
|
111
|
-
const val = this.valueProvider.getValue(this.internalValue.value, this.customFormat).from;
|
|
113
|
+
const val = this.valueProvider.getValue(this.internalValue.value, this.dateTimeData.customFormat).from;
|
|
112
114
|
if (val) {
|
|
113
|
-
this.internalValue = this.dateApi.getValue(val, this.customFormat);
|
|
115
|
+
this.internalValue = this.dateApi.getValue(val, this.dateTimeData.customFormat);
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
118
|
}
|
|
@@ -125,7 +127,7 @@ export class DateTimeInputDirective extends DateTimeBase {
|
|
|
125
127
|
return;
|
|
126
128
|
}
|
|
127
129
|
this.setInternalValue(this.rawValue);
|
|
128
|
-
this.ɵValue = formatDateTime(this.internalValue, this.valueFormat, this.customFormat);
|
|
130
|
+
this.ɵValue = formatDateTime(this.internalValue, this.dateTimeData.valueFormat, this.dateTimeData.customFormat);
|
|
129
131
|
this.valueChange.next();
|
|
130
132
|
}
|
|
131
133
|
/**
|
|
@@ -143,7 +145,7 @@ export class DateTimeInputDirective extends DateTimeBase {
|
|
|
143
145
|
this.blur.emit(event);
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
|
-
DateTimeInputDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeInputDirective, deps: [{ token: i0.ElementRef }, { token: DATE_API }, { token:
|
|
148
|
+
DateTimeInputDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeInputDirective, deps: [{ token: i0.ElementRef }, { token: DATE_API }, { token: i1.DateValueProvider }], target: i0.ɵɵFactoryTarget.Directive });
|
|
147
149
|
DateTimeInputDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.6", type: DateTimeInputDirective, selector: "input[dateTime][dateTimeInput]", providers: [
|
|
148
150
|
{
|
|
149
151
|
provide: DATE_TIME_INPUT,
|
|
@@ -183,8 +185,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
|
|
|
183
185
|
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: undefined, decorators: [{
|
|
184
186
|
type: Inject,
|
|
185
187
|
args: [DATE_API]
|
|
186
|
-
}] }, { type: undefined, decorators: [{
|
|
187
|
-
type: Inject,
|
|
188
|
-
args: [FORMAT_PROVIDER]
|
|
189
188
|
}] }, { type: i1.DateValueProvider }]; }, propDecorators: { handleInput: [], handleFocus: [], handleBlur: [] } });
|
|
190
189
|
//# sourceMappingURL=dateTimeInput.directive.js.map
|