@sedoo/unidoo 0.0.57 → 0.0.61

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sedoo/unidoo",
3
- "version": "0.0.57",
3
+ "version": "0.0.61",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "build": "vue-cli-service build --target lib --name unidoo src/plugin.js",
@@ -8,6 +8,8 @@ export default class CalendarHeatmap {
8
8
  this.max = Math.ceil((Math.max(...values.map(day => day.count)) / 5) * 4)
9
9
  }
10
10
  this.values = values.map(v => { return { date: this._valuesDateFormat(v.date), count: v.count } })
11
+ this.times = this._getTimes(year)
12
+ this.times.sort()
11
13
  }
12
14
 
13
15
  get activities () {
@@ -44,6 +46,13 @@ export default class CalendarHeatmap {
44
46
  return new Date(year, month + 1, 0).getDate()
45
47
  }
46
48
 
49
+ daysInYear(year) {
50
+ const start = new Date(year, 0, 0)
51
+ const end = new Date(year, 11, 31)
52
+ const diff = end - start
53
+ return Math.floor(diff / (1000 * 60 * 60 * 24))
54
+ }
55
+
47
56
  getColorIndex (value) {
48
57
  if (value == null || value === undefined) {
49
58
  return 0
@@ -72,10 +81,95 @@ export default class CalendarHeatmap {
72
81
  }
73
82
  }
74
83
 
84
+ getNextAvailableDate(date, countGreaterThanZero) {
85
+ if (date) {
86
+ date.setHours(0, 0, 0)
87
+ if (this.times && this.times.length) {
88
+ let index = this.times.indexOf(this._encodeDate(date, null))
89
+ if (index < 0) index = this.times.indexOf(this._encodeDate(date, 1))
90
+ if (index < 0) index = this.times.indexOf(this._encodeDate(date, 0))
91
+ if (index >= 0) {
92
+ const maxIndex = this.times.length - 1
93
+ let n = index + 1
94
+ if (countGreaterThanZero) {
95
+ while (n < maxIndex) {
96
+ const curr = this.times[n]
97
+ if (curr.endsWith('i')) return this._decodeDate(curr)
98
+ n++
99
+ }
100
+ } else {
101
+ while (n < maxIndex) {
102
+ const curr = this.times[n]
103
+ if (!curr.endsWith('n')) return this._decodeDate(curr)
104
+ n++
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }
110
+ return null
111
+ }
112
+
113
+ getPreviousAvailableDate(date, countGreaterThanZero) {
114
+ if (date) {
115
+ date.setHours(0, 0, 0)
116
+ if (this.times && this.times.length) {
117
+ let index = this.times.indexOf(this._encodeDate(date, null))
118
+ if (index < 0) index = this.times.indexOf(this._encodeDate(date, 1))
119
+ if (index < 0) index = this.times.indexOf(this._encodeDate(date, 0))
120
+ if (index > 0) {
121
+ let n = index - 1
122
+ if (countGreaterThanZero) {
123
+ while (n > 0) {
124
+ const curr = this.times[n]
125
+ if (curr.endsWith('i')) return this._decodeDate(curr)
126
+ n--
127
+ }
128
+ } else {
129
+ while (n > 0) {
130
+ const curr = this.times[n]
131
+ if (!curr.endsWith('n')) return this._decodeDate(curr)
132
+ n--
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+ return null
139
+ }
140
+
141
+ _getTimes (year) {
142
+ const date = new Date(year, 0, 1)
143
+ return Array.from({ length: this.daysInYear(year) },
144
+ () => {
145
+ const dDate = new Date(date.getFullYear(), date.getMonth(), date.getDate())
146
+ dDate.setHours(0, 0, 0)
147
+ const dayValues = this.activities[this._keyDayParser(dDate)]
148
+ date.setDate(date.getDate() + 1)
149
+ return this._encodeDate(dDate, (dayValues) ? dayValues.count : null)
150
+ }
151
+ )
152
+ }
153
+
75
154
  _valuesDateFormat (d) {
76
155
  if (!d) return ''
77
- const date = (d instanceof Date) ? d : (new Date(d));
78
- return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`
156
+ const date = this._parseDate(d)
157
+ return `${date.getFullYear()}-${this._paddNumber(date.getMonth() + 1)}-${this._paddNumber(date.getDate())}`
158
+ }
159
+
160
+ _paddNumber (n) {
161
+ return ('' + n).padStart(2, '0')
162
+ }
163
+
164
+ _encodeDate (d, count) {
165
+ const date = this._parseDate(d)
166
+ return this._valuesDateFormat(date) + ((Number.isFinite(count)) ? ((count > 0) ? 'i' : 'o') : 'n')
167
+ }
168
+
169
+ _decodeDate (d) {
170
+ if (!d) return null
171
+ const sdate = d.slice(0, -1)
172
+ return new Date(sdate)
79
173
  }
80
174
 
81
175
  _parseDate (entry) {
@@ -93,6 +93,7 @@ export default {
93
93
  watch: {
94
94
  dateValue (val) {
95
95
  this.focusDate(val)
96
+ this.updateDateSwitcher(val)
96
97
  },
97
98
  year (val) {
98
99
  if (val !== this.year) {
@@ -130,14 +131,23 @@ export default {
130
131
  },
131
132
  beforeMount () {
132
133
  Plugin.EventBus.$on("unidoo-heatmap-set-date", params => {
133
- if(this.heatmapKey && params.key === this.heatmapKey){
134
- if(params.date){
134
+ if(this.heatmapKey) {
135
+ if (params.key === this.heatmapKey && params.date){
135
136
  this.setDate(params.date)
136
- }
137
+ }
137
138
  } else if(params.date) {
138
139
  this.setDate(params.date)
139
140
  }
140
141
  })
142
+ Plugin.EventBus.$on("unidoo-heatmap-get-date", params => {
143
+ if(this.heatmapKey) {
144
+ if (params.key === this.heatmapKey){
145
+ this.updateDateSwitcher(this.dateValue)
146
+ }
147
+ } else {
148
+ this.updateDateSwitcher(this.dateValue)
149
+ }
150
+ })
141
151
  },
142
152
  methods: {
143
153
  computeClass (day) {
@@ -185,8 +195,28 @@ export default {
185
195
  setDate (d) {
186
196
  if (!d) return
187
197
  const day = this.heatmap.getDayFromDate(d);
188
- this.handleClick(null, day);
189
-
198
+ this.handleClick(null, day);
199
+ },
200
+ updateDateSwitcher (d) {
201
+ this.$unidooDateSwitcher.update({
202
+ hasPrevious: this.hasPreviousDate(d),
203
+ hasNext : this.hasNextDate(d),
204
+ previousAvailable : this.heatmap.getPreviousAvailableDate(d),
205
+ nextAvailable : this.heatmap.getNextAvailableDate(d)
206
+ }, this.heatmapKey);
207
+ },
208
+ hasPreviousDate (d) {
209
+ if(!d || this.year != d.getFullYear()) return false
210
+ const firstDay = new Date(this.year, 0, 1);
211
+ if(d <= firstDay) return false;
212
+ return true;
213
+ },
214
+ hasNextDate (d) {
215
+ if(!d || this.year != d.getFullYear()) return false
216
+ const today = new Date();
217
+ today.setHours(0,0,0,0);
218
+ if(d >= today) return false;
219
+ return true;
190
220
  },
191
221
  focusDate (d) {
192
222
  if (!d) return
@@ -1,46 +1,112 @@
1
1
  <template>
2
2
  <div date-switch>
3
- <v-btn icon x-small style="margin-right: 5px;" @click="switchDate(-1)">
3
+ <v-btn icon x-small :disabled="!previousAvailable" style="margin-right: 4px;" @click="goToPreviousAvailable(1)">
4
4
  <v-icon>mdi-skip-previous</v-icon>
5
5
  </v-btn>
6
+ <v-btn icon x-small :disabled="!hasPrevious" style="margin-right: 8px;" @click="switchDate(-1)">
7
+ <v-icon>mdi-rewind</v-icon>
8
+ </v-btn>
6
9
  <v-icon>mdi-calendar-month</v-icon>
7
- <v-btn icon x-small style="margin-left: 5px;" @click="switchDate(1)">
10
+ <v-btn icon x-small :disabled="!hasNext" style="margin-left: 8px;" @click="switchDate(1)">
11
+ <v-icon>mdi-fast-forward</v-icon>
12
+ </v-btn>
13
+ <v-btn icon x-small :disabled="!nextAvailable" style="margin-left: 4px;" @click="goToNextAvailable(1)">
8
14
  <v-icon>mdi-skip-next</v-icon>
9
15
  </v-btn>
10
16
  </div>
11
17
  </template>
12
18
 
13
19
  <script>
14
- export default {
15
- name: 'date-switcher',
20
+ import Plugin from '../../plugin.js'
16
21
 
22
+ export default {
17
23
  props: {
18
24
  date : {
19
25
  type : [String, Date],
20
26
  default: null
27
+ },
28
+ heatmapKey: {
29
+ type: String,
30
+ default: null
31
+ }
32
+ },
33
+ data () {
34
+ return {
35
+ hasNext: false,
36
+ hasPrevious: false,
37
+ nextAvailable: {
38
+ type: Date,
39
+ default: null
40
+ },
41
+ previousAvailable: {
42
+ type: Date,
43
+ default: null
44
+ },
21
45
  }
22
46
  },
23
-
24
47
  computed:{
25
48
  cleanedDate(){
26
- if(this.date){
27
- if(typeof this.date === 'date'){
28
- return date;
29
- } else if(typeof this.date === 'string'){
30
- return new Date(this.date);
31
- }
32
- }
33
- return null;
49
+ return this.cleanDate(this.date);
34
50
  }
35
51
  },
52
+ beforeMount () {
53
+ Plugin.EventBus.$on("unidoo-dateswitcher-update", params => {
54
+ if(this.heatmapKey) {
55
+ if (params.key === this.heatmapKey && params.data){
56
+ this.updateNearDates(params.data);
57
+ }
58
+ } else if(params.data) {
59
+ this.updateNearDates(params.data);
60
+ }
61
+ })
62
+ },
63
+
64
+ mounted () {
65
+ this.$unidooHeatmap.getDate(this.heatmapKey);
66
+ },
36
67
 
37
68
  methods: {
69
+
70
+ goToNextAvailable() {
71
+ if(this.hasNext) {
72
+ this.$unidooHeatmap.setDate(this.cleanDate(this.nextAvailable), this.heatmapKey);
73
+ }
74
+ },
75
+
76
+ goToPreviousAvailable() {
77
+ if(this.hasPrevious) {
78
+ this.$unidooHeatmap.setDate(this.cleanDate(this.previousAvailable), this.heatmapKey);
79
+ }
80
+ },
81
+
38
82
  switchDate(n){
39
83
  if(this.cleanedDate && n){
40
- let newDate = new Date(this.cleanedDate);
41
- newDate.setDate(this.cleanedDate.getDate() + n);
42
- this.$unidooHeatmap.setDate(newDate);
84
+ if((n > 0 && this.hasNext) || (n < 0 && this.hasPrevious)){
85
+ let newDate = new Date(this.cleanedDate);
86
+ newDate.setDate(this.cleanedDate.getDate() + n);
87
+ this.$unidooHeatmap.setDate(newDate, this.heatmapKey);
88
+ }
43
89
  }
90
+ },
91
+
92
+ updateNearDates(data){
93
+ if(data){
94
+ this.hasNext = data.hasNext
95
+ this.hasPrevious = data.hasPrevious
96
+ this.nextAvailable = data.nextAvailable
97
+ this.previousAvailable = data.previousAvailable
98
+ }
99
+ },
100
+
101
+ cleanDate(date){
102
+ if(date){
103
+ if(date instanceof Date){
104
+ return date;
105
+ } else if(typeof date === 'string'){
106
+ return new Date(date);
107
+ }
108
+ }
109
+ return null;
44
110
  }
45
111
  }
46
112
  }
@@ -51,6 +117,7 @@ export default {
51
117
  display: flex;
52
118
  align-items: center;
53
119
  padding: 1px;
120
+ width: fit-content;
54
121
  background: rgb(245,245,245);
55
122
  border-radius: 5px;
56
123
  }
@@ -5,7 +5,7 @@
5
5
 
6
6
  <div mask @click="zoomPlayer"></div>
7
7
 
8
- <div body style="height: 100%, margin: auto">
8
+ <div body>
9
9
 
10
10
  <div sub-body :style="subBodyStyle">
11
11
 
@@ -14,11 +14,11 @@
14
14
  <v-row viewer-part :style="{ order: ((playerBarTop) ? 2 : 4) }">
15
15
 
16
16
  <v-list-item player-layout-slider-part >
17
- <v-col>
17
+ <div style="display: flex; flex-direction: column; width: 100%">
18
18
  <div custom-top-left >
19
19
  <slot name="customField"></slot>
20
20
  </div>
21
- <div style="display: flex; justify-content: center; margin-top: 25px;">
21
+ <div style="display: flex; justify-content: center; margin-top: 10px;">
22
22
  <slot name="frameTitle">
23
23
 
24
24
  </slot>
@@ -80,7 +80,7 @@
80
80
  </v-slider>
81
81
 
82
82
  <iframe ref="sizeHandlerIframe" src="about:blank" style="width:100%; height:0; border:0;"></iframe>
83
- </v-col>
83
+ </div>
84
84
  </v-list-item>
85
85
 
86
86
  </v-row>
@@ -466,6 +466,7 @@ export default {
466
466
  [player-layout] [body] [sub-body] {
467
467
  display: grid;
468
468
  background: white;
469
+ align-items: center;
469
470
  }
470
471
 
471
472
  [player-layout] [mask] {
@@ -484,6 +485,7 @@ export default {
484
485
  [viewer-part] {
485
486
  margin-top: 0;
486
487
  margin-bottom: 0;
488
+ height: 100%;
487
489
  }
488
490
 
489
491
  [player-layout-slider-part] {
@@ -513,22 +515,25 @@ export default {
513
515
 
514
516
  [reload-button] {
515
517
  position: absolute;
516
- top: 0;
518
+ top: -5px;
517
519
  right: 15px;
518
520
  }
519
521
 
520
522
  [player-layout].zoomed [body] {
521
523
  position: fixed;
524
+ display: block;
522
525
  z-index: 99999;
523
526
  top: 6vh;
524
527
  left: 4vw;
525
528
  right: 4vw;
526
- max-height: 92vh;
527
529
  overflow: auto;
528
530
  margin-top: -5px;
529
531
  margin-bottom: 5px;
530
532
  padding-left : 15px;
531
533
  padding-right : 15px;
534
+ height: auto;
535
+ max-height: 92vh;
536
+ border-radius: 5px;
532
537
  }
533
538
 
534
539
  [player-layout].zoomed [mask] {
package/src/plugin.js CHANGED
@@ -154,6 +154,16 @@ function install(Vue) {
154
154
  setDate(date, key) {
155
155
  plugin.EventBus.$emit("unidoo-heatmap-set-date", { date: date, key: key })
156
156
  },
157
+
158
+ getDate(key) {
159
+ plugin.EventBus.$emit("unidoo-heatmap-get-date", { key: key })
160
+ }
161
+ }
162
+
163
+ Vue.prototype.$unidooDateSwitcher = {
164
+ update(data, key) {
165
+ plugin.EventBus.$emit("unidoo-dateswitcher-update", { data: data, key: key })
166
+ },
157
167
  }
158
168
  }
159
169