@colijnit/corecomponents_v12 255.1.10 → 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.
@@ -14121,46 +14121,58 @@
14121
14121
  this.cdRef = cdRef;
14122
14122
  this.datePipe = datePipe;
14123
14123
  this.showClass = true;
14124
- this.hours = [];
14124
+ this.hourLabels = [];
14125
14125
  this.scheduledObjects = {};
14126
+ this.activeHour = null;
14127
+ this.activeHalfHour = null;
14126
14128
  this.draggedObject = null;
14127
14129
  this.customTemplateUsed = false;
14128
14130
  this.timeChangeEvent = new i0.EventEmitter();
14131
+ this.newObjectPlanEvent = new i0.EventEmitter();
14132
+ document.addEventListener('click', this.onDocumentClick.bind(this));
14129
14133
  }
14130
14134
  HourSchedulingComponent.prototype.ngOnInit = function () {
14131
- if (!this.childProp) {
14132
- this.startTime = parseInt(this.datePipe.transform(new Date(this.schedule[this.startTimeProp]).toISOString(), 'H:mm'));
14133
- this.endTime = parseInt(this.datePipe.transform(new Date(this.schedule[this.endTimeProp]).toISOString(), 'H:mm'));
14134
- }
14135
- else {
14136
- this.startTime = parseInt(this.datePipe.transform(new Date(this.schedule[this.childProp][this.startTimeProp]).toISOString(), 'H:mm'));
14137
- this.endTime = parseInt(this.datePipe.transform(new Date(this.schedule[this.childProp][this.endTimeProp]).toISOString(), 'H:mm'));
14138
- }
14139
14135
  this.generateTimeBlocks();
14136
+ this.generateScheduledObjects();
14137
+ };
14138
+ HourSchedulingComponent.prototype.ngOnDestroy = function () {
14139
+ document.removeEventListener('click', this.onDocumentClick.bind(this));
14140
14140
  };
14141
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 () {
14142
14152
  var objectsList = this.schedule[this.objectsProp];
14143
- for (var hour = this.startTime; hour <= this.endTime; hour++) {
14144
- this.hours.push(this.formatHour(hour));
14145
- this.scheduledObjects[this.formatHour(hour)] = this._getObjectsForHour(hour, objectsList);
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);
14146
14160
  }
14147
14161
  };
14148
- HourSchedulingComponent.prototype._getObjectsForHour = function (hour, objectsList) {
14162
+ HourSchedulingComponent.prototype._getObjectsForHourAndMinutes = function (hour, minutes, objectsList) {
14149
14163
  var _this = this;
14150
14164
  var objectsForHour = [];
14151
14165
  objectsList.forEach(function (obj) {
14152
- if (_this.convertToHourNotation(obj[_this.startTimeProp]) === hour) {
14166
+ var split = _this.convertToHourNotation(obj[_this.startTimeProp]).split(':');
14167
+ if (parseInt(split[0]) === hour && parseInt(split[1]) === minutes) {
14153
14168
  objectsForHour.push(Object.assign({}, obj));
14154
14169
  }
14155
14170
  });
14156
14171
  return objectsForHour;
14157
14172
  };
14158
- HourSchedulingComponent.prototype.formatHour = function (hour) {
14159
- return hour + ":00";
14160
- };
14161
14173
  HourSchedulingComponent.prototype.onDragStart = function (event, obj) {
14162
14174
  var currentTarget = event.currentTarget;
14163
- var currentHourSpan = currentTarget.parentElement.parentElement.querySelector('.hour-label span');
14175
+ var currentHourSpan = currentTarget.parentElement.parentElement.querySelector('.hidden-hour-label');
14164
14176
  var currentHour = currentHourSpan.textContent;
14165
14177
  this.draggedObject = obj;
14166
14178
  event.dataTransfer.setData('text', JSON.stringify({ obj: this.draggedObject, currentHour: currentHour }));
@@ -14170,32 +14182,41 @@
14170
14182
  };
14171
14183
  HourSchedulingComponent.prototype.onDragOver = function (event) {
14172
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
14173
14191
  };
14174
14192
  HourSchedulingComponent.prototype.onDrop = function (event, hour) {
14175
- var _a;
14193
+ var _c;
14176
14194
  var _this = this;
14177
14195
  event.preventDefault();
14178
14196
  event.stopPropagation();
14179
- var data = JSON.parse(event.dataTransfer.getData('text'));
14180
- if (!data || !data.obj) {
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() });
14181
14202
  return;
14182
14203
  }
14183
- var newStartHour = parseInt(hour.split(':')[0], 10);
14184
- var newEndHour = newStartHour + 1;
14185
- var originalStartHour = this.convertToHourNotation(data.obj[this.startTimeProp]);
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]);
14186
14208
  // Get the unique identifier value from the object using the `idProp`
