@rypen-dev/shared-components 7.0.20 → 7.1.0
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/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/components/FileDropzone.vue +91 -87
- package/src/components/FileUpload.vue +61 -63
- package/src/components/GenericLoader.vue +4 -7
- package/src/components/Loader.vue +1 -10
- package/src/components/LookupTextBox.vue +117 -109
- package/src/components/ModalWrapper.vue +27 -36
- package/src/components/NumberInput.vue +1 -2
- package/src/components/Pagination.vue +90 -92
- package/src/components/ProductImageSelector.vue +139 -140
- package/src/components/SearchableDropdownInput.vue +120 -115
- package/src/components/Slideshow.vue +96 -89
- package/src/components/TimespanInput.vue +87 -88
- package/src/components/icons/IconApprove.vue +3 -1
- package/src/components/icons/IconBase.vue +22 -21
- package/src/components/icons/IconCaret.vue +3 -1
- package/src/components/icons/IconClose.vue +3 -1
- package/src/components/icons/IconQrCode.vue +3 -1
- package/src/components/icons/IconSave.vue +3 -1
- package/src/components/icons/IconShare.vue +3 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div :id="id + '-container'" ref="
|
|
2
|
+
<div :id="id + '-container'" ref="containerref" class="input-container searchable-dropdown-container" @focusin="focusOn" @focusout="focusOff" tabindex="0">
|
|
3
3
|
<div class="input-container select false-select" :class="computedClass">
|
|
4
4
|
<span class="value">{{ value ? value.Name : 'Select' }}</span>
|
|
5
5
|
<div class="options-list-container">
|
|
6
6
|
<div class="input-container search small">
|
|
7
|
-
<input ref="
|
|
7
|
+
<input ref="inputref" type="text" autocomplete="off" role="combobox" :aria-controls="id + '-list'" aria-autocomplete="list" :aria-expanded="focused" v-model="searchValue" :maxlength="maxLength" :disabled="disabled" />
|
|
8
8
|
</div>
|
|
9
9
|
<div class="options-list" role="listbox" :aria-label="label" :id="id + '-list'">
|
|
10
10
|
<span v-if="filteredOptions.length === 0" class="option empty">No {{ searchType }} found</span>
|
|
@@ -14,127 +14,132 @@
|
|
|
14
14
|
</div>
|
|
15
15
|
</div>
|
|
16
16
|
</template>
|
|
17
|
-
<script>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
searchType: {
|
|
46
|
-
type: String,
|
|
47
|
-
default: 'products'
|
|
48
|
-
},
|
|
49
|
-
cssClass: String,
|
|
17
|
+
<script setup>
|
|
18
|
+
import { ref, reactive, computed, watch, onMounted } from 'vue';
|
|
19
|
+
|
|
20
|
+
const props = defineProps({
|
|
21
|
+
id: String,
|
|
22
|
+
label: String,
|
|
23
|
+
externalValueId: String,
|
|
24
|
+
externalValueName: String,
|
|
25
|
+
loading: {
|
|
26
|
+
type: Boolean,
|
|
27
|
+
default: false,
|
|
28
|
+
},
|
|
29
|
+
options: {
|
|
30
|
+
type: Array,
|
|
31
|
+
default: () => [],
|
|
32
|
+
},
|
|
33
|
+
invalid: {
|
|
34
|
+
type: Boolean,
|
|
35
|
+
default: false,
|
|
36
|
+
},
|
|
37
|
+
maxLength: {
|
|
38
|
+
type: Number,
|
|
39
|
+
default: 200,
|
|
40
|
+
},
|
|
41
|
+
disabled: {
|
|
42
|
+
type: Boolean,
|
|
43
|
+
default: false,
|
|
50
44
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
searchType: {
|
|
46
|
+
type: String,
|
|
47
|
+
default: 'products'
|
|
48
|
+
},
|
|
49
|
+
cssClass: String,
|
|
50
|
+
});
|
|
51
|
+
const emit = defineEmits(['update']);
|
|
55
52
|
|
|
56
|
-
|
|
53
|
+
const value = ref(null);
|
|
54
|
+
const searchValue = ref('');
|
|
55
|
+
const focused = ref(false);
|
|
56
|
+
const filteredOptions = reactive([]);
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
},
|
|
61
|
-
created: function () {
|
|
62
|
-
if (this.externalValueId && this.externalValueName) {
|
|
63
|
-
this.value = { Id: this.externalValueId, Name: this.externalValueName };
|
|
64
|
-
}
|
|
58
|
+
const containerref = ref(null);
|
|
59
|
+
const inputref = ref(null);
|
|
65
60
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
methods: {
|
|
71
|
-
filterResults() {
|
|
72
|
-
let newResults = [];
|
|
73
|
-
|
|
74
|
-
if (this.searchValue) {
|
|
75
|
-
const search = this.searchValue.toLowerCase();
|
|
76
|
-
|
|
77
|
-
this.options.forEach(option => {
|
|
78
|
-
if (option.Name && option.Name.toLowerCase().indexOf(search) > -1) {
|
|
79
|
-
newResults.push(option);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
} else {
|
|
83
|
-
newResults = this.options.slice();
|
|
84
|
-
}
|
|
61
|
+
onMounted(() => {
|
|
62
|
+
if (props.externalValueId && props.externalValueName) {
|
|
63
|
+
value.value = { Id: props.externalValueId, Name: props.externalValueName };
|
|
64
|
+
}
|
|
85
65
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
66
|
+
if (props.options.length) {
|
|
67
|
+
filteredOptions.splice(0);
|
|
68
|
+
filteredOptions.push(...props.options);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
89
71
|
|
|
90
|
-
|
|
91
|
-
|
|
72
|
+
function filterResults() {
|
|
73
|
+
let newResults = [];
|
|
92
74
|
|
|
93
|
-
|
|
75
|
+
if (searchValue.value) {
|
|
76
|
+
const search = searchValue.value.toLowerCase();
|
|
94
77
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
this.focused = false;
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
focusInput() {
|
|
102
|
-
this.focused = true;
|
|
103
|
-
},
|
|
104
|
-
focusSearchInput() {
|
|
105
|
-
this.focused = true;
|
|
106
|
-
if (this.$refs.input) {
|
|
107
|
-
this.$refs.input.focus();
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
focusOn(e) {
|
|
111
|
-
//console.log(e.target);
|
|
112
|
-
this.focused = true;
|
|
113
|
-
},
|
|
114
|
-
focusOff(e) {
|
|
115
|
-
setTimeout(() => {
|
|
116
|
-
if (!this.$refs.container || !document.activeElement || (document.activeElement.id !== this.id + '-container' && !this.$refs.container.contains(document.activeElement))) {
|
|
117
|
-
this.focused = false;
|
|
118
|
-
this.searchValue = null;
|
|
119
|
-
}
|
|
120
|
-
}, 200);
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
computed: {
|
|
124
|
-
computedClass() {
|
|
125
|
-
return (this.cssClass || '') + (this.focused ? ' open' : '') + (this.invalid ? ' error' : '');
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
watch: {
|
|
129
|
-
loading(newValue, prevValue) {
|
|
130
|
-
if (!newValue && prevValue) {
|
|
131
|
-
this.searchValue = '';
|
|
132
|
-
this.filterResults();
|
|
78
|
+
props.options.forEach(option => {
|
|
79
|
+
if (option.Name && option.Name.toLowerCase().indexOf(search) > -1) {
|
|
80
|
+
newResults.push(option);
|
|
133
81
|
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
82
|
+
});
|
|
83
|
+
} else {
|
|
84
|
+
newResults = props.options.slice();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
filteredOptions.splice(0);
|
|
88
|
+
filteredOptions.push(...newResults);
|
|
139
89
|
}
|
|
90
|
+
|
|
91
|
+
function selectValue(value) {
|
|
92
|
+
value.value = value;
|
|
93
|
+
|
|
94
|
+
emit('update', value);
|
|
95
|
+
|
|
96
|
+
if (containerref.value) {
|
|
97
|
+
containerref.value.blur();
|
|
98
|
+
}
|
|
99
|
+
focused.value = false;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function focusInput() {
|
|
103
|
+
focused.value = true;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function focusSearchInput() {
|
|
107
|
+
focused.value = true;
|
|
108
|
+
if (inputref.value) {
|
|
109
|
+
inputref.value.focus();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function focusOn(e) {
|
|
114
|
+
focused.value = true;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function focusOff(e) {
|
|
118
|
+
setTimeout(() => {
|
|
119
|
+
if (!containerref.value || !document.activeElement || (document.activeElement.id !== props.id + '-container' && !containerref.value.contains(document.activeElement))) {
|
|
120
|
+
focused.value = false;
|
|
121
|
+
searchValue.value = '';
|
|
122
|
+
}
|
|
123
|
+
}, 200);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const computedClass = computed(() => {
|
|
127
|
+
return (props.cssClass || '') + (focused.value ? ' open' : '') + (props.invalid ? ' error' : '');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
watch(() => props.loading, (newValue, prevValue) => {
|
|
131
|
+
if (!newValue && prevValue) {
|
|
132
|
+
searchValue.value = '';
|
|
133
|
+
filterResults();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
watch(() => searchValue.value, (newValue) => {
|
|
138
|
+
filterResults();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
defineExpose({
|
|
142
|
+
focusInput,
|
|
143
|
+
focusSearchInput,
|
|
144
|
+
});
|
|
140
145
|
</script>
|
|
@@ -16,100 +16,107 @@
|
|
|
16
16
|
</div>
|
|
17
17
|
</template>
|
|
18
18
|
|
|
19
|
-
<script>
|
|
20
|
-
|
|
21
|
-
name: 'Slideshow',
|
|
22
|
-
props: {
|
|
23
|
-
imageBasePath: {
|
|
24
|
-
type: String,
|
|
25
|
-
default: '', //IMAGE_BASE_PATH
|
|
26
|
-
},
|
|
19
|
+
<script setup>
|
|
20
|
+
import { ref, onMounted, computed } from 'vue';
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
usePrefix: {
|
|
33
|
-
type: Boolean,
|
|
34
|
-
default: true,
|
|
35
|
-
},
|
|
36
|
-
auto: {
|
|
37
|
-
type: Boolean,
|
|
38
|
-
default: true,
|
|
39
|
-
},
|
|
40
|
-
small: {
|
|
41
|
-
type: Boolean,
|
|
42
|
-
default: false,
|
|
43
|
-
},
|
|
44
|
-
widthSuffix: {
|
|
45
|
-
type: Number,
|
|
46
|
-
default: null,
|
|
47
|
-
},
|
|
48
|
-
delay: {
|
|
49
|
-
type: Number,
|
|
50
|
-
default: 7000,
|
|
51
|
-
},
|
|
52
|
-
forceNav: {
|
|
53
|
-
type: Boolean,
|
|
54
|
-
default: false,
|
|
55
|
-
},
|
|
22
|
+
const props = defineProps({
|
|
23
|
+
imageBasePath: {
|
|
24
|
+
type: String,
|
|
25
|
+
default: '', //IMAGE_BASE_PATH
|
|
56
26
|
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
timer: null,
|
|
61
|
-
}
|
|
27
|
+
slides: {
|
|
28
|
+
type: Array,
|
|
29
|
+
default: () => [],
|
|
62
30
|
},
|
|
63
|
-
|
|
64
|
-
|
|
31
|
+
usePrefix: {
|
|
32
|
+
type: Boolean,
|
|
33
|
+
default: true,
|
|
65
34
|
},
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
this.triggerStartTimer();
|
|
78
|
-
},
|
|
79
|
-
triggerStartTimer() {
|
|
80
|
-
if (this.auto) {
|
|
81
|
-
this.startTimer();
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
startTimer() {
|
|
85
|
-
if (this.slides.length > 0) {
|
|
86
|
-
if (this.timer !== null) {
|
|
87
|
-
clearTimeout(this.timer);
|
|
88
|
-
}
|
|
89
|
-
this.timer = setTimeout(this.goToNext, this.delay);
|
|
90
|
-
}
|
|
91
|
-
},
|
|
92
|
-
triggerClearTimer() {
|
|
93
|
-
if (this.auto) {
|
|
94
|
-
this.clearTimer();
|
|
95
|
-
}
|
|
96
|
-
},
|
|
97
|
-
clearTimer() {
|
|
98
|
-
clearTimeout(this.timer);
|
|
99
|
-
this.timer = null;
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
backgroundImage(slide) {
|
|
103
|
-
return { backgroundImage: 'url("' + (this.usePrefix ? this.imageBasePath : '') + slide + (this.widthSuffix ? ';width=' + this.widthSuffix : '') + '")' };
|
|
104
|
-
},
|
|
35
|
+
auto: {
|
|
36
|
+
type: Boolean,
|
|
37
|
+
default: true,
|
|
38
|
+
},
|
|
39
|
+
small: {
|
|
40
|
+
type: Boolean,
|
|
41
|
+
default: false,
|
|
42
|
+
},
|
|
43
|
+
widthSuffix: {
|
|
44
|
+
type: Number,
|
|
45
|
+
default: null,
|
|
105
46
|
},
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
47
|
+
delay: {
|
|
48
|
+
type: Number,
|
|
49
|
+
default: 7000,
|
|
50
|
+
},
|
|
51
|
+
forceNav: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
default: false,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const emit = defineEmits(['change']);
|
|
57
|
+
|
|
58
|
+
onMounted(() => {
|
|
59
|
+
triggerStartTimer();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// timer and auto slide functionality
|
|
63
|
+
const timer = ref(null);
|
|
64
|
+
|
|
65
|
+
function triggerStartTimer() {
|
|
66
|
+
if (props.auto) {
|
|
67
|
+
startTimer();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function startTimer() {
|
|
72
|
+
if (props.slides.length > 0) {
|
|
73
|
+
if (timer.value !== null) {
|
|
74
|
+
clearTimeout(timer.value);
|
|
75
|
+
}
|
|
76
|
+
timer.value = setTimeout(goToNext, props.delay);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function triggerClearTimer() {
|
|
81
|
+
if (props.auto) {
|
|
82
|
+
clearTimer();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function clearTimer() {
|
|
87
|
+
if (timer.value !== null) {
|
|
88
|
+
clearTimeout(timer.value);
|
|
89
|
+
timer.value = null;
|
|
113
90
|
}
|
|
114
91
|
}
|
|
92
|
+
|
|
93
|
+
// sliding functionality
|
|
94
|
+
const currentIndex = ref(0);
|
|
95
|
+
|
|
96
|
+
function goToPrevious() {
|
|
97
|
+
goToSlide(previousIndex.value);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function goToNext() {
|
|
101
|
+
goToSlide(nextIndex.value);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function goToSlide(index) {
|
|
105
|
+
triggerClearTimer();
|
|
106
|
+
currentIndex.value = index;
|
|
107
|
+
emit('change', index);
|
|
108
|
+
triggerStartTimer();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const previousIndex = computed(() => {
|
|
112
|
+
return currentIndex.value === 0 ? props.slides.length - 1 : currentIndex.value - 1;
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const nextIndex = computed(() => {
|
|
116
|
+
return currentIndex.value === props.slides.length - 1 ? 0 : currentIndex.value + 1;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
function backgroundImage(slide) {
|
|
120
|
+
return { backgroundImage: 'url("' + (props.usePrefix ? props.imageBasePath : '') + slide + (props.widthSuffix ? ';width=' + props.widthSuffix : '') + '")' };
|
|
121
|
+
}
|
|
115
122
|
</script>
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
</div>
|
|
14
14
|
</div>
|
|
15
15
|
</template>
|
|
16
|
-
<script>
|
|
16
|
+
<script setup>
|
|
17
17
|
const TIMESPAN_INTERVALS = {
|
|
18
18
|
DAYS: 'DAYS',
|
|
19
19
|
WEEKS: 'WEEKS',
|
|
@@ -21,100 +21,99 @@
|
|
|
21
21
|
YEARS: 'YEARS',
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
name: 'TimespanInput',
|
|
26
|
-
props: {
|
|
27
|
-
initialValue: Number,
|
|
28
|
-
name: String,
|
|
29
|
-
},
|
|
30
|
-
data () {
|
|
31
|
-
return {
|
|
32
|
-
TIMESPAN_INTERVALS: TIMESPAN_INTERVALS,
|
|
24
|
+
import { ref, onMounted, nextTick, computed } from 'vue';
|
|
33
25
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
created: function () {
|
|
39
|
-
this.setInitialValueAndInterval()
|
|
26
|
+
const props = defineProps({
|
|
27
|
+
initialValue: {
|
|
28
|
+
type: Number,
|
|
29
|
+
default: 0,
|
|
40
30
|
},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
let newInterval = TIMESPAN_INTERVALS.DAYS;
|
|
45
|
-
|
|
46
|
-
if (newValue && !isNaN(newValue)) {
|
|
47
|
-
if (newValue % 365 === 0) {
|
|
48
|
-
newValue = newValue / 365;
|
|
49
|
-
newInterval = TIMESPAN_INTERVALS.YEARS;
|
|
50
|
-
} else if (newValue % 7 === 0) {
|
|
51
|
-
newValue = newValue / 7;
|
|
52
|
-
newInterval = TIMESPAN_INTERVALS.WEEKS;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
31
|
+
name: String,
|
|
32
|
+
});
|
|
33
|
+
const emit = defineEmits(['update']);
|
|
55
34
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (value && !isNaN(value)) {
|
|
64
|
-
if (this.selectedInterval === TIMESPAN_INTERVALS.DAYS) {
|
|
65
|
-
if (newValue % 365 === 0) {
|
|
66
|
-
newValue = newValue / 365;
|
|
67
|
-
newInterval = TIMESPAN_INTERVALS.YEARS;
|
|
68
|
-
} else if (newValue % 7 === 0) {
|
|
69
|
-
newValue = newValue / 7;
|
|
70
|
-
newInterval = TIMESPAN_INTERVALS.WEEKS;
|
|
71
|
-
}
|
|
72
|
-
} else if (this.selectedInterval === TIMESPAN_INTERVALS.MONTHS) {
|
|
73
|
-
if (value % 12 === 0) {
|
|
74
|
-
newValue = value / 12;
|
|
75
|
-
newInterval = TIMESPAN_INTERVALS.YEARS;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
newValue = '';
|
|
80
|
-
newInterval = TIMESPAN_INTERVALS.DAYS;
|
|
81
|
-
}
|
|
35
|
+
const value = ref('');
|
|
36
|
+
const selectedInterval = ref(TIMESPAN_INTERVALS.DAYS);
|
|
37
|
+
|
|
38
|
+
onMounted(() => {
|
|
39
|
+
setInitialValueAndInterval();
|
|
40
|
+
});
|
|
82
41
|
|
|
83
|
-
|
|
84
|
-
|
|
42
|
+
function setInitialValueAndInterval() {
|
|
43
|
+
let newValue = props.initialValue;
|
|
44
|
+
let newInterval = TIMESPAN_INTERVALS.DAYS;
|
|
85
45
|
|
|
86
|
-
|
|
87
|
-
|
|
46
|
+
if (newValue && !isNaN(newValue)) {
|
|
47
|
+
if (newValue % 365 === 0) {
|
|
48
|
+
newValue = newValue / 365;
|
|
49
|
+
newInterval = TIMESPAN_INTERVALS.YEARS;
|
|
50
|
+
} else if (newValue % 7 === 0) {
|
|
51
|
+
newValue = newValue / 7;
|
|
52
|
+
newInterval = TIMESPAN_INTERVALS.WEEKS;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
value.value = newValue;
|
|
57
|
+
selectedInterval.value = newInterval;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function syncValueAndInterval(value, callback) {
|
|
61
|
+
let newValue = value;
|
|
62
|
+
let newInterval = selectedInterval.value;
|
|
63
|
+
|
|
64
|
+
if (value && !isNaN(value)) {
|
|
65
|
+
if (selectedInterval.value === TIMESPAN_INTERVALS.DAYS) {
|
|
66
|
+
if (newValue % 365 === 0) {
|
|
67
|
+
newValue = newValue / 365;
|
|
68
|
+
newInterval = TIMESPAN_INTERVALS.YEARS;
|
|
69
|
+
} else if (newValue % 7 === 0) {
|
|
70
|
+
newValue = newValue / 7;
|
|
71
|
+
newInterval = TIMESPAN_INTERVALS.WEEKS;
|
|
88
72
|
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this.selectedInterval = value;
|
|
94
|
-
|
|
95
|
-
this.syncValueAndInterval(this.value, this.sendUpdate);
|
|
96
|
-
},
|
|
97
|
-
updateValue(e) {
|
|
98
|
-
const { value } = e.currentTarget;
|
|
99
|
-
this.syncValueAndInterval(value, this.sendUpdate);
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
sendUpdate() {
|
|
103
|
-
this.$emit('update', this.realValue, this.name);
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
computed: {
|
|
107
|
-
realValue() {
|
|
108
|
-
let finalValue = this.value;
|
|
109
|
-
|
|
110
|
-
if (this.selectedInterval === TIMESPAN_INTERVALS.WEEKS) {
|
|
111
|
-
finalValue = finalValue * 7;
|
|
112
|
-
} else if (this.selectedInterval === TIMESPAN_INTERVALS.YEARS) {
|
|
113
|
-
finalValue = finalValue * 365;
|
|
73
|
+
} else if (selectedInterval.value === TIMESPAN_INTERVALS.MONTHS) {
|
|
74
|
+
if (value % 12 === 0) {
|
|
75
|
+
newValue = value / 12;
|
|
76
|
+
newInterval = TIMESPAN_INTERVALS.YEARS;
|
|
114
77
|
}
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
newValue = '';
|
|
81
|
+
newInterval = TIMESPAN_INTERVALS.DAYS;
|
|
82
|
+
}
|
|
115
83
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
84
|
+
value.value = newValue;
|
|
85
|
+
selectedInterval.value = newInterval;
|
|
86
|
+
|
|
87
|
+
if (callback !== undefined) {
|
|
88
|
+
nextTick(callback);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function updateTimeInterval(e) {
|
|
93
|
+
const { value } = e.target;
|
|
94
|
+
selectedInterval.value = value;
|
|
95
|
+
|
|
96
|
+
syncValueAndInterval(value, sendUpdate);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
function updateValue(e) {
|
|
100
|
+
const { value } = e.currentTarget;
|
|
101
|
+
syncValueAndInterval(value, sendUpdate);
|
|
119
102
|
};
|
|
103
|
+
|
|
104
|
+
function sendUpdate() {
|
|
105
|
+
emit('update', realValue.value, props.name);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const realValue = computed(() => {
|
|
109
|
+
let finalValue = value.value;
|
|
110
|
+
|
|
111
|
+
if (selectedInterval.value === TIMESPAN_INTERVALS.WEEKS) {
|
|
112
|
+
finalValue = finalValue * 7;
|
|
113
|
+
} else if (selectedInterval.value === TIMESPAN_INTERVALS.YEARS) {
|
|
114
|
+
finalValue = finalValue * 365;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return finalValue;
|
|
118
|
+
});
|
|
120
119
|
</script>
|