Skip to content
Snippets Groups Projects
Commit 0f826ba2 authored by chris's avatar chris
Browse files

delete essay widget

parent a0f0cf71
No related branches found
No related tags found
1 merge request!523Delete widgets
...@@ -68,32 +68,6 @@ const SubmitButton = styled.button` ...@@ -68,32 +68,6 @@ const SubmitButton = styled.button`
`} `}
`; `;
const initialContent = `<p class="paragraph"></p>
<div id="1624fa06-2075-488a-9912-9794a3763aca" class="multiple-drop-down-container" feedback="">
<p class="paragraph">Lorem ipsum dolor sit amet,<span id="fa9ff44d-19a6-4f47-99d9-d77d3dc02fbf" class="multiple-drop-down-option" options="[{&quot;label&quot;:&quot;option 1&quot;,&quot;value&quot;:&quot;6c4aa0f3-43b1-40a7-a066-bc73449523df&quot;},{&quot;label&quot;:&quot;option 2&quot;,&quot;value&quot;:&quot;29365b0c-c00d-40c1-8a5e-118dbdf47e50&quot;},{&quot;label&quot;:&quot;option 3&quot;,&quot;value&quot;:&quot;743a425e-6340-4a72-a07c-d2e78154fcc8&quot;}]" correct="6c4aa0f3-43b1-40a7-a066-bc73449523df" answer="29365b0c-c00d-40c1-8a5e-118dbdf47e50"></span>consectetur adipiscing elit. Nulla cursus ultricies enim, id condimentum dui facilisis a. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Sed euismod posuere orci. Praesent consectetur augue ut lorem suscipit, nec molestie libero pellentesque.</p>
<p class="paragraph">Nullam porttitor ligula neque. In aliquam<span id="f8380222-11fa-46e7-91a9-0bf67ff3d1d7" class="multiple-drop-down-option" options="[{&quot;label&quot;:&quot;option 4&quot;,&quot;value&quot;:&quot;4e2c45fe-0aad-4c59-9a92-ed44f01a82e2&quot;},{&quot;label&quot;:&quot;option 5&quot;,&quot;value&quot;:&quot;15e27b91-682a-4e10-a5d0-149192fd2e4c&quot;},{&quot;label&quot;:&quot;option 6&quot;,&quot;value&quot;:&quot;886c921d-2e75-41ea-a1a6-2d49e7921a57&quot;},{&quot;label&quot;:&quot;option 7&quot;,&quot;value&quot;:&quot;d14c2409-f66a-47d1-8f63-72686d24df37&quot;}]" correct="4e2c45fe-0aad-4c59-9a92-ed44f01a82e2" answer="4e2c45fe-0aad-4c59-9a92-ed44f01a82e2"></span> ex neque, sit amet sagittis nulla volutpat sed. Nulla blandit facilisis ante, vel tempus ante porta quis. Interdum et malesuada fames ac ante ipsum primis in faucibus. Integer nulla tellus, dictum at laoreet eu, hendrerit at quam. Sed consectetur, neque vel ornare malesuada, eros sem commodo purus, <span id="c13f5243-03c0-433c-8e44-440d536d9150" class="multiple-drop-down-option" options="[{&quot;label&quot;:&quot;option 9&quot;,&quot;value&quot;:&quot;3b9cd3b4-9e70-45de-975d-31407c48812c&quot;},{&quot;label&quot;:&quot;option 10&quot;,&quot;value&quot;:&quot;3baf86a8-a3fa-4e64-bfe8-f01ce4320489&quot;},{&quot;label&quot;:&quot;option 11&quot;,&quot;value&quot;:&quot;f1c6023c-5cde-445a-b9fb-cc23f06c8132&quot;}]" correct="f1c6023c-5cde-445a-b9fb-cc23f06c8132" answer="f1c6023c-5cde-445a-b9fb-cc23f06c8132"></span> sagittis volutpat elit leo in diam. Aliquam mattis, est non placerat euismod, nisl nisl vestibulum mauris, non interdum dui urna et tellus.</p>
</div>
<p class="paragraph"></p>
<div id="2257aaf4-20cf-44ff-bd45-0e0a4561b764" class="matching-container" options="[{&quot;label&quot;:&quot;option 1&quot;,&quot;value&quot;:&quot;941cebeb-58bd-44c5-bf42-c78d20c23b7a&quot;},{&quot;label&quot;:&quot;option 2&quot;,&quot;value&quot;:&quot;ab2e7cfc-c700-4ba2-9ac3-3040974f67bf&quot;}]" feedback="">
<p class="paragraph">
<div id="2bf9d3ca-166d-4354-9ebf-5d0fc6e75d8d" class="matching-option" isfirst="true" answer="">some text</div>
</p>
</div>
<div id="d4fa43fc-3a92-4591-a8a4-e6271e42fc323" class="multiple-choice">
<div class="multiple-choice-question" id="38de8538-647a-489d-8474-f92d0d256c32">
<p class="paragraph">question</p>
</div>
<div class="multiple-choice-option" id="debb868e-bbfe-4ba2-bf93-c963153ff791" correct="false" answer="false" feedback="feedback 1">
<p class="paragraph">answer 1</p>
</div>
<div class="multiple-choice-option" id="810bcf10-4fcb-4d1e-9dab-ce35cbd28527" correct="true" answer="false" feedback="feedback 2">
<p class="paragraph">answer 2</p>
</div>
</div>
<div id="d4fa43fc-3a92-4591-a8a4-e6271e42fc02" class="fill-the-gap" feedback="some feedback">
<p class="paragraph">first <span id="16ec8f33-db5b-4839-9567-8aa73b776bcf" class="fill-the-gap" answer="">answer1; answer2; answer3</span> second <span id="72f23a71-e774-4834-acba-f357afb6a243" class="fill-the-gap" answer="">answer 4; answer5;</span></p>
</div>`;
// const initialContent = { // const initialContent = {
// type: 'doc', // type: 'doc',
// content: [ // content: [
...@@ -118,6 +92,8 @@ const initialContent = `<p class="paragraph"></p> ...@@ -118,6 +92,8 @@ const initialContent = `<p class="paragraph"></p>
// ], // ],
// }; // };
const initialContent = ``;
const Hhmi = () => { const Hhmi = () => {
const [stateProps, setStateProps] = useState({ const [stateProps, setStateProps] = useState({
readOnly: false, readOnly: false,
...@@ -191,7 +167,7 @@ const Hhmi = () => { ...@@ -191,7 +167,7 @@ const Hhmi = () => {
ref={editorRef} ref={editorRef}
customValues={{ showFeedBack: submitted, testMode }} customValues={{ showFeedBack: submitted, testMode }}
fileUpload={file => renderImage(file)} fileUpload={file => renderImage(file)}
// value={content} value={content}
// targetFormat="JSON" // targetFormat="JSON"
readonly={readOnly} readonly={readOnly}
layout={HhmiLayout} layout={HhmiLayout}
......
import React from 'react'; import React, { useContext } from 'react';
import styled from 'styled-components';
import { WaxContext } from 'wax-prosemirror-core';
import EditorComponent from '../../MultipleChoiceQuestionService/components/EditorComponent'; import EditorComponent from '../../MultipleChoiceQuestionService/components/EditorComponent';
const EditorWrapper = styled.div`
display: ${props =>
props.testMode || props.showFeedBack ? 'block' : 'none'};
`;
export default ({ node, view, getPos }) => { export default ({ node, view, getPos }) => {
const context = useContext(WaxContext);
const {
pmViews: { main },
} = context;
const customProps = main.props.customValues;
const { testMode, showFeedBack } = customProps;
return ( return (
<EditorComponent <EditorWrapper showFeedBack={showFeedBack} testMode={testMode}>
getPos={getPos} <EditorComponent
node={node} forceEditable={testMode}
placeholderText="Type your essay answer" getPos={getPos}
QuestionType="EssayQuestion" node={node}
view={view} placeholderText="Type your essay answer"
/> QuestionType="EssayQuestion"
view={view}
/>
</EditorWrapper>
); );
}; };
import React from 'react'; import React, { useContext } from 'react';
import styled from 'styled-components';
import { WaxContext } from 'wax-prosemirror-core';
import EditorComponent from '../../MultipleChoiceQuestionService/components/EditorComponent'; import EditorComponent from '../../MultipleChoiceQuestionService/components/EditorComponent';
const EditorWrapper = styled.div`
display: ${props => (props.testMode ? 'none' : 'block')};
`;
export default ({ node, view, getPos }) => { export default ({ node, view, getPos }) => {
const context = useContext(WaxContext);
const {
pmViews: { main },
} = context;
const customProps = main.props.customValues;
const { testMode } = customProps;
return ( return (
<EditorComponent <EditorWrapper testMode={testMode}>
getPos={getPos} <EditorComponent
node={node} getPos={getPos}
placeholderText="Provide response summary and rubric" node={node}
QuestionType="EssayQuestion" placeholderText="Provide response summary and rubric"
view={view} QuestionType="EssayQuestion"
/> view={view}
/>
</EditorWrapper>
); );
}; };
import React, { useContext, useRef, useState } from 'react'; import React, { useContext } from 'react';
import { import { WaxContext, DocumentHelpers, Icon } from 'wax-prosemirror-core';
WaxContext,
ComponentPlugin,
DocumentHelpers,
Icon,
} from 'wax-prosemirror-core';
import { th } from '@pubsweet/ui-toolkit';
import styled from 'styled-components'; import styled from 'styled-components';
import ContainerEditor from '../../FillTheGapQuestionService/components/ContainerEditor'; import ContainerEditor from '../../FillTheGapQuestionService/components/ContainerEditor';
...@@ -17,7 +11,7 @@ const EssayQuestionWrapper = styled.div` ...@@ -17,7 +11,7 @@ const EssayQuestionWrapper = styled.div`
const EssayQuestionContainerTool = styled.div` const EssayQuestionContainerTool = styled.div`
border: 3px solid #f5f5f7; border: 3px solid #f5f5f7;
border-bottom: none; border-bottom: none;
height: 32px;
span:first-of-type { span:first-of-type {
position: relative; position: relative;
top: 3px; top: 3px;
...@@ -31,7 +25,7 @@ const ActionButton = styled.button` ...@@ -31,7 +25,7 @@ const ActionButton = styled.button`
border: none; border: none;
position: relative; position: relative;
bottom: 14px; bottom: 14px;
left: -11px; left: 6px;
float: right; float: right;
`; `;
...@@ -60,7 +54,20 @@ export default ({ node, view, getPos }) => { ...@@ -60,7 +54,20 @@ export default ({ node, view, getPos }) => {
const readOnly = !isEditable; const readOnly = !isEditable;
const removeQuestion = () => {}; const removeQuestion = () => {
const allNodes = getNodes(context.pmViews.main);
allNodes.forEach(singleNode => {
if (singleNode.node.attrs.id === node.attrs.id) {
context.pmViews.main.dispatch(
context.pmViews.main.state.tr.delete(
singleNode.pos,
singleNode.pos + singleNode.node.nodeSize,
),
);
}
});
};
return ( return (
<EssayQuestionWrapper> <EssayQuestionWrapper>
...@@ -81,6 +88,7 @@ export default ({ node, view, getPos }) => { ...@@ -81,6 +88,7 @@ export default ({ node, view, getPos }) => {
<ContainerEditor <ContainerEditor
disallowedTools={['FillTheGap', 'MultipleChoice']} disallowedTools={['FillTheGap', 'MultipleChoice']}
getPos={getPos} getPos={getPos}
isNotEditable
node={node} node={node}
view={view} view={view}
/> />
...@@ -88,3 +96,14 @@ export default ({ node, view, getPos }) => { ...@@ -88,3 +96,14 @@ export default ({ node, view, getPos }) => {
</EssayQuestionWrapper> </EssayQuestionWrapper>
); );
}; };
const getNodes = view => {
const allNodes = DocumentHelpers.findBlockNodes(view.state.doc);
const fillTheGapContainerNodes = [];
allNodes.forEach(node => {
if (node.node.type.name === 'essay_container') {
fillTheGapContainerNodes.push(node);
}
});
return fillTheGapContainerNodes;
};
...@@ -68,6 +68,7 @@ const QuestionEditorComponent = ({ ...@@ -68,6 +68,7 @@ const QuestionEditorComponent = ({
getPos, getPos,
placeholderText = 'Type your item', placeholderText = 'Type your item',
QuestionType = 'Multiple', QuestionType = 'Multiple',
forceEditable = false,
}) => { }) => {
const editorRef = useRef(); const editorRef = useRef();
...@@ -78,9 +79,10 @@ const QuestionEditorComponent = ({ ...@@ -78,9 +79,10 @@ const QuestionEditorComponent = ({
} = context; } = context;
let questionView; let questionView;
const questionId = node.attrs.id; const questionId = node.attrs.id;
const isEditable = main.props.editable(editable => { let isEditable = main.props.editable(editable => {
return editable; return editable;
}); });
if (forceEditable) isEditable = true;
let finalPlugins = [FakeCursorPlugin(), gapCursor(), dropCursor()]; let finalPlugins = [FakeCursorPlugin(), gapCursor(), dropCursor()];
...@@ -210,7 +212,9 @@ const QuestionEditorComponent = ({ ...@@ -210,7 +212,9 @@ const QuestionEditorComponent = ({
const addToHistory = !tr.getMeta('exludeToHistoryFromOutside'); const addToHistory = !tr.getMeta('exludeToHistoryFromOutside');
const { state, transactions } = questionView.state.applyTransaction(tr); const { state, transactions } = questionView.state.applyTransaction(tr);
questionView.updateState(state); questionView.updateState(state);
context.updateView({}, questionId); setTimeout(() => {
context.updateView({}, questionId);
});
if (!tr.getMeta('fromOutside')) { if (!tr.getMeta('fromOutside')) {
const outerTr = view.state.tr; const outerTr = view.state.tr;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment