@anglr/datetime 8.0.0-beta.20240125080204 → 8.0.0
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 +34 -0
- package/es2022/date-fns/src/services/dateFnsDateApi.service.js +6 -7
- package/es2022/date-fns/src/services/dateFnsDateApi.service.js.map +1 -1
- package/es2022/moment/src/services/momentDateApi.service.js +6 -7
- package/es2022/moment/src/services/momentDateApi.service.js.map +1 -1
- package/es2022/src/directives/buttonDateTimeInput/buttonDateTimeInput.directive.js +10 -37
- package/es2022/src/directives/buttonDateTimeInput/buttonDateTimeInput.directive.js.map +1 -1
- package/es2022/src/directives/datePickerInput/datePickerInput.directive.js +4 -5
- package/es2022/src/directives/datePickerInput/datePickerInput.directive.js.map +1 -1
- package/es2022/src/directives/dateTimeInputHandler/dateTimeInputHandler.directive.js +7 -8
- package/es2022/src/directives/dateTimeInputHandler/dateTimeInputHandler.directive.js.map +1 -1
- package/es2022/src/directives/dateTimePickerInput/dateTimePickerInput.directive.js +4 -5
- package/es2022/src/directives/dateTimePickerInput/dateTimePickerInput.directive.js.map +1 -1
- package/es2022/src/directives/simpleDatePickerInput/simpleDatePickerInput.directive.js +4 -5
- package/es2022/src/directives/simpleDatePickerInput/simpleDatePickerInput.directive.js.map +1 -1
- package/es2022/src/directives/simpleDateTimeInputHandler/simpleDateTimeInputHandler.directive.js +7 -8
- package/es2022/src/directives/simpleDateTimeInputHandler/simpleDateTimeInputHandler.directive.js.map +1 -1
- package/es2022/src/directives/simpleDateTimePickerInput/simpleDateTimePickerInput.directive.js +4 -5
- package/es2022/src/directives/simpleDateTimePickerInput/simpleDateTimePickerInput.directive.js.map +1 -1
- package/es2022/src/directives/withNow/withNow.directive.js +6 -7
- package/es2022/src/directives/withNow/withNow.directive.js.map +1 -1
- package/es2022/src/directives/withTime/withTime.directive.js +5 -6
- package/es2022/src/directives/withTime/withTime.directive.js.map +1 -1
- package/es2022/src/directives/withToday/withToday.directive.js +6 -7
- package/es2022/src/directives/withToday/withToday.directive.js.map +1 -1
- package/es2022/src/misc/enums.js +6 -2
- package/es2022/src/misc/enums.js.map +1 -1
- package/es2022/src/misc/utils.js +33 -18
- package/es2022/src/misc/utils.js.map +1 -1
- package/es2022/src/misc/validators.js +12 -8
- package/es2022/src/misc/validators.js.map +1 -1
- package/es2022/src/modules/calendar/components/monthCalendar/monthCalendar.component.js +6 -7
- package/es2022/src/modules/calendar/components/monthCalendar/monthCalendar.component.js.map +1 -1
- package/es2022/src/modules/calendar/directives/calendarDayTemplate/calendarDayTemplate.directive.js +5 -6
- package/es2022/src/modules/calendar/directives/calendarDayTemplate/calendarDayTemplate.directive.js.map +1 -1
- package/es2022/src/modules/calendar/modules/monthCalendar.module.js +5 -6
- package/es2022/src/modules/calendar/modules/monthCalendar.module.js.map +1 -1
- package/es2022/src/modules/calendar/services/eventParser/eventParser.service.js +6 -7
- package/es2022/src/modules/calendar/services/eventParser/eventParser.service.js.map +1 -1
- package/es2022/src/modules/datePipes.module.js +5 -6
- package/es2022/src/modules/datePipes.module.js.map +1 -1
- package/es2022/src/modules/dateTime/directives/dateTime/dateTime.directive.js +11 -6
- package/es2022/src/modules/dateTime/directives/dateTime/dateTime.directive.js.map +1 -1
- package/es2022/src/modules/dateTime/directives/dateTimeBase.js +5 -6
- package/es2022/src/modules/dateTime/directives/dateTimeBase.js.map +1 -1
- package/es2022/src/modules/dateTime/directives/dateTimeControlValueAccessor/dateTimeControlValueAccessor.directive.js +6 -7
- package/es2022/src/modules/dateTime/directives/dateTimeControlValueAccessor/dateTimeControlValueAccessor.directive.js.map +1 -1
- package/es2022/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.js +11 -38
- package/es2022/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.js.map +1 -1
- package/es2022/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.js +8 -9
- package/es2022/src/modules/dateTime/directives/dateTimeMaxValidator/dateTimeMaxValidator.directive.js.map +1 -1
- package/es2022/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.js +8 -9
- package/es2022/src/modules/dateTime/directives/dateTimeMinValidator/dateTimeMinValidator.directive.js.map +1 -1
- package/es2022/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.js +7 -8
- package/es2022/src/modules/dateTime/directives/dateTimeValidator/dateTimeValidator.directive.js.map +1 -1
- package/es2022/src/modules/dateTime/modules/dateTime.module.js +5 -6
- package/es2022/src/modules/dateTime/modules/dateTime.module.js.map +1 -1
- package/es2022/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.js +10 -36
- package/es2022/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.js.map +1 -1
- package/es2022/src/modules/dateTimePicker/components/dayPicker/dayPicker.component.js +5 -6
- package/es2022/src/modules/dateTimePicker/components/dayPicker/dayPicker.component.js.map +1 -1
- package/es2022/src/modules/dateTimePicker/components/monthPicker/monthPicker.component.js +6 -7
- package/es2022/src/modules/dateTimePicker/components/monthPicker/monthPicker.component.js.map +1 -1
- package/es2022/src/modules/dateTimePicker/components/rollerTimePicker/rollerTimePicker.component.js +4 -5
- package/es2022/src/modules/dateTimePicker/components/rollerTimePicker/rollerTimePicker.component.js.map +1 -1
- package/es2022/src/modules/dateTimePicker/components/yearPicker/yearPicker.component.js +4 -5
- package/es2022/src/modules/dateTimePicker/components/yearPicker/yearPicker.component.js.map +1 -1
- package/es2022/src/modules/dateTimePicker/directives/dateTimePicker/dateTimePicker.directive.js +7 -7
- package/es2022/src/modules/dateTimePicker/directives/dateTimePicker/dateTimePicker.directive.js.map +1 -1
- package/es2022/src/modules/dateTimePicker/directives/loopScroll/loopScroll.directive.js +5 -6
- package/es2022/src/modules/dateTimePicker/directives/loopScroll/loopScroll.directive.js.map +1 -1
- package/es2022/src/modules/dateTimePicker/directives/loopScrollData/loopScrollData.directive.js +5 -6
- package/es2022/src/modules/dateTimePicker/directives/loopScrollData/loopScrollData.directive.js.map +1 -1
- package/es2022/src/modules/dateTimePicker/modules/dateTimePicker.module.js +5 -6
- package/es2022/src/modules/dateTimePicker/modules/dateTimePicker.module.js.map +1 -1
- package/es2022/src/pipes/dateConvert.pipe.js +6 -7
- package/es2022/src/pipes/dateConvert.pipe.js.map +1 -1
- package/es2022/src/pipes/dateFormat.pipe.js +6 -7
- package/es2022/src/pipes/dateFormat.pipe.js.map +1 -1
- package/es2022/src/services/datePositionParser/datePositionParser.service.js +4 -5
- package/es2022/src/services/datePositionParser/datePositionParser.service.js.map +1 -1
- package/es2022/src/services/dateTimeRelativeParser/dateTimeRelativeParser.service.js +5 -6
- package/es2022/src/services/dateTimeRelativeParser/dateTimeRelativeParser.service.js.map +1 -1
- package/es2022/src/services/dateValueProvider/dateValueProvider.service.js +6 -7
- package/es2022/src/services/dateValueProvider/dateValueProvider.service.js.map +1 -1
- package/package.json +31 -31
- package/src/directives/buttonDateTimeInput/buttonDateTimeInput.directive.d.ts.map +1 -1
- package/src/misc/enums.d.ts +6 -2
- package/src/misc/enums.d.ts.map +1 -1
- package/src/misc/utils.d.ts +5 -3
- package/src/misc/utils.d.ts.map +1 -1
- package/src/misc/validators.d.ts +17 -3
- package/src/misc/validators.d.ts.map +1 -1
- package/src/modules/dateTime/directives/dateTime/dateTime.directive.d.ts +5 -1
- package/src/modules/dateTime/directives/dateTime/dateTime.directive.d.ts.map +1 -1
- package/src/modules/dateTime/directives/dateTimeInput/dateTimeInput.directive.d.ts.map +1 -1
- package/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.d.ts.map +1 -1
- package/src/modules/dateTimePicker/directives/dateTimePicker/dateTimePicker.directive.d.ts.map +1 -1
- package/version.bak +1 -1
package/es2022/src/misc/utils.js
CHANGED
|
@@ -6,8 +6,9 @@ import { DateTimeValueFormat } from './enums';
|
|
|
6
6
|
* @param dateApi - Date api used for obtaining result
|
|
7
7
|
* @param dateTimeFormat - Date time format type, optional, if not specified autodetection of format will be used
|
|
8
8
|
* @param stringFormat - String format for parsing string dates, required only for string dates
|
|
9
|
+
* @param dataFormat - String format for parsing string dates, required only for string dates, has higher priority than `stringFormat`
|
|
9
10
|
*/
|
|
10
|
-
export function parseDateTime(value, dateApi, dateTimeFormat, stringFormat) {
|
|
11
|
+
export function parseDateTime(value, dateApi, dateTimeFormat, stringFormat, dataFormat) {
|
|
11
12
|
if (isBlank(value)) {
|
|
12
13
|
return value;
|
|
13
14
|
}
|
|
@@ -24,40 +25,46 @@ export function parseDateTime(value, dateApi, dateTimeFormat, stringFormat) {
|
|
|
24
25
|
throw new Error('DateTime: requested datetime format is not range, but value is range!');
|
|
25
26
|
}
|
|
26
27
|
return [
|
|
27
|
-
isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null),
|
|
28
|
-
isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance, null),
|
|
28
|
+
isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null, null),
|
|
29
|
+
isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance, null, null),
|
|
29
30
|
];
|
|
30
31
|
}
|
|
31
32
|
//value should be date instance, or number, or string, but it is not
|
|
32
33
|
if (dateTimeFormat != DateTimeValueFormat.DateInstance &&
|
|
33
34
|
dateTimeFormat != DateTimeValueFormat.FormattedString &&
|
|
34
|
-
dateTimeFormat != DateTimeValueFormat.UnixTimestamp
|
|
35
|
+
dateTimeFormat != DateTimeValueFormat.UnixTimestamp &&
|
|
36
|
+
dateTimeFormat != DateTimeValueFormat.DataString) {
|
|
35
37
|
throw new Error('DateTime: unable to get date time value, should be date instance, or string, or number!');
|
|
36
38
|
}
|
|
39
|
+
if (dateTimeFormat == DateTimeValueFormat.DataString) {
|
|
40
|
+
//value is string, instance of date or unix timestamp
|
|
41
|
+
return dateApi.getValue(value, dataFormat ?? undefined);
|
|
42
|
+
}
|
|
37
43
|
//value is string, instance of date or unix timestamp
|
|
38
44
|
return dateApi.getValue(value, stringFormat ?? undefined);
|
|
39
45
|
}
|
|
40
46
|
//value is range
|
|
41
47
|
if (isDateTimeValue(value)) {
|
|
42
48
|
return [
|
|
43
|
-
isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null),
|
|
44
|
-
isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance, null),
|
|
49
|
+
isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null, null),
|
|
50
|
+
isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance, null, null),
|
|
45
51
|
];
|
|
46
52
|
}
|
|
47
53
|
//string format, but format string was not provided
|
|
48
|
-
if (isString(value) && isBlank(stringFormat)) {
|
|
54
|
+
if (isString(value) && isBlank(stringFormat) && isBlank(dataFormat)) {
|
|
49
55
|
throw new Error('DateTime: unable to parse string date, because format is missing!');
|
|
50
56
|
}
|
|
51
57
|
//value is string, instance of date or unix timestamp
|
|
52
|
-
return dateApi.getValue(value, stringFormat ?? undefined);
|
|
58
|
+
return dateApi.getValue(value, dataFormat ?? stringFormat ?? undefined);
|
|
53
59
|
}
|
|
54
60
|
/**
|
|
55
61
|
* Formats value into specified format of date time
|
|
56
62
|
* @param value - Value that should be converted to input output date time value
|
|
57
63
|
* @param dateTimeFormat - Date time format type
|
|
58
|
-
* @param stringFormat - String format for
|
|
64
|
+
* @param stringFormat - String format for formatting string dates, required only for string dates
|
|
65
|
+
* @param dataFormat - String format for formatting string dates, required only for string dates, has higher priority than `stringFormat`
|
|
59
66
|
*/
|
|
60
|
-
export function formatDateTime(value, dateTimeFormat, stringFormat) {
|
|
67
|
+
export function formatDateTime(value, dateTimeFormat, stringFormat, dataFormat) {
|
|
61
68
|
if (isBlank(value)) {
|
|
62
69
|
return value;
|
|
63
70
|
}
|
|
@@ -76,6 +83,14 @@ export function formatDateTime(value, dateTimeFormat, stringFormat) {
|
|
|
76
83
|
if (dateTimeFormat == DateTimeValueFormat.RangeOfDateInstances) {
|
|
77
84
|
throw new Error('DateTime: value is not array of values, but format is range!');
|
|
78
85
|
}
|
|
86
|
+
//data string date time
|
|
87
|
+
if (dateTimeFormat == DateTimeValueFormat.DataString) {
|
|
88
|
+
//string format is missing for string date time
|
|
89
|
+
if (isBlank(dataFormat)) {
|
|
90
|
+
throw new Error('DateTime: missing data string format for string date time!');
|
|
91
|
+
}
|
|
92
|
+
return value.format(dataFormat);
|
|
93
|
+
}
|
|
79
94
|
//string date time
|
|
80
95
|
if (dateTimeFormat == DateTimeValueFormat.FormattedString) {
|
|
81
96
|
//string format is missing for string date time
|
|
@@ -120,7 +135,7 @@ export function parseRawInput(rawValue, dateApi, dateTimeData, valueProvider) {
|
|
|
120
135
|
return [null, null];
|
|
121
136
|
}
|
|
122
137
|
const internalValue = getInternalValue(rawValue, dateApi, dateTimeData, valueProvider);
|
|
123
|
-
const value = formatDateTime(internalValue, dateTimeData.valueFormat, dateTimeData.customFormat);
|
|
138
|
+
const value = formatDateTime(internalValue, dateTimeData.valueFormat, dateTimeData.customFormat, dateTimeData.dataFormat);
|
|
124
139
|
return [internalValue, value];
|
|
125
140
|
}
|
|
126
141
|
/**
|
|
@@ -131,7 +146,7 @@ export function parseRawInput(rawValue, dateApi, dateTimeData, valueProvider) {
|
|
|
131
146
|
* @param valueProvider - Provider used for obtaining rounded value according format
|
|
132
147
|
*/
|
|
133
148
|
export function getInternalValue(value, dateApi, dateTimeData, valueProvider) {
|
|
134
|
-
let internalValue = parseDateTime(value, dateApi, null, dateTimeData.customFormat);
|
|
149
|
+
let internalValue = parseDateTime(value, dateApi, null, dateTimeData.customFormat, dateTimeData.dataFormat);
|
|
135
150
|
if (isBlank(internalValue)) {
|
|
136
151
|
return;
|
|
137
152
|
}
|
|
@@ -140,22 +155,22 @@ export function getInternalValue(value, dateApi, dateTimeData, valueProvider) {
|
|
|
140
155
|
if (Array.isArray(internalValue)) {
|
|
141
156
|
const [from, to] = internalValue;
|
|
142
157
|
if (from) {
|
|
143
|
-
const val = valueProvider.getValue(from.value, dateTimeData.customFormat).from;
|
|
158
|
+
const val = valueProvider.getValue(from.value, dateTimeData.dataFormat ?? dateTimeData.customFormat).from;
|
|
144
159
|
if (val) {
|
|
145
|
-
internalValue[0] = dateApi.getValue(val, dateTimeData.customFormat);
|
|
160
|
+
internalValue[0] = dateApi.getValue(val, dateTimeData.dataFormat ?? dateTimeData.customFormat);
|
|
146
161
|
}
|
|
147
162
|
}
|
|
148
163
|
if (to) {
|
|
149
|
-
const val = valueProvider.getValue(to.value, dateTimeData.customFormat).to;
|
|
164
|
+
const val = valueProvider.getValue(to.value, dateTimeData.dataFormat ?? dateTimeData.customFormat).to;
|
|
150
165
|
if (val) {
|
|
151
|
-
internalValue[1] = dateApi.getValue(val, dateTimeData.customFormat);
|
|
166
|
+
internalValue[1] = dateApi.getValue(val, dateTimeData.dataFormat ?? dateTimeData.customFormat);
|
|
152
167
|
}
|
|
153
168
|
}
|
|
154
169
|
}
|
|
155
170
|
else {
|
|
156
|
-
const val = valueProvider.getValue(internalValue.value, dateTimeData.customFormat).from;
|
|
171
|
+
const val = valueProvider.getValue(internalValue.value, dateTimeData.dataFormat ?? dateTimeData.customFormat).from;
|
|
157
172
|
if (val) {
|
|
158
|
-
internalValue = dateApi.getValue(val, dateTimeData.customFormat);
|
|
173
|
+
internalValue = dateApi.getValue(val, dateTimeData.dataFormat ?? dateTimeData.customFormat);
|
|
159
174
|
}
|
|
160
175
|
}
|
|
161
176
|
return internalValue;
|
|
@@ -1 +1 @@
|
|
|
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,EAAC,MAAM,gBAAgB,CAAC;AAKhF,OAAO,EAAC,mBAAmB,EAAC,MAAM,SAAS,CAAC;AAG5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AC;AACzB,CAAC","sourcesContent":["import {isBlank, isJsObject, isPresent, isString, nameof} from '@jscrpt/common';\n\nimport {DateTimeValue} from '../interfaces';\nimport type {DateTimeSADirective} from '../modules/dateTime/directives/dateTime/dateTime.directive';\nimport {DateApi, DateApiObject, DateValue, DateValueProvider} 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}\n\n/**\n * Parses raw value into internal value and value\n * @param rawValue - Raw value to be parsed\n * @param dateApi - Date api for manipulation with date\n * @param dateTimeData - Object storing information about format\n * @param valueProvider - Provider used for obtaining rounded value according format\n */\nexport function parseRawInput<TDate>(rawValue: string, \n dateApi: DateApi<TDate>,\n dateTimeData: DateTimeSADirective<TDate>,\n valueProvider: DateValueProvider<TDate>,): [DateTimeObjectValue<TDate>|undefined|null, DateTimeInputOutputValue<TDate>|undefined|null]\n{\n if(!rawValue)\n {\n return [null, null];\n }\n\n const internalValue = getInternalValue(rawValue, dateApi, dateTimeData, valueProvider);\n const value = formatDateTime(internalValue, dateTimeData.valueFormat, dateTimeData.customFormat);\n\n return [internalValue, value];\n}\n\n/**\n * Gets internal value and fix lowest time difference\n * @param value - Value to be get as internal value\n * @param dateApi - Date api for manipulation with date\n * @param dateTimeData - Object storing information about format\n * @param valueProvider - Provider used for obtaining rounded value according format\n */\nexport function getInternalValue<TDate>(value: DateTimeInputOutputValue<TDate>|undefined|null,\n dateApi: DateApi<TDate>,\n dateTimeData: DateTimeSADirective<TDate>,\n valueProvider: DateValueProvider<TDate>,): DateTimeObjectValue<TDate>|undefined|null\n{\n let internalValue = parseDateTime(value, dateApi, null, dateTimeData.customFormat);\n\n if(isBlank(internalValue))\n {\n return;\n }\n\n //update for specified format, round value\n\n //ranged value\n if(Array.isArray(internalValue))\n {\n const [from, to] = internalValue;\n\n if(from)\n {\n const val = valueProvider.getValue(from.value, dateTimeData.customFormat).from;\n\n if(val)\n {\n internalValue[0] = dateApi.getValue(val, dateTimeData.customFormat);\n }\n }\n\n if(to)\n {\n const val = valueProvider.getValue(to.value, dateTimeData.customFormat).to;\n\n if(val)\n {\n internalValue[1] = dateApi.getValue(val, dateTimeData.customFormat);\n }\n }\n }\n else\n {\n const val = valueProvider.getValue(internalValue.value, dateTimeData.customFormat).from;\n\n if(val)\n {\n internalValue = dateApi.getValue(val, dateTimeData.customFormat);\n }\n }\n\n return internalValue;\n}"]}
|
|
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,EAAC,MAAM,gBAAgB,CAAC;AAKhF,OAAO,EAAC,mBAAmB,EAAC,MAAM,SAAS,CAAC;AAG5C;;;;;;;GAOG;AACH,MAAM,UAAU,aAAa,CAAkB,KAAqD,EACrD,OAAuB,EACvB,cAAkD,EAClD,YAAmC,EACnC,UAAiC;IAE5E,IAAG,OAAO,CAAC,KAAK,CAAC,EACjB;QACI,OAAO,KAAK,CAAC;KAChB;IAED,qBAAqB;IACrB,IAAG,SAAS,CAAC,cAAc,CAAC,EAC5B;QACI,4DAA4D;QAC5D,IAAG,cAAc,IAAI,mBAAmB,CAAC,eAAe,IAAI,OAAO,CAAC,YAAY,CAAC,EACjF;YACI,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;SACxF;QAED,gBAAgB;QAChB,IAAG,eAAe,CAAC,KAAK,CAAC,EACzB;YACI,iCAAiC;YACjC,IAAG,cAAc,IAAI,mBAAmB,CAAC,oBAAoB,EAC7D;gBACI,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;aAC5F;YAED,OAAO;gBACH,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,mBAAmB,CAAC,YAAY,EAAE,IAAI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CAAC","sourcesContent":["import {isBlank, isJsObject, isPresent, isString, nameof} from '@jscrpt/common';\n\nimport {DateTimeValue} from '../interfaces';\nimport type {DateTimeSADirective} from '../modules/dateTime/directives/dateTime/dateTime.directive';\nimport {DateApi, DateApiObject, DateValue, DateValueProvider} 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 * @param dataFormat - String format for parsing string dates, required only for string dates, has higher priority than `stringFormat`\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,\n dataFormat: 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, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance, null, 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 dateTimeFormat != DateTimeValueFormat.DataString)\n {\n throw new Error('DateTime: unable to get date time value, should be date instance, or string, or number!');\n }\n\n if(dateTimeFormat == DateTimeValueFormat.DataString)\n {\n //value is string, instance of date or unix timestamp\n return dateApi.getValue(value, dataFormat ?? undefined);\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, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance , null, null) as DateApiObject<TDate>,\n ];\n }\n\n //string format, but format string was not provided\n if(isString(value) && isBlank(stringFormat) && isBlank(dataFormat))\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, dataFormat ?? 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 formatting string dates, required only for string dates\n * @param dataFormat - String format for formatting string dates, required only for string dates, has higher priority than `stringFormat`\n */\nexport function formatDateTime<TDate = unknown>(value: DateTimeObjectValue<TDate>|undefined|null,\n dateTimeFormat: DateTimeValueFormat,\n stringFormat: string|undefined|null,\n dataFormat: 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 //data string date time\n if(dateTimeFormat == DateTimeValueFormat.DataString)\n {\n //string format is missing for string date time\n if(isBlank(dataFormat))\n {\n throw new Error('DateTime: missing data string format for string date time!');\n }\n\n return value.format(dataFormat);\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}\n\n/**\n * Parses raw value into internal value and value\n * @param rawValue - Raw value to be parsed\n * @param dateApi - Date api for manipulation with date\n * @param dateTimeData - Object storing information about format\n * @param valueProvider - Provider used for obtaining rounded value according format\n */\nexport function parseRawInput<TDate>(rawValue: string, \n dateApi: DateApi<TDate>,\n dateTimeData: DateTimeSADirective<TDate>,\n valueProvider: DateValueProvider<TDate>,): [DateTimeObjectValue<TDate>|undefined|null, DateTimeInputOutputValue<TDate>|undefined|null]\n{\n if(!rawValue)\n {\n return [null, null];\n }\n\n const internalValue = getInternalValue(rawValue, dateApi, dateTimeData, valueProvider);\n const value = formatDateTime(internalValue, dateTimeData.valueFormat, dateTimeData.customFormat, dateTimeData.dataFormat);\n\n return [internalValue, value];\n}\n\n/**\n * Gets internal value and fix lowest time difference\n * @param value - Value to be get as internal value\n * @param dateApi - Date api for manipulation with date\n * @param dateTimeData - Object storing information about format\n * @param valueProvider - Provider used for obtaining rounded value according format\n */\nexport function getInternalValue<TDate>(value: DateTimeInputOutputValue<TDate>|undefined|null,\n dateApi: DateApi<TDate>,\n dateTimeData: DateTimeSADirective<TDate>,\n valueProvider: DateValueProvider<TDate>,): DateTimeObjectValue<TDate>|undefined|null\n{\n let internalValue = parseDateTime(value, dateApi, null, dateTimeData.customFormat, dateTimeData.dataFormat);\n\n if(isBlank(internalValue))\n {\n return;\n }\n\n //update for specified format, round value\n\n //ranged value\n if(Array.isArray(internalValue))\n {\n const [from, to] = internalValue;\n\n if(from)\n {\n const val = valueProvider.getValue(from.value, dateTimeData.dataFormat ?? dateTimeData.customFormat).from;\n\n if(val)\n {\n internalValue[0] = dateApi.getValue(val, dateTimeData.dataFormat ?? dateTimeData.customFormat);\n }\n }\n\n if(to)\n {\n const val = valueProvider.getValue(to.value, dateTimeData.dataFormat ?? dateTimeData.customFormat).to;\n\n if(val)\n {\n internalValue[1] = dateApi.getValue(val, dateTimeData.dataFormat ?? dateTimeData.customFormat);\n }\n }\n }\n else\n {\n const val = valueProvider.getValue(internalValue.value, dateTimeData.dataFormat ?? dateTimeData.customFormat).from;\n\n if(val)\n {\n internalValue = dateApi.getValue(val, dateTimeData.dataFormat ?? dateTimeData.customFormat);\n }\n }\n\n return internalValue;\n}"]}
|
|
@@ -8,13 +8,14 @@ import { DATE_API } from './tokens';
|
|
|
8
8
|
* @param dateApi - Date api used for parsing date time
|
|
9
9
|
* @param valueFormat - Optional required format
|
|
10
10
|
* @param stringFormat - Optional string format of value
|
|
11
|
+
* @param dataFormat - Optional string data format of value
|
|
11
12
|
*/
|
|
12
|
-
export function datetimeValidator(dateApi, valueFormat, stringFormat) {
|
|
13
|
+
export function datetimeValidator(dateApi, valueFormat, stringFormat, dataFormat) {
|
|
13
14
|
return (control) => {
|
|
14
15
|
if (isBlank(control.value)) {
|
|
15
16
|
return null;
|
|
16
17
|
}
|
|
17
|
-
const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);
|
|
18
|
+
const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat, dataFormat);
|
|
18
19
|
if (!parsedValue) {
|
|
19
20
|
return null;
|
|
20
21
|
}
|
|
@@ -41,13 +42,13 @@ export function dateTimeModelValidatorFactory(args) {
|
|
|
41
42
|
if (!dateApi) {
|
|
42
43
|
throw new Error('DateTime: missing DateApi! Please provide one.');
|
|
43
44
|
}
|
|
44
|
-
return datetimeValidator(dateApi, args.valueFormat, args.stringFormat);
|
|
45
|
+
return datetimeValidator(dateApi, args.valueFormat, args.stringFormat, args.dataFormat);
|
|
45
46
|
}, args);
|
|
46
47
|
}
|
|
47
48
|
/**
|
|
48
49
|
* Sets date time validator to property on which is used
|
|
49
50
|
*/
|
|
50
|
-
export function DateTime(valueFormatOrStringFormat, stringFormat) {
|
|
51
|
+
export function DateTime(valueFormatOrStringFormat, stringFormat, dataFormat) {
|
|
51
52
|
let valueFormat;
|
|
52
53
|
if (isNumber(valueFormatOrStringFormat)) {
|
|
53
54
|
valueFormat = valueFormatOrStringFormat;
|
|
@@ -59,6 +60,7 @@ export function DateTime(valueFormatOrStringFormat, stringFormat) {
|
|
|
59
60
|
validators: [dateTimeModelValidatorFactory({
|
|
60
61
|
stringFormat,
|
|
61
62
|
valueFormat,
|
|
63
|
+
dataFormat,
|
|
62
64
|
})]
|
|
63
65
|
});
|
|
64
66
|
}
|
|
@@ -68,8 +70,9 @@ export function DateTime(valueFormatOrStringFormat, stringFormat) {
|
|
|
68
70
|
* @param maxValue - Maximal date time value that should be used for validation against
|
|
69
71
|
* @param valueFormat - Optional required format
|
|
70
72
|
* @param stringFormat - Optional string format of value
|
|
73
|
+
* @param dataFormat - Optional string data format of value
|
|
71
74
|
*/
|
|
72
|
-
export function datetimeMaxValidator(dateApi, maxValue, valueFormat, stringFormat) {
|
|
75
|
+
export function datetimeMaxValidator(dateApi, maxValue, valueFormat, stringFormat, dataFormat) {
|
|
73
76
|
return (control) => {
|
|
74
77
|
if (isBlank(control.value) || isBlank(maxValue)) {
|
|
75
78
|
return null;
|
|
@@ -82,7 +85,7 @@ export function datetimeMaxValidator(dateApi, maxValue, valueFormat, stringForma
|
|
|
82
85
|
}
|
|
83
86
|
maxValue = value;
|
|
84
87
|
}
|
|
85
|
-
const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);
|
|
88
|
+
const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat, dataFormat);
|
|
86
89
|
if (!parsedValue) {
|
|
87
90
|
return null;
|
|
88
91
|
}
|
|
@@ -106,8 +109,9 @@ export function datetimeMaxValidator(dateApi, maxValue, valueFormat, stringForma
|
|
|
106
109
|
* @param minValue - Minimal date time value that should be used for validation against
|
|
107
110
|
* @param valueFormat - Optional required format
|
|
108
111
|
* @param stringFormat - Optional string format of value
|
|
112
|
+
* @param dataFormat - Optional string data format of value
|
|
109
113
|
*/
|
|
110
|
-
export function datetimeMinValidator(dateApi, minValue, valueFormat, stringFormat) {
|
|
114
|
+
export function datetimeMinValidator(dateApi, minValue, valueFormat, stringFormat, dataFormat) {
|
|
111
115
|
return (control) => {
|
|
112
116
|
if (isBlank(control.value) || isBlank(minValue)) {
|
|
113
117
|
return null;
|
|
@@ -120,7 +124,7 @@ export function datetimeMinValidator(dateApi, minValue, valueFormat, stringForma
|
|
|
120
124
|
}
|
|
121
125
|
minValue = value;
|
|
122
126
|
}
|
|
123
|
-
const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);
|
|
127
|
+
const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat, dataFormat);
|
|
124
128
|
if (!parsedValue) {
|
|
125
129
|
return null;
|
|
126
130
|
}
|
|
@@ -1 +1 @@
|
|
|
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,EA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CAAC;IAChB,CAAC,CAAC;AACN,CAAC","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, DateValue} from '../services';\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)\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)\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"]}
|
|
1
|
+
{"version":3,"file":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IAAG,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAC9B;YACI,IAAG,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,EACnE;gBACI,OAAO;oBACH,aAAa,EAAE,WAAW,CAAC,KAAK;iBACnC,CAAC;aACL;SACJ;aAED;YACI,0BAA0B;SAC7B;QAED,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;AACN,CAAC","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, DateValue} from '../services';\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 * Format of data string value\n */\n dataFormat?: 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 * @param dataFormat - Optional string data format of value\n */\nexport function datetimeValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,\n dataFormat: 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, dataFormat);\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, args.dataFormat);\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\n * @param valueFormat - Format of validated value\n * @param stringFormat - Format of string value\n * @param dataFormat - Format of data string value\n */\nexport function DateTime(valueFormat: DateTimeValueFormat, stringFormat: string|undefined|null, dataFormat: 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, dataFormat?: 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 dataFormat,\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 * @param dataFormat - Optional string data 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,\n dataFormat: 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)\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, dataFormat);\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 * @param dataFormat - Optional string data 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,\n dataFormat: 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)\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, dataFormat);\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"]}
|
|
@@ -11,7 +11,7 @@ import * as i3 from "../../directives/calendarDayTemplate/calendarDayTemplate.di
|
|
|
11
11
|
/**
|
|
12
12
|
* Component used for displaying month calendar
|
|
13
13
|
*/
|
|
14
|
-
class MonthCalendarComponent {
|
|
14
|
+
export class MonthCalendarComponent {
|
|
15
15
|
dateApi;
|
|
16
16
|
formatProvider;
|
|
17
17
|
eventParser;
|
|
@@ -184,24 +184,23 @@ class MonthCalendarComponent {
|
|
|
184
184
|
* Custom input type for `dayAspectRatio` input
|
|
185
185
|
*/
|
|
186
186
|
static ngAcceptInputType_dayAspectRatio;
|
|
187
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
188
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "
|
|
187
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: MonthCalendarComponent, deps: [{ token: DATE_API }, { token: FORMAT_PROVIDER }, { token: i1.EventParser }], target: i0.ɵɵFactoryTarget.Component });
|
|
188
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.1.1", type: MonthCalendarComponent, selector: "month-calendar", inputs: { showWeekNumber: "showWeekNumber", display: "display", weekDayName: "weekDayName", dayAspectRatio: "dayAspectRatio", events: "events" }, providers: [
|
|
189
189
|
EventParser,
|
|
190
190
|
], queries: [{ propertyName: "customCalendarDayTemplate", first: true, predicate: CalendarDayTemplateDirective, descendants: true, read: TemplateRef, static: true }], viewQueries: [{ propertyName: "defaultCalendarDayTemplate", first: true, predicate: CalendarDayTemplateDirective, descendants: true, read: TemplateRef, static: true }], usesOnChanges: true, ngImport: i0, template: "<div *calendarDayTemplate=\"let data\" class=\"default-calendar-day\" [class.is-weekend]=\"data.isWeekend\" [class.is-other-month]=\"!data.isCurrentMonth\">{{data.day}}</div>\n\n<div></div>\n\n<div *ngFor=\"let dayName of weekDayNames\" [class.week-day-name]=\"dayName\">{{dayName}}</div>\n\n<ng-container *ngFor=\"let weekData of calendarData | keyvalue\">\n <div class=\"week-number\">\n <ng-container *ngIf=\"showWeekNumber\">{{weekData.key}}</ng-container>\n </div>\n \n <div *ngFor=\"let dayData of weekData.value\" [style.padding-bottom.%]=\"dayAspectRatioValue\" class=\"day-wrapper\">\n <div class=\"day-content\"><ng-container *ngTemplateOutlet=\"calendarDayTemplate; context: {$implicit: dayData}\"></ng-container></div>\n </div>\n</ng-container>\n", dependencies: [{ kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i3.CalendarDayTemplateDirective, selector: "[calendarDayTemplate]" }, { kind: "pipe", type: i2.KeyValuePipe, name: "keyvalue" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
191
191
|
}
|
|
192
|
-
|
|
193
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: MonthCalendarComponent, decorators: [{
|
|
192
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: MonthCalendarComponent, decorators: [{
|
|
194
193
|
type: Component,
|
|
195
194
|
args: [{ selector: 'month-calendar', providers: [
|
|
196
195
|
EventParser,
|
|
197
196
|
], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div *calendarDayTemplate=\"let data\" class=\"default-calendar-day\" [class.is-weekend]=\"data.isWeekend\" [class.is-other-month]=\"!data.isCurrentMonth\">{{data.day}}</div>\n\n<div></div>\n\n<div *ngFor=\"let dayName of weekDayNames\" [class.week-day-name]=\"dayName\">{{dayName}}</div>\n\n<ng-container *ngFor=\"let weekData of calendarData | keyvalue\">\n <div class=\"week-number\">\n <ng-container *ngIf=\"showWeekNumber\">{{weekData.key}}</ng-container>\n </div>\n \n <div *ngFor=\"let dayData of weekData.value\" [style.padding-bottom.%]=\"dayAspectRatioValue\" class=\"day-wrapper\">\n <div class=\"day-content\"><ng-container *ngTemplateOutlet=\"calendarDayTemplate; context: {$implicit: dayData}\"></ng-container></div>\n </div>\n</ng-container>\n" }]
|
|
198
|
-
}], ctorParameters:
|
|
197
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
199
198
|
type: Inject,
|
|
200
199
|
args: [DATE_API]
|
|
201
200
|
}] }, { type: undefined, decorators: [{
|
|
202
201
|
type: Inject,
|
|
203
202
|
args: [FORMAT_PROVIDER]
|
|
204
|
-
}] }, { type: i1.EventParser }]
|
|
203
|
+
}] }, { type: i1.EventParser }], propDecorators: { defaultCalendarDayTemplate: [{
|
|
205
204
|
type: ViewChild,
|
|
206
205
|
args: [CalendarDayTemplateDirective, { static: true, read: TemplateRef }]
|
|
207
206
|
}], customCalendarDayTemplate: [{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monthCalendar.component.js","sourceRoot":"","sources":["../../../../../../src/modules/calendar/components/monthCalendar/monthCalendar.component.ts","../../../../../../src/modules/calendar/components/monthCalendar/monthCalendar.component.html"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,uBAAuB,EAAE,KAAK,EAAE,MAAM,EAAU,SAAS,EAAE,WAAW,EAAE,YAAY,EAA2B,MAAM,eAAe,CAAC;AACxJ,OAAO,EAAa,QAAQ,EAAE,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAG5D,OAAO,EAAC,4BAA4B,EAA6B,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAC,sBAAsB,EAAE,sBAAsB,EAAC,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,QAAQ,EAAE,eAAe,EAAC,MAAM,yBAAyB,CAAC;;;;;AAIlE;;GAEG;AACH,MAUa,sBAAsB;IAwFS;IACO;IACzB;IAxFtB,8FAA8F;IAE9F;;OAEG;IACO,mBAAmB,GAAW,sBAAsB,CAAC,UAAU,CAAC;IAE1E;;OAEG;IACO,YAAY,GAAiD,EAAE,CAAC;IAE1E;;OAEG;IACH,IAAc,mBAAmB;QAE7B,OAAO,IAAI,CAAC,yBAAyB,IAAI,IAAI,CAAC,0BAA0B,CAAC;IAC7E,CAAC;IAED;;OAEG;IACO,YAAY,GAAa,EAAE,CAAC;IAEtC,qFAAqF;IAErF;;OAEG;IAEO,0BAA0B,CAA2C;IAE/E;;OAEG;IAEO,yBAAyB,CAAyD;IAE5F,gFAAgF;IAEhF;;OAEG;IAEI,cAAc,GAAY,KAAK,CAAC;IAEvC;;OAEG;IAEI,OAAO,CAAuB;IAErC;;OAEG;IAEI,WAAW,GAA2B,sBAAsB,CAAC,K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F,GAAG,CAAC,MAAM,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;aACjC;SACJ;IACL,CAAC;IAED,wEAAwE;IAExE;;OAEG;IACI,MAAM,CAAC,6BAA6B,CAAsC;IAEjF;;OAEG;IACI,MAAM,CAAC,gCAAgC,CAA6C;uGAlPlF,sBAAsB,kBAwFX,QAAQ,aACR,eAAe;2FAzF1B,sBAAsB,2LAL/B;YACI,WAAW;SACd,iFAyCa,4BAA4B,2BAAuB,WAAW,uGANjE,4BAA4B,2BAAuB,WAAW,gECxD7E,qxBAeA;;SDSa,sBAAsB;2FAAtB,sBAAsB;kBAVlC,SAAS;+BAEI,gBAAgB,aAG1B;wBACI,WAAW;qBACd,mBACgB,uBAAuB,CAAC,MAAM;;0BA0FlC,MAAM;2BAAC,QAAQ;;0BACf,MAAM;2BAAC,eAAe;sEAxDzB,0BAA0B;sBADnC,SAAS;uBAAC,4BAA4B,EAAE,EAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAC;gBAOhE,yBAAyB;sBADlC,YAAY;uBAAC,4BAA4B,EAAE,EAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAC;gBAStE,cAAc;sBADpB,KAAK;gBAOC,OAAO;sBADb,KAAK;gBAOC,WAAW;sBADjB,KAAK;gBAOK,cAAc;sBADxB,KAAK;gBAqBC,MAAM;sBADZ,KAAK","sourcesContent":["import {Component, ChangeDetectionStrategy, Input, Inject, OnInit, ViewChild, TemplateRef, ContentChild, OnChanges, SimpleChanges} from '@angular/core';\nimport {Dictionary, isString, nameof} from '@jscrpt/common';\n\nimport {CalendarDayData, EventData} from '../../interfaces';\nimport {CalendarDayTemplateDirective, CalendarDayTemplateContext} from '../../directives';\nimport {MonthCalendarDayFormat, CalendarDayAspectRatio} from '../../misc';\nimport {EventParser} from '../../services';\nimport {DATE_API, FORMAT_PROVIDER} from '../../../../misc/tokens';\nimport {DateApi} from '../../../../services';\nimport {FormatProvider} from '../../../../interfaces';\n\n/**\n * Component used for displaying month calendar\n */\n@Component(\n{\n selector: 'month-calendar',\n templateUrl: 'monthCalendar.component.html',\n providers:\n [\n EventParser,\n ],\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class MonthCalendarComponent<TDate = unknown, TEvent = unknown> implements OnInit, OnChanges\n{\n //######################### protected properties - template bindings #########################\n\n /**\n * Aspect ratio for displayed calendar day cell\n */\n protected dayAspectRatioValue: number = CalendarDayAspectRatio.ThreeToTwo;\n\n /**\n * Data that represents calendar data\n */\n protected calendarData: Dictionary<CalendarDayData<TDate, TEvent>[]> = {};\n\n /**\n * Calendar day template to be used\n */\n protected get calendarDayTemplate(): TemplateRef<CalendarDayTemplateContext>\n {\n return this.customCalendarDayTemplate ?? this.defaultCalendarDayTemplate;\n }\n\n /**\n * Array of weekday names\n */\n protected weekDayNames: string[] = [];\n\n //######################### protected properties - children #########################\n\n /**\n * Default calendar day template\n */\n @ViewChild(CalendarDayTemplateDirective, {static: true, read: TemplateRef})\n protected defaultCalendarDayTemplate!: TemplateRef<CalendarDayTemplateContext>;\n\n /**\n * Custom calendar day template\n */\n @ContentChild(CalendarDayTemplateDirective, {static: true, read: TemplateRef})\n protected customCalendarDayTemplate: TemplateRef<CalendarDayTemplateContext>|undefined|null;\n\n //######################### public properties - inputs #########################\n\n /**\n * Indication that week number should be displayed\n */\n @Input()\n public showWeekNumber: boolean = false;\n\n /**\n * Date that should be displayed in month calendar\n */\n @Input()\n public display: TDate|undefined|null;\n\n /**\n * Format for displaying week day names\n */\n @Input()\n public weekDayName: MonthCalendarDayFormat = MonthCalendarDayFormat.Short;\n\n /**\n * Aspect ratio for displayed calendar day cell\n */\n @Input()\n public get dayAspectRatio(): number\n {\n return this.dayAspectRatioValue;\n }\n public set dayAspectRatio(value: number)\n {\n if(isString(value))\n {\n this.dayAspectRatioValue = CalendarDayAspectRatio[value] as unknown as number;\n\n return;\n }\n\n this.dayAspectRatioValue = value;\n }\n\n /**\n * Array of events that should be displayed\n */\n @Input()\n public events: EventData<TDate, TEvent>[] = [];\n\n //######################### constructor #########################\n constructor(@Inject(DATE_API) protected dateApi: DateApi<TDate>,\n @Inject(FORMAT_PROVIDER) protected formatProvider: FormatProvider,\n protected eventParser: EventParser<TDate, TEvent>,)\n {\n }\n\n //######################### public methods - implementation of OnInit #########################\n\n /**\n * Initialize component\n */\n public ngOnInit(): void\n {\n this.initWeekdayNames();\n this.initializeDisplayCalendar();\n }\n\n //######################### public methods - implementation of OnChanges #########################\n\n /**\n * Called when input value changes\n */\n public ngOnChanges(changes: SimpleChanges): void\n {\n if(nameof<MonthCalendarComponent>('weekDayName') in changes)\n {\n this.initWeekdayNames();\n }\n\n if(nameof<MonthCalendarComponent>('display') in changes)\n {\n this.initializeDisplayCalendar();\n }\n\n if(nameof<MonthCalendarComponent>('events') in changes && !(nameof<MonthCalendarComponent>('display') in changes))\n {\n this.initAndAttachEventData();\n }\n }\n\n //######################### protected methods #########################\n\n /**\n * Initialize weekday names\n */\n protected initWeekdayNames(): void\n {\n this.weekDayNames = [];\n const dateApi = this.dateApi.now().startOfWeek();\n\n switch(this.weekDayName)\n {\n default:\n // case MonthCalendarDayFormat.None:\n {\n for(let x = 0; x < 7; x++)\n {\n this.weekDayNames.push('');\n }\n\n break;\n }\n case MonthCalendarDayFormat.Short:\n {\n for(let x = 0; x < 7; x++)\n {\n this.weekDayNames.push(dateApi.format(this.formatProvider.dayNameShort));\n dateApi.addDays(1);\n }\n\n break;\n }\n case MonthCalendarDayFormat.Full:\n {\n for(let x = 0; x < 7; x++)\n {\n this.weekDayNames.push(dateApi.format(this.formatProvider.dayName));\n dateApi.addDays(1);\n }\n\n break;\n }\n }\n }\n\n /**\n * Initialize date for calendar that should be displayed\n */\n protected initializeDisplayCalendar(): void\n {\n this.display ??= this.dateApi.now().value;\n\n const workDate = this.dateApi.getValue(this.display);\n\n workDate.startOfMonth()\n .startOfWeek();\n\n this.calendarData = {};\n\n do\n {\n const weekData: CalendarDayData<TDate, TEvent>[] = this.calendarData[workDate.format(this.formatProvider.week)] = [];\n\n for(let x = 0; x < 7; x++)\n {\n weekData.push(\n {\n date: workDate.value,\n day: workDate.dayOfMonth(),\n events: [],\n isCurrentMonth: workDate.isSameMonth(this.display),\n isWeekend: workDate.isWeekend(),\n week: +workDate.format(this.formatProvider.week),\n });\n\n workDate.addDays(1);\n }\n\n workDate.startOfWeek();\n }\n while(workDate.isSameMonth(this.display));\n\n this.initAndAttachEventData();\n }\n\n /**\n * Initialize and attaches event data\n */\n protected initAndAttachEventData(): void\n {\n const events = this.eventParser.getEventsPerDay(this.events);\n\n for(const week in this.calendarData)\n {\n const weekData = this.calendarData[week];\n\n for(const day of weekData)\n {\n const found = events.find(itm => this.dateApi.getValue(itm[0]).isSame(day.date));\n day.events = found?.[1] ?? [];\n }\n }\n }\n\n //######################### ng language server #########################\n\n /**\n * Custom input type for `weekDayName` input\n */\n public static ngAcceptInputType_weekDayName: keyof typeof MonthCalendarDayFormat;\n\n /**\n * Custom input type for `dayAspectRatio` input\n */\n public static ngAcceptInputType_dayAspectRatio: keyof typeof CalendarDayAspectRatio|number;\n}","<div *calendarDayTemplate=\"let data\" class=\"default-calendar-day\" [class.is-weekend]=\"data.isWeekend\" [class.is-other-month]=\"!data.isCurrentMonth\">{{data.day}}</div>\n\n<div></div>\n\n<div *ngFor=\"let dayName of weekDayNames\" [class.week-day-name]=\"dayName\">{{dayName}}</div>\n\n<ng-container *ngFor=\"let weekData of calendarData | keyvalue\">\n <div class=\"week-number\">\n <ng-container *ngIf=\"showWeekNumber\">{{weekData.key}}</ng-container>\n </div>\n \n <div *ngFor=\"let dayData of weekData.value\" [style.padding-bottom.%]=\"dayAspectRatioValue\" class=\"day-wrapper\">\n <div class=\"day-content\"><ng-container *ngTemplateOutlet=\"calendarDayTemplate; context: {$implicit: dayData}\"></ng-container></div>\n </div>\n</ng-container>\n"]}
|
|
1
|
+
{"version":3,"file":"monthCalendar.component.js","sourceRoot":"","sources":["../../../../../../src/modules/calendar/components/monthCalendar/monthCalendar.component.ts","../../../../../../src/modules/calendar/components/monthCalendar/monthCalendar.component.html"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,uBAAuB,EAAE,KAAK,EAAE,MAAM,EAAU,SAAS,EAAE,WAAW,EAAE,YAAY,EAA2B,MAAM,eAAe,CAAC;AACxJ,OAAO,EAAa,QAAQ,EAAE,MAAM,EAAC,MAAM,gBAAgB,CAAC;AAG5D,OAAO,EAAC,4BAA4B,EAA6B,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAC,sBAAsB,EAAE,sBAAsB,EAAC,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAC,QAAQ,EAAE,eAAe,EAAC,MAAM,yBAAyB,CAAC;;;;;AAIlE;;GAEG;AAWH,MAAM,OAAO,sBAAsB;IAwFS;IACO;IACzB;IAxFtB,8FAA8F;IAE9F;;OAEG;IACO,mBAAmB,GAAW,sBAAsB,CAAC,UAAU,CAAC;IAE1E;;OAEG;IACO,YAAY,GAAiD,EAAE,CAAC;IAE1E;;OAEG;IACH,IAAc,mBAAmB;QAE7B,OAAO,IAAI,CAAC,yBAAyB,IAAI,IAAI,CAAC,0BAA0B,CAAC;IAC7E,CAAC;IAED;;OAEG;IACO,YAAY,GAAa,EAAE,CAAC;IAEtC,qFAAqF;IAErF;;OAEG;IAEO,0BAA0B,CAA2C;IAE/E;;OAEG;IAEO,yBAAyB,CAAyD;IAE5F,gFAAgF;IAEhF;;OAEG;IAEI,cAAc,GAAY,KAAK,CAAC;IAEvC;;OAEG;IAEI,OAAO,CAAuB;IAErC;;OAEG;IAEI,WAAW,GAA2B,sBAAsB,CAAC,KAAK,CAAC;IAE1E;;OAEG;IACH,IACW,cAAc;QAErB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IACpC,CAAC;IACD,IAAW,cAAc,CAAC,KAAa;QAEnC,IAAG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M,CAAC,6BAA6B,CAAsC;IAEjF;;OAEG;IACI,MAAM,CAAC,gCAAgC,CAA6C;uGAlPlF,sBAAsB,kBAwFX,QAAQ,aACR,eAAe;2FAzF1B,sBAAsB,2LAL/B;YACI,WAAW;SACd,iFAyCa,4BAA4B,2BAAuB,WAAW,uGANjE,4BAA4B,2BAAuB,WAAW,gECxD7E,qxBAeA;;2FDSa,sBAAsB;kBAVlC,SAAS;+BAEI,gBAAgB,aAG1B;wBACI,WAAW;qBACd,mBACgB,uBAAuB,CAAC,MAAM;;0BA0FlC,MAAM;2BAAC,QAAQ;;0BACf,MAAM;2BAAC,eAAe;mEAxDzB,0BAA0B;sBADnC,SAAS;uBAAC,4BAA4B,EAAE,EAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAC;gBAOhE,yBAAyB;sBADlC,YAAY;uBAAC,4BAA4B,EAAE,EAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAC;gBAStE,cAAc;sBADpB,KAAK;gBAOC,OAAO;sBADb,KAAK;gBAOC,WAAW;sBADjB,KAAK;gBAOK,cAAc;sBADxB,KAAK;gBAqBC,MAAM;sBADZ,KAAK","sourcesContent":["import {Component, ChangeDetectionStrategy, Input, Inject, OnInit, ViewChild, TemplateRef, ContentChild, OnChanges, SimpleChanges} from '@angular/core';\nimport {Dictionary, isString, nameof} from '@jscrpt/common';\n\nimport {CalendarDayData, EventData} from '../../interfaces';\nimport {CalendarDayTemplateDirective, CalendarDayTemplateContext} from '../../directives';\nimport {MonthCalendarDayFormat, CalendarDayAspectRatio} from '../../misc';\nimport {EventParser} from '../../services';\nimport {DATE_API, FORMAT_PROVIDER} from '../../../../misc/tokens';\nimport {DateApi} from '../../../../services';\nimport {FormatProvider} from '../../../../interfaces';\n\n/**\n * Component used for displaying month calendar\n */\n@Component(\n{\n selector: 'month-calendar',\n templateUrl: 'monthCalendar.component.html',\n providers:\n [\n EventParser,\n ],\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class MonthCalendarComponent<TDate = unknown, TEvent = unknown> implements OnInit, OnChanges\n{\n //######################### protected properties - template bindings #########################\n\n /**\n * Aspect ratio for displayed calendar day cell\n */\n protected dayAspectRatioValue: number = CalendarDayAspectRatio.ThreeToTwo;\n\n /**\n * Data that represents calendar data\n */\n protected calendarData: Dictionary<CalendarDayData<TDate, TEvent>[]> = {};\n\n /**\n * Calendar day template to be used\n */\n protected get calendarDayTemplate(): TemplateRef<CalendarDayTemplateContext>\n {\n return this.customCalendarDayTemplate ?? this.defaultCalendarDayTemplate;\n }\n\n /**\n * Array of weekday names\n */\n protected weekDayNames: string[] = [];\n\n //######################### protected properties - children #########################\n\n /**\n * Default calendar day template\n */\n @ViewChild(CalendarDayTemplateDirective, {static: true, read: TemplateRef})\n protected defaultCalendarDayTemplate!: TemplateRef<CalendarDayTemplateContext>;\n\n /**\n * Custom calendar day template\n */\n @ContentChild(CalendarDayTemplateDirective, {static: true, read: TemplateRef})\n protected customCalendarDayTemplate: TemplateRef<CalendarDayTemplateContext>|undefined|null;\n\n //######################### public properties - inputs #########################\n\n /**\n * Indication that week number should be displayed\n */\n @Input()\n public showWeekNumber: boolean = false;\n\n /**\n * Date that should be displayed in month calendar\n */\n @Input()\n public display: TDate|undefined|null;\n\n /**\n * Format for displaying week day names\n */\n @Input()\n public weekDayName: MonthCalendarDayFormat = MonthCalendarDayFormat.Short;\n\n /**\n * Aspect ratio for displayed calendar day cell\n */\n @Input()\n public get dayAspectRatio(): number\n {\n return this.dayAspectRatioValue;\n }\n public set dayAspectRatio(value: number)\n {\n if(isString(value))\n {\n this.dayAspectRatioValue = CalendarDayAspectRatio[value] as unknown as number;\n\n return;\n }\n\n this.dayAspectRatioValue = value;\n }\n\n /**\n * Array of events that should be displayed\n */\n @Input()\n public events: EventData<TDate, TEvent>[] = [];\n\n //######################### constructor #########################\n constructor(@Inject(DATE_API) protected dateApi: DateApi<TDate>,\n @Inject(FORMAT_PROVIDER) protected formatProvider: FormatProvider,\n protected eventParser: EventParser<TDate, TEvent>,)\n {\n }\n\n //######################### public methods - implementation of OnInit #########################\n\n /**\n * Initialize component\n */\n public ngOnInit(): void\n {\n this.initWeekdayNames();\n this.initializeDisplayCalendar();\n }\n\n //######################### public methods - implementation of OnChanges #########################\n\n /**\n * Called when input value changes\n */\n public ngOnChanges(changes: SimpleChanges): void\n {\n if(nameof<MonthCalendarComponent>('weekDayName') in changes)\n {\n this.initWeekdayNames();\n }\n\n if(nameof<MonthCalendarComponent>('display') in changes)\n {\n this.initializeDisplayCalendar();\n }\n\n if(nameof<MonthCalendarComponent>('events') in changes && !(nameof<MonthCalendarComponent>('display') in changes))\n {\n this.initAndAttachEventData();\n }\n }\n\n //######################### protected methods #########################\n\n /**\n * Initialize weekday names\n */\n protected initWeekdayNames(): void\n {\n this.weekDayNames = [];\n const dateApi = this.dateApi.now().startOfWeek();\n\n switch(this.weekDayName)\n {\n default:\n // case MonthCalendarDayFormat.None:\n {\n for(let x = 0; x < 7; x++)\n {\n this.weekDayNames.push('');\n }\n\n break;\n }\n case MonthCalendarDayFormat.Short:\n {\n for(let x = 0; x < 7; x++)\n {\n this.weekDayNames.push(dateApi.format(this.formatProvider.dayNameShort));\n dateApi.addDays(1);\n }\n\n break;\n }\n case MonthCalendarDayFormat.Full:\n {\n for(let x = 0; x < 7; x++)\n {\n this.weekDayNames.push(dateApi.format(this.formatProvider.dayName));\n dateApi.addDays(1);\n }\n\n break;\n }\n }\n }\n\n /**\n * Initialize date for calendar that should be displayed\n */\n protected initializeDisplayCalendar(): void\n {\n this.display ??= this.dateApi.now().value;\n\n const workDate = this.dateApi.getValue(this.display);\n\n workDate.startOfMonth()\n .startOfWeek();\n\n this.calendarData = {};\n\n do\n {\n const weekData: CalendarDayData<TDate, TEvent>[] = this.calendarData[workDate.format(this.formatProvider.week)] = [];\n\n for(let x = 0; x < 7; x++)\n {\n weekData.push(\n {\n date: workDate.value,\n day: workDate.dayOfMonth(),\n events: [],\n isCurrentMonth: workDate.isSameMonth(this.display),\n isWeekend: workDate.isWeekend(),\n week: +workDate.format(this.formatProvider.week),\n });\n\n workDate.addDays(1);\n }\n\n workDate.startOfWeek();\n }\n while(workDate.isSameMonth(this.display));\n\n this.initAndAttachEventData();\n }\n\n /**\n * Initialize and attaches event data\n */\n protected initAndAttachEventData(): void\n {\n const events = this.eventParser.getEventsPerDay(this.events);\n\n for(const week in this.calendarData)\n {\n const weekData = this.calendarData[week];\n\n for(const day of weekData)\n {\n const found = events.find(itm => this.dateApi.getValue(itm[0]).isSame(day.date));\n day.events = found?.[1] ?? [];\n }\n }\n }\n\n //######################### ng language server #########################\n\n /**\n * Custom input type for `weekDayName` input\n */\n public static ngAcceptInputType_weekDayName: keyof typeof MonthCalendarDayFormat;\n\n /**\n * Custom input type for `dayAspectRatio` input\n */\n public static ngAcceptInputType_dayAspectRatio: keyof typeof CalendarDayAspectRatio|number;\n}","<div *calendarDayTemplate=\"let data\" class=\"default-calendar-day\" [class.is-weekend]=\"data.isWeekend\" [class.is-other-month]=\"!data.isCurrentMonth\">{{data.day}}</div>\n\n<div></div>\n\n<div *ngFor=\"let dayName of weekDayNames\" [class.week-day-name]=\"dayName\">{{dayName}}</div>\n\n<ng-container *ngFor=\"let weekData of calendarData | keyvalue\">\n <div class=\"week-number\">\n <ng-container *ngIf=\"showWeekNumber\">{{weekData.key}}</ng-container>\n </div>\n \n <div *ngFor=\"let dayData of weekData.value\" [style.padding-bottom.%]=\"dayAspectRatioValue\" class=\"day-wrapper\">\n <div class=\"day-content\"><ng-container *ngTemplateOutlet=\"calendarDayTemplate; context: {$implicit: dayData}\"></ng-container></div>\n </div>\n</ng-container>\n"]}
|
package/es2022/src/modules/calendar/directives/calendarDayTemplate/calendarDayTemplate.directive.js
CHANGED
|
@@ -3,7 +3,7 @@ import * as i0 from "@angular/core";
|
|
|
3
3
|
/**
|
|
4
4
|
* Directive used for obtaining custom calendar day template
|
|
5
5
|
*/
|
|
6
|
-
class CalendarDayTemplateDirective {
|
|
6
|
+
export class CalendarDayTemplateDirective {
|
|
7
7
|
template;
|
|
8
8
|
//######################### constructor #########################
|
|
9
9
|
constructor(template) {
|
|
@@ -16,14 +16,13 @@ class CalendarDayTemplateDirective {
|
|
|
16
16
|
static ngTemplateContextGuard(_dir, _ctx) {
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
20
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "
|
|
19
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: CalendarDayTemplateDirective, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
20
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.1.1", type: CalendarDayTemplateDirective, selector: "[calendarDayTemplate]", ngImport: i0 });
|
|
21
21
|
}
|
|
22
|
-
|
|
23
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: CalendarDayTemplateDirective, decorators: [{
|
|
22
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: CalendarDayTemplateDirective, decorators: [{
|
|
24
23
|
type: Directive,
|
|
25
24
|
args: [{
|
|
26
25
|
selector: '[calendarDayTemplate]'
|
|
27
26
|
}]
|
|
28
|
-
}], ctorParameters:
|
|
27
|
+
}], ctorParameters: () => [{ type: i0.TemplateRef }] });
|
|
29
28
|
//# sourceMappingURL=calendarDayTemplate.directive.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calendarDayTemplate.directive.js","sourceRoot":"","sources":["../../../../../../src/modules/calendar/directives/calendarDayTemplate/calendarDayTemplate.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;;AAIrD;;GAEG;
|
|
1
|
+
{"version":3,"file":"calendarDayTemplate.directive.js","sourceRoot":"","sources":["../../../../../../src/modules/calendar/directives/calendarDayTemplate/calendarDayTemplate.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;;AAIrD;;GAEG;AAKH,MAAM,OAAO,4BAA4B;IAGlB;IADnB,iEAAiE;IACjE,YAAmB,QAAgE;QAAhE,aAAQ,GAAR,QAAQ,CAAwD;IAEnF,CAAC;IAED,wEAAwE;IAExE;;OAEG;IACH,MAAM,CAAC,sBAAsB,CAAC,IAAkC,EAAE,IAAa;QAE3E,OAAO,IAAI,CAAC;IAChB,CAAC;uGAfQ,4BAA4B;2FAA5B,4BAA4B;;2FAA5B,4BAA4B;kBAJxC,SAAS;mBACV;oBACI,QAAQ,EAAE,uBAAuB;iBACpC","sourcesContent":["import {Directive, TemplateRef} from '@angular/core';\n\nimport {CalendarDayTemplateContext} from './calendarDayTemplate.context';\n\n/**\n * Directive used for obtaining custom calendar day template\n */\n@Directive(\n{\n selector: '[calendarDayTemplate]'\n})\nexport class CalendarDayTemplateDirective<TDate = unknown, TEvent = unknown>\n{\n //######################### constructor #########################\n constructor(public template: TemplateRef<CalendarDayTemplateContext<TDate, TEvent>>)\n {\n }\n\n //######################### ng language server #########################\n \n /**\n * Allows typechecking for template\n */\n static ngTemplateContextGuard(_dir: CalendarDayTemplateDirective, _ctx: unknown): _ctx is CalendarDayTemplateContext\n {\n return true;\n }\n}"]}
|
|
@@ -6,15 +6,14 @@ import * as i0 from "@angular/core";
|
|
|
6
6
|
/**
|
|
7
7
|
* Module used for calendar displaying month
|
|
8
8
|
*/
|
|
9
|
-
class MonthCalendarModule {
|
|
10
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
11
|
-
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "
|
|
9
|
+
export class MonthCalendarModule {
|
|
10
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: MonthCalendarModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
11
|
+
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.1.1", ngImport: i0, type: MonthCalendarModule, declarations: [MonthCalendarComponent,
|
|
12
12
|
CalendarDayTemplateDirective], imports: [CommonModule], exports: [MonthCalendarComponent,
|
|
13
13
|
CalendarDayTemplateDirective] });
|
|
14
|
-
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
14
|
+
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: MonthCalendarModule, imports: [CommonModule] });
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: MonthCalendarModule, decorators: [{
|
|
16
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: MonthCalendarModule, decorators: [{
|
|
18
17
|
type: NgModule,
|
|
19
18
|
args: [{
|
|
20
19
|
imports: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"monthCalendar.module.js","sourceRoot":"","sources":["../../../../../src/modules/calendar/modules/monthCalendar.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAC,sBAAsB,EAAC,MAAM,eAAe,CAAC;AACrD,OAAO,EAAC,4BAA4B,EAAC,MAAM,eAAe,CAAC;;AAE3D;;GAEG;
|
|
1
|
+
{"version":3,"file":"monthCalendar.module.js","sourceRoot":"","sources":["../../../../../src/modules/calendar/modules/monthCalendar.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAC,sBAAsB,EAAC,MAAM,eAAe,CAAC;AACrD,OAAO,EAAC,4BAA4B,EAAC,MAAM,eAAe,CAAC;;AAE3D;;GAEG;AAkBH,MAAM,OAAO,mBAAmB;uGAAnB,mBAAmB;wGAAnB,mBAAmB,iBATxB,sBAAsB;YACtB,4BAA4B,aAL5B,YAAY,aASZ,sBAAsB;YACtB,4BAA4B;wGAGvB,mBAAmB,YAbxB,YAAY;;2FAaP,mBAAmB;kBAjB/B,QAAQ;mBACT;oBACI,OAAO,EACP;wBACI,YAAY;qBACf;oBACD,YAAY,EACZ;wBACI,sBAAsB;wBACtB,4BAA4B;qBAC/B;oBACD,OAAO,EACP;wBACI,sBAAsB;wBACtB,4BAA4B;qBAC/B;iBACJ","sourcesContent":["import {NgModule} from '@angular/core';\nimport {CommonModule} from '@angular/common';\n\nimport {MonthCalendarComponent} from '../components';\nimport {CalendarDayTemplateDirective} from '../directives';\n\n/**\n * Module used for calendar displaying month\n */\n@NgModule(\n{\n imports:\n [\n CommonModule,\n ],\n declarations:\n [\n MonthCalendarComponent,\n CalendarDayTemplateDirective,\n ],\n exports:\n [\n MonthCalendarComponent,\n CalendarDayTemplateDirective,\n ],\n})\nexport class MonthCalendarModule\n{\n}"]}
|
|
@@ -4,7 +4,7 @@ import * as i0 from "@angular/core";
|
|
|
4
4
|
/**
|
|
5
5
|
* Service used for parsing events into events to requested period
|
|
6
6
|
*/
|
|
7
|
-
class EventParser {
|
|
7
|
+
export class EventParser {
|
|
8
8
|
dateApi;
|
|
9
9
|
//######################### constructor #########################
|
|
10
10
|
constructor(dateApi) {
|
|
@@ -63,14 +63,13 @@ class EventParser {
|
|
|
63
63
|
}
|
|
64
64
|
return result;
|
|
65
65
|
}
|
|
66
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
67
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
66
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: EventParser, deps: [{ token: DATE_API }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
67
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: EventParser });
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.1", ngImport: i0, type: EventParser, decorators: [{
|
|
69
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.1", ngImport: i0, type: EventParser, decorators: [{
|
|
71
70
|
type: Injectable
|
|
72
|
-
}], ctorParameters:
|
|
71
|
+
}], ctorParameters: () => [{ type: undefined, decorators: [{
|
|
73
72
|
type: Inject,
|
|
74
73
|
args: [DATE_API]
|
|
75
|
-
}] }]
|
|
74
|
+
}] }] });
|
|
76
75
|
//# sourceMappingURL=eventParser.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventParser.service.js","sourceRoot":"","sources":["../../../../../../src/modules/calendar/services/eventParser/eventParser.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAC,QAAQ,EAAC,MAAM,yBAAyB,CAAC;;AAIjD;;GAEG;
|
|
1
|
+
{"version":3,"file":"eventParser.service.js","sourceRoot":"","sources":["../../../../../../src/modules/calendar/services/eventParser/eventParser.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAC,QAAQ,EAAC,MAAM,yBAAyB,CAAC;;AAIjD;;GAEG;AAEH,MAAM,OAAO,WAAW;IAGoB;IADxC,iE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O,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC;aACpC,QACK,CAAC,CAAC,KAAK,CAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,EAAE;SAC3G;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;uGAhFQ,WAAW,kBAGA,QAAQ;2GAHnB,WAAW;;2FAAX,WAAW;kBADvB,UAAU;;0BAIM,MAAM;2BAAC,QAAQ","sourcesContent":["import {Inject, Injectable} from '@angular/core';\n\nimport {DATE_API} from '../../../../misc/tokens';\nimport {DateApi} from '../../../../services';\nimport {CalendarEventDayMetadata, EventData, ɵEventData} from '../../interfaces';\n\n/**\n * Service used for parsing events into events to requested period\n */\n@Injectable()\nexport class EventParser<TDate = unknown, TEvent = unknown>\n{\n //######################### constructor #########################\n constructor(@Inject(DATE_API) protected dateApi: DateApi<TDate>,)\n {\n }\n\n //######################### public methods #########################\n\n /**\n * Gets events parsed per day\n * @param events - Array of events to be parsed\n */\n public getEventsPerDay(events: EventData<TDate, TEvent>[]): [TDate, CalendarEventDayMetadata<TDate, TEvent>[]][]\n {\n const eventsLocal = events.map(itm =>\n {\n return <ɵEventData<TDate, TEvent>>\n {\n data: itm.data,\n dateFrom: itm.dateFrom,\n dateTo: itm.dateTo,\n dateApiFrom: this.dateApi.getValue(itm.dateFrom),\n dateApiTo: itm.dateTo ? this.dateApi.getValue(itm.dateTo) : null,\n };\n });\n\n eventsLocal.sort((a, b) =>\n {\n if(a.dateApiFrom.isAfter(b.dateApiFrom.value))\n {\n return 1;\n }\n\n if(a.dateApiFrom.isBefore(b.dateApiFrom.value))\n {\n return -1;\n }\n\n return 0;\n });\n\n const result: [TDate, CalendarEventDayMetadata<TDate, TEvent>[]][] = [];\n\n for(const event of eventsLocal)\n {\n const workDate = event.dateApiFrom.clone().startOfDay();\n const data: CalendarEventDayMetadata<TDate, TEvent>[] = result.find(itm => workDate.isSameDay(itm[0]))?.[1] ?? [];\n const index = data.length;\n\n do\n {\n let data: [TDate, CalendarEventDayMetadata<TDate, TEvent>[]]|undefined = result.find(itm => workDate.isSameDay(itm[0]));\n\n if(!data)\n {\n data = [workDate.value, []];\n result.push(data);\n }\n\n const evnts: CalendarEventDayMetadata<TDate, TEvent>[] = data[1];\n evnts[index] =\n {\n data: event.data,\n dateApiFrom: event.dateApiFrom,\n dateApiTo: event.dateApiTo,\n dateFrom: event.dateFrom,\n dateTo: event.dateTo,\n onGoingFrom: workDate.startOfDay().isAfter(event.dateApiFrom),\n allDay: (workDate.isSame(event.dateApiFrom) || workDate.isAfter(event.dateApiFrom)) &&\n !!event.dateApiTo && (workDate.endOfDay().isSame(event.dateApiTo) || workDate.isBefore(event.dateApiTo)),\n onGoingTo: !!event.dateApiTo && workDate.isBefore(event.dateApiTo),\n };\n \n workDate.addDays(1).startOfDay();\n }\n while(!!event.dateApiTo && (workDate.isBefore(event.dateApiTo) || workDate.isSameDay(event.dateApiTo)));\n }\n\n return result;\n }\n}"]}
|