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