Commit 57f8361d authored by Filip Šenk's avatar Filip Šenk Committed by Marek Veselý
Browse files

Added content field to questinnaire in editor

parent f50d3863
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -81,6 +81,16 @@ export const QUESTIONNAIRE_FORM: Form = {
    label: 'Title',
    tooltip: '',
  },
  content: {
    label: 'Content',
    tooltip: '',
    optional: true,
  },
  file: {
    label: 'Files',
    tooltip: '',
    optional: true,
  },
  questions: {
    label: 'Questions',
    tooltip: '',
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ const FileSelectorLabel: FC<FileSelectorProps> = ({
}) => (
  <TooltipLabel
    label={label}
    style={{ flexGrow: '1', paddingBlock: '1rem' }}
    style={{ flexGrow: '1', marginBlock: '1rem' }}
    htmlFor=''
  >
    <FileSelector onChange={onChange} selectedFiles={selectedFiles} />
+48 −1
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ import {
  Collapse,
  InputGroup,
  NumericInput,
  TextArea,
} from '@blueprintjs/core'
import { css } from '@emotion/css'
import { ShallowGetSet } from '@inject/shared'
@@ -13,8 +14,13 @@ import {
  addQuestionnaire,
  getQuestionnaireByInjectInfoId,
} from '../../../indexeddb/operations'
import type { InjectType, Questionnaire } from '../../../indexeddb/types'
import type {
  ContentFile,
  InjectType,
  Questionnaire,
} from '../../../indexeddb/types'
import { InjectsRoute } from '../../../routes/create/injects.index'
import FileSelectorLabel from '../../FileSelector/FileSelectorLabel'
import SaveButtonGroup from '../../SaveButtonGroup'
import TooltipLabel from '../../Tooltips/TooltipLabel'
import TooltipSwitch from '../../Tooltips/TooltipSwitch'
@@ -30,6 +36,8 @@ import RadioForm from './RadioForm'

export interface QuestionnaireInjectData {
  title: string
  content: string
  files: ContentFile[]
  postExerciseSubmission: boolean
  repeatable: boolean
  onFail: MilestoneType[]
@@ -56,6 +64,8 @@ const QuestionnaireForm: FC<{
        maxAttempts: questionnaire.maxAttempts,
        repeatable: questionnaire.repeatable,
        onFail: questionnaire.onFail,
        content: questionnaire.content,
        files: questionnaire.files,
      })
    }

@@ -67,6 +77,8 @@ const QuestionnaireForm: FC<{
        repeatable: false,
        onFail: [],
        maxAttempts: 1,
        content: '',
        files: [],
      })
    }
  }, [questionnaire, injectInfoId, state])
@@ -93,6 +105,41 @@ const QuestionnaireForm: FC<{
        </ShallowGetSet>
      </TooltipLabel>

      <TooltipLabel label={QUESTIONNAIRE_FORM.content}>
        <ShallowGetSet
          store={state}
          get={state => state.content}
          set={state => state.set}
        >
          {(value, setValue) => (
            <TextArea
              value={value}
              className={css`
                resize: none !important;
                min-height: 5rem;
              `}
              autoResize
              fill
              placeholder='Input text'
              onChange={e => setValue('content', e.target.value)}
            />
          )}
        </ShallowGetSet>
      </TooltipLabel>
      <ShallowGetSet
        store={state}
        get={({ files }) => files}
        set={({ set }) => set}
      >
        {(files, set) => (
          <FileSelectorLabel
            label={QUESTIONNAIRE_FORM.file}
            selectedFiles={files}
            onChange={newFiles => set('files', newFiles)}
          />
        )}
      </ShallowGetSet>

      <ShallowGetSet
        store={state}
        get={state => state.postExerciseSubmission}
+6 −0
Original line number Diff line number Diff line
@@ -157,6 +157,8 @@ export const initInjectSpecState = (type: InjectType) =>
          ...overlayEmpty,
          ...connectionsEmpty,
          title: '',
          content: '',
          files: [],
          postExerciseSubmission: false,
          repeatable: false,
          onFail: [],
@@ -169,6 +171,8 @@ export const initInjectSpecState = (type: InjectType) =>
              maxAttempts,
              repeatable,
              onFail,
              content,
              files,
            } = get() as State<InjectType.QUESTIONNAIRE>
            try {
              await updateQuestionnaire({
@@ -178,6 +182,8 @@ export const initInjectSpecState = (type: InjectType) =>
                repeatable,
                maxAttempts,
                onFail,
                content,
                files,
              })
              await genericUpdate(injectInfoId)
            } catch (error) {
+1 −1
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ db.version(dbVersion).stores({
  informationInjects: '&injectInfoId, content, files, informationChannelId',
  informationChannels: '++id, name',
  questionnaires:
    '&injectInfoId, &title, postExerciseSubmission, repeatable, maxAttempts, onFail',
    '&injectInfoId, &title, postExerciseSubmission, repeatable, maxAttempts, onFail, content, files',
  questionnaireQuestions: '++id, injectInfoId, text, type',
  questionnaireQuestionRadio:
    '[id+injectInfoId], correct, labels, labelsActivateControl, labelsDeactivateControl, max',
Loading