WIP Реальзовала изменение события на сервер

This commit is contained in:
Daria Golova
2022-11-07 15:00:58 +03:00
parent 86b4a91d23
commit 4afd678f4a
7 changed files with 102 additions and 64 deletions

View File

@@ -50,7 +50,7 @@ export default {
border: 2px solid var(--border-light-grey-color) border: 2px solid var(--border-light-grey-color)
border-radius: 4px border-radius: 4px
background-color: var(--default-white) background-color: var(--default-white)
color: var(--font-dark-blue-color) color: var(--font-black-color)
.date .date
background: url("../../assets/icons/calendar-input.svg") no-repeat 100% 50% background: url("../../assets/icons/calendar-input.svg") no-repeat 100% 50%
&::-webkit-calendar-picker-indicator &::-webkit-calendar-picker-indicator

View File

@@ -42,7 +42,7 @@ export default {
.input-wrapper .input-wrapper
border-radius: 4px border-radius: 4px
background-color: var(--default-white) background-color: var(--default-white)
color: var(--font-dark-blue-color) color: var(--font-black-color)
.date .date
background: url("../../assets/icons/calendar-input.svg") no-repeat 100% 50% background: url("../../assets/icons/calendar-input.svg") no-repeat 100% 50%
&::-webkit-calendar-picker-indicator &::-webkit-calendar-picker-indicator

View File

@@ -42,5 +42,5 @@ export default {
.input-wrapper .input-wrapper
border-radius: 4px border-radius: 4px
background-color: var(--default-white) background-color: var(--default-white)
color: var(--font-dark-blue-color) color: var(--font-black-color)
</style> </style>

View File

@@ -1,6 +1,8 @@
<template lang="pug"> <template lang="pug">
.base-select(@click="open = !open", :class="{'open': open, 'border-none': borderNone}") .base-select(@click="open = !open", :class="{'open': open, 'border-none': borderNone}")
.placeholder.text-base(:class="{'value-color': value}") {{ value || placeholder }} .placeholder.text-base(:class="{'value-color': value}") {{ value || placeholder }}
.flex.items-center
.select-form-separator.cursor-pointer.mr-4(v-if="separator")
span.icon-down-arrow.open-icon(:class="{'open': open }") span.icon-down-arrow.open-icon(:class="{'open': open }")
base-menu(v-if="open") base-menu(v-if="open")
.items-container(@click="open = false", @mouseleave="leaveSelect") .items-container(@click="open = false", @mouseleave="leaveSelect")
@@ -20,6 +22,7 @@ export default {
default: () => [], default: () => [],
}, },
borderNone: Boolean, borderNone: Boolean,
separator: Boolean,
}, },
emits: ["update:modelValue"], emits: ["update:modelValue"],
data() { data() {
@@ -96,4 +99,9 @@ export default {
border: none border: none
.value-color .value-color
opacity: 1 opacity: 1
.select-form-separator
background-color: var(--btn-blue-color-3)
height: 24px
width: 1px
border-radius: 1px
</style> </style>

View File

@@ -18,6 +18,7 @@
@next-date="switchNextDate" @next-date="switchNextDate"
@selected-layout="changeCalendarLayout" @selected-layout="changeCalendarLayout"
@open-change-form="openFormCreateEvent" @open-change-form="openFormCreateEvent"
@update-events="fetchEventsData"
) )
</template> </template>
@@ -68,10 +69,7 @@ export default {
saveMembersData(res) { saveMembersData(res) {
this.membersData = res.results; this.membersData = res.results;
}, },
fetchEventsData() { fetchPersonsData() {
fetchWrapper
.get("registry/event/")
.then((res) => this.saveEventsData(res));
fetchWrapper fetchWrapper
.get("general/employee/") .get("general/employee/")
.then((res) => this.saveEmployeesData(res)); .then((res) => this.saveEmployeesData(res));
@@ -79,6 +77,11 @@ export default {
.get("general/person/") .get("general/person/")
.then((res) => this.saveMembersData(res)); .then((res) => this.saveMembersData(res));
}, },
fetchEventsData() {
fetchWrapper
.get("registry/event/")
.then((res) => this.saveEventsData(res));
},
changeWidth(value) { changeWidth(value) {
this.sidebarWidth = value; this.sidebarWidth = value;
}, },
@@ -90,6 +93,7 @@ export default {
}, },
}, },
mounted() { mounted() {
this.fetchPersonsData();
this.fetchEventsData(); this.fetchEventsData();
}, },
}; };

