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

View File

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

View File

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

View File

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

View File

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