@@ -668,19 +668,107 @@ isCurrentVersion questionnaire eventUuid =
668668
669669
670670getItemTitle : QuestionnaireQuestionnaire -> List String -> List Question -> Maybe String
671- getItemTitle questionnaire itemPath itemTemplateQuestions =
672- let
673- firstQuestionUuid =
674- Maybe . unwrap " " Question . getUuid ( List . head itemTemplateQuestions)
671+ getItemTitle =
672+ getItemTitleRecursive []
675673
676- titleFromMarkdown value =
677- Markdown . toString value
678- |> String . split " \n "
679- |> List . find ( not << String . isEmpty)
680- in
681- Dict . get ( pathToString ( itemPath ++ [ firstQuestionUuid ] )) questionnaire. replies
682- |> Maybe . andThen ( . value >> ReplyValue . getStringReply >> titleFromMarkdown)
683- |> Maybe . andThen String . toMaybe
674+
675+ getItemTitleRecursive : List String -> QuestionnaireQuestionnaire -> List String -> List Question -> Maybe String
676+ getItemTitleRecursive itemUuids questionnaire itemPath itemTemplateQuestions =
677+ case List . head itemTemplateQuestions of
678+ Nothing ->
679+ Nothing
680+
681+ Just itemTemplateQuestion ->
682+ let
683+ titleFromMarkdown value =
684+ Markdown . toString value
685+ |> String . split " \n "
686+ |> List . find ( not << String . isEmpty)
687+
688+ getReply common =
689+ Dict . get ( pathToString ( itemPath ++ [ common. uuid ] )) questionnaire. replies
690+
691+ getReplyValueString common =
692+ getReply common
693+ |> Maybe . andThen ( titleFromMarkdown << ReplyValue . getStringReply << . value)
694+ |> Maybe . andThen String . toMaybe
695+ in
696+ case itemTemplateQuestion of
697+ OptionsQuestion common _ ->
698+ getReply common
699+ |> Maybe . map ( KnowledgeModel . getAnswerName questionnaire. knowledgeModel << ReplyValue . getAnswerUuid << . value)
700+ |> Maybe . andThen String . toMaybe
701+
702+ ListQuestion common _ ->
703+ getReply common
704+ |> Maybe . andThen ( List . head << ReplyValue . getItemUuids << . value)
705+ |> Maybe . andThen
706+ ( \ firstItemUuid ->
707+ let
708+ newItemPath =
709+ itemPath ++ [ common. uuid, firstItemUuid ]
710+
711+ newItemTemplateQuestion =
712+ KnowledgeModel . getQuestionItemTemplateQuestions common. uuid questionnaire. knowledgeModel
713+ in
714+ getItemTitleRecursive itemUuids questionnaire newItemPath newItemTemplateQuestion
715+ )
716+
717+ ValueQuestion common _ ->
718+ getReplyValueString common
719+
720+ IntegrationQuestion common _ ->
721+ getReplyValueString common
722+
723+ MultiChoiceQuestion common _ ->
724+ getReply common
725+ |> Maybe . map ( ReplyValue . getChoiceUuid << . value)
726+ |> Maybe . andThen
727+ ( \ uuids ->
728+ if List . isEmpty uuids then
729+ Nothing
730+
731+ else
732+ List . map ( KnowledgeModel . getChoiceName questionnaire. knowledgeModel) uuids
733+ |> List . filter ( not << String . isEmpty)
734+ |> String . join " , "
735+ |> Just
736+ )
737+
738+ ItemSelectQuestion common itemSelectQuestion ->
739+ getReply common
740+ |> Maybe . map ( ReplyValue . getSelectedItemUuid << . value)
741+ |> Maybe . andThen
742+ ( \ itemUuid ->
743+ let
744+ findByPathAndItemUuid listQuestionUuid key value =
745+ String . endsWith listQuestionUuid key
746+ && List . member itemUuid ( ReplyValue . getItemUuids value. value)
747+
748+ createTargetItemPath ( key, _ ) =
749+ String . split " ." key ++ [ itemUuid ]
750+
751+ getTargetItemTitleByPath listQuestionUuid newItemPath =
752+ if List . member itemUuid itemUuids then
753+ Nothing
754+
755+ else
756+ getItemTitleRecursive ( itemUuid :: itemUuids) questionnaire newItemPath ( KnowledgeModel . getQuestionItemTemplateQuestions listQuestionUuid questionnaire. knowledgeModel)
757+
758+ getTargetItemTitle listQuestionUuid =
759+ questionnaire. replies
760+ |> Dict . find ( findByPathAndItemUuid listQuestionUuid)
761+ |> Maybe . map createTargetItemPath
762+ |> Maybe . andThen ( getTargetItemTitleByPath listQuestionUuid)
763+ in
764+ Maybe . andThen getTargetItemTitle itemSelectQuestion. listQuestionUuid
765+ )
766+
767+ FileQuestion common _ ->
768+ getReply common
769+ |> Maybe . andThen ( ReplyValue . getFileUuid << . value)
770+ |> Maybe . andThen ( getFile questionnaire)
771+ |> Maybe . map . fileName
684772
685773
686774getFile : QuestionnaireQuestionnaire -> Uuid -> Maybe QuestionnaireFileSimple
0 commit comments