View File

@@ -13,7 +13,7 @@
border-none border-none
) )
base-input( base-input(
v-if="selectedEventData.employees", v-else,
v-model:value="employeeName", v-model:value="employeeName",
:width-input="72", :width-input="72",
disabled, disabled,
@@ -46,7 +46,7 @@
border-none border-none
) )
base-input( base-input(
v-if="selectedEventData.members", v-else,
v-model:value="memberName", v-model:value="memberName",
disabled, disabled,
:width-input="346" :width-input="346"
@@ -85,14 +85,22 @@
placeholder="E-mail" placeholder="E-mail"
:width-input="72" :width-input="72"
) )
base-button.styled-button.text-base.font-semibold( base-button.create-button.text-base.font-semibold(
:size="40" v-if="!selectedEventData.id",
:disabled="disabledButton" :size="40",
:disabled="disabledCreateButton",
@click="sendEventData" @click="sendEventData"
) Создать событие ) Создать событие
base-button.update-button.text-base.font-semibold(
v-else,
:size="40",
:disabled="disabledUpdateButton",
@click="updateEventData",
) Сохранить
</template> </template>
<script> <script>
import { fetchWrapper } from "@/shared/fetchWrapper.js";
import BaseInputTime from "@/components/base/BaseInputTime.vue"; import BaseInputTime from "@/components/base/BaseInputTime.vue";
import BaseInput from "@/components/base/BaseInput.vue"; import BaseInput from "@/components/base/BaseInput.vue";
import BaseInputDate from "@/components/base/BaseInputDate.vue"; import BaseInputDate from "@/components/base/BaseInputDate.vue";
@@ -196,7 +204,6 @@ export default {
contacts: elem.contacts, contacts: elem.contacts,
}); });
}); });
console.log(filteredArray);
return filteredArray; return filteredArray;
} }
return []; return [];
@@ -228,19 +235,32 @@ export default {
} }
return ""; return "";
}, },
disabledButton() { disabledCreateButton() {
if ( if (
this.eventDate && this.eventDate &&
this.startTime && this.startTime &&
this.endTime && this.endTime &&
this.members && this.members.person &&
this.employees && this.employees.employee &&
this.kind this.kind
) { ) {
return false; return false;
} }
return true; return true;
}, },
disabledUpdateButton() {
let start = moment.parseZone(this.selectedEventData.start);
let end = moment.parseZone(this.selectedEventData.end);
if (
this.eventDate === start.format("YYYY-MM-DD") &&
this.startTime === start.format("HH:mm") &&
this.endTime === end.format("HH:mm") &&
this.kind === this.selectedEventData.kind
) {
return true;
}
return false;
},
startDate() { startDate() {
return this.selectedEventData.start return this.selectedEventData.start
? moment.parseZone(this.selectedEventData.start) ? moment.parseZone(this.selectedEventData.start)
@@ -256,29 +276,27 @@ export default {
return this.selectedEventData.employees; return this.selectedEventData.employees;
} }
return { return {
id: null,
employee: null, employee: null,
role: this.EMPLOYEE_TYPE, role: this.EMPLOYEE_TYPE,
}; };
}, },
eventMember() {
return this.selectedEventData.members
? this.selectedEventData.members
: {
person: null,
role: this.MEMBER_TYPE,
};
},
eventKind() { eventKind() {
return this.selectedEventData.kind ? this.selectedEventData.kind : ""; return this.selectedEventData.kind ? this.selectedEventData.kind : "";
}, },
eventId() { eventId() {
return this.selectedEventData.id ? this.selectedEventData.id : ""; return this.selectedEventData.id ? this.selectedEventData.id : "";
}, },
eventMember() {
return this.selectedEventData.members
? this.selectedEventData.members
: {
id: null,
person: null,
role: this.MEMBER_TYPE,
};
},
kindSelectWidth() { kindSelectWidth() {
return { return {
width: this.kind ? `${this.kind.length * 9 + 65}px` : "164px", width: this.kind ? `${this.kind.length * 9 + 86}px` : "180px",
}; };
}, },
}, },
@@ -298,25 +316,33 @@ export default {
}, },
sendEventData() { sendEventData() {
this.eventData = { this.eventData = {
id: this.id,
start: this.mergeDate(this.eventDate, this.startTime), start: this.mergeDate(this.eventDate, this.startTime),
end: this.mergeDate(this.eventDate, this.endTime), end: this.mergeDate(this.eventDate, this.endTime),
kind: this.kind, kind: this.kind,
employees: this.selectedEventData.employees employees: this.findPerson(
? this.employees
: this.findEmployee(
this.ownersData, this.ownersData,
this.ownersList, this.ownersList,
this.employees.employee this.employees,
"employee"
), ),
members: this.selectedEventData.members members: this.findPerson(
? this.members
: this.findMember(
this.membersData, this.membersData,
this.membersList, this.membersList,
this.members.person this.members,
"person"
), ),
}; };
this.postCreateEvent(this.eventData);
this.clearForm();
this.eventData = {};
},
updateEventData() {
this.eventData = {
start: this.mergeDate(this.eventDate, this.startTime),
end: this.mergeDate(this.eventDate, this.endTime),
kind: this.kind,
};
this.postUpdateEvent(this.id, this.eventData);
this.clearForm(); this.clearForm();
this.eventData = {}; this.eventData = {};
}, },
@@ -325,37 +351,31 @@ export default {
this.closeForm(); this.closeForm();
}, },
mergeDate(eventDate, time) { mergeDate(eventDate, time) {
return moment(`${eventDate} ${time}`).format(); return moment(`${eventDate} ${time}`).format("YYYY-MM-DDTHH:mm:ss");
}, },
findEmployee(requestedList, serializedList, employee) { findPerson(requestedList, serializedList, object, field) {
let foundId = serializedList.find(({ label }) => label === employee).id; let foundId = serializedList.find(
({ label }) => label === object[field]
).id;
let foundPerson = requestedList.find(({ id }) => id === foundId); let foundPerson = requestedList.find(({ id }) => id === foundId);
return { return {
id: this.employees.id, [field]: {
employee: {
id: foundPerson.id, id: foundPerson.id,
last_name: foundPerson.last_name, last_name: foundPerson.last_name,
first_name: foundPerson.first_name, first_name: foundPerson.first_name,
patronymic: foundPerson.patronymic, patronymic: foundPerson.patronymic,
color: foundPerson.color, color: foundPerson.color,
}, },
role: this.employees.role, role: object.role,
}; };
}, },
findMember(requestedList, serializedList, member) { postCreateEvent(event) {
let foundId = serializedList.find(({ label }) => label === member).id; fetchWrapper.post("registry/event/create/", event);
let foundPerson = requestedList.find(({ id }) => id === foundId);
return {
id: this.members.id,
person: {
id: foundPerson.id,
last_name: foundPerson.last_name,
first_name: foundPerson.first_name,
patronymic: foundPerson.patronymic,
color: foundPerson.color,
}, },
role: this.members.role, postUpdateEvent(id, event) {
}; fetchWrapper
.post(`registry/event/${id}/update/`, event)
.then(this.$emit("update-events"));
}, },
}, },
watch: { watch: {
@@ -435,8 +455,10 @@ export default {
color: var(--font-dark-blue-color) color: var(--font-dark-blue-color)
&:hover &:hover
color: var(--btn-blue-color) color: var(--btn-blue-color)
.styled-button .create-button
width: 183px width: 183px
.select .select
height: 40px height: 40px
.update-button
width: 132px
</style> </style>

View File

@@ -49,6 +49,7 @@
:members-data="membersData" :members-data="membersData"
:selected-event-data="selectedEvent" :selected-event-data="selectedEvent"
@clear-selected-event-data="clearSelectedEvent" @clear-selected-event-data="clearSelectedEvent"
@update-events="transmitUpdateEvents"
) )
</template> </template>
@@ -311,6 +312,9 @@ export default {
clearSelectedEvent() { clearSelectedEvent() {
this.selectedEvent = {}; this.selectedEvent = {};
}, },
transmitUpdateEvents() {
this.$emit("update-events");
},
}, },
watch: { watch: {
currentTime() { currentTime() {