@colijnit/corecomponents_v12 255.1.9 → 255.1.11
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/bundles/colijnit-corecomponents_v12.umd.js +110 -39
- package/bundles/colijnit-corecomponents_v12.umd.js.map +1 -1
- package/colijnit-corecomponents_v12.metadata.json +1 -1
- package/esm2015/lib/components/hour-scheduling/hour-scheduling.component.js +177 -64
- package/fesm2015/colijnit-corecomponents_v12.js +175 -62
- package/fesm2015/colijnit-corecomponents_v12.js.map +1 -1
- package/lib/components/hour-scheduling/hour-scheduling.component.d.ts +27 -14
- package/lib/components/hour-scheduling/style/_layout.scss +30 -13
- package/package.json +1 -1
|
@@ -14117,49 +14117,62 @@
|
|
|
14117
14117
|
];
|
|
14118
14118
|
|
|
14119
14119
|
var HourSchedulingComponent = /** @class */ (function () {
|
|
14120
|
-
function HourSchedulingComponent(cdRef,
|
|
14120
|
+
function HourSchedulingComponent(cdRef, datePipe) {
|
|
14121
14121
|
this.cdRef = cdRef;
|
|
14122
|
-
this.
|
|
14122
|
+
this.datePipe = datePipe;
|
|
14123
14123
|
this.showClass = true;
|
|
14124
|
-
this.
|
|
14125
|
-
this.hours = [];
|
|
14124
|
+
this.hourLabels = [];
|
|
14126
14125
|
this.scheduledObjects = {};
|
|
14126
|
+
this.activeHour = null;
|
|
14127
|
+
this.activeHalfHour = null;
|
|
14127
14128
|
this.draggedObject = null;
|
|
14129
|
+
this.customTemplateUsed = false;
|
|
14130
|
+
this.timeChangeEvent = new i0.EventEmitter();
|
|
14131
|
+
this.newObjectPlanEvent = new i0.EventEmitter();
|
|
14132
|
+
document.addEventListener('click', this.onDocumentClick.bind(this));
|
|
14128
14133
|
}
|
|
14129
14134
|
HourSchedulingComponent.prototype.ngOnInit = function () {
|
|
14130
|
-
if (!this.childProp) {
|
|
14131
|
-
this.startTime = parseInt(this._datepipe.transform(new Date(this.schedule[this.startTimeProp]).toISOString(), 'H:mm'));
|
|
14132
|
-
this.endTime = parseInt(this._datepipe.transform(new Date(this.schedule[this.endTimeProp]).toISOString(), 'H:mm'));
|
|
14133
|
-
}
|
|
14134
|
-
else {
|
|
14135
|
-
this.startTime = parseInt(this._datepipe.transform(new Date(this.schedule[this.childProp][this.startTimeProp]).toISOString(), 'H:mm'));
|
|
14136
|
-
this.endTime = parseInt(this._datepipe.transform(new Date(this.schedule[this.childProp][this.endTimeProp]).toISOString(), 'H:mm'));
|
|
14137
|
-
}
|
|
14138
14135
|
this.generateTimeBlocks();
|
|
14136
|
+
this.generateScheduledObjects();
|
|
14137
|
+
};
|
|
14138
|
+
HourSchedulingComponent.prototype.ngOnDestroy = function () {
|
|
14139
|
+
document.removeEventListener('click', this.onDocumentClick.bind(this));
|
|
14139
14140
|
};
|
|
14140
14141
|
HourSchedulingComponent.prototype.generateTimeBlocks = function () {
|
|
14142
|
+
var startUnix = !this.childProp ? this.dateToUnixEpoch(new Date(this.schedule[this.startTimeProp])) : this.dateToUnixEpoch(new Date(this.schedule[this.childProp][this.startTimeProp]));
|
|
14143
|
+
var endUnix = !this.childProp ? this.dateToUnixEpoch(new Date(this.schedule[this.endTimeProp])) : this.dateToUnixEpoch(new Date(this.schedule[this.childProp][this.endTimeProp]));
|
|
14144
|
+
var interval = 60 * 60;
|
|
14145
|
+
for (var hourCount = startUnix; hourCount <= endUnix; hourCount += interval) {
|
|
14146
|
+
var hour = new Date(hourCount * 1000);
|
|
14147
|
+
var hourString = hour.getHours() + ":" + (hour.getMinutes() === 0 ? '00' : hour.getMinutes());
|
|
14148
|
+
this.hourLabels.push(hourString);
|
|
14149
|
+
}
|
|
14150
|
+
};
|
|
14151
|
+
HourSchedulingComponent.prototype.generateScheduledObjects = function () {
|
|
14141
14152
|
var objectsList = this.schedule[this.objectsProp];
|
|
14142
|
-
|
|
14143
|
-
|
|
14144
|
-
|
|
14153
|
+
var startUnix = !this.childProp ? this.dateToUnixEpoch(new Date(this.schedule[this.startTimeProp])) : this.dateToUnixEpoch(new Date(this.schedule[this.childProp][this.startTimeProp]));
|
|
14154
|
+
var endUnix = !this.childProp ? this.dateToUnixEpoch(new Date(this.schedule[this.endTimeProp])) : this.dateToUnixEpoch(new Date(this.schedule[this.childProp][this.endTimeProp]));
|
|
14155
|
+
var interval = 30 * 60;
|
|
14156
|
+
for (var hourCount = startUnix; hourCount <= endUnix; hourCount += interval) {
|
|
14157
|
+
var hour = new Date(hourCount * 1000);
|
|
14158
|
+
var hourString = hour.getHours() + ":" + (hour.getMinutes() === 0 ? '00' : hour.getMinutes());
|
|
14159
|
+
this.scheduledObjects[hourString] = this._getObjectsForHourAndMinutes(hour.getHours(), hour.getMinutes(), objectsList);
|
|
14145
14160
|
}
|
|
14146
14161
|
};
|
|
14147
|
-
HourSchedulingComponent.prototype.
|
|
14162
|
+
HourSchedulingComponent.prototype._getObjectsForHourAndMinutes = function (hour, minutes, objectsList) {
|
|
14148
14163
|
var _this = this;
|
|
14149
14164
|
var objectsForHour = [];
|
|
14150
14165
|
objectsList.forEach(function (obj) {
|
|
14151
|
-
|
|
14166
|
+
var split = _this.convertToHourNotation(obj[_this.startTimeProp]).split(':');
|
|
14167
|
+
if (parseInt(split[0]) === hour && parseInt(split[1]) === minutes) {
|
|
14152
14168
|
objectsForHour.push(Object.assign({}, obj));
|
|
14153
14169
|
}
|
|
14154
14170
|
});
|
|
14155
14171
|
return objectsForHour;
|
|
14156
14172
|
};
|
|
14157
|
-
HourSchedulingComponent.prototype.formatHour = function (hour) {
|
|
14158
|
-
return hour + ":00";
|
|
14159
|
-
};
|
|
14160
14173
|
HourSchedulingComponent.prototype.onDragStart = function (event, obj) {
|
|
14161
14174
|
var currentTarget = event.currentTarget;
|
|
14162
|
-
var currentHourSpan = currentTarget.parentElement.parentElement.querySelector('.hour-label
|
|
14175
|
+
var currentHourSpan = currentTarget.parentElement.parentElement.querySelector('.hidden-hour-label');
|
|
14163
14176
|
var currentHour = currentHourSpan.textContent;
|
|
14164
14177
|
this.draggedObject = obj;
|
|
14165
14178
|
event.dataTransfer.setData('text', JSON.stringify({ obj: this.draggedObject, currentHour: currentHour }));
|
|
@@ -14169,53 +14182,109 @@
|
|
|
14169
14182
|
};
|
|
14170
14183
|
HourSchedulingComponent.prototype.onDragOver = function (event) {
|
|
14171
14184
|
event.preventDefault();
|
|
14185
|
+
var currentTarget = event.currentTarget;
|
|
14186
|
+
currentTarget.classList.add('drag-over');
|
|
14187
|
+
};
|
|
14188
|
+
HourSchedulingComponent.prototype.onDragLeave = function (event) {
|
|
14189
|
+
var currentTarget = event.currentTarget;
|
|
14190
|
+
currentTarget.classList.remove('drag-over'); // Remove 'drag-over' class
|
|
14172
14191
|
};
|
|
14173
14192
|
HourSchedulingComponent.prototype.onDrop = function (event, hour) {
|
|
14174
|
-
var
|
|
14193
|
+
var _c;
|
|
14175
14194
|
var _this = this;
|
|
14176
14195
|
event.preventDefault();
|
|
14177
14196
|
event.stopPropagation();
|
|
14178
|
-
var
|
|
14179
|
-
|
|
14197
|
+
var currentTarget = event.currentTarget;
|
|
14198
|
+
currentTarget.classList.remove('drag-over');
|
|
14199
|
+
var parsed = this.tryParseJSONObject(event.dataTransfer.getData("text"));
|
|
14200
|
+
if (!parsed) {
|
|
14201
|
+
this.newObjectPlanEvent.emit({ currentHour: hour, data: parsed.toString() });
|
|
14180
14202
|
return;
|
|
14181
14203
|
}
|
|
14182
|
-
var
|
|
14183
|
-
var
|
|
14184
|
-
var
|
|
14204
|
+
var splitHour = hour.split(':');
|
|
14205
|
+
var newEndMinutes = splitHour[1] === "00" ? 30 : 0;
|
|
14206
|
+
var newEndHour = splitHour[1] === "30" ? (parseInt(splitHour[0]) + 1) : parseInt(splitHour[0]);
|
|
14207
|
+
var originalStartHour = this.convertToHourNotation(parsed.obj[this.startTimeProp]);
|
|
14185
14208
|
// Get the unique identifier value from the object using the `idProp`
|
|
14186
|
-
var objId =
|
|
14209
|
+
var objId = parsed.obj[this.idProp];
|
|
14187
14210
|
// Ensure we create a new object to avoid mutation issues
|
|
14188
|
-
var updatedObject = Object.assign(Object.assign({},
|
|
14189
|
-
var updatedObject2 = Object.assign(Object.assign({}, data.obj), (_a = {}, _a[this.startTimeProp] = this.createDate(newStartHour), _a[this.endTimeProp] = this.createDate(newEndHour), _a));
|
|
14211
|
+
var updatedObject = Object.assign(Object.assign({}, parsed.obj), (_c = {}, _c[this.startTimeProp] = this.createDate(parseInt(splitHour[0]), parseInt(splitHour[1])), _c[this.endTimeProp] = this.createDate(newEndHour, newEndMinutes), _c));
|
|
14190
14212
|
// Remove the object from its old hour block using its unique id
|
|
14191
|
-
var originalHourBlock = this.formatHour(originalStartHour);
|
|
14213
|
+
var originalHourBlock = this.formatHour(parseInt(originalStartHour.split(':')[0]), parseInt(originalStartHour.split(':')[1]));
|
|
14192
14214
|
this.scheduledObjects[originalHourBlock] = this.scheduledObjects[originalHourBlock].filter(function (o) { return o[_this.idProp] !== objId; });
|
|
14193
14215
|
// Add the object to the new hour block
|
|
14194
|
-
|
|
14195
|
-
|
|
14196
|
-
this.scheduledObjects[newHourBlock] = [];
|
|
14216
|
+
if (!this.scheduledObjects[hour]) {
|
|
14217
|
+
this.scheduledObjects[hour] = [];
|
|
14197
14218
|
}
|
|
14198
|
-
this.scheduledObjects[
|
|
14219
|
+
this.scheduledObjects[hour].push(updatedObject);
|
|
14199
14220
|
// Clear the dragged object
|
|
14200
14221
|
this.draggedObject = null;
|
|
14222
|
+
this.timeChangeEvent.emit(updatedObject);
|
|
14201
14223
|
// Trigger change detection to update the view
|
|
14202
14224
|
this.cdRef.detectChanges();
|
|
14203
14225
|
};
|
|
14204
14226
|
HourSchedulingComponent.prototype.convertToHourNotation = function (date) {
|
|
14205
|
-
return
|
|
14227
|
+
return this.datePipe.transform(new Date(date).toISOString(), 'HH:mm');
|
|
14206
14228
|
};
|
|
14207
|
-
HourSchedulingComponent.prototype.createDate = function (hours) {
|
|
14229
|
+
HourSchedulingComponent.prototype.createDate = function (hours, minutes) {
|
|
14208
14230
|
var date = new Date();
|
|
14209
14231
|
date.setHours(hours);
|
|
14210
|
-
date.setMinutes(
|
|
14232
|
+
date.setMinutes(minutes ? minutes : 0);
|
|
14211
14233
|
return date;
|
|
14212
14234
|
};
|
|
14235
|
+
HourSchedulingComponent.prototype.dateToUnixEpoch = function (date) {
|
|
14236
|
+
return Math.floor(date.getTime()) / 1000;
|
|
14237
|
+
};
|
|
14238
|
+
HourSchedulingComponent.prototype.formatHour = function (hour, minutes) {
|
|
14239
|
+
return hour + ":" + (minutes ? minutes : '00');
|
|
14240
|
+
};
|
|
14241
|
+
HourSchedulingComponent.prototype.addMinutes = function (hour) {
|
|
14242
|
+
var split = hour.split(":");
|
|
14243
|
+
split[1] = "30";
|
|
14244
|
+
return split.join(':');
|
|
14245
|
+
};
|
|
14246
|
+
HourSchedulingComponent.prototype.onDocumentClick = function (event) {
|
|
14247
|
+
var targetElement = event.target;
|
|
14248
|
+
// Clear active state when clicking outside
|
|
14249
|
+
if (!targetElement.closest('.object-display')) {
|
|
14250
|
+
this.activeHalfHour = null;
|
|
14251
|
+
this.cdRef.detectChanges();
|
|
14252
|
+
}
|
|
14253
|
+
};
|
|
14254
|
+
HourSchedulingComponent.prototype.onObjectDisplayClick = function (hour, half) {
|
|
14255
|
+
var _a, _b;
|
|
14256
|
+
var halfHourIdentifier = hour + "-" + half;
|
|
14257
|
+
if (this.activeHalfHour === halfHourIdentifier) {
|
|
14258
|
+
// Deactivate if clicked again
|
|
14259
|
+
this.activeHalfHour = null;
|
|
14260
|
+
}
|
|
14261
|
+
else if (((_a = this.scheduledObjects[hour]) === null || _a === void 0 ? void 0 : _a.length) > 0 || ((_b = this.scheduledObjects[this.addMinutes(hour)]) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
14262
|
+
// Activate the half-hour if there are objects
|
|
14263
|
+
this.activeHalfHour = halfHourIdentifier;
|
|
14264
|
+
}
|
|
14265
|
+
};
|
|
14266
|
+
HourSchedulingComponent.prototype.tryParseJSONObject = function (jsonString) {
|
|
14267
|
+
try {
|
|
14268
|
+
var o = JSON.parse(jsonString);
|
|
14269
|
+
// Handle non-exception-throwing cases:
|
|
14270
|
+
// Neither JSON.parse(false) or JSON.parse(1234) throw errors, hence the type-checking,
|
|
14271
|
+
// but... JSON.parse(null) returns null, and typeof null === "object",
|
|
14272
|
+
// so we must check for that, too. Thankfully, null is falsey, so this suffices:
|
|
14273
|
+
if (o && typeof o === "object") {
|
|
14274
|
+
return o;
|
|
14275
|
+
}
|
|
14276
|
+
}
|
|
14277
|
+
catch (e) {
|
|
14278
|
+
}
|
|
14279
|
+
return false;
|
|
14280
|
+
};
|
|
14281
|
+
;
|
|
14213
14282
|
return HourSchedulingComponent;
|
|
14214
14283
|
}());
|
|
14215
14284
|
HourSchedulingComponent.decorators = [
|
|
14216
14285
|
{ type: i0.Component, args: [{
|
|
14217
14286
|
selector: 'co-hour-scheduling',
|
|
14218
|
-
template: "\n <div class=\"time-block\" *ngFor=\"let hour of
|
|
14287
|
+
template: "\n <div class=\"time-block\" *ngFor=\"let hour of hourLabels\">\n <div class=\"hour-label\"><span [textContent]=\"hour\"></span></div>\n <div class=\"object-display\">\n <div class=\"first-half-hour object-half\"\n [ngClass]=\"{'has-objects': scheduledObjects[hour]?.length > 0, 'active': activeHalfHour === hour + '-firstHalf'}\"\n (dragover)=\"onDragOver($event)\"\n (dragleave)=\"onDragLeave($event)\"\n (click)=\"onObjectDisplayClick(hour, 'firstHalf')\"\n (drop)=\"onDrop($event, hour)\">\n <ng-container *ngIf=\"!customTemplateUsed\">\n <ng-container *ngIf=\"scheduledObjects[hour]\">\n <span class=\"hidden-hour-label\" [hidden]=\"true\" [textContent]=\"hour\"></span>\n <div\n *ngFor=\"let obj of scheduledObjects[hour]\"\n class=\"scheduled-object\"\n [draggable]=\"true\"\n (dragstart)=\"onDragStart($event, obj)\"\n >\n <span class=\"hidden-hour-label\" [hidden]=\"true\" [textContent]=\"addMinutes(hour)\"></span>\n <span class=\"title\" [textContent]=\"obj.title\"></span>\n <span class=\"sub-title\" [textContent]=\"obj.subTitle\"></span>\n </div>\n </ng-container>\n </ng-container>\n\n <ng-container *ngIf=\"customTemplateUsed\">\n <ng-template\n [ngTemplateOutlet]=\"customTemplate\"\n [ngTemplateOutletContext]=\"{\n hour: hour,\n hiddenHour: hour,\n objects: scheduledObjects[hour]\n }\"\n >\n </ng-template>\n </ng-container>\n </div>\n\n <div class=\"second-half-hour object-half\"\n [ngClass]=\"{'has-objects': scheduledObjects[addMinutes(hour)]?.length > 0, 'active': activeHalfHour === hour + '-secondHalf'}\"\n (dragover)=\"onDragOver($event)\"\n (dragleave)=\"onDragLeave($event)\"\n (click)=\"onObjectDisplayClick(hour, 'secondHalf')\"\n (drop)=\"onDrop($event, addMinutes(hour))\">\n <ng-container *ngIf=\"!customTemplateUsed\">\n <ng-container *ngIf=\"scheduledObjects[addMinutes(hour)]\">\n <div\n *ngFor=\"let obj of scheduledObjects[addMinutes(hour)]\"\n class=\"scheduled-object\"\n [draggable]=\"true\"\n (dragstart)=\"onDragStart($event, obj)\"\n >\n <span class=\"title\" [textContent]=\"obj.title\"></span>\n <span class=\"sub-title\" [textContent]=\"obj.subTitle\"></span>\n <span class=\"hidden-hour-label\" [hidden]=\"true\" [textContent]=\"addMinutes(hour)\"></span>\n </div>\n </ng-container>\n </ng-container>\n\n <ng-container *ngIf=\"customTemplateUsed\">\n <ng-template\n [ngTemplateOutlet]=\"customTemplate\"\n [ngTemplateOutletContext]=\"{\n hour: hour,\n hiddenHour: addMinutes(hour),\n objects: scheduledObjects[addMinutes(hour)]\n }\"\n >\n </ng-template>\n </ng-container>\n </div>\n\n\n </div>\n </div>\n ",
|
|
14219
14288
|
encapsulation: i0.ViewEncapsulation.None
|
|
14220
14289
|
},] }
|
|
14221
14290
|
];
|
|
@@ -14232,6 +14301,8 @@
|
|
|
14232
14301
|
customTemplate: [{ type: i0.Input }],
|
|
14233
14302
|
customTemplateUsed: [{ type: i0.Input }],
|
|
14234
14303
|
idProp: [{ type: i0.Input }],
|
|
14304
|
+
timeChangeEvent: [{ type: i0.Output }],
|
|
14305
|
+
newObjectPlanEvent: [{ type: i0.Output }],
|
|
14235
14306
|
generateTimeBlocks: [{ type: i0.HostBinding, args: ['class.co-hour-scheduling',] }]
|
|
14236
14307
|
};
|
|
14237
14308
|
|