Merge branch 'UC-202' into 'master'

[WIP] Добавил delete, возможность создания события на 1 день, поправил стили,...

See merge request andrusyakka/urban-couscous!244
This commit is contained in:
Vasiliy Gavrilin
2023-01-09 14:21:07 +00:00
3 changed files with 87 additions and 66 deletions

View File

@@ -17,6 +17,8 @@
:start-month="startMonth", :start-month="startMonth",
:clear-employee="clearEmployee", :clear-employee="clearEmployee",
:show-time="showTime", :show-time="showTime",
:clear-select="clearSelect",
:select-employee="selectEmployee",
@schedule-employee="createScheduleEmployee", @schedule-employee="createScheduleEmployee",
@schedules="distributeRequest" @schedules="distributeRequest"
) )
@@ -24,6 +26,7 @@
:buttons="buttons", :buttons="buttons",
:times="times", :times="times",
:create-schedules="postCreateSchedules", :create-schedules="postCreateSchedules",
:delete-schedule="deleteSchedule"
) )
</template> </template>
@@ -43,6 +46,10 @@ export default {
scheduleList: [], scheduleList: [],
clearEmployee: [], clearEmployee: [],
serialized: [], serialized: [],
selectEmployee: {
label: "",
id: null,
},
times: { start_time: "", end_time: "" }, times: { start_time: "", end_time: "" },
timesShift: { start_time: "", end_time: "" }, timesShift: { start_time: "", end_time: "" },
buttons: [ buttons: [
@@ -59,7 +66,7 @@ export default {
name: "Отпуск/больничный", name: "Отпуск/больничный",
work: "VACATION", work: "VACATION",
active: false, active: false,
color: "#D7D9FF", color: "var(--btn-blue-color-2)",
text: "'О'", text: "'О'",
}, },
{ {
@@ -73,7 +80,6 @@ export default {
], ],
startMonth: moment().startOf("month"), startMonth: moment().startOf("month"),
showTime: false, showTime: false,
currentEmployee: {},
schedulesDate: {}, schedulesDate: {},
}; };
}, },
@@ -86,6 +92,15 @@ export default {
changeShowTime() { changeShowTime() {
this.showTime = !this.showTime; this.showTime = !this.showTime;
}, },
clearSelect(employee) {
if (employee) {
employee.label = "";
employee.id = null;
} else {
this.selectEmployee.label = "";
this.selectEmployeeid = null;
}
},
fetchSchedules() { fetchSchedules() {
fetchWrapper fetchWrapper
.get("general/employee/") .get("general/employee/")
@@ -96,6 +111,7 @@ export default {
}, },
fetchSchedulesEmployee() { fetchSchedulesEmployee() {
this.scheduleList = []; this.scheduleList = [];
this.clearSelect();
fetchWrapper fetchWrapper
.get( .get(
`accounts/schedules/?date_after=${this.startMonth.format( `accounts/schedules/?date_after=${this.startMonth.format(
@@ -150,10 +166,9 @@ export default {
this.serialized.every((el) => el.id !== item.id) this.serialized.every((el) => el.id !== item.id)
); );
}, },
distributeRequest(inside, outside, currentEmployee) { distributeRequest(inside, outside) {
this.insideSchedules = inside; this.insideSchedules = inside;
this.outsideSchedules = outside; this.outsideSchedules = outside;
this.currentEmployee = currentEmployee;
}, },
postCreateSchedules() { postCreateSchedules() {
let data = { let data = {
@@ -198,16 +213,21 @@ export default {
.then(() => this.fetchSchedules()); .then(() => this.fetchSchedules());
}, },
createScheduleEmployee(e, id) { createScheduleEmployee(e, id) {
let schedules = {
start_date: e.start,
end_date: e.end,
};
this.schedulesDate = { this.schedulesDate = {
start_date: e.start, start_date: e.start,
end_date: e.end, end_date: e.end ? e.end : e.start,
id: id, id: id,
}; };
this.serialized.find((elem) => elem.id === e.id).schedule = schedules; },
deleteSchedule() {
let ids = "";
if (this.insideSchedules.length > 0) {
this.insideSchedules.forEach((e) => (ids += e.id + ","));
ids = ids.slice(0, -1);
fetchWrapper
.del(`accounts/schedules/${ids}/delete/`)
.then(() => this.fetchSchedules());
}
}, },
switchPreviousMonth() { switchPreviousMonth() {
this.startMonth = this.startMonth.clone().subtract(1, "M"); this.startMonth = this.startMonth.clone().subtract(1, "M");

View File

@@ -15,13 +15,17 @@
:style="{minWidth: '190px', minHeight: '43px', border: item.active ? '1.5px solid #5E5E5E' : 'none'}", :style="{minWidth: '190px', minHeight: '43px', border: item.active ? '1.5px solid #5E5E5E' : 'none'}",
@click="choiceSchedule(item.class)" @click="choiceSchedule(item.class)"
) {{item.name}} ) {{item.name}}
.graph-template.flex .graph-template.flex.flex-col.justify-between
base-custom-select( base-custom-select(
:items="scheduleList", :items="scheduleList",
center, center,
v-model="schedule", v-model="schedule",
placeholder="Шаблоны графиков" placeholder="Шаблоны графиков"
) )
base-button.delete-button.font-semibold(
:size="40",
@click="deleteSchedule"
) Удалить
.flex.justify-center .flex.justify-center
base-button.font-semibold(:size="40", @click="createSchedules") Сохранить base-button.font-semibold(:size="40", @click="createSchedules") Сохранить
</template> </template>
@@ -38,6 +42,7 @@ export default {
buttons: Array, buttons: Array,
times: Object, times: Object,
createSchedules: Function, createSchedules: Function,
deleteSchedule: Function,
}, },
data() { data() {
return { return {
@@ -108,14 +113,15 @@ export default {
border: none border: none
.button-vacation .button-vacation
background: #D7D9FF background: var(--btn-blue-color-2)
border: none border: none
opacity: 1
&:active &:active
background-color: #D7D9FF background: var(--btn-blue-color-2)
opacity: 1 opacity: 1
border: none border: none
&:hover &:hover
background-color: #D7D9FF background: var(--btn-blue-color-2)
opacity: 0.8 opacity: 0.8
border: none border: none
@@ -133,5 +139,9 @@ export default {
.graph-template .graph-template
width: 218px width: 218px
height: 40px height: 102px
.delete-button
background-color: var(--bg-event-red-color)
border: none
</style> </style>

View File

@@ -26,42 +26,41 @@
v-for="day in result", v-for="day in result",
:key="day", :key="day",
:id="schedule.id + day", :id="schedule.id + day",
@click="choiceCell(day, schedule.id, schedule); clearData()", @click="choiceCell(day, schedule.id, schedule); clearSelect(selectEmployee)",
:class="choiceState(day, schedule.id)", :class="choiceState(day, schedule.id)",
:style="{backgroundColor: choiceDay(day, schedule.id) ? choiceColor(day, schedule) : ''}" :style="{backgroundColor: choiceDay(day, schedule.id) ? choiceColor(day, schedule) : ''}"
) )
.flex( .flex(
:class="{'cell-work': choiceState(day, schedule.id).status, 'show-time': showTime}" :class="{'cell-work': choiceState(day, schedule.id).status, 'show-time': showTime}"
) {{choiceDay(day, schedule.id) ? choiceWorks(day, schedule) : ''}} ) {{choiceDay(day, schedule.id) ? choiceWorks(day, schedule) : ''}}
.schedule-select.flex.w-full.pr-2(v-if="clearEmployee") .schedule-select.flex.w-full.pr-2(v-if="clearEmployee")
.edit.flex.items-center.justify-center.h-11.w-11(v-if="currentEmployee.label") .edit.flex.items-center.justify-center.h-11.w-11(v-if="selectEmployee.label")
.flex.icon-edit(v-if="currentEmployee.label") .flex.icon-edit(v-if="selectEmployee.label")
//- base-button( //- base-button(
//- confirm, //- confirm,
//- rounded, //- rounded,
//- outlined, //- outlined,
//- :size="20", //- :size="20",
//- @click="saveEmployee", //- @click="saveEmployee",
//- v-if="currentEmployee.label" //- v-if="selectEmployee.label"
//- ) //- )
//- .icon-ok.text-xsm(class="pt-[3px]") //- .icon-ok.text-xsm(class="pt-[3px]")
.text.flex.justify-center.items-center.cursor-pointer(:class="{'select-name': currentEmployee.label}") .text.flex.justify-center.items-center.cursor-pointer(:class="{'select-name': selectEmployee.label}")
base-custom-select( base-custom-select(
v-if="!currentEmployee.label", v-if="!selectEmployee.label",
:items="ownersList", :items="ownersList",
v-model="currentEmployee", v-model="selectEmployee",
placeholder="Добавить сотрудника", placeholder="Добавить сотрудника",
:style="{border: 'none', justifyContent: 'center'}" :style="{border: 'none', justifyContent: 'center'}"
) )
.flex.justify-center(v-else) {{currentEmployee.label}} .flex.justify-center(v-else) {{selectEmployee.label}}
.cell.flex.flex-col.items-center.justify-center.w-11.h-11.cursor-pointer( .cell.flex.flex-col.items-center.justify-center.w-11.h-11.cursor-pointer(
v-if="currentEmployee.label", v-if="selectEmployee.label",
v-for="day in result", v-for="day in result",
:key="day", :key="day",
:id="currentEmployee.id + day", :id="selectEmployee.id + day",
@click="choiceCell(day, currentEmployee.id)", @click="choiceCell(day, selectEmployee.id)",
:class="choiceState(day, currentEmployee.id)" :class="choiceState(day, selectEmployee.id)"
) )
</template> </template>
@@ -81,16 +80,14 @@ export default {
startMonth: Object, startMonth: Object,
clearEmployee: Array, clearEmployee: Array,
showTime: Boolean, showTime: Boolean,
clearSelect: Function,
selectEmployee: Object,
}, },
data() { data() {
return { return {
days: "", days: "",
result: [], result: [],
employee: [], employee: [],
currentEmployee: {
label: "",
id: null,
},
dateInterval: { dateInterval: {
id: "", id: "",
start: "", start: "",
@@ -98,6 +95,7 @@ export default {
text: "", text: "",
}, },
activeButton: null, activeButton: null,
choiceMonth: null,
}; };
}, },
computed: { computed: {
@@ -143,9 +141,9 @@ export default {
setActiveButton() { setActiveButton() {
this.activeButton = this.buttons.find((e) => e.active); this.activeButton = this.buttons.find((e) => e.active);
}, },
choiceCell(time, id, schedule) { choiceCell(day, id, schedule) {
if (this.showTime) return; if (this.showTime) return;
let formatTime = time.format("YYYY-MM-DD"); let formatTime = day.format("YYYY-MM-DD");
let insideSchedules = schedule?.schedules.filter( let insideSchedules = schedule?.schedules.filter(
(el) => (el) =>
(el.date > this.dateInterval.start && (el.date > this.dateInterval.start &&
@@ -154,11 +152,7 @@ export default {
el.date === this.dateInterval.end el.date === this.dateInterval.end
); );
if ( if (this.dateInterval.id !== id) {
this.dateInterval.start &&
this.dateInterval.end &&
this.dateInterval.id !== id
) {
this.dateInterval.start = ""; this.dateInterval.start = "";
this.dateInterval.end = ""; this.dateInterval.end = "";
this.dateInterval.id = ""; this.dateInterval.id = "";
@@ -167,13 +161,14 @@ export default {
if (!this.dateInterval.start) { if (!this.dateInterval.start) {
this.dateInterval.start = formatTime; this.dateInterval.start = formatTime;
this.dateInterval.id = id; this.dateInterval.id = id;
} else if (time.isAfter(this.dateInterval.start)) { this.$emit("schedule-employee", this.dateInterval, id);
} else if (day.isAfter(this.dateInterval.start)) {
this.dateInterval.end = formatTime; this.dateInterval.end = formatTime;
this.$emit("schedule-employee", this.dateInterval, id); this.$emit("schedule-employee", this.dateInterval, id);
} else this.dateInterval.start = formatTime; } else this.dateInterval.start = formatTime;
if ( if (
!this.currentEmployee.label && !this.selectEmployee.label &&
this.dateInterval.start && this.dateInterval.start &&
this.dateInterval.end && this.dateInterval.end &&
insideSchedules insideSchedules
@@ -206,12 +201,7 @@ export default {
start_date: moment(lastDate).add(1, "d").format("YYYY-MM-DD"), start_date: moment(lastDate).add(1, "d").format("YYYY-MM-DD"),
end_date: this.dateInterval.end, end_date: this.dateInterval.end,
}); });
this.$emit( this.$emit("schedules", insideSchedules, outsideSchedules);
"schedules",
insideSchedules,
outsideSchedules,
this.currentEmployee
);
}, },
choiceState(day, id) { choiceState(day, id) {
let formatDay = day.format("YYYY-MM-DD"); let formatDay = day.format("YYYY-MM-DD");
@@ -232,16 +222,11 @@ export default {
return { return {
status: (resStart || resMiddle || resEnd) && !!this.activeButton, status: (resStart || resMiddle || resEnd) && !!this.activeButton,
"set-time": this.showTime, "set-date":
"from-date": !!resStart && !this.activeButton, (!!resStart || !!resMiddle || !!resEnd) && !this.activeButton,
"to-date": !!resEnd && !this.activeButton,
"middle-dates": !!resMiddle && !this.activeButton,
}; };
}, },
clearData() {
this.currentEmployee.label = "";
this.currentEmployee.id = null;
},
choiceWorks(day, employee) { choiceWorks(day, employee) {
if (this.showTime) { if (this.showTime) {
return this.choiceTime(employee, day); return this.choiceTime(employee, day);
@@ -259,9 +244,10 @@ export default {
return this.buttons.find((e) => e.work === res)?.color; return this.buttons.find((e) => e.work === res)?.color;
}, },
changeDays() { changeDays() {
this.days = moment().daysInMonth(); this.days = moment(this.choiceMonth, "YYYY-MM-DD").daysInMonth();
}, },
pushMonth() { pushMonth() {
this.result = [];
this.result.push(this.startMonth); this.result.push(this.startMonth);
for (let i = 2; i <= this.days; i++) { for (let i = 2; i <= this.days; i++) {
this.result.push(this.startMonth.clone().add(i - 1, "d")); this.result.push(this.startMonth.clone().add(i - 1, "d"));
@@ -285,7 +271,18 @@ export default {
: "1"; : "1";
}, },
}, },
watch: {
startMonth: {
immediate: true,
handler(newMonth) {
if (newMonth) {
this.choiceMonth = newMonth.format("YYYY-MM-DD");
this.changeDays();
this.pushMonth();
}
},
},
},
mounted() { mounted() {
this.changeDays(); this.changeDays();
this.pushMonth(); this.pushMonth();
@@ -318,7 +315,6 @@ export default {
border-top-right-radius: 2px border-top-right-radius: 2px
.schedule-select .schedule-select
border-top: 1.5px solid var(--border-light-grey-color-1)
&:hover &:hover
background-color: var(--border-light-grey-color-1) background-color: var(--border-light-grey-color-1)
@@ -339,6 +335,7 @@ export default {
.select-name .select-name
width: 25% width: 25%
border-right: 1.5px solid var(--border-light-grey-color-1) border-right: 1.5px solid var(--border-light-grey-color-1)
border-bottom: 1.5px solid var(--border-light-grey-color-1)
.name-employee .name-employee
width: 25% width: 25%
@@ -369,12 +366,6 @@ export default {
.status::after .status::after
content: var(--text-status) content: var(--text-status)
.from-date .set-date
background-color: limegreen !important background-color: var(--btn-blue-color-4) !important
.to-date
background-color: red !important
.middle-dates
background-color: yellow !important
</style> </style>