@websy/websy-designs 1.2.6 → 1.2.7

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.
@@ -391,18 +391,20 @@ class WebsyDatePicker {
391
391
  this.currentselection = []
392
392
  this.validDates = []
393
393
  this.validYears = []
394
+ this.validHours = []
394
395
  this.customRangeSelected = true
395
396
  this.shiftPressed = false
396
397
  const DEFAULTS = {
397
398
  defaultRange: 0,
398
399
  allowClear: true,
400
+ hideRanges: false,
399
401
  minAllowedDate: this.floorDate(new Date(new Date((new Date().setFullYear(new Date().getFullYear() - 1))).setDate(1))),
400
402
  maxAllowedDate: this.floorDate(new Date((new Date()))),
401
403
  minAllowedYear: 1970,
402
404
  maxAllowedYear: new Date().getFullYear(),
403
405
  daysOfWeek: ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
404
406
  monthsOfYear: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
405
- hours: new Array(24).fill(0).map((d, i) => (i < 10 ? '0' : '') + i + ':00'),
407
+ hours: new Array(24).fill(0).map((d, i) => ({text: (i < 10 ? '0' : '') + i + ':00', num: (1 / 24 * i)})),
406
408
  mode: 'date',
407
409
  monthMap: {
408
410
  0: 'Jan',
@@ -487,7 +489,12 @@ class WebsyDatePicker {
487
489
  range: [this.floorDate(new Date(new Date(new Date().setDate(1)).setMonth(new Date().getMonth() - 24))), this.floorDate(new Date(new Date().setDate(1)))]
488
490
  }
489
491
  ],
490
- hour: []
492
+ hour: [
493
+ {
494
+ label: 'All',
495
+ range: ['00:00', '23:00']
496
+ }
497
+ ]
491
498
  }
492
499
  this.options = Object.assign({}, DEFAULTS, options)
493
500
  this.selectedRange = this.options.defaultRange || 0
@@ -523,8 +530,8 @@ class WebsyDatePicker {
523
530
  html += `
524
531
  </div>
525
532
  <div id='${this.elementId}_mask' class='websy-date-picker-mask'></div>
526
- <div id='${this.elementId}_content' class='websy-date-picker-content'>
527
- <div class='websy-date-picker-ranges'>
533
+ <div id='${this.elementId}_content' class='websy-date-picker-content ${this.options.hideRanges === true ? 'hide-ranges' : ''}'>
534
+ <div class='websy-date-picker-ranges' >
528
535
  <ul id='${this.elementId}_rangelist'>
529
536
  ${this.renderRanges()}
530
537
  </ul>
@@ -562,11 +569,26 @@ class WebsyDatePicker {
562
569
  if (this.options.onChange) {
563
570
  console.log('confirm', this.selectedRangeDates)
564
571
  console.log('confirm', this.currentselection)
565
- if (this.customRangeSelected === true) {
566
- this.options.onChange(this.selectedRangeDates, true)
572
+ if (this.customRangeSelected === true) {
573
+ if (this.options.mode === 'hour') {
574
+ let hoursOut = []
575
+ for (let i = this.selectedRangeDates[0]; i < this.selectedRangeDates[1] + 1; i++) {
576
+ hoursOut.push(this.options.hours[i])
577
+ }
578
+ this.options.onChange(hoursOut, true)
579
+ }
580
+ else {
581
+ this.options.onChange(this.selectedRangeDates, true)
582
+ }
567
583
  }
568
584
  else {
569
- this.options.onChange(this.currentselection, false)
585
+ if (this.options.mode === 'hour') {
586
+ let hoursOut = this.selectedRangeDates.map(h => this.options.hours[h])
587
+ this.options.onChange(hoursOut, true)
588
+ }
589
+ else {
590
+ this.options.onChange(this.currentselection, false)
591
+ }
570
592
  }
571
593
  }
572
594
  this.updateRange()
@@ -701,7 +723,7 @@ class WebsyDatePicker {
701
723
  console.log('diff', diff)
702
724
  }
703
725
  else if (this.options.mode === 'hour') {
704
- //
726
+ diff = this.selectedRangeDates[this.selectedRangeDates.length - 1] - this.selectedRangeDates[0]
705
727
  }
706
728
  for (let i = 0; i < diff + 1; i++) {
707
729
  let d
@@ -724,7 +746,9 @@ class WebsyDatePicker {
724
746
  rangeEnd = this.selectedRangeDates[this.selectedRangeDates.length - 1].getTime()
725
747
  }
726
748
  else if (this.options.mode === 'hour') {
727
- //
749
+ d = this.selectedRangeDates[0] + i
750
+ rangeStart = this.selectedRangeDates[0]
751
+ rangeEnd = this.selectedRangeDates[this.selectedRangeDates.length - 1]
728
752
  }
729
753
  let dateEl
730
754
  if (this.options.mode === 'date') {
@@ -740,7 +764,7 @@ class WebsyDatePicker {
740
764
  dateEl = document.getElementById(`${this.elementId}_${d}_monthyear`)
741
765
  }
742
766
  else if (this.options.mode === 'hour') {
743
- //
767
+ dateEl = document.getElementById(`${this.elementId}_${d}_hour`)
744
768
  }
745
769
  if (dateEl) {
746
770
  dateEl.classList.add('selected')
@@ -766,7 +790,7 @@ class WebsyDatePicker {
766
790
  dateEl = document.getElementById(`${this.elementId}_${d}_monthyear`)
767
791
  }
768
792
  else if (this.options.mode === 'hour') {
769
- //
793
+ dateEl = document.getElementById(`${this.elementId}_${d}_hour`)
770
794
  }
771
795
  dateEl.classList.add('selected')
772
796
  dateEl.classList.add('first')
@@ -808,6 +832,7 @@ class WebsyDatePicker {
808
832
  let disabled = []
809
833
  this.validDates = []
810
834
  this.validYears = []
835
+ this.validHours = []
811
836
  this.monthYears = {}
812
837
  this.monthYearMonths = []
813
838
  if (disabledDates) {
@@ -822,7 +847,7 @@ class WebsyDatePicker {
822
847
  //
823
848
  }
824
849
  else if (this.options.mode === 'hour') {
825
- //
850
+ return d
826
851
  }
827
852
  return d.getTime()
828
853
  })
@@ -840,7 +865,7 @@ class WebsyDatePicker {
840
865
  diff = Math.ceil((this.options.maxAllowedDate.getTime() - this.options.minAllowedDate.getTime()) / this.oneDay) + 1
841
866
  }
842
867
  else if (this.options.mode === 'hour') {
843
- //
868
+ diff = 24
844
869
  }
845
870
  let months = {}
846
871
  let yearList = []
@@ -877,9 +902,16 @@ class WebsyDatePicker {
877
902
  }
878
903
  }
879
904
  else if (this.options.mode === 'hour') {
880
- //
905
+ //
881
906
  }
882
907
  }
908
+ if (this.options.mode === 'hour') {
909
+ this.options.hours.forEach(h => {
910
+ if (disabled.indexOf(h.text) === -1) {
911
+ this.validHours.push(h)
912
+ }
913
+ })
914
+ }
883
915
  // check each range to see if it can be enabled
884
916
  for (let i = 0; i < this.options.ranges[this.options.mode].length; i++) {
885
917
  const r = this.options.ranges[this.options.mode][i]
@@ -928,7 +960,23 @@ class WebsyDatePicker {
928
960
  //
929
961
  }
930
962
  else if (this.options.mode === 'hour') {
931
- //
963
+ if (this.validDates.indexOf(r.range[0]) !== -1) {
964
+ r.disabled = false
965
+ }
966
+ else if (r.range[1]) {
967
+ if (this.validDates.indexOf(r.range[1]) !== -1) {
968
+ r.disabled = false
969
+ }
970
+ else {
971
+ // check the full range until a match is found
972
+ for (let i = r.range[0]; i <= r.range[1]; i++) {
973
+ if (this.validDates.indexOf(r.range[0] + i) !== -1) {
974
+ r.disabled = false
975
+ break
976
+ }
977
+ }
978
+ }
979
+ }
932
980
  }
933
981
  }
934
982
  let html = ''
@@ -990,7 +1038,9 @@ class WebsyDatePicker {
990
1038
  html += `</div>`
991
1039
  }
992
1040
  else if (this.options.mode === 'hour') {
993
- //
1041
+ html += `<div id='${this.elementId}_dateList' class='websy-dp-date-list'><ul>`
1042
+ html += this.options.hours.map(h => `<li id='${this.elementId}_${+h.text.split(':')[0]}_hour' data-hour='${h.text}' class='websy-dp-date websy-dp-hour'>${h.text}</li>`).join('')
1043
+ html += `</ul></div>`
994
1044
  }
995
1045
  return html
996
1046
  }
@@ -1042,7 +1092,13 @@ class WebsyDatePicker {
1042
1092
  console.log('current selection', this.currentselection)
1043
1093
  }
1044
1094
  else {
1045
- this.currentselection.push(timestamp)
1095
+ let index = this.currentselection.indexOf(timestamp)
1096
+ if (index !== -1) {
1097
+ this.currentselection.splice(index, 1)
1098
+ }
1099
+ else {
1100
+ this.currentselection.push(timestamp)
1101
+ }
1046
1102
  this.currentselection.sort((a, b) => a - b)
1047
1103
  this.customRangeSelected = false
1048
1104
  }
@@ -1058,7 +1114,7 @@ class WebsyDatePicker {
1058
1114
  //
1059
1115
  }
1060
1116
  else if (this.options.mode === 'hour') {
1061
- //
1117
+ this.selectedRangeDates = [this.currentselection[0], this.currentselection[1] || this.currentselection[0]]
1062
1118
  }
1063
1119
  // if (this.currentselection.length === 2) {
1064
1120
  // this.currentselection = []
@@ -1122,7 +1178,8 @@ class WebsyDatePicker {
1122
1178
  this.options.maxAllowedDate = range[1] || range[0]
1123
1179
  }
1124
1180
  else if (this.options.mode === 'hour') {
1125
- //
1181
+ this.options.minAllowedHour = range[0]
1182
+ this.options.maxAllowedHour = range[1] || range[0]
1126
1183
  }
1127
1184
  }
1128
1185
  updateRange () {
@@ -1145,7 +1202,7 @@ class WebsyDatePicker {
1145
1202
  return `${this.options.monthMap[d.getMonth()]} ${d.getFullYear()}`
1146
1203
  }
1147
1204
  else if (this.options.mode === 'hour') {
1148
- //
1205
+ return d
1149
1206
  }
1150
1207
  })
1151
1208
  let start = list[0]
@@ -1156,6 +1213,10 @@ class WebsyDatePicker {
1156
1213
  else {
1157
1214
  start = `${list.length} selected`
1158
1215
  }
1216
+ if (this.options.mode === 'hour') {
1217
+ start = this.options.hours[start].text
1218
+ end = `${this.customRangeSelected === true ? ' - ' : ''}${this.options.hours[list[list.length - 1]].text}`
1219
+ }
1159
1220
  range = { label: `${start}${end}` }
1160
1221
  }
1161
1222
  else {