Merge pull request #40 from dderbentsov/UC-11
Настроила индикатор и перекраску текущего времени
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
.calendar-container
|
.calendar-container
|
||||||
calendar-schedule(
|
calendar-schedule(
|
||||||
:currentDate="currentDate"
|
:current-date="currentDate"
|
||||||
:timeInformation="timeInformation"
|
:time-information="timeInformation"
|
||||||
@previous-date="switchPreviousDate"
|
@previous-date="switchPreviousDate"
|
||||||
@next-date="switchNextDate"
|
@next-date="switchNextDate"
|
||||||
@selected-layout="changeCalendarLayout"
|
@selected-layout="changeCalendarLayout"
|
||||||
|
|||||||
@@ -3,10 +3,19 @@
|
|||||||
.header.flex.items-center.justify-between.py-2.px-6
|
.header.flex.items-center.justify-between.py-2.px-6
|
||||||
.body.flex.flex-col
|
.body.flex.flex-col
|
||||||
.line-wrapper
|
.line-wrapper
|
||||||
.line.flex.items-center(v-for="hour in hoursArray" :key="hour")
|
.line.flex.items-center(
|
||||||
|
v-for="hour in hoursArray"
|
||||||
|
:key="hour"
|
||||||
|
)
|
||||||
.middle-line
|
.middle-line
|
||||||
.time-circle-indicator.-left-6px(v-if="isShownIndicator" :style="circleIndicatorLocation")
|
.time-circle-indicator.-left-6px(
|
||||||
span.time-line-indicator.block(v-if="isShownIndicator" :style="lineIndicatorLocation")
|
v-if="isShownIndicator"
|
||||||
|
:style="circleIndicatorLocation"
|
||||||
|
)
|
||||||
|
span.time-line-indicator.block(
|
||||||
|
v-if="isShownIndicator"
|
||||||
|
:style="lineIndicatorLocation"
|
||||||
|
)
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -17,10 +26,13 @@ export default {
|
|||||||
hoursArray: Array,
|
hoursArray: Array,
|
||||||
currentTime: String,
|
currentTime: String,
|
||||||
currentDate: Object,
|
currentDate: Object,
|
||||||
|
dayStartTime: Number,
|
||||||
|
dayEndTime: Number,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
isShownIndicator: true,
|
isShownIndicator: true,
|
||||||
|
pixelsPerHour: 62,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -34,14 +46,22 @@ export default {
|
|||||||
top: `${this.calculateIndicatorLocation() - 6}px`,
|
top: `${this.calculateIndicatorLocation() - 6}px`,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
scheduleSize() {
|
||||||
|
return (this.dayEndTime - this.dayStartTime) * this.pixelsPerHour;
|
||||||
|
},
|
||||||
|
pixelsPerMinute() {
|
||||||
|
return this.pixelsPerHour / 60;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
calculateIndicatorLocation() {
|
calculateIndicatorLocation() {
|
||||||
let newTime = this.currentTime
|
let newTime = this.currentTime
|
||||||
.split(":")
|
.split(":")
|
||||||
.map((elem) => parseInt(elem, 10));
|
.map((elem) => parseInt(elem, 10));
|
||||||
let result = (newTime[0] - 8) * 62 + newTime[1] * 1.03;
|
let result =
|
||||||
if (result > 620) {
|
(newTime[0] - this.dayStartTime) * this.pixelsPerHour +
|
||||||
|
newTime[1] * this.pixelsPerMinute;
|
||||||
|
if (result > this.scheduleSize || result < 0) {
|
||||||
this.isShownIndicator = false;
|
this.isShownIndicator = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,39 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
.calendar-clock-column.flex.flex-col.items-end.gap-y-43.pt-9.pb-12.px-3
|
.calendar-clock-column.flex.flex-col.items-end.gap-y-43.pt-9.pb-12.px-3
|
||||||
span.font-medium.text-base(v-for="hour in hoursArray" :key="hour" :class="currentHourStyle(hour)") {{ hour }}
|
span.font-medium.text-base(
|
||||||
|
v-for="hour in hoursArray"
|
||||||
|
:key="hour"
|
||||||
|
:class="currentHourStyle(hour)"
|
||||||
|
) {{ hour }}
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import * as moment from "moment/moment";
|
|
||||||
export default {
|
export default {
|
||||||
name: "CalendarClockColumn",
|
name: "CalendarClockColumn",
|
||||||
props: {
|
props: {
|
||||||
hoursArray: Array,
|
hoursArray: Array,
|
||||||
currentTime: String,
|
currentTime: String,
|
||||||
currentDate: Object,
|
currentDate: Object,
|
||||||
|
dayEndTime: Number,
|
||||||
|
isCurrentDate: Boolean,
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
currentHour() {
|
currentHour() {
|
||||||
return parseInt(this.currentTime.slice(0, -6), 10);
|
return this.convertTime(this.currentTime, 0, -6);
|
||||||
},
|
},
|
||||||
isCurrentDay() {
|
currentMinute() {
|
||||||
return (
|
return this.convertTime(this.currentTime, 3, -3);
|
||||||
this.currentDate.format("DD.MM.YYYY") === moment().format("DD.MM.YYYY")
|
},
|
||||||
);
|
isEndDay() {
|
||||||
|
return this.dayEndTime === this.currentHour && this.currentMinute > 0;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
currentHourStyle(elem) {
|
currentHourStyle(elem) {
|
||||||
if (
|
if (
|
||||||
parseInt(elem.slice(0, 3), 10) === this.currentHour &&
|
this.convertTime(elem, 0, 3) === this.currentHour &&
|
||||||
this.isCurrentDay
|
!this.isEndDay &&
|
||||||
|
this.isCurrentDate
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
"current-time": true,
|
"current-time": true,
|
||||||
@@ -37,6 +44,9 @@ export default {
|
|||||||
"current-time": false,
|
"current-time": false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
convertTime(str, startIndex, endIndex) {
|
||||||
|
return parseInt(str.slice(startIndex, endIndex), 10);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -5,12 +5,11 @@
|
|||||||
base-arrow-button.right-arrow.mr-6(@click="nextHandler")
|
base-arrow-button.right-arrow.mr-6(@click="nextHandler")
|
||||||
.text.flex.items-center
|
.text.flex.items-center
|
||||||
span.font-medium.text-base {{ dateString }}
|
span.font-medium.text-base {{ dateString }}
|
||||||
span.today.font-bold.text-xxs(v-if="isToday") Сегодня
|
span.today.font-bold.text-xxs(v-if="isCurrentDate") Сегодня
|
||||||
calendar-layout-switch(@selected="changeSelectedLayout")
|
calendar-layout-switch(@selected="changeSelectedLayout")
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import * as moment from "moment/moment";
|
|
||||||
import BaseArrowButton from "@/components/base/buttons/BaseArrowButton.vue";
|
import BaseArrowButton from "@/components/base/buttons/BaseArrowButton.vue";
|
||||||
import CalendarLayoutSwitch from "./CalendarLayoutSwitch.vue";
|
import CalendarLayoutSwitch from "./CalendarLayoutSwitch.vue";
|
||||||
export default {
|
export default {
|
||||||
@@ -18,11 +17,7 @@ export default {
|
|||||||
components: { BaseArrowButton, CalendarLayoutSwitch },
|
components: { BaseArrowButton, CalendarLayoutSwitch },
|
||||||
props: {
|
props: {
|
||||||
currentDate: Object,
|
currentDate: Object,
|
||||||
},
|
isCurrentDate: Boolean,
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
isToday: true,
|
|
||||||
};
|
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
dateString() {
|
dateString() {
|
||||||
@@ -47,12 +42,6 @@ export default {
|
|||||||
this.$emit("next-date");
|
this.$emit("next-date");
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
|
||||||
currentDate: function () {
|
|
||||||
this.isToday =
|
|
||||||
this.currentDate.format("DD.MM.YYYY") === moment().format("DD.MM.YYYY");
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
.layout-switch-wrapper.inline-block
|
.layout-switch-wrapper.inline-block
|
||||||
button#day.py-2.px-3(:class="dayLayoutState" @click="changeSelectedLayout") День
|
button#day.py-2.px-3(
|
||||||
button#week.py-2.px-3(:class="weekLayoutState" @click="changeSelectedLayout") Неделя
|
:class="dayLayoutState"
|
||||||
|
@click="changeSelectedLayout"
|
||||||
|
) День
|
||||||
|
button#week.py-2.px-3(
|
||||||
|
:class="weekLayoutState"
|
||||||
|
@click="changeSelectedLayout"
|
||||||
|
) Неделя
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
@@ -1,13 +1,26 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
.schedule.ml-2
|
.schedule.ml-2
|
||||||
calendar-header(
|
calendar-header(
|
||||||
:currentDate="currentDate"
|
:current-date="currentDate"
|
||||||
|
:is-current-date="isCurrentDate"
|
||||||
@previous-date="previousDate"
|
@previous-date="previousDate"
|
||||||
@next-date="nextDate"
|
@next-date="nextDate"
|
||||||
@selected-layout="selectedLayout")
|
@selected-layout="selectedLayout"
|
||||||
|
)
|
||||||
.schedule-body.flex
|
.schedule-body.flex
|
||||||
calendar-clock-column(:hoursArray="hoursArray" :currentTime="currentTime" :currentDate="currentDate")
|
calendar-clock-column(
|
||||||
calendar-background(:hoursArray="hoursArray" :currentTime="currentTime" :currentDate="currentDate")
|
:hours-array="hoursArray"
|
||||||
|
:current-time="currentTime"
|
||||||
|
:is-current-date="isCurrentDate"
|
||||||
|
:day-end-time="validateEndTime"
|
||||||
|
)
|
||||||
|
calendar-background(
|
||||||
|
:hours-array="hoursArray"
|
||||||
|
:current-time="currentTime"
|
||||||
|
:current-date="currentDate"
|
||||||
|
:day-start-time="validateStartTime"
|
||||||
|
:day-end-time="validateEndTime"
|
||||||
|
)
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -37,15 +50,25 @@ export default {
|
|||||||
currentTime: "",
|
currentTime: "",
|
||||||
hoursArray: [],
|
hoursArray: [],
|
||||||
timer: null,
|
timer: null,
|
||||||
|
isCurrentDate: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
hours() {
|
hours() {
|
||||||
return parseInt(this.currentTime.slice(0, -6), 10);
|
return this.convertTime(this.currentTime, 0, -6);
|
||||||
|
},
|
||||||
|
minutes() {
|
||||||
|
return this.convertTime(this.currentTime, 3, -3);
|
||||||
},
|
},
|
||||||
hoursMinutes() {
|
hoursMinutes() {
|
||||||
return this.currentTime.slice(0, -3);
|
return this.currentTime.slice(0, -3);
|
||||||
},
|
},
|
||||||
|
validateStartTime() {
|
||||||
|
return this.verifyTime(this.timeInformation.dayStartTime);
|
||||||
|
},
|
||||||
|
validateEndTime() {
|
||||||
|
return this.verifyTime(this.timeInformation.dayEndTime);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
previousDate() {
|
previousDate() {
|
||||||
@@ -58,11 +81,14 @@ export default {
|
|||||||
this.$emit("selected-layout", option);
|
this.$emit("selected-layout", option);
|
||||||
},
|
},
|
||||||
startTimer() {
|
startTimer() {
|
||||||
if (this.hours >= 8 && this.hours < 18) {
|
if (
|
||||||
|
this.hours >= this.validateStartTime &&
|
||||||
|
this.hours < this.validateEndTime
|
||||||
|
) {
|
||||||
this.timer = setInterval(() => {
|
this.timer = setInterval(() => {
|
||||||
this.changeCurrentTime();
|
this.changeCurrentTime();
|
||||||
this.changeHoursArray();
|
this.changeHoursArray();
|
||||||
}, 30000);
|
}, 5000);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
stopTimer() {
|
stopTimer() {
|
||||||
@@ -73,25 +99,56 @@ export default {
|
|||||||
this.currentTime = moment().format("HH:mm:ss");
|
this.currentTime = moment().format("HH:mm:ss");
|
||||||
},
|
},
|
||||||
hoursArrayInitialization() {
|
hoursArrayInitialization() {
|
||||||
for (let i = 8; i <= 18; i++) {
|
this.hoursArray = [];
|
||||||
if (i === this.hours && this.hours >= 8 && this.hours < 18) {
|
for (let i = this.validateStartTime; i <= this.validateEndTime; i++) {
|
||||||
|
if (
|
||||||
|
i === this.hours &&
|
||||||
|
this.hours !== this.validateEndTime &&
|
||||||
|
this.isCurrentDate
|
||||||
|
) {
|
||||||
this.hoursArray.push(this.hoursMinutes);
|
this.hoursArray.push(this.hoursMinutes);
|
||||||
} else this.hoursArray.push(`${i}:00`);
|
} else this.hoursArray.push(`${i}:00`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
changeHoursArray() {
|
changeHoursArray() {
|
||||||
this.hoursArray = this.hoursArray.map((elem) => {
|
this.hoursArray = this.hoursArray.map((elem) => {
|
||||||
if (parseInt(elem.slice(0, -3), 10) === this.hours) {
|
if (this.convertTime(elem, 0, -3) === this.hours) {
|
||||||
return this.hoursMinutes;
|
return this.hoursMinutes;
|
||||||
}
|
}
|
||||||
return elem;
|
return elem;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
verifyTime(dayTime) {
|
||||||
|
let timeArray = dayTime.split(":").map((elem) => parseInt(elem, 10));
|
||||||
|
let newTime = timeArray[1] > 30 ? timeArray[0] + 1 : timeArray[0];
|
||||||
|
return newTime;
|
||||||
|
},
|
||||||
|
convertTime(str, startIndex, endIndex) {
|
||||||
|
return parseInt(str.slice(startIndex, endIndex), 10);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
currentTime() {
|
currentTime() {
|
||||||
if (this.hours >= 18) {
|
if (
|
||||||
|
this.hours === this.validateEndTime &&
|
||||||
|
this.minutes > 0 &&
|
||||||
|
this.timer
|
||||||
|
) {
|
||||||
this.stopTimer();
|
this.stopTimer();
|
||||||
|
this.hoursArrayInitialization();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
currentDate: function () {
|
||||||
|
this.isCurrentDate =
|
||||||
|
this.currentDate.format("DD.MM.YYYY") === moment().format("DD.MM.YYYY");
|
||||||
|
if (this.timer) {
|
||||||
|
this.stopTimer();
|
||||||
|
this.hoursArrayInitialization();
|
||||||
|
}
|
||||||
|
if (this.isCurrentDate) {
|
||||||
|
this.changeCurrentTime();
|
||||||
|
this.hoursArrayInitialization();
|
||||||
|
this.startTimer();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user