@mediafly/js-ui 51.3.2 → 51.3.3-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 +4 -0
- package/lib/constants/constants.js +2 -1
- package/lib/constants/constants.js.map +1 -1
- package/lib/date-input/date-input.js +33 -12
- package/lib/date-input/date-input.js.map +1 -1
- package/lib/date-input/validate-date.js +12 -8
- package/lib/date-input/validate-date.js.map +1 -1
- package/lib/date-time-zone-picker/date-time-zone-factory.js +62 -49
- package/lib/date-time-zone-picker/date-time-zone-factory.js.map +1 -1
- package/lib/date-time-zone-picker/date-time-zone-picker.html +1 -1
- package/lib/date-time-zone-picker/date-time-zone-picker.js +82 -37
- package/lib/date-time-zone-picker/date-time-zone-picker.js.map +1 -1
- package/lib/date-time-zone-picker/datepicker.html +1 -2
- package/lib/date-time-zone-picker/datepicker.js +71 -19
- package/lib/date-time-zone-picker/datepicker.js.map +1 -1
- package/lib/date-time-zone-picker/time-format-filter.js +6 -6
- package/lib/date-time-zone-picker/time-format-filter.js.map +1 -1
- package/lib/date-time-zone-picker/timepicker.js +35 -20
- package/lib/date-time-zone-picker/timepicker.js.map +1 -1
- package/lib/time-input/time-input.js +27 -23
- package/lib/time-input/time-input.js.map +1 -1
- package/lib/time-input/validate-time.js +6 -2
- package/lib/time-input/validate-time.js.map +1 -1
- package/lib/tsconfig.deploy.tsbuildinfo +166 -24
- package/package.json +4 -4
- package/src/components/constants/constants.js +2 -1
- package/src/components/date-input/date-input.js +31 -12
- package/src/components/date-input/validate-date.js +14 -10
- package/src/components/date-time-zone-picker/date-time-zone-factory.ts +62 -49
- package/src/components/date-time-zone-picker/date-time-zone-picker.html +1 -1
- package/src/components/date-time-zone-picker/date-time-zone-picker.ts +87 -44
- package/src/components/date-time-zone-picker/datepicker.html +1 -2
- package/src/components/date-time-zone-picker/datepicker.ts +76 -20
- package/src/components/date-time-zone-picker/time-format-filter.ts +6 -6
- package/src/components/date-time-zone-picker/timepicker.js +46 -28
- package/src/components/time-input/time-input.js +27 -24
- package/src/components/time-input/validate-time.js +6 -2
- package/src/index.spec.js +1 -1
- package/webpack.config.js +6 -0
- package/tsconfig.tsbuildinfo +0 -7221
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const angular_1 = __importDefault(require("angular"));
|
|
7
|
-
const
|
|
7
|
+
const luxon_1 = require("luxon");
|
|
8
8
|
const pikaday_1 = __importDefault(require("pikaday"));
|
|
9
9
|
const form_validation_utils_1 = require("../form-validation-utils/form-validation-utils");
|
|
10
10
|
// Wrapper directive for pikaday datepicker component
|
|
@@ -31,7 +31,7 @@ angular_1.default.module('app').directive('mflyDatePicker', [
|
|
|
31
31
|
date: ''
|
|
32
32
|
};
|
|
33
33
|
// if a "small" format is required we need to set it here
|
|
34
|
-
const dateStringFormat = ($scope.format === 'short') ? '
|
|
34
|
+
const dateStringFormat = ($scope.format === 'short') ? 'd-MMM-yyyy' : 'd-MMMM-yyyy';
|
|
35
35
|
// The Pikaday component does some odd formatting at times
|
|
36
36
|
// This flag helps avoid this anomaly when it occurs
|
|
37
37
|
let preventPikadayUpdate = false;
|
|
@@ -42,10 +42,9 @@ angular_1.default.module('app').directive('mflyDatePicker', [
|
|
|
42
42
|
const wrapperDiv = element.find('div');
|
|
43
43
|
// set up default options for the pikaday component
|
|
44
44
|
const pikadayOptions = {
|
|
45
|
-
field:
|
|
46
|
-
trigger: wrapperDiv[0],
|
|
45
|
+
field: wrapperDiv[0],
|
|
47
46
|
firstDay: 1,
|
|
48
|
-
format: dateStringFormat,
|
|
47
|
+
format: dateStringFormat.toUpperCase(),
|
|
49
48
|
yearRange: 10,
|
|
50
49
|
setDefaultDate: true,
|
|
51
50
|
defaultDate: '',
|
|
@@ -63,17 +62,33 @@ angular_1.default.module('app').directive('mflyDatePicker', [
|
|
|
63
62
|
// Handler for when a date is 'selected' with the picker
|
|
64
63
|
// selection happens on enter, blur, and by using the popup calendars
|
|
65
64
|
onSelect() {
|
|
66
|
-
// update the bound date moment
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
// update the bound date moment - convert from JS Date to DateTime
|
|
66
|
+
const selectedDate = picker.getDate();
|
|
67
|
+
const updateDate = () => {
|
|
68
|
+
var _a, _b, _c, _d, _e, _f;
|
|
69
|
+
$scope.dateMoment = selectedDate ? luxon_1.DateTime.fromJSDate(selectedDate) : null;
|
|
70
|
+
// fire a change in the parent directive for the api
|
|
71
|
+
$scope.onDateChange({ newDate: $scope.dateMoment });
|
|
72
|
+
// Set the form control as dirty and valid when date changes
|
|
73
|
+
(_c = (_b = (_a = $scope.form) === null || _a === void 0 ? void 0 : _a.validation) === null || _b === void 0 ? void 0 : _b.mflyDatepicker) === null || _c === void 0 ? void 0 : _c.$setDirty();
|
|
74
|
+
(_f = (_e = (_d = $scope.form) === null || _d === void 0 ? void 0 : _d.validation) === null || _e === void 0 ? void 0 : _e.mflyDatepicker) === null || _f === void 0 ? void 0 : _f.$setValidity('invalidDate', true);
|
|
75
|
+
};
|
|
76
|
+
// Safely handle the digest cycle
|
|
77
|
+
if ($scope.$root.$$phase !== '$digest' && $scope.$root.$$phase !== '$apply') {
|
|
78
|
+
$scope.$apply(updateDate);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
updateDate();
|
|
82
|
+
}
|
|
70
83
|
}
|
|
71
84
|
};
|
|
72
85
|
// Handle for the Pikaday component
|
|
73
86
|
const picker = new pikaday_1.default(pikadayOptions);
|
|
74
87
|
$scope.$watch('dateMoment', function (newValue, oldValue) {
|
|
75
88
|
if (newValue === oldValue) { // i.e., initializing
|
|
76
|
-
|
|
89
|
+
if ($scope.dateMoment) {
|
|
90
|
+
picker.setDate($scope.dateMoment.toJSDate());
|
|
91
|
+
}
|
|
77
92
|
form_validation_utils_1.recursivelySetPristine($scope.form.validation);
|
|
78
93
|
return;
|
|
79
94
|
}
|
|
@@ -88,7 +103,9 @@ angular_1.default.module('app').directive('mflyDatePicker', [
|
|
|
88
103
|
}
|
|
89
104
|
// Otherwise, it may be a legit change. For example, if the model was
|
|
90
105
|
// programmatically changed from somewhere outside the component.
|
|
91
|
-
picker.
|
|
106
|
+
picker.setDate(newValue.toJSDate(), true); // true = do not trigger onSelect
|
|
107
|
+
// Also update the input value to match our format
|
|
108
|
+
$scope.dateInputValue.date = newValue.toFormat(dateStringFormat);
|
|
92
109
|
});
|
|
93
110
|
// watch necessary to style preceding add-on element (CSS has no prev sibling selector)
|
|
94
111
|
$scope.$watch('form.validation.mflyDatepicker', function (newValue) {
|
|
@@ -102,25 +119,52 @@ angular_1.default.module('app').directive('mflyDatePicker', [
|
|
|
102
119
|
}
|
|
103
120
|
});
|
|
104
121
|
$scope.setPikadayMoment = function () {
|
|
105
|
-
|
|
122
|
+
// Try parsing with any valid format, just like in validateDate
|
|
123
|
+
let tempDateTime;
|
|
124
|
+
for (const format of dateTimeZoneFactory.validDateFormats) {
|
|
125
|
+
tempDateTime = luxon_1.DateTime.fromFormat($scope.dateInputValue.date, format);
|
|
126
|
+
if (tempDateTime.isValid) {
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
106
130
|
// The pikaday will oddly format 2 digit years to 0003
|
|
107
|
-
// The year is correct in the
|
|
108
|
-
// To prevent we will set the
|
|
109
|
-
if (!preventPikadayUpdate) {
|
|
110
|
-
|
|
131
|
+
// The year is correct in the dateTime, but you can see the odd string when formatted
|
|
132
|
+
// To prevent we will set the dateTime manually if the user is not backspacing/deleting
|
|
133
|
+
if (!preventPikadayUpdate && tempDateTime && tempDateTime.isValid) {
|
|
134
|
+
// Set the date without triggering onSelect to avoid circular updates
|
|
135
|
+
picker.setDate(tempDateTime.toJSDate(), true);
|
|
136
|
+
// Manually update the dateMoment to trigger reformatting
|
|
137
|
+
const updateDateTime = () => {
|
|
138
|
+
$scope.dateMoment = tempDateTime;
|
|
139
|
+
$scope.onDateChange({ newDate: tempDateTime });
|
|
140
|
+
};
|
|
141
|
+
// Safely handle the digest cycle
|
|
142
|
+
if ($scope.$root.$$phase !== '$digest' && $scope.$root.$$phase !== '$apply') {
|
|
143
|
+
$scope.$apply(updateDateTime);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
updateDateTime();
|
|
147
|
+
}
|
|
111
148
|
}
|
|
112
149
|
else {
|
|
113
150
|
preventPikadayUpdate = false;
|
|
114
151
|
}
|
|
115
152
|
};
|
|
116
|
-
// called
|
|
153
|
+
// called every time the text input is changed manually
|
|
117
154
|
$scope.validateDate = function () {
|
|
118
155
|
// pikaday interrupts the normal binding - manually update scope
|
|
119
156
|
$scope.dateInputValue.date = angular_1.default.element(inputElement[0]).val();
|
|
120
157
|
let isValid = true;
|
|
121
158
|
if ($scope.dateInputValue.date && $scope.dateInputValue.date.length > 0) {
|
|
122
|
-
// attempt to create a date
|
|
123
|
-
isValid =
|
|
159
|
+
// attempt to create a date from value using any valid format
|
|
160
|
+
isValid = false;
|
|
161
|
+
for (const format of dateTimeZoneFactory.validDateFormats) {
|
|
162
|
+
const parsed = luxon_1.DateTime.fromFormat($scope.dateInputValue.date, format);
|
|
163
|
+
if (parsed.isValid) {
|
|
164
|
+
isValid = true;
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
124
168
|
if (isValid) {
|
|
125
169
|
$scope.setPikadayMoment();
|
|
126
170
|
}
|
|
@@ -143,6 +187,14 @@ angular_1.default.module('app').directive('mflyDatePicker', [
|
|
|
143
187
|
preventPikadayUpdate = true;
|
|
144
188
|
}
|
|
145
189
|
};
|
|
190
|
+
$scope.onBlur = function () {
|
|
191
|
+
// Hide the Pikaday calendar popup
|
|
192
|
+
picker.hide();
|
|
193
|
+
// Update focus state
|
|
194
|
+
$scope.focusAddOn = false;
|
|
195
|
+
// Validate the date
|
|
196
|
+
$scope.validateDate();
|
|
197
|
+
};
|
|
146
198
|
$scope.requiredText = translateFactory.instant('JSUI.REQUIRED');
|
|
147
199
|
$scope.invalidDateText = translateFactory.instant('JSUI.INVALID_DATE');
|
|
148
200
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datepicker.js","sourceRoot":"","sources":["../../src/components/date-time-zone-picker/datepicker.ts"],"names":[],"mappings":";;;;;AAAA,sDAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"datepicker.js","sourceRoot":"","sources":["../../src/components/date-time-zone-picker/datepicker.ts"],"names":[],"mappings":";;;;;AAAA,sDAA6B;AAC7B,iCAAgC;AAChC,sDAA6B;AAC7B,0FAAuF;AAOvF,qDAAqD;AACrD,yDAAyD;AACzD,iBAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,gBAAgB,EAAE;IACjD,qBAAqB;IACrB,kBAAkB;IAClB,SAAS,cAAc,CACtB,mBAAmB,EACnB,gBAAkC;QAGnC,OAAO;YACN,QAAQ,EAAE,GAAG;YACb,KAAK,EAAE;gBACN,OAAO,EAAE,GAAG;gBACZ,UAAU,EAAE,GAAG;gBACf,UAAU,EAAE,GAAG;gBACf,MAAM,EAAE,GAAG;gBACX,UAAU,EAAE,GAAG;gBACf,YAAY,EAAE,GAAG;gBACjB,MAAM,EAAE,GAAG;aACX;YACD,QAAQ,EAAE,OAAO,CAAC,mBAAmB,CAAC;YACtC,IAAI,CAAC,MAAyB,EAAE,OAA4B;gBAC3D,sCAAsC;gBACtC,MAAM,CAAC,cAAc,GAAG;oBACvB,IAAI,EAAE,EAAE;iBACR,CAAA;gBAED,yDAAyD;gBACzD,MAAM,gBAAgB,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,aAAa,CAAA;gBAEnF,0DAA0D;gBAC1D,oDAAoD;gBACpD,IAAI,oBAAoB,GAAG,KAAK,CAAA;gBAEhC,+CAA+C;gBAC/C,MAAM,YAAY,G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MAAM;oBACpC,IAAI,MAAM,CAAC,KAAK,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,KAAK,EAAE,EAAE;wBAC9C,qEAAqE;wBACrE,wFAAwF;wBACxF,oBAAoB,GAAG,IAAI,CAAA;qBAC3B;gBACF,CAAC,CAAA;gBAED,MAAM,CAAC,MAAM,GAAG;oBACf,kCAAkC;oBAClC,MAAM,CAAC,IAAI,EAAE,CAAA;oBAEb,qBAAqB;oBACrB,MAAM,CAAC,UAAU,GAAG,KAAK,CAAA;oBAEzB,oBAAoB;oBACpB,MAAM,CAAC,YAAY,EAAE,CAAA;gBACtB,CAAC,CAAA;gBAED,MAAM,CAAC,YAAY,GAAG,gBAAgB,CAAC,OAAO,CAAC,eAAe,CAAC,CAAA;gBAC/D,MAAM,CAAC,eAAe,GAAG,gBAAgB,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;YACvE,CAAC;SACD,CAAA;IACF,CAAC;CAAC,CAAC,CAAA"}
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const angular_1 = __importDefault(require("angular"));
|
|
7
7
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
const
|
|
8
|
+
const luxon_1 = require("luxon");
|
|
9
9
|
// This filter takes a datetime string with UTC offset, like `2015-09-30T00:00:00-08:00`
|
|
10
10
|
// and converts it to a short format with time zone code displayed, like `12:00 AM AKST`.
|
|
11
11
|
// It returns an empty string if the input is bad (undefined or empty string).
|
|
@@ -14,7 +14,7 @@ angular_1.default.module('app').filter('formatDate', function formatDate() {
|
|
|
14
14
|
if (lodash_1.default.isEmpty(date)) {
|
|
15
15
|
return '';
|
|
16
16
|
}
|
|
17
|
-
const formattedDateTime =
|
|
17
|
+
const formattedDateTime = luxon_1.DateTime.fromISO(date, { setZone: true }).toFormat('M/dd/yy');
|
|
18
18
|
return formattedDateTime;
|
|
19
19
|
};
|
|
20
20
|
});
|
|
@@ -24,8 +24,8 @@ angular_1.default.module('app').filter('formatTimeWithTimeZone', ['dateTimeZoneF
|
|
|
24
24
|
return '';
|
|
25
25
|
}
|
|
26
26
|
// Parse zone preserves the string date's offset --ignoring offset in locale)
|
|
27
|
-
const dateTimeZone =
|
|
28
|
-
const formattedTime = dateTimeZone.
|
|
27
|
+
const dateTimeZone = luxon_1.DateTime.fromISO(date, { setZone: true });
|
|
28
|
+
const formattedTime = dateTimeZone.toFormat('h:mm a');
|
|
29
29
|
// NOTE: getTimeZone expects a momentDate
|
|
30
30
|
const formattedZone = dateTimeZoneFactory.getTimeZone(dateTimeZone).display;
|
|
31
31
|
return `${formattedTime} ${formattedZone}`;
|
|
@@ -37,8 +37,8 @@ angular_1.default.module('app').filter('formatDateTimeWithTimeZone', ['dateTimeZ
|
|
|
37
37
|
return '';
|
|
38
38
|
}
|
|
39
39
|
// Parse zone preserves the string date's offset --ignoring offset in locale)
|
|
40
|
-
const dateTimeZone =
|
|
41
|
-
const formattedDateTime =
|
|
40
|
+
const dateTimeZone = luxon_1.DateTime.fromISO(date, { setZone: true });
|
|
41
|
+
const formattedDateTime = luxon_1.DateTime.fromISO(date, { setZone: true }).toFormat('M/dd/yy h:mm a');
|
|
42
42
|
// NOTE: getTimeZone expects a momentDate
|
|
43
43
|
const formattedZone = dateTimeZoneFactory.getTimeZone(dateTimeZone).display;
|
|
44
44
|
return `${formattedDateTime} ${formattedZone}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-format-filter.js","sourceRoot":"","sources":["../../src/components/date-time-zone-picker/time-format-filter.ts"],"names":[],"mappings":";;;;;AAAA,sDAA6B;AAC7B,oDAAsB;AACtB,
|
|
1
|
+
{"version":3,"file":"time-format-filter.js","sourceRoot":"","sources":["../../src/components/date-time-zone-picker/time-format-filter.ts"],"names":[],"mappings":";;;;;AAAA,sDAA6B;AAC7B,oDAAsB;AACtB,iCAAgC;AAEhC,wFAAwF;AAC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YAEf,IAAI,gBAAC,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;gBACpB,OAAO,EAAE,CAAA;aACT;YAED,6EAA6E;YAC7E,MAAM,YAAY,GAAG,gBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;YAE9D,MAAM,iBAAiB,GAAG,gBAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAA;YAE9F,yCAAyC;YACzC,MAAM,aAAa,GAAG,mBAAmB,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,OAAO,CAAA;YAE3E,OAAO,GAAG,iBAAiB,IAAI,aAAa,EAAE,CAAA;QAC/C,CAAC,CAAA;IACF,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const angular_1 = __importDefault(require("angular"));
|
|
7
7
|
const timepicker_html_1 = __importDefault(require("./timepicker.html"));
|
|
8
|
-
const
|
|
8
|
+
const { DateTime } = require('luxon');
|
|
9
9
|
angular_1.default.module('app').directive('mflyTimePicker', ['translateFactory', function mflyTimePicker(translateFactory) {
|
|
10
10
|
return {
|
|
11
11
|
restrict: 'E',
|
|
@@ -22,6 +22,7 @@ angular_1.default.module('app').directive('mflyTimePicker', ['translateFactory',
|
|
|
22
22
|
'h:mm A',
|
|
23
23
|
'h:mmA'
|
|
24
24
|
];
|
|
25
|
+
const luxonFormats = ['H:mm', 'h:mm a', 'h:mma'];
|
|
25
26
|
$scope.timeValue = {
|
|
26
27
|
time: '',
|
|
27
28
|
initialized: false
|
|
@@ -34,12 +35,20 @@ angular_1.default.module('app').directive('mflyTimePicker', ['translateFactory',
|
|
|
34
35
|
// programmatically, we need to update the time picker accordingly.
|
|
35
36
|
$scope.$watch('timeMoment', function (newValue) {
|
|
36
37
|
if (newValue) {
|
|
37
|
-
$scope.timeValue.time = $scope.timeMoment.
|
|
38
|
+
$scope.timeValue.time = $scope.timeMoment.toFormat('h:mm a');
|
|
38
39
|
}
|
|
39
40
|
});
|
|
40
41
|
$scope.validateTime = function () {
|
|
41
42
|
if ($scope.timeValue.time) {
|
|
42
|
-
var isValid =
|
|
43
|
+
var isValid = false;
|
|
44
|
+
// Try each format until one works
|
|
45
|
+
for (const format of luxonFormats) {
|
|
46
|
+
const parsed = DateTime.fromFormat($scope.timeValue.time, format);
|
|
47
|
+
if (parsed.isValid) {
|
|
48
|
+
isValid = true;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
43
52
|
$scope.form.validation.mflyTimepicker.$setValidity('invalidTime', isValid);
|
|
44
53
|
if (isValid) {
|
|
45
54
|
processTime();
|
|
@@ -50,7 +59,7 @@ angular_1.default.module('app').directive('mflyTimePicker', ['translateFactory',
|
|
|
50
59
|
$scope.form.validation.mflyTimepicker.$setValidity('invalidTime', false);
|
|
51
60
|
}
|
|
52
61
|
};
|
|
53
|
-
//watch necessary to style
|
|
62
|
+
//watch necessary to style preceding add-on element (CSS has no prev sibling selector)
|
|
54
63
|
$scope.$watch('form.validation.mflyTimepicker', function (newValue) {
|
|
55
64
|
if (newValue) {
|
|
56
65
|
$scope.$watch('form.validation.mflyTimepicker.$valid', function (newValue) {
|
|
@@ -63,10 +72,18 @@ angular_1.default.module('app').directive('mflyTimePicker', ['translateFactory',
|
|
|
63
72
|
});
|
|
64
73
|
function processTime() {
|
|
65
74
|
if ($scope.timeValue.time && $scope.form.validation.mflyTimepicker.$valid) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
let tempDateTime;
|
|
76
|
+
for (const format of luxonFormats) {
|
|
77
|
+
tempDateTime = DateTime.fromFormat($scope.timeValue.time, format);
|
|
78
|
+
if (tempDateTime.isValid)
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
$scope.timeMoment = $scope.timeMoment.set({
|
|
82
|
+
hour: tempDateTime.hour,
|
|
83
|
+
minute: tempDateTime.minute,
|
|
84
|
+
second: 0,
|
|
85
|
+
millisecond: 0,
|
|
86
|
+
});
|
|
70
87
|
//callback to the parent component
|
|
71
88
|
$scope.onTimeChange();
|
|
72
89
|
}
|
|
@@ -78,20 +95,18 @@ angular_1.default.module('app').directive('mflyTimePicker', ['translateFactory',
|
|
|
78
95
|
}
|
|
79
96
|
function populateDropdown() {
|
|
80
97
|
if ($scope.timeMoment) {
|
|
81
|
-
$scope.timeValue.time = $scope.timeMoment.
|
|
98
|
+
$scope.timeValue.time = $scope.timeMoment.toFormat('hh:mm a');
|
|
82
99
|
}
|
|
83
|
-
//
|
|
84
|
-
var
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
tempMoment.minute(0);
|
|
90
|
-
//push 30 min intervals into our dropdown array until the date changes
|
|
100
|
+
// Populate the drop down with available times
|
|
101
|
+
var tempDateTime = DateTime.now().startOf('day');
|
|
102
|
+
var todaysDate = tempDateTime.day;
|
|
103
|
+
// Starting from 12:00 am
|
|
104
|
+
tempDateTime = tempDateTime.set({ hour: 0, minute: 0, second: 0, millisecond: 0 });
|
|
105
|
+
// Add a time entry on every 30 minutes
|
|
91
106
|
do {
|
|
92
|
-
$scope.dropdownItems.push(
|
|
93
|
-
|
|
94
|
-
} while (todaysDate ===
|
|
107
|
+
$scope.dropdownItems.push(tempDateTime.toFormat('hh:mm a'));
|
|
108
|
+
tempDateTime = tempDateTime.plus({ minutes: 30 });
|
|
109
|
+
} while (todaysDate === tempDateTime.day);
|
|
95
110
|
}
|
|
96
111
|
$scope.itemClicked = function (itemValue) {
|
|
97
112
|
$scope.form.validation.mflyTimepicker.$setDirty();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timepicker.js","sourceRoot":"","sources":["../../src/components/date-time-zone-picker/timepicker.js"],"names":[],"mappings":";;;;;AAAA,sDAA6B;AAC7B,wEAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"timepicker.js","sourceRoot":"","sources":["../../src/components/date-time-zone-picker/timepicker.js"],"names":[],"mappings":";;;;;AAAA,sDAA6B;AAC7B,wEAAwC;AACxC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAErC,iBAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,gBAAgB,EAAE,CAAC,kBAAkB,EAAE,SAAS,cAAc,CAAC,gBAAgB;QAE9G,OAAO;YACN,QAAQ,EAAE,GAAG;YACb,OAAO,EAAE,IAAI;YACb,KAAK,EAAE;gBACN,OAAO,EAAE,GAAG;gBACZ,UAAU,EAAE,GAAG;gBACf,YAAY,EAAE,GAAG;aACjB;YACD,QAAQ,EAAR,yBAAQ;YACR,IAAI,EAAE,UAAU,MAAM;gBACrB,IAAI,gBAAgB,GAAG;oBACtB,MAAM;oBACN,QAAQ;oBACR,OAAO;iBACP,CAAC;gBAEF,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAEjD,MAAM,CAAC,SAAS,GAAG;oBAClB,IAAI,EAAE,EAAE;oBACR,WAAW,EAAE,KAAK;iBAClB,CAAC;gBAEF,gDAAgD;gBAChD,MAAM,CAAC,aAAa,GAAG,EAAE,CAAC;gBAC1B,kCAAkC;gBAClC,gBAAgB,EAAE,CAAC;gBAEnB,6DAA6D;gBAC7D,mEAAmE;gBACnE,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,UAAU,QAAQ;oBAC7C,IAAI,QAAQ,EAAE;wBACb,MAAM,CAAC,SAAS,CAAC,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;qBAC7D;gBACF,CAAC,CAAC,CAAC;gBAEH,MAAM,CAAC,YAAY,GAAG;oBACrB,I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AAE,EAAE,CAAC,CAAC;qBAClD,QAAQ,UAAU,KAAK,YAAY,CAAC,GAAG,EAAE;gBAC3C,CAAC;gBAGD,MAAM,CAAC,WAAW,GAAG,UAAU,SAAS;oBACvC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,SAAS,EAAE,CAAC;oBAClD,MAAM,CAAC,SAAS,CAAC,IAAI,GAAG,SAAS,CAAC;oBAClC,MAAM,CAAC,YAAY,EAAE,CAAC;gBACvB,CAAC,CAAC;gBAEF,MAAM,CAAC,eAAe,GAAG,gBAAgB,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;YACxE,CAAC;SACD,CAAC;IACH,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const angular_1 = __importDefault(require("angular"));
|
|
7
7
|
const time_input_html_1 = __importDefault(require("./time-input.html"));
|
|
8
|
-
const
|
|
8
|
+
const { DateTime } = require('luxon');
|
|
9
9
|
angular_1.default.module('app').directive('mflyTimeInput', [
|
|
10
10
|
'$timeout',
|
|
11
11
|
'translateFactory',
|
|
@@ -25,19 +25,13 @@ angular_1.default.module('app').directive('mflyTimeInput', [
|
|
|
25
25
|
// Ng-model functionality
|
|
26
26
|
// ----------------------------------------
|
|
27
27
|
$scope.vm = {};
|
|
28
|
-
// See: https://momentjs.com/docs/#/parsing/string-format/
|
|
29
|
-
var validTimeFormats = [
|
|
30
|
-
'H:mm',
|
|
31
|
-
'h:mm A',
|
|
32
|
-
'h:mmA'
|
|
33
|
-
];
|
|
34
28
|
// Format the ng-model value as a time string.
|
|
35
29
|
// The result of this function is assigned to `ngModelCtrl.$viewValue`.
|
|
36
30
|
ngModelCtrl.$formatters.push(function (nativeDate) {
|
|
37
31
|
if (!nativeDate) {
|
|
38
32
|
return '';
|
|
39
33
|
}
|
|
40
|
-
return
|
|
34
|
+
return DateTime.fromJSDate(nativeDate).toFormat('h:mm a');
|
|
41
35
|
});
|
|
42
36
|
// Display the time string in the UI.
|
|
43
37
|
ngModelCtrl.$render = function () {
|
|
@@ -57,13 +51,23 @@ angular_1.default.module('app').directive('mflyTimeInput', [
|
|
|
57
51
|
// component of "today". If a model value exists, we need to set the
|
|
58
52
|
// outgoing date object's date part back to the original model value
|
|
59
53
|
// since the user did not intend to change that part.
|
|
60
|
-
|
|
54
|
+
let targetDateTime;
|
|
55
|
+
const luxonFormats = ['H:mm', 'h:mm a', 'h:mma'];
|
|
56
|
+
// Try each format until one works
|
|
57
|
+
for (const format of luxonFormats) {
|
|
58
|
+
targetDateTime = DateTime.fromFormat(viewValue, format);
|
|
59
|
+
if (targetDateTime.isValid)
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
61
62
|
if (ngModelCtrl.$modelValue) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
const modelDateTime = DateTime.fromJSDate(ngModelCtrl.$modelValue);
|
|
64
|
+
targetDateTime = targetDateTime.set({
|
|
65
|
+
year: modelDateTime.year,
|
|
66
|
+
month: modelDateTime.month,
|
|
67
|
+
day: modelDateTime.day
|
|
68
|
+
});
|
|
65
69
|
}
|
|
66
|
-
return
|
|
70
|
+
return targetDateTime.toJSDate();
|
|
67
71
|
});
|
|
68
72
|
// When the user input changes the scope model, push it through the
|
|
69
73
|
// parsing pipeline by calling `setViewValue`.
|
|
@@ -75,14 +79,14 @@ angular_1.default.module('app').directive('mflyTimeInput', [
|
|
|
75
79
|
$scope.invalidTimeText = translateFactory.instant('JSUI.INVALID_TIME');
|
|
76
80
|
// Time dropdown
|
|
77
81
|
// ----------------------------------------
|
|
78
|
-
|
|
79
|
-
|
|
82
|
+
const beginningOfToday = DateTime.now().startOf('day');
|
|
83
|
+
let timeCursor = beginningOfToday;
|
|
80
84
|
$scope.dropdownEntries = [];
|
|
81
85
|
// Populate time entries for all 30-min intervals on today's date
|
|
82
86
|
do {
|
|
83
|
-
$scope.dropdownEntries.push(timeCursor.
|
|
84
|
-
timeCursor.
|
|
85
|
-
} while (timeCursor.
|
|
87
|
+
$scope.dropdownEntries.push(timeCursor.toFormat('h:mm a'));
|
|
88
|
+
timeCursor = timeCursor.plus({ minutes: 30 });
|
|
89
|
+
} while (timeCursor.day === beginningOfToday.day);
|
|
86
90
|
// When a time is clicked, update the view model
|
|
87
91
|
$scope.setTime = function (timeString) {
|
|
88
92
|
$scope.vm.time = timeString;
|
|
@@ -100,13 +104,13 @@ angular_1.default.module('app').directive('mflyTimeInput', [
|
|
|
100
104
|
// Otherwise, we need to do some calculations.
|
|
101
105
|
function entriesForTime(time) {
|
|
102
106
|
// Find the number of minutes until our target time.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
107
|
+
const target = DateTime.fromJSDate(time);
|
|
108
|
+
const midnight = target.startOf('day');
|
|
109
|
+
const minutesFromMidnight = target.diff(midnight, 'minutes').minutes;
|
|
106
110
|
// Round up to the next 30 minute interval.
|
|
107
|
-
|
|
111
|
+
const roundedMinutes = Math.ceil((minutesFromMidnight + 1) / 30) * 30;
|
|
108
112
|
// Divide by 30 to get number of places we should scroll down.
|
|
109
|
-
return
|
|
113
|
+
return roundedMinutes / 30;
|
|
110
114
|
}
|
|
111
115
|
// If `dropdownDefault` is specified by the consumer, we should
|
|
112
116
|
// default to that time instead.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-input.js","sourceRoot":"","sources":["../../src/components/time-input/time-input.js"],"names":[],"mappings":";;;;;AAAA,sDAA6B;AAC7B,wEAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"time-input.js","sourceRoot":"","sources":["../../src/components/time-input/time-input.js"],"names":[],"mappings":";;;;;AAAA,sDAA6B;AAC7B,wEAAwC;AACxC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAGrC,iBAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAA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,eAAe,CAAC,CAAC;qBACjD;oBAED,mEAAmE;oBACnE,6CAA6C;oBAC7C,IAAI,WAAW,CAAC,WAAW,EAAE;wBAC5B,OAAO,GAAG,cAAc,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;qBAClD;oBAED,oEAAoE;oBACpE,IAAI,OAAO,GAAG,CAAC,WAAW,GAAG,OAAO,CAAC,GAAG,UAAU,CAAC;oBAEnD,+DAA+D;oBAC/D,6CAA6C;oBAC7C,QAAQ,CAAC;wBACR,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;oBACzB,CAAC,EAAE,CAAC,CAAC,CAAC;gBACP,CAAC,CAAC;YACH,CAAC;SACD,CAAC;IACH,CAAC;CAAC,CAAC,CAAC"}
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const angular_1 = __importDefault(require("angular"));
|
|
7
|
-
const
|
|
7
|
+
const { DateTime } = require('luxon');
|
|
8
8
|
angular_1.default.module('app').directive('mflyValidateTime', function mflyValidateTime() {
|
|
9
9
|
function link($scope, $element, $attrs, $ctrl) {
|
|
10
10
|
$ctrl.$validators.timeFormat = function (modelValue, viewValue) {
|
|
@@ -18,7 +18,11 @@ angular_1.default.module('app').directive('mflyValidateTime', function mflyValid
|
|
|
18
18
|
if (viewValue === '') {
|
|
19
19
|
return true;
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
// Check if the time is valid according to the given formats
|
|
22
|
+
return validTimeFormats.some(format => {
|
|
23
|
+
const parsed = DateTime.fromFormat(viewValue, format === 'H:mm' ? 'H:mm' : 'h:mm a');
|
|
24
|
+
return parsed.isValid;
|
|
25
|
+
});
|
|
22
26
|
};
|
|
23
27
|
}
|
|
24
28
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate-time.js","sourceRoot":"","sources":["../../src/components/time-input/validate-time.js"],"names":[],"mappings":";;;;;AAAA,sDAA6B;AAC7B,
|
|
1
|
+
{"version":3,"file":"validate-time.js","sourceRoot":"","sources":["../../src/components/time-input/validate-time.js"],"names":[],"mappings":";;;;;AAAA,sDAA6B;AAC7B,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;AAErC,iBAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,kBAAkB,EAAE,SAAS,gBAAgB;IAE5E,SAAS,IAAI,CAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK;QAE7C,KAAK,CAAC,WAAW,CAAC,UAAU,GAAG,UAAU,UAAU,EAAE,SAAS;YAE7D,qDAAqD;YACrD,IAAI,gBAAgB,GAAG;gBACtB,MAAM;gBACN,QAAQ;gBACR,OAAO;aACP,CAAC;YAEF,sEAAsE;YACtE,IAAI,SAAS,KAAK,EAAE,EAAE;gBACrB,OAAO,IAAI,CAAC;aACZ;YAED,4DAA4D;YAC5D,OAAO,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;gBACrC,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAA;gBACpF,OAAO,MAAM,CAAC,OAAO,CAAA;YACtB,CAAC,CAAC,CAAA;QACH,CAAC,CAAC;IACH,CAAC;IAED,OAAO;QACN,OAAO,EAAE,SAAS;QAClB,IAAI,EAAE,IAAI;KACV,CAAC;AACH,CAAC,CAAC,CAAC"}
|