Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
97cd5d9
feature(): refactor business hour component adding rules
jcwirko Sep 19, 2024
8658e8b
rollback demo holidays data
jcwirko Sep 19, 2024
559091a
Change order of elements in select
jcwirko Sep 19, 2024
148f36e
remove spaces
jcwirko Sep 19, 2024
5b79e48
bump version
jcwirko Sep 19, 2024
1326511
generate new build
jcwirko Sep 20, 2024
a4bacee
Refactor variables in businesshours component
jcwirko Sep 20, 2024
f879b9c
rebuild dist folder
jcwirko Sep 20, 2024
0042fd3
feature(): fix TYPO and 24hs in closed time
jcwirko Sep 24, 2024
0b02e68
feature(): generate a new dist folder
jcwirko Sep 24, 2024
03b815b
feature(): fix midgnight issue
jcwirko Sep 24, 2024
e537a73
feature(): set close hour empty when open is 24hrs
jcwirko Sep 24, 2024
df2f27c
hide midnight when open is 24hs
jcwirko Sep 24, 2024
d157fef
feature(): add props to disable and hide 24hs in close select
jcwirko Sep 24, 2024
ab328f7
feature(): generate new dist
jcwirko Sep 24, 2024
17e65a2
feature(): add blur event after select a new value
jcwirko Sep 24, 2024
081ce44
feature(): add new dist folder
jcwirko Sep 24, 2024
9e9168b
feature(): generate new dist and add some changes
jcwirko Sep 24, 2024
0d8e009
feature(): rollback disabled option for first row
jcwirko Sep 24, 2024
aa38cc8
feature(): generate new build
jcwirko Sep 24, 2024
63248e2
feature(): disable close time when open is 24hrs
jcwirko Sep 24, 2024
1782f74
feature(): add logger
jcwirko Sep 24, 2024
a0deb2d
feature(): add code to debug in talk
jcwirko Sep 24, 2024
4004f4c
feature(): add code to debug in talk
jcwirko Sep 24, 2024
a8cd1e7
feature(): add changes to test talk
jcwirko Sep 24, 2024
7e2496e
feature(): add changes to test talk
jcwirko Sep 24, 2024
7643699
feature(): add changes to test talk
jcwirko Sep 24, 2024
6ae2e78
feature(): add changes to test talk
jcwirko Sep 24, 2024
1948dab
feature(): add changes to test talk
jcwirko Sep 24, 2024
ed39386
feature(): add changes to test talk
jcwirko Sep 24, 2024
2616b44
feature(): add changes to test talk
jcwirko Sep 24, 2024
e768562
feature(): add changes to test talk
jcwirko Sep 24, 2024
d9ee024
feature(): remove alert and computed and add mounted
jcwirko Sep 24, 2024
a6a3d4e
feature(): remove unused computed
jcwirko Sep 24, 2024
07b7bce
feature(): new dist folder
jcwirko Sep 24, 2024
b5ca7a2
feature(): move props before data
jcwirko Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 69 additions & 3 deletions src/components/BusinessHours.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export default {
default: () => ({
switchOpen: 'Open',
switchClosed: 'Closed',
placeholderOpens: 'Opens',
placeholderCloses: 'Closes',
placeholderOpens: 'Open',
placeholderCloses: 'Closed',
addHours: 'Add hours',
open: {
invalidInput:
Expand Down Expand Up @@ -120,8 +120,74 @@ export default {
},
methods: {
hoursChange: function(val) {
val = this.setClosingTimeBasedOnOpening(val)

this.$emit('updated-hours', val);
}
},
calculateOpenTime(closeTime) {
const minutesPerHour = 60;
const additionalHours = 9;
const minHours = 0; // 12:00 AM is represented as 0 hours
const [hours, minutes] = [
parseInt(closeTime.substring(0, 2), 10),
parseInt(closeTime.substring(2, 4), 10),
];

// Calculate the total minutes of the closing time
let totalMinutes = hours * minutesPerHour + minutes - (additionalHours * minutesPerHour);

// If the calculated open time is earlier than 12:00 AM, set it to 12:00 AM
if (totalMinutes < minHours * minutesPerHour) {
totalMinutes = minHours * minutesPerHour;
}

// Calculate the new hours and minutes for the open time
let newHours = Math.floor(totalMinutes / 60);
let newMinutes = totalMinutes % 60;

// Format the new open time as a string with padded zeros
return String(newHours).padStart(2, '0') + String(newMinutes).padStart(2, '0');
},
calculateCloseTime(openTime) {
const minutesPerHour = 60;
const additionalHours = 9;
const maxHours = 23;
const [hours, minutes] = [
parseInt(openTime.substring(0, 2), 10),
parseInt(openTime.substring(2, 4), 10),
];

let totalMinutes = hours * minutesPerHour + minutes + (additionalHours * minutesPerHour);
const maxMinutes = maxHours * minutesPerHour + 30;

if (totalMinutes > maxMinutes) {
totalMinutes = maxMinutes;
}

let newHours = Math.floor(totalMinutes / 60);
let newMinutes = totalMinutes % 60;

return String(newHours).padStart(2, '0') + String(newMinutes).padStart(2, '0');
},
setClosingTimeBasedOnOpening(val) {
const key = Object.keys(val)[0];

val[key].forEach((day, index) => {
if (val.open === '' && val.isOpen) {
val[key][index].close = '';
}

if (day.isOpen && day.close !== '24hrs' && day.close !== '' && day.open === '') {
val[key][index].open = this.calculateOpenTime(day.close);
}

if (day.isOpen && day.open !== '24hrs' && day.open !== '' && day.close === '') {
val[key][index].close = this.calculateCloseTime(day.open);
}
});

return val;
},
}
};
</script>
Expand Down
51 changes: 46 additions & 5 deletions src/components/BusinessHoursSelect.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
<template>
<select :name="optionName" @change="inputEventHandler" v-model="selected">
<option v-show="isFirstRow(index) && onlyOneRow(hours)" value>{{
defaultText
}}</option>
<select :name="optionName"
:class="selectClass"
v-model="selected"
@focus="hidePlaceholder"
@change="inputEventHandler"
@blur="showPlaceholder">
<option v-show="isFirstRow(index) && onlyOneRow(hours)"
value
disabled
selected
v-if="isPlaceholderVisible"
class="placeholder-text"
>
{{ defaultText}}
</option>
<option v-show="isFirstRow(index)" value="24hrs">{{
localization.t24hours
}}</option>
Expand All @@ -24,6 +35,36 @@ import { helperMixin } from '../mixins/helperMixin';
import { formFieldMixin } from '../mixins/formFieldMixin';
export default {
name: 'BusinessHoursSelect',
mixins: [helperMixin, formFieldMixin]
mixins: [helperMixin, formFieldMixin],
data () {
return {
isPlaceholderVisible: true
}
},
computed: {
selectClass() {
if (this.selected === "" || this.selected === "") {
return "placeholder-text"; // Apply custom class
} else {
return "";
}
}
},
methods: {
hidePlaceholder() {
this.isPlaceholderVisible = false;
},
showPlaceholder() {
this.isPlaceholderVisible = true;
},
},
};
</script>

<style scoped>

.placeholder-text {
color: #878686;
}

</style>