From 8b5097f049bbd52860f40d32fd8711c543823658 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Tue, 31 Oct 2023 12:51:36 +0200
Subject: [PATCH] toolgroups and nodeview

---
 editors/demo/src/HHMI/HHMI.js                 |  5 ++-
 .../NumericalAnswerContainerNodeView.js       | 40 +++++++++++++++++++
 .../NumericalAnswerQuestion.js                | 34 ++++++++++++++++
 .../NumericalAnswerService.js                 |  4 ++
 .../NumericalAnswer.js                        | 13 ++++++
 .../NumericalAnswerToolGroupService.js        | 10 +++++
 .../DropDownComponent.js                      |  5 +++
 7 files changed, 109 insertions(+), 2 deletions(-)
 create mode 100644 wax-questions-service/src/NumericalAnswerService/NumericalAnswerContainerNodeView.js
 create mode 100644 wax-questions-service/src/NumericalAnswerService/NumericalAnswerQuestion.js
 create mode 100644 wax-questions-service/src/NumericalAnswerService/NumericalAnswerToolGroupService/NumericalAnswer.js
 create mode 100644 wax-questions-service/src/NumericalAnswerService/NumericalAnswerToolGroupService/NumericalAnswerToolGroupService.js

diff --git a/editors/demo/src/HHMI/HHMI.js b/editors/demo/src/HHMI/HHMI.js
index 1b9ce865f..19ab37c7b 100644
--- a/editors/demo/src/HHMI/HHMI.js
+++ b/editors/demo/src/HHMI/HHMI.js
@@ -167,10 +167,11 @@ const Hhmi = () => {
         ref={editorRef}
         customValues={{ showFeedBack: submitted, testMode }}
         fileUpload={file => renderImage(file)}
-        value={content}
+        // value={content}
+        targetFormat="JSON"
         readonly={readOnly}
         layout={HhmiLayout}
-        // onChange={source => console.log(source)}
+        onChange={source => console.log(source)}
       />
     </>
   );
diff --git a/wax-questions-service/src/NumericalAnswerService/NumericalAnswerContainerNodeView.js b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerContainerNodeView.js
new file mode 100644
index 000000000..460e1f78e
--- /dev/null
+++ b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerContainerNodeView.js
@@ -0,0 +1,40 @@
+import { QuestionsNodeView } from 'wax-prosemirror-core';
+
+export default class NumericalAnswerContainerNodeView extends QuestionsNodeView {
+  constructor(
+    node,
+    view,
+    getPos,
+    decorations,
+    createPortal,
+    Component,
+    context,
+  ) {
+    super(node, view, getPos, decorations, createPortal, Component, context);
+
+    this.node = node;
+    this.outerView = view;
+    this.getPos = getPos;
+    this.context = context;
+  }
+
+  static name() {
+    return 'numerical_answer_container';
+  }
+
+  selectNode() {
+    this.context.pmViews[this.node.attrs.id].focus();
+  }
+
+  stopEvent(event) {
+    if (event.target.type === 'textarea' || !event.target.type) {
+      return true;
+    }
+
+    return (
+      this.context.pmViews[this.node.attrs.id] !== undefined &&
+      event.target !== undefined &&
+      this.context.pmViews[this.node.attrs.id].dom.contains(event.target)
+    );
+  }
+}
diff --git a/wax-questions-service/src/NumericalAnswerService/NumericalAnswerQuestion.js b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerQuestion.js
new file mode 100644
index 000000000..ba6a9891e
--- /dev/null
+++ b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerQuestion.js
@@ -0,0 +1,34 @@
+import { injectable } from 'inversify';
+import { findWrapping } from 'prosemirror-transform';
+import { v4 as uuidv4 } from 'uuid';
+import { Commands, Tools } from 'wax-prosemirror-core';
+import helpers from '../MultipleChoiceQuestionService/helpers/helpers';
+
+@injectable()
+class NumericalAnswerQuestion extends Tools {
+  title = 'Numerical Answer Question';
+  icon = '';
+  name = 'Numerical Answer';
+
+  get run() {
+    return main => {};
+  }
+
+  get active() {
+    return state => {
+      if (
+        Commands.isParentOfType(
+          state,
+          state.config.schema.nodes.numerical_answer_container,
+        )
+      ) {
+        return true;
+      }
+      return false;
+    };
+  }
+
+  select = (state, activeViewId, activeView) => {};
+}
+
+export default NumericalAnswerQuestion;
diff --git a/wax-questions-service/src/NumericalAnswerService/NumericalAnswerService.js b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerService.js
index 4460c4373..2a55b85b7 100644
--- a/wax-questions-service/src/NumericalAnswerService/NumericalAnswerService.js
+++ b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerService.js
@@ -8,6 +8,10 @@ class NumericalAnswerService extends Service {
     this.container.bind('').to();
     const createNode = this.container.get('CreateNode');
     const addPortal = this.container.get('AddPortal');
+
+    createNode({
+      numerical_answer_container: NumericalAnswerContainerNode,
+    });
   }
 
   dependencies = [];
diff --git a/wax-questions-service/src/NumericalAnswerService/NumericalAnswerToolGroupService/NumericalAnswer.js b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerToolGroupService/NumericalAnswer.js
new file mode 100644
index 000000000..7c57f06f2
--- /dev/null
+++ b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerToolGroupService/NumericalAnswer.js
@@ -0,0 +1,13 @@
+import { injectable, inject } from 'inversify';
+import { ToolGroup } from 'wax-prosemirror-core';
+
+@injectable()
+class NumericalAnswer extends ToolGroup {
+  tools = [];
+  constructor() {
+    super();
+    this.tools = [];
+  }
+}
+
+export default NumericalAnswer;
diff --git a/wax-questions-service/src/NumericalAnswerService/NumericalAnswerToolGroupService/NumericalAnswerToolGroupService.js b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerToolGroupService/NumericalAnswerToolGroupService.js
new file mode 100644
index 000000000..d18bd11a9
--- /dev/null
+++ b/wax-questions-service/src/NumericalAnswerService/NumericalAnswerToolGroupService/NumericalAnswerToolGroupService.js
@@ -0,0 +1,10 @@
+import { Service } from 'wax-prosemirror-core';
+import NumericalAnswer from './NumericalAnswer';
+
+class NumericalAnswerToolGroupService extends Service {
+  register() {
+    this.container.bind('NumericalAnswer').to(NumericalAnswer);
+  }
+}
+
+export default NumericalAnswerToolGroupService;
diff --git a/wax-questions-service/src/QuestionsDropDownToolGroupService/DropDownComponent.js b/wax-questions-service/src/QuestionsDropDownToolGroupService/DropDownComponent.js
index 1d4ef29d9..eed85c98d 100644
--- a/wax-questions-service/src/QuestionsDropDownToolGroupService/DropDownComponent.js
+++ b/wax-questions-service/src/QuestionsDropDownToolGroupService/DropDownComponent.js
@@ -107,6 +107,11 @@ const DropDownComponent = ({ view, tools }) => {
       value: '7',
       item: tools[7],
     },
+    // {
+    //   label: 'Numerical answer',
+    //   value: '8',
+    //   item: tools[8],
+    // },
   ];
 
   const context = useContext(WaxContext);
-- 
GitLab