@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.
@@ -13691,45 +13691,57 @@ class HourSchedulingComponent {
13691
13691
  this.cdRef = cdRef;
13692
13692
  this.datePipe = datePipe;
13693
13693
  this.showClass = true;
13694
- this.hours = [];
13694
+ this.hourLabels = [];
13695
13695
  this.scheduledObjects = {};
13696
+ this.activeHour = null;
13697
+ this.activeHalfHour = null;
13696
13698
  this.draggedObject = null;
13697
13699
  this.customTemplateUsed = false;
13698
13700
  this.timeChangeEvent = new EventEmitter();
13701
+ this.newObjectPlanEvent = new EventEmitter();
13702
+ document.addEventListener('click', this.onDocumentClick.bind(this));
13699
13703
  }
13700
13704
  ngOnInit() {
13701
- if (!this.childProp) {
13702
- this.startTime = parseInt(this.datePipe.transform(new Date(this.schedule[this.startTimeProp]).toISOString(), 'H:mm'));
13703
- this.endTime = parseInt(this.datePipe.transform(new Date(this.schedule[this.endTimeProp]).toISOString(), 'H:mm'));
13704
- }
13705
- else {
13706
- this.startTime = parseInt(this.datePipe.transform(new Date(this.schedule[this.childProp][this.startTimeProp]).toISOString(), 'H:mm'));
13707
- this.endTime = parseInt(this.datePipe.transform(new Date(this.schedule[this.childProp][this.endTimeProp]).toISOString(), 'H:mm'));
13708
- }
13709
13705
  this.generateTimeBlocks();
13706
+ this.generateScheduledObjects();
13707
+ }
13708
+ ngOnDestroy() {
13709
+ document.removeEventListener('click', this.onDocumentClick.bind(this));
13710
13710
  }
