From 5455b9ee24733982352668ce10f3217ce7f93e45 Mon Sep 17 00:00:00 2001 From: Daria Golova Date: Thu, 15 Dec 2022 16:32:19 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B8?= =?UTF-8?q?=20=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/calendar/TheCalendar.vue | 1 + .../calendar/components/CalendarColumn.vue | 2 +- .../components/CalendarFormAddEvent.vue | 98 +++++++++++++++++-- 3 files changed, 90 insertions(+), 11 deletions(-) diff --git a/src/pages/calendar/TheCalendar.vue b/src/pages/calendar/TheCalendar.vue index b617619..7cdb9f6 100644 --- a/src/pages/calendar/TheCalendar.vue +++ b/src/pages/calendar/TheCalendar.vue @@ -31,6 +31,7 @@ :owners-data="employeesData", :selected-event-data="selectedEvent", :event-types="eventTypes", + :time-information="timeInformation", @clear-selected-event-data="clearSelectedEvent", @close-change-form="setChangeFormState" ) diff --git a/src/pages/calendar/components/CalendarColumn.vue b/src/pages/calendar/components/CalendarColumn.vue index 40663e4..99243c0 100644 --- a/src/pages/calendar/components/CalendarColumn.vue +++ b/src/pages/calendar/components/CalendarColumn.vue @@ -84,7 +84,7 @@ export default { start[1] * this.pixelsPerMinute; if ( parseInt(start[0], 10) < this.dayStartTime || - parseInt(end, 10) >= this.dayEndTime + parseInt(end, 10) > this.dayEndTime ) { return { top: "0px", diff --git a/src/pages/calendar/components/CalendarFormAddEvent.vue b/src/pages/calendar/components/CalendarFormAddEvent.vue index 13a8d12..92840c4 100644 --- a/src/pages/calendar/components/CalendarFormAddEvent.vue +++ b/src/pages/calendar/components/CalendarFormAddEvent.vue @@ -105,6 +105,12 @@ export default { return []; }, }, + timeInformation: { + type: Object, + default() { + return {}; + }, + }, }, data() { return { @@ -268,6 +274,75 @@ export default { }, }, methods: { + checkTimeLimits(eventTime, scheduleTime, timeType) { + if (timeType === "start") + return ( + parseInt(eventTime.split(":")[0]) < + parseInt(scheduleTime.split(":")[0]) + ); + if (timeType === "end") { + let firstTime = eventTime.split(":").map((elem) => parseInt(elem)); + let secondTime = scheduleTime.split(":").map((elem) => parseInt(elem)); + if (firstTime[0] === secondTime[0]) return firstTime[1] > secondTime[1]; + else return firstTime[0] > secondTime[0]; + } + }, + checkTime() { + let counter = 0; + if ( + this.checkTimeLimits( + this.startTime, + this.timeInformation.dayStartTime, + "start" + ) + ) { + this.addErrorNotification( + "Некорректное время начала события", + "Время начала события раньше начала рабочего дня" + ); + counter += 1; + } + if ( + this.checkTimeLimits( + this.endTime, + this.timeInformation.dayEndTime, + "end" + ) + ) { + this.addErrorNotification( + "Некорректное время окончания события", + "Время окончания события позже окончания рабочего дня" + ); + counter += 1; + } + if ( + this.checkTimeLimits( + this.endTime, + this.timeInformation.dayStartTime, + "start" + ) + ) { + this.addErrorNotification( + "Некорректное время окончания события", + "Время окончания события раньше начала рабочего дня" + ); + counter += 1; + } + if ( + this.checkTimeLimits( + this.startTime, + this.timeInformation.dayEndTime, + "end" + ) + ) { + this.addErrorNotification( + "Некорректное время начала события", + "Время начала события позже окончания рабочего дня" + ); + counter += 1; + } + return counter === 0; + }, trimOwnerName(lastName, firsName, patronymic) { return `${lastName} ${firsName[0]}.${patronymic[0]}.`; }, @@ -275,19 +350,22 @@ export default { return `${lastName} ${firsName} ${patronymic}`; }, async sendEventData() { - this.eventData = { - start: this.mergeDate(this.eventDate, this.startTime), - end: this.mergeDate(this.eventDate, this.endTime), - kind: this.kind.label, - employees: [ - this.findPerson(this.ownersData, this.employees, "employee"), - ], - members: [this.findPerson(this.membersData, this.members, "person")], - }; + if (!this.checkTime()) return; + else + this.eventData = { + start: this.mergeDate(this.eventDate, this.startTime), + end: this.mergeDate(this.eventDate, this.endTime), + kind: this.kind.label, + employees: [ + this.findPerson(this.ownersData, this.employees, "employee"), + ], + members: [this.findPerson(this.membersData, this.members, "person")], + }; await this.postCreateEvent(this.eventData); this.eventData = {}; }, async updateEventData() { + if (!this.checkTime()) return; if ( Object.keys( this.findPerson(this.ownersData, this.employees, "employee") @@ -384,7 +462,7 @@ export default { } }, addErrorNotification(title, message) { - addNotification(new Date().getTime(), title, message, "error", 5000); + addNotification(title, title, message, "error", 5000); }, addSuccessNotification(message) { addNotification(new Date().getTime(), message, "", "success", 5000); From 217e971f5062b349686cc11faec36d5272063b95 Mon Sep 17 00:00:00 2001 From: Daria Golova Date: Thu, 15 Dec 2022 16:35:07 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BD=20=D0=BB?= =?UTF-8?q?=D0=B8=D1=88=D0=BD=D0=B8=D0=B9=20else?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/CalendarFormAddEvent.vue | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/pages/calendar/components/CalendarFormAddEvent.vue b/src/pages/calendar/components/CalendarFormAddEvent.vue index 92840c4..7bc4ec5 100644 --- a/src/pages/calendar/components/CalendarFormAddEvent.vue +++ b/src/pages/calendar/components/CalendarFormAddEvent.vue @@ -351,16 +351,15 @@ export default { }, async sendEventData() { if (!this.checkTime()) return; - else - this.eventData = { - start: this.mergeDate(this.eventDate, this.startTime), - end: this.mergeDate(this.eventDate, this.endTime), - kind: this.kind.label, - employees: [ - this.findPerson(this.ownersData, this.employees, "employee"), - ], - members: [this.findPerson(this.membersData, this.members, "person")], - }; + this.eventData = { + start: this.mergeDate(this.eventDate, this.startTime), + end: this.mergeDate(this.eventDate, this.endTime), + kind: this.kind.label, + employees: [ + this.findPerson(this.ownersData, this.employees, "employee"), + ], + members: [this.findPerson(this.membersData, this.members, "person")], + }; await this.postCreateEvent(this.eventData); this.eventData = {}; },