P-42 Автор не удаляется

This commit is contained in:
iriska-gri committed 2024-07-03 13:59:45 +03:00
1 parent e87a9f9fc8
commit 58ff68bcdc
3 files changed
+119 -87

No files matched your search

+4 -3
View File
@@ -105,10 +105,11 @@ class TableEventParticipantSerializer(serializers.ModelSerializer):
class EmployeeSerializer(serializers.ModelSerializer):
title = serializers.CharField(source='name')
selected=serializers.BooleanField(default=False)
editor=serializers.BooleanField(default=False)
employees = serializers.SerializerMethodField('get_deps')
class Meta:
model = DictDepartment
fields = ["title","id","employees",'selected']
fields = ["title","id","employees",'selected', 'editor']
def get_deps(self,obj):
@@ -122,11 +123,11 @@ class UserSerializerBase(serializers.ModelSerializer):
fields = ['title', "id" ]
class UsersSerializer(UserSerializerBase):
editor=serializers.BooleanField(default=False)
selected=serializers.BooleanField(default=False)
class Meta:
model = DictEmployee
fields = ['title', "id", 'id_dict_department','selected' ]
fields = ['title', "id", 'id_dict_department','selected','editor' ]
class DeleteCalendarSerializer(serializers.Serializer):
@@ -1,8 +1,4 @@
<template>
<!-- <div>
{{staff}}
</div> -->
<v-autocomplete
v-model="selectedStaff"
:items="staff"
@@ -39,7 +35,7 @@
<template v-slot:prepend>
<v-checkbox-btn
:model-value="staff.every((e) => e.selected == true)"
:model-value="staff.every((e) => e[okey] == true)"
></v-checkbox-btn>
</template>
</v-list-item>
@@ -63,10 +59,10 @@
:true-value="true"
:false-value="false"
:indeterminate="
item.raw.employees.some((e) => e.selected == true) &&
!item.raw.employees.every((e) => e.selected == true)
item.raw.employees.some((e) => e[okey] == true) &&
!item.raw.employees.every((e) => e[okey] == true)
"
:model-value="item.raw.selected"
:model-value="item.raw[okey]"
></v-checkbox-btn>
</template>
</v-list-item>
@@ -84,7 +80,7 @@
<template v-slot:prepend>
<v-checkbox-btn
color="indigo-darken-4"
:model-value="x.selected"
:model-value="x[okey]"
:disabled="x.id == accountStore.user.is_idEmployee"
></v-checkbox-btn>
</template>
@@ -106,32 +102,30 @@ export default {
type: Array,
default: () => [],
},
okey: {
type: String,
default: "selected",
},
},
setup(props, { emit }) {
const filtered = ref("");
const accountStore = useAccountStore();
const back = ref([])
const back = ref([]);
const selectedStaff = computed({
get() {
let selected = [];
let idEmployees = [];
props.staff.forEach((e) => {
e.employees
.filter((n) => n.selected == true)
.forEach((res) => {
idEmployees.push({
participant_calendar: res.id,
});
});
if (e.employees.every((n) => n.selected == true)) {
e.selected = true;
// e.employees.filter(n => n[props.okey] == true)
if (e.employees.every((n) => n[props.okey] == true)) {
e[props.okey] = true;
selected.push(e);
} else {
e.selected = false;
selected.push(...e.employees.filter((n) => n.selected == true));
e[props.okey] = false;
selected.push(...e.employees.filter((n) => n[props.okey] == true));
}
});
return selected;
@@ -140,37 +134,44 @@ export default {
set(item) {
if ("employees" in item) {
item.employees.forEach((e) => {
if (e.id != accountStore.user.is_idEmployee) {
e.selected = !e.selected;
}
account(e);
});
// console.log()
console.log(item, "item.employeesitem.employees");
emit("returnIdParticant", item.employees);
} else if (item.length) {
let val = item.every((e) => e.selected == true) ? false : true;
cbstaff(item, val);
console.log(item)
emit("returnIdParticant", back.value);
emit("returnIdParticant", {
okey: props.okey,
staff: item.employees,
});
} else if (item.length) {
let val = item.every((e) => e[props.okey] == true) ? false : true;
cbstaff(item, val);
emit("returnIdParticant", { okey: props.okey, staff: back.value });
} else {
item.selected = !item.selected;
emit("returnIdParticant", [item]);
account(item)
emit("returnIdParticant", { okey: props.okey, staff: [item] });
}
},
});
const cbstaff = (item, value) => {
item.forEach((e) => {
if (e.id != accountStore.user.is_idEmployee) {
e.selected = value;
const account = (val) => {
if (props.okey == "selected") {
if (val.id != accountStore.user.is_idEmployee) {
val.selected = !val.selected;
} else {
val.editor = !val.editor;
}
}
};
if (!("employees" in e)) {
back.value.push(e)
}
const cbstaff = (item, value) => {
item.forEach((e) => {
account(e);
if (!("employees" in e)) {
back.value.push(e);
}
if ("employees" in e) {
cbstaff(e.employees, value);
}
@@ -45,18 +45,11 @@
<v-row no-gutters class="align-center pb-3">
<v-col class="text-body-2 text-text_grey" lg="2"> Участники </v-col>
<v-col>
<calendar-create-select
:staff="newStaff"
@returnIdParticant="returnIdParticant"
/>
<!-- <calendar-create-select
:participant="propsCalendar.participant"
@returnIdParticant="returnIdParticant"
/>
--></v-col
></v-row
>
/> </v-col
></v-row>
</v-col>
<v-col class="d-flex flex-grow-0">
<v-textarea
@@ -74,6 +67,11 @@
<v-row no-gutters class="align-center">
<v-col class="text-body-2 text-text_grey" lg="2"> Редакторы </v-col>
<v-col>
<calendar-create-select
:staff="newStaff.filter(e=>e.employees.some(n=>n.selected==true))"
:okey="'editor'"
@returnIdParticant="returnIdParticant"
/>
<!-- <calendar-create-select
:editor="true"
:participant="
@@ -118,29 +116,47 @@ export default {
},
setup(props, { emit }) {
const postParticant = {};
const form_calendar = ref(null);
const for_editor = ref([]);
const accountStore = useAccountStore();
const returnIdParticant = (idPart, selected) => {
idPart.forEach((e) => {
if(e.selected == true) {
propsCalendar.value.participant.push({ "editor": false, "participant_calendar": e.id })
const returnIdParticant = (idPart) => {
idPart.staff.forEach((e) => {
if(idPart.okey == 'editor') {
let ind = propsCalendar.value.participant.findIndex(
(l) => l.participant_calendar == e.id
)
if (ind >= 0) {
propsCalendar.value.participant[ind].editor = e.editor
}
else {
propsCalendar.value.participant.push({
editor: e.editor,
participant_calendar: e.id,
});
}
}
else {
let ind = propsCalendar.value.participant.findIndex(l => l.participant_calendar == e.id
)
propsCalendar.value.participant.splice(ind, 1)
if (e.selected == true) {
propsCalendar.value.participant.push({
editor: false,
participant_calendar: e.id,
});
} else {
let ind = propsCalendar.value.participant.findIndex(
(l) => l.participant_calendar == e.id
);
propsCalendar.value.participant.splice(ind, 1);
}
})
// postParticant.value = { ...props.calendar, participant: propsCalendar.value.participant };
// console.log(postParticant.value, 'postParticant.value')
}
});
};
const propsCalendar = computed({
@@ -172,7 +188,10 @@ export default {
const postCalendar = (val) => {
if (val) {
axiosApiInstance
.post(`api/calendar_of_events/my_calendars/`, { ...props.calendar, participant: propsCalendar.value.participant })
.post(`api/calendar_of_events/my_calendars/`, {
...props.calendar,
participant: propsCalendar.value.participant,
})
.then((result) => {
feedalert.alert = true;
feedalert.text = result.data.mess;
@@ -191,32 +210,42 @@ export default {
.then((res) => {
// console.log(res.data, "res.data");
staff.value = res.data.filter((e) => e.employees.length > 0);
console.log(staff.value, "propsCalendar.value");
});
const newStaff = computed({get() {
staff.value.forEach((e) => {
const editorStaff = computed({
get() {
// console.log(staff.value, '111111111111111111')
// console.log(propsCalendar.value.participant, 'propsCalendar.value.participantpropsCalendar.value.participant')
// let r= staff.value.filter(e=> e.selected ==true)
// return r
}
})
const newStaff = computed({
get() {
staff.value.forEach((e) => {
if (propsCalendar.value.participant.length > 0) {
e.employees.forEach((empl) => {
if (
let a =
propsCalendar.value.participant.find(
(a) => a.participant_calendar === empl.id
)
if (
a
) {
empl.selected = true;
empl.editor = a.editor
}
});
}
})
return staff.value
}
}
)
});
return staff.value;
},
});
const color = [
"red",
@@ -273,7 +302,8 @@ export default {
titleCard,
newCalendar,
staff,
newStaff
newStaff,
editorStaff
};
},
};