13711
13711
  generateTimeBlocks() {
13712
+ let startUnix = !this.childProp ? this.dateToUnixEpoch(new Date(this.schedule[this.startTimeProp])) : this.dateToUnixEpoch(new Date(this.schedule[this.childProp][this.startTimeProp]));
13713
+ let endUnix = !this.childProp ? this.dateToUnixEpoch(new Date(this.schedule[this.endTimeProp])) : this.dateToUnixEpoch(new Date(this.schedule[this.childProp][this.endTimeProp]));
13714
+ let interval = 60 * 60;
13715
+ for (let hourCount = startUnix; hourCount <= endUnix; hourCount += interval) {
13716
+ let hour = new Date(hourCount * 1000);
13717
+ let hourString = `${hour.getHours()}:${hour.getMinutes() === 0 ? '00' : hour.getMinutes()}`;
13718
+ this.hourLabels.push(hourString);
13719
+ }
13720
+ }
13721
+ generateScheduledObjects() {
13712
13722
  const objectsList = this.schedule[this.objectsProp];
13713
- for (let hour = this.startTime; hour <= this.endTime; hour++) {
13714
- this.hours.push(this.formatHour(hour));
13715
- this.scheduledObjects[this.formatHour(hour)] = this._getObjectsForHour(hour, objectsList);
13723
+ let startUnix = !this.childProp ? this.dateToUnixEpoch(new Date(this.schedule[this.startTimeProp])) : this.dateToUnixEpoch(new Date(this.schedule[this.childProp][this.startTimeProp]));
13724
+ let endUnix = !this.childProp ? this.dateToUnixEpoch(new Date(this.schedule[this.endTimeProp])) : this.dateToUnixEpoch(new Date(this.schedule[this.childProp][this.endTimeProp]));
13725
+ let interval = 30 * 60;
13726
+ for (let hourCount = startUnix; hourCount <= endUnix; hourCount += interval) {
13727
+ let hour = new Date(hourCount * 1000);
13728
+ let hourString = `${hour.getHours()}:${hour.getMinutes() === 0 ? '00' : hour.getMinutes()}`;
13729
+ this.scheduledObjects[hourString] = this._getObjectsForHourAndMinutes(hour.getHours(), hour.getMinutes(), objectsList);
13716
13730
  }
13717
13731
  }
13718
- _getObjectsForHour(hour, objectsList) {
13732
+ _getObjectsForHourAndMinutes(hour, minutes, objectsList) {
13719
13733
  const objectsForHour = [];
13720
13734
  objectsList.forEach((obj) => {
13721
- if (this.convertToHourNotation(obj[this.startTimeProp]) === hour) {
13735
+ let split = this.convertToHourNotation(obj[this.startTimeProp]).split(':');
13736
+ if (parseInt(split[0]) === hour && parseInt(split[1]) === minutes) {
13722
13737
  objectsForHour.push(Object.assign({}, obj));
13723
13738
  }
13724
13739
  });
13725
13740
  return objectsForHour;
13726
13741
  }
13727
- formatHour(hour) {
13728
- return `${hour}:00`;
13729
- }
13730
13742
  onDragStart(event, obj) {
13731
13743
  const currentTarget = event.currentTarget;
13732
- const currentHourSpan = currentTarget.parentElement.parentElement.querySelector('.hour-label span');
13744
+ const currentHourSpan = currentTarget.parentElement.parentElement.querySelector('.hidden-hour-label');
13733
13745
  const currentHour = currentHourSpan.textContent;
13734
13746
  this.draggedObject = obj;
13735
13747
  event.dataTransfer.setData('text', JSON.stringify({ obj: this.draggedObject, currentHour }));
@@ -13739,30 +13751,39 @@ class HourSchedulingComponent {
13739
13751
  }
13740
13752
  onDragOver(event) {
13741
13753
  event.preventDefault();
13754
+ const currentTarget = event.currentTarget;
13755
+ currentTarget.classList.add('drag-over');
13756
+ }
13757
+ onDragLeave(event) {
13758
+ const currentTarget = event.currentTarget;
13759
+ currentTarget.classList.remove('drag-over'); // Remove 'drag-over' class
13742
13760
  }
13743
13761
  onDrop(event, hour) {
13744
13762
  event.preventDefault();
13745
13763
  event.stopPropagation();
13746
- const data = JSON.parse(event.dataTransfer.getData('text'));
13747
- if (!data || !data.obj) {
13764
+ const currentTarget = event.currentTarget;
13765
+ currentTarget.classList.remove('drag-over');
13766
+ let parsed = this.tryParseJSONObject(event.dataTransfer.getData("text"));
13767
+ if (!parsed) {
13768
+ this.newObjectPlanEvent.emit({ currentHour: hour, data: parsed.toString() });
13748
13769
  return;
13749
13770
  }
13750
- const newStartHour = parseInt(hour.split(':')[0], 10);
13751
- const newEndHour = newStartHour + 1;
13752
- const originalStartHour = this.convertToHourNotation(data.obj[this.startTimeProp]);
13771
+ const splitHour = hour.split(':');
13772
+ const newEndMinutes = splitHour[1] === "00" ? 30 : 0;
13773
+ const newEndHour = splitHour[1] === "30" ? (parseInt(splitHour[0]) + 1) : parseInt(splitHour[0]);
13774
+ const originalStartHour = this.convertToHourNotation(parsed.obj[this.startTimeProp]);
13753
13775
  // Get the unique identifier value from the object using the `idProp`
13754
- const objId = data.obj[this.idProp];
13776
+ const objId = parsed.obj[this.idProp];
13755
13777
  // Ensure we create a new object to avoid mutation issues
13756
- const updatedObject = Object.assign(Object.assign({}, data.obj), { [this.startTimeProp]: this.createDate(newStartHour), [this.endTimeProp]: this.createDate(newEndHour) });
13778
+ const updatedObject = Object.assign(Object.assign({}, parsed.obj), { [this.startTimeProp]: this.createDate(parseInt(splitHour[0]), parseInt(splitHour[1])), [this.endTimeProp]: this.createDate(newEndHour, newEndMinutes) });
13757
13779
  // Remove the object from its old hour block using its unique id
13758
- const originalHourBlock = this.formatHour(originalStartHour);
13780
+ const originalHourBlock = this.formatHour(parseInt(originalStartHour.split(':')[0]), parseInt(originalStartHour.split(':')[1]));
13759
13781
  this.scheduledObjects[originalHourBlock] = this.scheduledObjects[originalHourBlock].filter(o => o[this.idProp] !== objId);
13760
13782
  // Add the object to the new hour block
13761
- const newHourBlock = this.formatHour(newStartHour);
13762
- if (!this.scheduledObjects[newHourBlock]) {
13763
- this.scheduledObjects[newHourBlock] = [];
13783
+ if (!this.scheduledObjects[hour]) {
13784
+ this.scheduledObjects[hour] = [];
13764
13785
  }
13765
- this.scheduledObjects[newHourBlock].push(updatedObject);
13786
+ this.scheduledObjects[hour].push(updatedObject);
13766
13787
  // Clear the dragged object
13767
13788
  this.draggedObject = null;
13768
13789
  this.timeChangeEvent.emit(updatedObject);
@@ -13770,50 +13791,139 @@ class HourSchedulingComponent {
13770
13791
  this.cdRef.detectChanges();
13771
13792
  }
13772
13793
  convertToHourNotation(date) {
13773
- return parseInt(this.datePipe.transform(new Date(date).toISOString(), 'H:mm'));
13794
+ return this.datePipe.transform(new Date(date).toISOString(), 'HH:mm');
13774
13795
  }
13775
- createDate(hours) {
13796
+ createDate(hours, minutes) {
13776
13797
  let date = new Date();
13777
13798
  date.setHours(hours);
13778
- date.setMinutes(0, 0, 0);
13799
+ date.setMinutes(minutes ? minutes : 0);
13779
13800
  return date;
13780
13801
  }
13802
+ dateToUnixEpoch(date) {
13803
+ return Math.floor(date.getTime()) / 1000;
13804
+ }
13805
+ formatHour(hour, minutes) {
13806
+ return `${hour}:${minutes ? minutes : '00'}`;
13807
+ }
13808
+ addMinutes(hour) {
13809
+ let split = hour.split(":");
13810
+ split[1] = "30";
13811
+ return split.join(':');
13812
+ }
13813
+ onDocumentClick(event) {
13814
+ const targetElement = event.target;
13815
+ // Clear active state when clicking outside
13816
+ if (!targetElement.closest('.object-display')) {
13817
+ this.activeHalfHour = null;
13818
+ this.cdRef.detectChanges();
13819
+ }
13820
+ }
13821
+ onObjectDisplayClick(hour, half) {
13822
+ var _a, _b;
13823
+ const halfHourIdentifier = `${hour}-${half}`;
13824
+ if (this.activeHalfHour === halfHourIdentifier) {
13825
+ // Deactivate if clicked again
13826
+ this.activeHalfHour = null;
13827
+ }
13828
+ 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) {
13829
+ // Activate the half-hour if there are objects
13830
+ this.activeHalfHour = halfHourIdentifier;
13831
+ }
13832
+ }
13833
+ tryParseJSONObject(jsonString) {
13834
+ try {
13835
+ let o = JSON.parse(jsonString);
13836
+ // Handle non-exception-throwing cases:
13837
+ // Neither JSON.parse(false) or JSON.parse(1234) throw errors, hence the type-checking,
13838
+ // but... JSON.parse(null) returns null, and typeof null === "object",
13839
+ // so we must check for that, too. Thankfully, null is falsey, so this suffices:
13840
+ if (o && typeof o === "object") {
13841
+ return o;
13842
+ }
13843
+ }
13844
+ catch (e) {
13845
+ }
13846
+ return false;
13847
+ }
13848
+ ;
13781
13849
  }
13782
13850
  HourSchedulingComponent.decorators = [
13783
13851
  { type: Component, args: [{
13784
13852
  selector: 'co-hour-scheduling',
13785
13853
  template: `
13786
- <div class="time-block" *ngFor="let hour of hours">
13854
+ <div class="time-block" *ngFor="let hour of hourLabels">
13787
13855
  <div class="hour-label"><span [textContent]="hour"></span></div>
13788
- <div
13789
- class="object-display"
13790
- (dragover)="onDragOver($event)"
13791
- (drop)="onDrop($event, hour)"
13792
- >
13793
- <ng-container *ngIf="!customTemplateUsed">
13794
- <ng-container *ngIf="scheduledObjects[hour]">
13795
- <div
13796
- *ngFor="let obj of scheduledObjects[hour]"
13797
- class="scheduled-object"
13798
- [draggable]="true"
13799
- (dragstart)="onDragStart($event, obj)"
13800
- >
13801
- <span class="title" [textContent]="obj.title"></span>
13802
- <span class="sub-title" [textContent]="obj.subTitle"></span>
13803
- </div>
13856
+ <div class="object-display">
13857
+ <div class="first-half-hour object-half"
13858
+ [ngClass]="{'has-objects': scheduledObjects[hour]?.length > 0, 'active': activeHalfHour === hour + '-firstHalf'}"
13859
+ (dragover)="onDragOver($event)"
13860
+ (dragleave)="onDragLeave($event)"
13861
+ (click)="onObjectDisplayClick(hour, 'firstHalf')"
13862
+ (drop)="onDrop($event, hour)">
13863
+ <ng-container *ngIf="!customTemplateUsed">
13864
+ <ng-container *ngIf="scheduledObjects[hour]">
13865
+ <span class="hidden-hour-label" [hidden]="true" [textContent]="hour"></span>
13866
+ <div
13867
+ *ngFor="let obj of scheduledObjects[hour]"
13868
+ class="scheduled-object"
13869
+ [draggable]="true"
13870
+ (dragstart)="onDragStart($event, obj)"
13871
+ >
13872
+ <span class="hidden-hour-label" [hidden]="true" [textContent]="addMinutes(hour)"></span>
13873
+ <span class="title" [textContent]="obj.title"></span>
13874
+ <span class="sub-title" [textContent]="obj.subTitle"></span>
13875
+ </div>
13876
+ </ng-container>
13804
13877
  </ng-container>
13805
- </ng-container>
13806
13878
 
13807
- <ng-container *ngIf="customTemplateUsed">
13808
- <ng-template
13809
- [ngTemplateOutlet]="customTemplate"
13810
- [ngTemplateOutletContext]="{
13879
+ <ng-container *ngIf="customTemplateUsed">
13880
+ <ng-template
13881
+ [ngTemplateOutlet]="customTemplate"
13882
+ [ngTemplateOutletContext]="{
13811
13883
  hour: hour,
13884
+ hiddenHour: hour,
13812
13885
  objects: scheduledObjects[hour]
13813
13886
  }"
13814
- >
13815
- </ng-template>
13816
- </ng-container>
13887
+ >
13888
+ </ng-template>
13889
+ </ng-container>
13890
+ </div>
13891
+
13892
+ <div class="second-half-hour object-half"
13893
+ [ngClass]="{'has-objects': scheduledObjects[addMinutes(hour)]?.length > 0, 'active': activeHalfHour === hour + '-secondHalf'}"
13894
+ (dragover)="onDragOver($event)"
13895
+ (dragleave)="onDragLeave($event)"
13896
+ (click)="onObjectDisplayClick(hour, 'secondHalf')"
13897
+ (drop)="onDrop($event, addMinutes(hour))">
13898
+ <ng-container *ngIf="!customTemplateUsed">
13899
+ <ng-container *ngIf="scheduledObjects[addMinutes(hour)]">
13900
+ <div
13901
+ *ngFor="let obj of scheduledObjects[addMinutes(hour)]"
13902
+ class="scheduled-object"
13903
+ [draggable]="true"
13904
+ (dragstart)="onDragStart($event, obj)"
13905
+ >
13906
+ <span class="title" [textContent]="obj.title"></span>
13907
+ <span class="sub-title" [textContent]="obj.subTitle"></span>
13908
+ <span class="hidden-hour-label" [hidden]="true" [textContent]="addMinutes(hour)"></span>
13909
+ </div>
13910
+ </ng-container>
13911
+ </ng-container>
13912
+
13913
+ <ng-container *ngIf="customTemplateUsed">
13914
+ <ng-template
13915
+ [ngTemplateOutlet]="customTemplate"
13916
+ [ngTemplateOutletContext]="{
13917
+ hour: hour,
13918
+ hiddenHour: addMinutes(hour),
13919
+ objects: scheduledObjects[addMinutes(hour)]
13920
+ }"
13921
+ >
13922
+ </ng-template>
13923
+ </ng-container>
13924
+ </div>
13925
+
13926
+
13817
13927
  </div>
13818
13928
  </div>
13819
13929
  `,
@@ -13834,6 +13944,7 @@ HourSchedulingComponent.propDecorators = {
13834
13944
  customTemplateUsed: [{ type: Input }],
13835
13945
  idProp: [{ type: Input }],
13836
13946
  timeChangeEvent: [{ type: Output }],
13947
+ newObjectPlanEvent: [{ type: Output }],
13837
13948
  generateTimeBlocks: [{ type: HostBinding, args: ['class.co-hour-scheduling',] }]
13838
13949
  };
13839
13950