удаление line результа при создании дерева
This commit is contained in:
parent
6482598841
commit
f86405ff22
@ -1,13 +1,12 @@
|
|||||||
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||||
import Cytoscape from "cytoscape";
|
import Cytoscape from "cytoscape";
|
||||||
import { Button } from "@mui/material";
|
|
||||||
import CytoscapeComponent from "react-cytoscapejs";
|
import CytoscapeComponent from "react-cytoscapejs";
|
||||||
import popper from "cytoscape-popper";
|
import popper from "cytoscape-popper";
|
||||||
import { useCurrentQuiz } from "@root/quizes/hooks";
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||||
import { updateRootContentId } from "@root/quizes/actions"
|
import { updateRootContentId } from "@root/quizes/actions"
|
||||||
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared"
|
import { AnyTypedQuizQuestion } from "@model/questionTypes/shared"
|
||||||
import { useQuestionsStore } from "@root/questions/store";
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
import { deleteQuestion, cleardragQuestionContentId, updateQuestion, updateOpenedModalSettingsId, getQuestionByContentId, clearRuleForAll } from "@root/questions/actions";
|
import { cleardragQuestionContentId, updateQuestion, updateOpenedModalSettingsId, getQuestionByContentId, clearRuleForAll, deleteQuestion } from "@root/questions/actions";
|
||||||
import { withErrorBoundary } from "react-error-boundary";
|
import { withErrorBoundary } from "react-error-boundary";
|
||||||
|
|
||||||
import { storeToNodes } from "./helper";
|
import { storeToNodes } from "./helper";
|
||||||
@ -112,6 +111,9 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let zoomTimeout = null
|
||||||
|
|
||||||
|
|
||||||
function CsComponent({
|
function CsComponent({
|
||||||
modalQuestionParentContentId,
|
modalQuestionParentContentId,
|
||||||
modalQuestionTargetContentId,
|
modalQuestionTargetContentId,
|
||||||
@ -216,6 +218,7 @@ function CsComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const removeNode = ({ targetNodeContentId }: { targetNodeContentId: string }) => {
|
const removeNode = ({ targetNodeContentId }: { targetNodeContentId: string }) => {
|
||||||
const deleteNodes = [] as string[]
|
const deleteNodes = [] as string[]
|
||||||
const deleteEdges: any = []
|
const deleteEdges: any = []
|
||||||
@ -331,6 +334,7 @@ function CsComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (startCreate) {
|
if (startCreate) {
|
||||||
addNode({ parentNodeContentId: startCreate });
|
addNode({ parentNodeContentId: startCreate });
|
||||||
@ -348,7 +352,6 @@ function CsComponent({
|
|||||||
|
|
||||||
|
|
||||||
const readyLO = (e) => {
|
const readyLO = (e) => {
|
||||||
console.log('REAdy')
|
|
||||||
if (e.cy.data('firstNode') === 'nonroot') {
|
if (e.cy.data('firstNode') === 'nonroot') {
|
||||||
e.cy.data('firstNode', 'root')
|
e.cy.data('firstNode', 'root')
|
||||||
e.cy.nodes().sort((a, b) => (a.data('root') ? 1 : -1)).layout(lyopts).run()
|
e.cy.nodes().sort((a, b) => (a.data('root') ? 1 : -1)).layout(lyopts).run()
|
||||||
@ -433,7 +436,6 @@ function CsComponent({
|
|||||||
task.task.forEach(n => {
|
task.task.forEach(n => {
|
||||||
const width = n.data('subtreeWidth')
|
const width = n.data('subtreeWidth')
|
||||||
|
|
||||||
console.log('ORORORORO', n.data(), yoffset, width, oldPos, task.parent.data('subtreeWidth'))
|
|
||||||
n.data('oldPos', { x: 250 * n.data('layer'), y: yoffset + width / 2 })
|
n.data('oldPos', { x: 250 * n.data('layer'), y: yoffset + width / 2 })
|
||||||
yoffset += width
|
yoffset += width
|
||||||
queue.push({ task: n.cy().edges(`[source="${n.id()}"]`).targets(), parent: n })
|
queue.push({ task: n.cy().edges(`[source="${n.id()}"]`).targets(), parent: n })
|
||||||
@ -462,7 +464,6 @@ function CsComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('KEKEKE')
|
|
||||||
document.querySelector("#root")?.addEventListener("mouseup", cleardragQuestionContentId);
|
document.querySelector("#root")?.addEventListener("mouseup", cleardragQuestionContentId);
|
||||||
const cy = cyRef.current;
|
const cy = cyRef.current;
|
||||||
const eles = cy?.add(storeToNodes(questions.filter((question: AnyTypedQuizQuestion) => (question.type !== "result" && question.type !== null))))
|
const eles = cy?.add(storeToNodes(questions.filter((question: AnyTypedQuizQuestion) => (question.type !== "result" && question.type !== null))))
|
||||||
@ -510,7 +511,6 @@ function CsComponent({
|
|||||||
if (!container) {
|
if (!container) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log('POP')
|
|
||||||
|
|
||||||
container.style.overflow = "hidden";
|
container.style.overflow = "hidden";
|
||||||
|
|
||||||
@ -540,7 +540,6 @@ function CsComponent({
|
|||||||
const bb = n.boundingBox()
|
const bb = n.boundingBox()
|
||||||
return bb.x2 > ext.x1 && bb.x1 < ext.x2 && bb.y2 > ext.y1 && bb.y1 < ext.y2
|
return bb.x2 > ext.x1 && bb.x1 < ext.x2 && bb.y2 > ext.y1 && bb.y1 < ext.y2
|
||||||
})
|
})
|
||||||
console.log('POPE')
|
|
||||||
|
|
||||||
nodesInView
|
nodesInView
|
||||||
.toArray()
|
.toArray()
|
||||||
@ -553,7 +552,6 @@ function CsComponent({
|
|||||||
modifiers: [{ name: "flip", options: { boundary: node } }],
|
modifiers: [{ name: "flip", options: { boundary: node } }],
|
||||||
},
|
},
|
||||||
content: ([item]) => {
|
content: ([item]) => {
|
||||||
console.log('POPPER', item.id())
|
|
||||||
const itemId = item.id();
|
const itemId = item.id();
|
||||||
const itemElement = layoutsContainer.current?.querySelector(
|
const itemElement = layoutsContainer.current?.querySelector(
|
||||||
`.popper-layout[data-id='${itemId}']`
|
`.popper-layout[data-id='${itemId}']`
|
||||||
@ -583,7 +581,6 @@ function CsComponent({
|
|||||||
modifiers: [{ name: "flip", options: { boundary: node } }],
|
modifiers: [{ name: "flip", options: { boundary: node } }],
|
||||||
},
|
},
|
||||||
content: ([item]) => {
|
content: ([item]) => {
|
||||||
console.log('POPPER+', item.id())
|
|
||||||
const itemId = item.id();
|
const itemId = item.id();
|
||||||
const itemElement = plusesContainer.current?.querySelector(
|
const itemElement = plusesContainer.current?.querySelector(
|
||||||
`.popper-plus[data-id='${itemId}']`
|
`.popper-plus[data-id='${itemId}']`
|
||||||
@ -612,7 +609,6 @@ function CsComponent({
|
|||||||
modifiers: [{ name: "flip", options: { boundary: node } }],
|
modifiers: [{ name: "flip", options: { boundary: node } }],
|
||||||
},
|
},
|
||||||
content: ([item]) => {
|
content: ([item]) => {
|
||||||
console.log('POPPERx', item.id())
|
|
||||||
const itemId = item.id();
|
const itemId = item.id();
|
||||||
const itemElement = crossesContainer.current?.querySelector(
|
const itemElement = crossesContainer.current?.querySelector(
|
||||||
`.popper-cross[data-id='${itemId}']`
|
`.popper-cross[data-id='${itemId}']`
|
||||||
@ -643,7 +639,6 @@ function CsComponent({
|
|||||||
modifiers: [{ name: "flip", options: { boundary: node } }],
|
modifiers: [{ name: "flip", options: { boundary: node } }],
|
||||||
},
|
},
|
||||||
content: ([item]) => {
|
content: ([item]) => {
|
||||||
console.log('POPPERg', item.id())
|
|
||||||
const itemId = item.id();
|
const itemId = item.id();
|
||||||
if (item.cy().edges(`[target="${itemId}"]`).sources().length === 0) {
|
if (item.cy().edges(`[target="${itemId}"]`).sources().length === 0) {
|
||||||
return;
|
return;
|
||||||
@ -670,7 +665,6 @@ function CsComponent({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const update = async () => {
|
const update = async () => {
|
||||||
console.log('POPPERi=u', item.id())
|
|
||||||
await plusesPopper.update();
|
await plusesPopper.update();
|
||||||
await crossesPopper.update();
|
await crossesPopper.update();
|
||||||
await gearsPopper.update();
|
await gearsPopper.update();
|
||||||
@ -678,7 +672,11 @@ function CsComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onZoom = (event: AbstractEventObject) => {
|
const onZoom = (event: AbstractEventObject) => {
|
||||||
console.log('ZOOOOM')
|
if (zoomTimeout) clearTimeout(zoomTimeout)
|
||||||
|
zoomTimeout = setTimeout(() => {
|
||||||
|
update()
|
||||||
|
}, 300)
|
||||||
|
|
||||||
const zoom = event.cy.zoom();
|
const zoom = event.cy.zoom();
|
||||||
|
|
||||||
//update();
|
//update();
|
||||||
@ -735,13 +733,13 @@ function CsComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
//node?.on("position", update);
|
//node?.on("position", update);
|
||||||
let pressed = false
|
let pressed = false
|
||||||
let hide = false
|
let hide = false
|
||||||
cy?.on('mousedown',() => {pressed = true})
|
cy?.on('mousedown', () => { pressed = true })
|
||||||
cy?.on('mouseup',() => {
|
cy?.on('mouseup', () => {
|
||||||
pressed = false
|
pressed = false
|
||||||
hide = false
|
hide = false
|
||||||
|
|
||||||
|
|
||||||
const gc = gearsContainer.current
|
const gc = gearsContainer.current
|
||||||
if (gc) gc.style.display = 'block'
|
if (gc) gc.style.display = 'block'
|
||||||
@ -751,46 +749,29 @@ let pressed = false
|
|||||||
if (pc) pc.style.display = 'block'
|
if (pc) pc.style.display = 'block'
|
||||||
if (xc) xc.style.display = 'block'
|
if (xc) xc.style.display = 'block'
|
||||||
if (lc) lc.style.display = 'block'
|
if (lc) lc.style.display = 'block'
|
||||||
update()
|
update()
|
||||||
})
|
})
|
||||||
|
|
||||||
cy?.on('mousemove',() => {
|
cy?.on('mousemove', () => {
|
||||||
if (pressed && !hide) {
|
if (pressed && !hide) {
|
||||||
hide = true
|
hide = true
|
||||||
const gc = gearsContainer.current
|
const gc = gearsContainer.current
|
||||||
if (gc) gc.style.display = 'none'
|
if (gc) gc.style.display = 'none'
|
||||||
const pc = plusesContainer.current
|
const pc = plusesContainer.current
|
||||||
const xc = crossesContainer.current
|
const xc = crossesContainer.current
|
||||||
const lc = layoutsContainer.current
|
const lc = layoutsContainer.current
|
||||||
if (pc) pc.style.display = 'none'
|
if (pc) pc.style.display = 'none'
|
||||||
if (xc) xc.style.display = 'none'
|
if (xc) xc.style.display = 'none'
|
||||||
if (lc) lc.style.display = 'block'
|
if (lc) lc.style.display = 'block'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
cy?.on("zoom render", onZoom);
|
cy?.on("zoom render", onZoom);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Button
|
|
||||||
sx={{
|
|
||||||
mb: "20px",
|
|
||||||
height: "27px",
|
|
||||||
color: "#7E2AEA",
|
|
||||||
textDecoration: "underline",
|
|
||||||
fontSize: "16px",
|
|
||||||
}}
|
|
||||||
variant="text"
|
|
||||||
onClick={() => {
|
|
||||||
|
|
||||||
//код сюда
|
|
||||||
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Выровнять
|
|
||||||
</Button>
|
|
||||||
<CytoscapeComponent
|
<CytoscapeComponent
|
||||||
wheelSensitivity={0.1}
|
wheelSensitivity={0.1}
|
||||||
elements={[]}
|
elements={[]}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Box } from "@mui/material"
|
import { Box } from "@mui/material"
|
||||||
import { useEffect, useRef, useState } from "react";
|
import { useEffect, useRef, useState } from "react";
|
||||||
import { updateDragQuestionContentId, updateQuestion } from "@root/questions/actions"
|
import { deleteQuestion, updateDragQuestionContentId, updateQuestion } from "@root/questions/actions"
|
||||||
import { updateRootContentId } from "@root/quizes/actions"
|
import { updateRootContentId } from "@root/quizes/actions"
|
||||||
import { useCurrentQuiz } from "@root/quizes/hooks"
|
import { useCurrentQuiz } from "@root/quizes/hooks"
|
||||||
import { useQuestionsStore } from "@root/questions/store"
|
import { useQuestionsStore } from "@root/questions/store"
|
||||||
@ -11,8 +11,9 @@ interface Props {
|
|||||||
modalQuestionTargetContentId: string;
|
modalQuestionTargetContentId: string;
|
||||||
}
|
}
|
||||||
export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetContentId }: Props) => {
|
export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetContentId }: Props) => {
|
||||||
|
|
||||||
const quiz = useCurrentQuiz();
|
const quiz = useCurrentQuiz();
|
||||||
const { dragQuestionContentId } = useQuestionsStore()
|
const { dragQuestionContentId, questions } = useQuestionsStore()
|
||||||
const Container = useRef<HTMLDivElement | null>(null);
|
const Container = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
const modalOpen = () => setOpenedModalQuestions(true)
|
const modalOpen = () => setOpenedModalQuestions(true)
|
||||||
@ -22,6 +23,11 @@ export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetCon
|
|||||||
if (dragQuestionContentId) {
|
if (dragQuestionContentId) {
|
||||||
updateRootContentId(quiz?.id, dragQuestionContentId)
|
updateRootContentId(quiz?.id, dragQuestionContentId)
|
||||||
updateQuestion(dragQuestionContentId, (question) => question.content.rule.parentId = "root")
|
updateQuestion(dragQuestionContentId, (question) => question.content.rule.parentId = "root")
|
||||||
|
//если были результаты - удалить
|
||||||
|
questions.forEach((q) => {
|
||||||
|
if (q.type === 'result') deleteQuestion(q.id)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
enqueueSnackbar("Нет информации о взятом опроснике")
|
enqueueSnackbar("Нет информации о взятом опроснике")
|
||||||
@ -44,6 +50,10 @@ export const FirstNodeField = ({ setOpenedModalQuestions, modalQuestionTargetCon
|
|||||||
if (modalQuestionTargetContentId) {
|
if (modalQuestionTargetContentId) {
|
||||||
updateRootContentId(quiz?.id, modalQuestionTargetContentId)
|
updateRootContentId(quiz?.id, modalQuestionTargetContentId)
|
||||||
updateQuestion(modalQuestionTargetContentId, (question) => question.content.rule.parentId = "root")
|
updateQuestion(modalQuestionTargetContentId, (question) => question.content.rule.parentId = "root")
|
||||||
|
//если были результаты - удалить
|
||||||
|
questions.forEach((q) => {
|
||||||
|
if (q.type === 'result') deleteQuestion(q.id)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
enqueueSnackbar("Нет информации о взятом опроснике")
|
enqueueSnackbar("Нет информации о взятом опроснике")
|
||||||
|
@ -11,7 +11,7 @@ import {
|
|||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
useTheme,
|
useTheme,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { copyQuestion, deleteQuestion, updateOpenBranchingPanel, updateDesireToOpenABranchingModal } from "@root/questions/actions";
|
import { copyQuestion, deleteQuestion, updateOpenBranchingPanel, updateDesireToOpenABranchingModal, updateOpenedModalSettingsId, clearRuleForAll } from "@root/questions/actions";
|
||||||
import MiniButtonSetting from "@ui_kit/MiniButtonSetting";
|
import MiniButtonSetting from "@ui_kit/MiniButtonSetting";
|
||||||
import { CopyIcon } from "../../assets/icons/questionsPage/CopyIcon";
|
import { CopyIcon } from "../../assets/icons/questionsPage/CopyIcon";
|
||||||
import Branching from "../../assets/icons/questionsPage/branching";
|
import Branching from "../../assets/icons/questionsPage/branching";
|
||||||
@ -22,7 +22,7 @@ import type { AnyTypedQuizQuestion } from "../../model/questionTypes/shared";
|
|||||||
import { useCurrentQuiz } from "@root/quizes/hooks";
|
import { useCurrentQuiz } from "@root/quizes/hooks";
|
||||||
import { enqueueSnackbar } from "notistack";
|
import { enqueueSnackbar } from "notistack";
|
||||||
import { useQuestionsStore } from "@root/questions/store";
|
import { useQuestionsStore } from "@root/questions/store";
|
||||||
import { updateOpenedModalSettingsId } from "@root/questions/actions";
|
import { updateRootContentId } from "@root/quizes/actions";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
switchState: string;
|
switchState: string;
|
||||||
@ -40,7 +40,7 @@ export default function ButtonsOptions({
|
|||||||
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
const isMobile = useMediaQuery(theme.breakpoints.down(790));
|
||||||
const isWrappMiniButtonSetting = useMediaQuery(theme.breakpoints.down(920));
|
const isWrappMiniButtonSetting = useMediaQuery(theme.breakpoints.down(920));
|
||||||
const quiz = useCurrentQuiz();
|
const quiz = useCurrentQuiz();
|
||||||
const { openBranchingPanel } = useQuestionsStore.getState()
|
const { questions } = useQuestionsStore.getState()
|
||||||
|
|
||||||
const openedModal = () => {
|
const openedModal = () => {
|
||||||
updateOpenedModalSettingsId(question.id)
|
updateOpenedModalSettingsId(question.id)
|
||||||
|
@ -33,7 +33,6 @@ export const ResultSettings = () => {
|
|||||||
isReadyToLeave = false;
|
isReadyToLeave = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
console.log(`setting isReadyToLeaveRef to ${isReadyToLeave}`);
|
|
||||||
isReadyToLeaveRef.current = isReadyToLeave;
|
isReadyToLeaveRef.current = isReadyToLeave;
|
||||||
}, [results])
|
}, [results])
|
||||||
|
|
||||||
|
@ -46,7 +46,6 @@ export const Number = ({ currentQuestion }: NumberProps) => {
|
|||||||
const max = window.Number(currentQuestion.content.range.split("—")[1]);
|
const max = window.Number(currentQuestion.content.range.split("—")[1]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("ans", currentQuestion.content.start);
|
|
||||||
if (answer) {
|
if (answer) {
|
||||||
setMinRange(answer.split("—")[0]);
|
setMinRange(answer.split("—")[0]);
|
||||||
setMaxRange(answer.split("—")[1]);
|
setMaxRange(answer.split("—")[1]);
|
||||||
|
Loading…
Reference in New Issue
Block a user