WIP Отображение нерабочего времени

This commit is contained in:
Daria Golova
2022-12-21 19:13:01 +03:00
parent 40e0c71347
commit 4aecbbca36
5 changed files with 117 additions and 26 deletions

View File

@@ -28,7 +28,6 @@
calendar-form-add-event(
v-if="isOpenForm",
:close-form="closeFormCreateEvent",
:owners-data="employeesData",
:selected-event-data="selectedEvent",
:event-statuses="eventStatuses",
:time-information="timeInformation",
@@ -76,7 +75,7 @@ export default {
showModal: false,
timeInformation: {
dayStartTime: "08:00",
dayEndTime: "20:00",
dayEndTime: "22:00",
},
eventsData: [],
employeesData: [],
@@ -146,7 +145,7 @@ export default {
},
fetchEmployeesData() {
fetchWrapper
.get("general/employee/")
.get(`general/employee/?date=${this.currentDate.format("YYYY-MM-DD")}`)
.then((res) => this.saveEmployeesData(res));
},
fetchEventsData() {
@@ -192,6 +191,9 @@ export default {
this.clearSelectedEvent();
}
},
currentDate() {
this.fetchEmployeesData();
},
},
mounted() {
this.fetchEmployeesData();

View File

@@ -12,7 +12,8 @@
span.owner-name.font-medium.text-base.mr-6 {{ ownerName }}
img.icon-wrapper.cursor-pointer(src="@/assets/icons/lock.svg")
column-header-checkbox
.body.pl-1.h-full(@dblclick="clickOnBackground")
.body(@dblclick="clickOnBackground")
.nonworking-time(:style="nonworkingStartTime")
transition-group(name="card")
calendar-event-card(
v-for="event, index in dayEvents",
@@ -27,18 +28,23 @@
@delete-event="transmitDeleteEvent",
:schedule-body-ref="scheduleBodyRef",
)
.nonworking-time.absolute(:style="nonworkingEndTime")
</template>
<script>
import ColumnHeaderCheckbox from "./CalendarColumnHeaderCheckbox.vue";
import BaseAvatar from "@/components/base/BaseAvatar";
import CalendarEventCard from "./CalendarEventCard.vue";
import * as moment from "moment/moment";
import TheNotificationProvider from "@/components/Notifications/TheNotificationProvider";
import { addNotification } from "@/components/Notifications/notificationContext";
export default {
name: "CalendarColumn",
components: {
CalendarEventCard,
BaseAvatar,
ColumnHeaderCheckbox,
TheNotificationProvider,
},
props: {
ownerData: Object,
@@ -63,6 +69,62 @@ export default {
};
},
computed: {
workingShift() {
console.log(this.ownerData);
if (!this.ownerData.id) return null;
let foundedSchedule = this.ownerData.schedule.find(
(elem) => elem.date === this.currentDate.format("YYYY-MM-DD")
);
if (!foundedSchedule) return null;
let start = foundedSchedule.start_time.slice(
0,
foundedSchedule.start_time.length - 3
);
let end = foundedSchedule.end_time.slice(
0,
foundedSchedule.end_time.length - 3
);
return {
start: start.split(":"),
end: end.split(":"),
fulltime: `${start} - ${end}`,
};
},
nonworkingStartTime() {
if (!this.ownerData.id || !this.workingShift) return {};
let height =
(this.workingShift.start[0] - this.dayStartTime) * this.pixelsPerHour +
this.workingShift.start[1] * this.pixelsPerMinute;
if (height <= 0)
return {
height: 0,
display: "none",
};
return {
height: `${height}px`,
};
},
nonworkingEndTime() {
if (!this.ownerData.id || !this.workingShift) return {};
let time = moment()
.hour(this.dayEndTime)
.minute(0)
.subtract(parseInt(this.workingShift.end[0]), "hours")
.subtract(parseInt(this.workingShift.end[1]), "minutes")
.format("HH:mm")
.split(":");
let position =
time[0] * this.pixelsPerHour + time[1] * this.pixelsPerMinute;
if (position <= 0)
return {
bottom: 0,
display: "none",
};
return {
bottom: 0,
height: `${position}px`,
};
},
ownerName() {
if (this.ownerData.id) {
let checkedFirstName =
@@ -120,23 +182,41 @@ export default {
transmitDeleteEvent(eventData) {
this.$emit("delete-event", eventData);
},
addErrorNotification(title, message) {
addNotification(title, title, message, "error", 5000);
},
clickOnBackground(e) {
let res = String((e.offsetY / this.pixelsPerHour).toFixed(2)).split(".");
let hours = parseInt(res[0]) + this.dayStartTime;
let minuts = Math.round(res[1] * 0.6);
if (minuts < 10) minuts = "0" + minuts;
if (hours < 10) hours = "0" + hours;
if (e.target.className !== "body")
this.addErrorNotification(
`Для сотрудника ${this.ownerName} рабочие часы: ${this.workingShift.fulltime}`,
"Вы пытаетесь добавить запись вне рабочего времени"
);
else
this.$emit("selected-event", {
employees: [
{
employee: this.ownerData,
employee: {
id: this.ownerData.id,
last_name: this.ownerData.last_name,
first_name: this.ownerData.first_name,
patronymic: this.ownerData.patronymic,
color: this.ownerData.color,
photo: this.ownerData.photo,
},
role: "owner",
},
],
start: `${this.currentDate.format(
"YYYY-MM-DD"
)}T${hours}:${minuts}:00Z`,
end: `${this.currentDate.format("YYYY-MM-DD")}T${hours}:${minuts}:00Z`,
end: `${this.currentDate.format(
"YYYY-MM-DD"
)}T${hours}:${minuts}:00Z`,
});
},
},
@@ -157,6 +237,7 @@ export default {
.body
position: relative
z-index: 3
height: 100%
.btn
opacity: 0.5
@@ -185,4 +266,9 @@ export default {
.card-move
transition: 0.3s ease
.nonworking-time
width: 100%
background-color: var(--font-dark-blue-color)
opacity: 0.05
</style>

View File

@@ -1,5 +1,5 @@
<template lang="pug">
.wrapper.cursor-pointer.my-1(
.wrapper.cursor-pointer.my-1.mx-1(
:style="themeColors",
:class="cardTheme",
ref="eventCard"

View File

@@ -95,12 +95,6 @@ export default {
emits: ["clear-selected-event-data", "close-change-form"],
props: {
closeForm: Function,
ownersData: {
type: Array,
default() {
return [];
},
},
selectedEventData: {
type: Object,
default() {
@@ -135,6 +129,7 @@ export default {
id: null,
ifClearedForm: true,
membersData: [],
ownersData: [],
};
},
computed: {
@@ -488,6 +483,14 @@ export default {
.get("general/person/?limit=100")
.then((res) => this.saveMembersData(res));
},
fetchOwnersData() {
fetchWrapper
.get("general/employee/")
.then((res) => this.saveOwnersData(res));
},
saveOwnersData(res) {
this.ownersData = res.results;
},
saveMembersData(res) {
this.membersData = res.results;
},
@@ -523,6 +526,7 @@ export default {
},
},
mounted() {
this.fetchOwnersData();
this.fetchMembersData();
},
};

View File

@@ -176,6 +176,7 @@ export default {
patronymic: elem.patronymic,
color: elem.color,
photo: elem.photo,
schedule: elem.schedule,
});
});
return filteredArray;
@@ -301,9 +302,7 @@ export default {
let filteredArray = [];
this.filteredEventsByDate.forEach((item) => {
let foundEvent = item.employees.find(
(elem) =>
JSON.stringify(elem.employee) === JSON.stringify(owner) &&
elem.role === "owner"
(elem) => elem.employee.id === owner.id && elem.role === "owner"
);
if (foundEvent) filteredArray.push(item);
});