14187
- var objId = data.obj[this.idProp];
14209
+ var objId = parsed.obj[this.idProp];
14188
14210
  // Ensure we create a new object to avoid mutation issues
14189
- var updatedObject = 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
- var newHourBlock = this.formatHour(newStartHour);
14195
- if (!this.scheduledObjects[newHourBlock]) {
14196
- this.scheduledObjects[newHourBlock] = [];
14216
+ if (!this.scheduledObjects[hour]) {
14217
+ this.scheduledObjects[hour] = [];
14197
14218
  }
14198
- this.scheduledObjects[newHourBlock].push(updatedObject);
14219
+ this.scheduledObjects[hour].push(updatedObject);
14199
14220
  // Clear the dragged object
14200
14221
  this.draggedObject = null;
14201
14222
  this.timeChangeEvent.emit(updatedObject);
@@ -14203,20 +14224,67 @@
14203
14224
  this.cdRef.detectChanges();
14204
14225
  };
14205
14226
  HourSchedulingComponent.prototype.convertToHourNotation = function (date) {
14206
- return parseInt(this.datePipe.transform(new Date(date).toISOString(), 'H:mm'));
14227
+ return this.datePipe.transform(new Date(date).toISOString(), 'HH:mm');
14207
14228
  };
14208
- HourSchedulingComponent.prototype.createDate = function (hours) {
14229
+ HourSchedulingComponent.prototype.createDate = function (hours, minutes) {
14209
14230
  var date = new Date();
14210
14231
  date.setHours(hours);
14211
- date.setMinutes(0, 0, 0);
14232
+ date.setMinutes(minutes ? minutes : 0);
14212
14233
  return date;
14213
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
+ ;
14214
14282
  return HourSchedulingComponent;
14215
14283
  }());
14216
14284
  HourSchedulingComponent.decorators = [
14217
14285
  { type: i0.Component, args: [{
14218
14286
  selector: 'co-hour-scheduling',
14219
- template: "\n <div class=\"time-block\" *ngFor=\"let hour of hours\">\n <div class=\"hour-label\"><span [textContent]=\"hour\"></span></div>\n <div\n class=\"object-display\"\n (dragover)=\"onDragOver($event)\"\n (drop)=\"onDrop($event, hour)\"\n >\n <ng-container *ngIf=\"!customTemplateUsed\">\n <ng-container *ngIf=\"scheduledObjects[hour]\">\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=\"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 objects: scheduledObjects[hour]\n }\"\n >\n </ng-template>\n </ng-container>\n </div>\n </div>\n ",
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 ",
14220
14288
  encapsulation: i0.ViewEncapsulation.None
14221
14289
  },] }
14222
14290
  ];
@@ -14234,6 +14302,7 @@
14234
14302
  customTemplateUsed: [{ type: i0.Input }],
14235
14303
  idProp: [{ type: i0.Input }],
14236
14304
  timeChangeEvent: [{ type: i0.Output }],
14305
+ newObjectPlanEvent: [{ type: i0.Output }],
14237
14306
  generateTimeBlocks: [{ type: i0.HostBinding, args: ['class.co-hour-scheduling',] }]
14238
14307
  };
14239
14308