@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
|
@@ -13687,48 +13687,61 @@ ColorSequenceService.decorators = [
|
|
|
13687
13687
|
];
|
|
13688
13688
|
|
|
13689
13689
|
class HourSchedulingComponent {
|
|
13690
|
-
constructor(cdRef,
|
|
13690
|
+
constructor(cdRef, datePipe) {
|
|
13691
13691
|
this.cdRef = cdRef;
|
|
13692
|
-
this.
|
|
13692
|
+
this.datePipe = datePipe;
|
|
13693
13693
|
this.showClass = true;
|
|
13694
|
-
this.
|
|
13695
|
-
this.hours = [];
|
|
13694
|
+
this.hourLabels = [];
|
|
13696
13695
|
this.scheduledObjects = {};
|
|
13696
|
+
this.activeHour = null;
|
|
13697
|
+
this.activeHalfHour = null;
|
|
13697
13698
|
this.draggedObject = null;
|
|
13699
|
+
this.customTemplateUsed = false;
|
|
13700
|
+
this.timeChangeEvent = new EventEmitter();
|
|
13701
|
+
this.newObjectPlanEvent = new EventEmitter();
|
|
13702
|
+
document.addEventListener('click', this.onDocumentClick.bind(this));
|
|
13698
13703
|
}
|
|
13699
13704
|
ngOnInit() {
|
|
13700
|
-
if (!this.childProp) {
|
|
13701
|
-
this.startTime = parseInt(this._datepipe.transform(new Date(this.schedule[this.startTimeProp]).toISOString(), 'H:mm'));
|
|
13702
|
-
this.endTime = parseInt(this._datepipe.transform(new Date(this.schedule[this.endTimeProp]).toISOString(), 'H:mm'));
|
|
13703
|
-
}
|
|
13704
|
-
else {
|
|
13705
|
-
this.startTime = parseInt(this._datepipe.transform(new Date(this.schedule[this.childProp][this.startTimeProp]).toISOString(), 'H:mm'));
|
|
13706
|
-
this.endTime = parseInt(this._datepipe.transform(new Date(this.schedule[this.childProp][this.endTimeProp]).toISOString(), 'H:mm'));
|
|
13707
|
-
}
|
|
13708
13705
|
this.generateTimeBlocks();
|
|
13706
|
+
this.generateScheduledObjects();
|
|
13707
|
+
}
|
|
13708
|
+
ngOnDestroy() {
|
|
13709
|
+
document.removeEventListener('click', this.onDocumentClick.bind(this));
|
|
13709
13710
|
}
|
|
13710
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() {
|
|
13711
13722
|
const objectsList = this.schedule[this.objectsProp];
|
|
13712
|
-
|
|
13713
|
-
|
|
13714
|
-
|
|
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);
|
|
13715
13730
|
}
|
|
13716
13731
|
}
|
|
13717
|
-
|
|
13732
|
+
_getObjectsForHourAndMinutes(hour, minutes, objectsList) {
|
|
13718
13733
|
const objectsForHour = [];
|
|
13719
13734
|
objectsList.forEach((obj) => {
|
|
13720
|
-
|
|
13735
|
+
let split = this.convertToHourNotation(obj[this.startTimeProp]).split(':');
|
|
13736
|
+
if (parseInt(split[0]) === hour && parseInt(split[1]) === minutes) {
|
|
13721
13737
|
objectsForHour.push(Object.assign({}, obj));
|
|
13722
13738
|
}
|
|
13723
13739
|
});
|
|
13724
13740
|
return objectsForHour;
|
|
13725
13741
|
}
|
|
13726
|
-
formatHour(hour) {
|
|
13727
|
-
return `${hour}:00`;
|
|
13728
|
-
}
|
|
13729
13742
|
onDragStart(event, obj) {
|
|
13730
13743
|
const currentTarget = event.currentTarget;
|
|
13731
|
-
const currentHourSpan = currentTarget.parentElement.parentElement.querySelector('.hour-label
|
|
13744
|
+
const currentHourSpan = currentTarget.parentElement.parentElement.querySelector('.hidden-hour-label');
|
|
13732
13745
|
const currentHour = currentHourSpan.textContent;
|
|
13733
13746
|
this.draggedObject = obj;
|
|
13734
13747
|
event.dataTransfer.setData('text', JSON.stringify({ obj: this.draggedObject, currentHour }));
|
|
@@ -13738,81 +13751,179 @@ class HourSchedulingComponent {
|
|
|
13738
13751
|
}
|
|
13739
13752
|
onDragOver(event) {
|
|
13740
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
|
|
13741
13760
|
}
|
|
13742
13761
|
onDrop(event, hour) {
|
|
13743
13762
|
event.preventDefault();
|
|
13744
13763
|
event.stopPropagation();
|
|
13745
|
-
const
|
|
13746
|
-
|
|
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() });
|
|
13747
13769
|
return;
|
|
13748
13770
|
}
|
|
13749
|
-
const
|
|
13750
|
-
const
|
|
13751
|
-
const
|
|
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]);
|
|
13752
13775
|
// Get the unique identifier value from the object using the `idProp`
|
|
13753
|
-
const objId =
|
|
13776
|
+
const objId = parsed.obj[this.idProp];
|
|
13754
13777
|
// Ensure we create a new object to avoid mutation issues
|
|
13755
|
-
const updatedObject = Object.assign(Object.assign({},
|
|
13756
|
-
const updatedObject2 = 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
|
-
|
|
13762
|
-
|
|
13763
|
-
this.scheduledObjects[newHourBlock] = [];
|
|
13783
|
+
if (!this.scheduledObjects[hour]) {
|
|
13784
|
+
this.scheduledObjects[hour] = [];
|
|
13764
13785
|
}
|
|
13765
|
-
this.scheduledObjects[
|
|
13786
|
+
this.scheduledObjects[hour].push(updatedObject);
|
|
13766
13787
|
// Clear the dragged object
|
|
13767
13788
|
this.draggedObject = null;
|
|
13789
|
+
this.timeChangeEvent.emit(updatedObject);
|
|
13768
13790
|
// Trigger change detection to update the view
|
|
13769
13791
|
this.cdRef.detectChanges();
|
|
13770
13792
|
}
|
|
13771
13793
|
convertToHourNotation(date) {
|
|
13772
|
-
return
|
|
13794
|
+
return this.datePipe.transform(new Date(date).toISOString(), 'HH:mm');
|
|
13773
13795
|
}
|
|
13774
|
-
createDate(hours) {
|
|
13796
|
+
createDate(hours, minutes) {
|
|
13775
13797
|
let date = new Date();
|
|
13776
13798
|
date.setHours(hours);
|
|
13777
|
-
date.setMinutes(
|
|
13799
|
+
date.setMinutes(minutes ? minutes : 0);
|
|
13778
13800
|
return date;
|
|
13779
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
|
+
;
|
|
13780
13849
|
}
|
|
13781
13850
|
HourSchedulingComponent.decorators = [
|
|
13782
13851
|
{ type: Component, args: [{
|
|
13783
13852
|
selector: 'co-hour-scheduling',
|
|
13784
13853
|
template: `
|
|
13785
|
-
<div class="time-block" *ngFor="let hour of
|
|
13854
|
+
<div class="time-block" *ngFor="let hour of hourLabels">
|
|
13786
13855
|
<div class="hour-label"><span [textContent]="hour"></span></div>
|
|
13787
|
-
<div
|
|
13788
|
-
class="object-
|
|
13789
|
-
|
|
13790
|
-
|
|
13791
|
-
|
|
13792
|
-
|
|
13793
|
-
|
|
13794
|
-
|
|
13795
|
-
|
|
13796
|
-
class="
|
|
13797
|
-
|
|
13798
|
-
|
|
13799
|
-
|
|
13800
|
-
|
|
13801
|
-
|
|
13802
|
-
|
|
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>
|
|
13803
13877
|
</ng-container>
|
|
13804
|
-
</ng-container>
|
|
13805
13878
|
|
|
13806
|
-
|
|
13807
|
-
|
|
13808
|
-
|
|
13809
|
-
|
|
13879
|
+
<ng-container *ngIf="customTemplateUsed">
|
|
13880
|
+
<ng-template
|
|
13881
|
+
[ngTemplateOutlet]="customTemplate"
|
|
13882
|
+
[ngTemplateOutletContext]="{
|
|
13810
13883
|
hour: hour,
|
|
13884
|
+
hiddenHour: hour,
|
|
13811
13885
|
objects: scheduledObjects[hour]
|
|
13812
13886
|
}"
|
|
13813
|
-
|
|
13814
|
-
|
|
13815
|
-
|
|
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
|
+
|
|
13816
13927
|
</div>
|
|
13817
13928
|
</div>
|
|
13818
13929
|
`,
|
|
@@ -13832,6 +13943,8 @@ HourSchedulingComponent.propDecorators = {
|
|
|
13832
13943
|
customTemplate: [{ type: Input }],
|
|
13833
13944
|
customTemplateUsed: [{ type: Input }],
|
|
13834
13945
|
idProp: [{ type: Input }],
|
|
13946
|
+
timeChangeEvent: [{ type: Output }],
|
|
13947
|
+
newObjectPlanEvent: [{ type: Output }],
|
|
13835
13948
|
generateTimeBlocks: [{ type: HostBinding, args: ['class.co-hour-scheduling',] }]
|
|
13836
13949
|
};
|
|
13837
13950
|
|