Enregistrement avant suppression

pull/1/head
Jean-Christophe Jameux 3 years ago
parent 3a3a3df71e
commit f5d56de513
  1. 560
      src/GenerateurH5P.elm

@ -358,9 +358,9 @@ type alias BranchingScenarioContentTypeMetadata =
type BranchingScenarioContentTypeParams type BranchingScenarioContentTypeParams
= UnknownBranchingScenarioContentTypeParams = BranchingQuestionBranchingScenarioContentTypeParams BranchingQuestion
| CoursePresentationBranchingScenarioContentTypeParams CoursePresentation | CoursePresentationBranchingScenarioContentTypeParams CoursePresentation
| BranchingQuestionBranchingScenarioContentTypeParams BranchingQuestion | UnknownBranchingScenarioContentTypeParams
branchingScenarioDecoder : D.Decoder BranchingScenario branchingScenarioDecoder : D.Decoder BranchingScenario
@ -1452,7 +1452,6 @@ nouveauTrueFalse =
type Context type Context
= PreambleContext = PreambleContext
| RootContext | RootContext
| UnknownContext
| BranchingScenarioContext | BranchingScenarioContext
| BranchingQuestionContext | BranchingQuestionContext
| BranchingQuestionAlternativeContext | BranchingQuestionAlternativeContext
@ -1461,413 +1460,294 @@ type Context
| InteractiveVideoContext | InteractiveVideoContext
parser = contentParser =
succeed (L.map toH5p) succeed (L.map toH5p)
|. preambleParser |. inContext PreambleContext preambleParser
|= inContext RootContext (blocs RootContext 1) |= inContext RootContext (many h5pParser 1)
|. end EndOfFile |. end EndOfFile
preambleParser = preambleParser =
inContext PreambleContext <| -- Plus compliqué que nécessaire, en vue d'améliorations futures
-- Plus compliqué que nécessaire, en vue d'amélioration
succeed identity succeed identity
|. whileNoStarOnFirstColumnOrEndOfFile |. blocContentParser
contentsParser context depth = many blocParser depth =
sequence sequence
{ start = Token "" GenericProblem { start = Token "" GenericProblem
, separator = Token "" GenericProblem , separator = Token "" GenericProblem
, end = Token "" GenericProblem , end = Token "" GenericProblem
, spaces = succeed () , spaces = succeed ()
, item = contentParser context depth , item = withStars blocParser depth
, trailing = Optional , trailing = Optional
} }
blocs context depth = type alias BlocRecord blocType =
sequence { headline : String
{ start = Token "" GenericProblem , content : String
, separator = Token "" GenericProblem , subBlocs : List blocType
, end = Token "" GenericProblem
, spaces = succeed ()
, item = bloc context depth
, trailing = Optional
} }
bloc context depth = h5pData =
succeed pair { sub =
|. stars depth [ branchingScenarioData
|= star , coursePresentationData
|. mySpaces , trueFalseData
|= oneOf , interactiveVideoData
[ succeed BranchingScenarioContext
|. keyword (Token "BranchingScenario" GenericProblem)
, succeed CoursePresentationContext
|. keyword (Token "CoursePresentation" GenericProblem)
, succeed TrueFalseContext
|. keyword (Token "TrueFalse" GenericProblem)
, succeed InteractiveVideoContext
|. keyword (Token "InteractiveVideo" GenericProblem)
, succeed UnknownContext
] ]
|. mySpaces }
|> andThen (blocHelp context depth)
blocHelp context depth ( maybeStar, subContext ) = branchingScenarioData =
if maybeStar then { string = Just "BranchingScenario"
problem InconsistantStructure , parser = branchingScenarioParser
, context = BranchingScenarioContext
}
else
case ( context, subContext ) of
( RootContext, BranchingScenarioContext ) ->
blocHelpHelp BranchingScenarioContext depth
( RootContext, CoursePresentationContext ) -> branchingQuestionData =
blocHelpHelp CoursePresentationContext depth { string = Nothing
, parser = branchingQuestionParser
, context = BranchingQuestionContext
}
( RootContext, TrueFalseContext ) -> h5pParser depth =
blocHelpHelp TrueFalseContext depth selectParser depth
[ branchingScenarioData
, coursePresentationData
, trueFalseData
, interactiveVideoData
]
( BranchingScenarioContext, CoursePresentationContext ) ->
blocHelpHelp CoursePresentationContext depth
( BranchingScenarioContext, UnknownContext ) -> branchingScenarioParser depth =
blocHelpHelp BranchingQuestionContext depth selectParser depth
[ coursePresentationData
, interactiveVideoData
, branchingQuestionData
]
( BranchingQuestionContext, UnknownContext ) ->
blocHelpHelp BranchingQuestionAlternativeContext depth
( CoursePresentationContext, TrueFalseContext ) -> branchingQuestionParser depth =
blocHelpHelp TrueFalseContext depth selectParser depth
[ branchingQuestionAlternativeData
]
( BranchingQuestionAlternativeContext, CoursePresentationContext ) ->
blocHelpHelp CoursePresentationContext depth
( BranchingQuestionAlternativeContext, UnknownContext ) -> coursePresentationData =
blocHelpHelp BranchingQuestionContext depth { string = Just "CoursePresentation"
, parser = coursePresentationParser
, context = CoursePresentationContext
}
( _, BranchingScenarioContext ) ->
problem (Problem "Un BranchingScenario doit se trouver à la racine")
( _, CoursePresentationContext ) -> trueFalseData =
problem (Problem """Un CoursePresentation doit se trouver à la racine, { string = Just "TrueFalse"
sous un BranchingScenario ou dans une alternative de BranchingQuestion""") , parser = trueFalseParser
, context = TrueFalseContext
}
( _, TrueFalseContext ) ->
problem (Problem "Un TrueFalse doit se trouver à la racine ou dans un CoursePresentation")
( _, InteractiveVideoContext ) -> interactiveVideoData =
problem <| UnknownContentType "InteractiveVideoContext" { string = Just "InteractiveVideo"
, parser = interactiveVideoParser
, context = InteractiveVideoContext
}
_ ->
problem <| UnknownContentType ""
branchingQuestionAlternativeData =
{ string = Nothing
, parser = branchingScenarioParser
, context = BranchingQuestionAlternativeContext
}
type H5pBloc
= BranchingScenarioH5pBloc (BlocRecord BranchingScenarioBloc)
| CoursePresentationH5pBloc (BlocRecord CoursePresentationBloc)
| TrueFalseH5pBloc (BlocRecord TrueFalseBloc)
| InteractiveVideoH5pBloc (BlocRecord InteractiveVideoBloc)
blocHelpHelp context depth =
selectParser depth keywordDataList =
let let
f endOfLine contentList = recorder contentTypeData headline blocContent =
H5pTree context endOfLine contentList { contentTypeData = contentTypeData
, headline = headline
, content = content
}
parserer keywordData =
succeed keywordData
|. (case keywordData.string of
Just string ->
keyword (Token string (Missing string))
Nothing ->
succeed ()
)
in in
inContext context <| succeed recorder
succeed f |= oneOf (L.map parserer keywordDataList)
|= tillEndOfLine |= headlineParser
|. whileNoStarOnFirstColumnOrEndOfFile |= blocContentParser
|= blocs context (depth + 1) |> andThen
(\record ->
inContext record.contentTypeData.context
contentParser context depth = (succeed record.contentTypeData.builder record.headline record.content
succeed pair |= many record.contentTypeData.parser (depth + 1)
|. stars depth
|= star
|. mySpaces
|= getChompedString
(chompWhile
(\c ->
c
/= ' '
&& c
/= '\n'
&& c
/= '\u{000D}'
&& c
/= '\u{000D}'
) )
) )
|> andThen
(\( maybeStar, maybeContentType ) ->
if maybeStar then
problem InconsistantStructure
else
case ( maybeContentType, context ) of
( "BranchingScenario", RootContext ) ->
contentParserHelp BranchingScenarioContext depth ""
( "BranchingScenario", _ ) -> wraper blocConstructor headline content subBlocs =
problem (Problem "Un BranchingScenario doit se trouver à la racine") blocConstructor
{ headline = headline
, content = content
, subBlocs = subBlocs
}
( "CoursePresentation", RootContext ) ->
contentParserHelp CoursePresentationContext depth ""
( "CoursePresentation", BranchingScenarioContext ) ->
contentParserHelp CoursePresentationContext depth ""
( "CoursePresentation", BranchingQuestionAlternativeContext ) -> {-
contentParserHelp CoursePresentationContext depth "" , succeed <|
if context == BranchingQuestionContext then
BranchingQuestionAlternativeBloc
( "CoursePresentation", _ ) -> else
problem (Problem """Un CoursePresentation doit se trouver à la racine, BranchingQuestionBloc
sous un BranchingScenario ou dans une alternative de BranchingQuestion""") -}
( "TrueFalse", RootContext ) ->
contentParserHelp TrueFalseContext depth ""
( "TrueFalse", CoursePresentationContext ) -> blocParserHelp context bloc =
contentParserHelp TrueFalseContext depth "" case ( context, bloc ) of
( RootContext, BranchingScenarioBloc blocRecord ) ->
buildBranchingScenario blocRecord.headline blocRecord.subBlocs
( "TrueFalse", _ ) -> ( RootContext, CoursePresentationBloc blocRecord ) ->
problem (Problem "Un TrueFalse doit se trouver à la racine ou dans un CoursePresentation") buildCoursePresentation blocRecord.subBlocks
( "", _ ) -> ( RootContext, TrueFalseBloc blocRecord ) ->
problem NoContent buildTrueFalse blocRecord.headline blocRecord.content
-- Dans les trois cas ci-dessous, le maybeContentType ne désigne ( BranchingScenarioContext, BranchingQuestionBloc blocRecord ) ->
-- pas un contentType, c'est une astuce pour récupérer le texte avaler. buildBranchingQuestion
-- (cf. bit dans la définition de contentParserHelp)
( _, BranchingScenarioContext ) ->
contentParserHelp BranchingQuestionContext depth maybeContentType
( _, BranchingQuestionAlternativeContext ) -> ( BranchingScenarioContext, CoursePresentationBloc blocRecord ) ->
contentParserHelp BranchingQuestionContext depth maybeContentType buildCoursePresentation subBlocks
( _, BranchingQuestionContext ) -> ( BranchingQuestionContext, BranchingQuestionAlternativeBloc blocRecord ) ->
contentParserHelp BranchingQuestionAlternativeContext depth maybeContentType buildBranchingQuestionAlternative
_ -> ( CoursePresentationContext, TrueFalseBloc blocRecord ) ->
problem <| UnknownContentType maybeContentType buildTrueFalse
)
( BranchingQuestionAlternativeContext, BranchingQuestionBloc blocRecord ) ->
buildBranchingQuestion
contentParserHelp context depth bit = ( BranchingQuestionAlternativeContext, CoursePresentationBloc blocRecord ) ->
let buildCoursePresentation
f endOfLine contentList =
H5pTree context (bit ++ endOfLine) contentList
in
inContext context <|
succeed f
|= tillEndOfLine
|. whileNoStarOnFirstColumnOrEndOfFile
|= contentsParser context (depth + 1)
( _, BranchingScenarioBloc blocRecord ) ->
problem (Problem "Un BranchingScenario doit se trouver à la racine")
whileNoStarOnFirstColumnOrEndOfFile = ( _, BranchingQuestionBloc blocRecord ) ->
succeed identity problem (Problem "Un embranchement doit se trouver dans un BranchingScenario ou sous un autre embranchement")
|. chompWhile ((/=) '*')
|= getCol
|> andThen
(\col ->
if col > 1 then
oneOf
[ end EndOfFile
, succeed ()
|. token (Token "*" EndOfFile)
|. whileNoStarOnFirstColumnOrEndOfFile
]
else ( _, CoursePresentationBloc blocRecord ) ->
succeed () problem (Problem """Un CoursePresentation doit se trouver à la racine,
) sous un BranchingScenario ou dans une alternative de BranchingQuestion""")
( _, TrueFalseBloc blocRecord ) ->
problem (Problem "Un TrueFalse doit se trouver à la racine ou dans un CoursePresentation")
stars depth = ( _, InteractiveVideoBloc blocRecord ) ->
symbol (Token (S.repeat depth "*") GenericProblem) problem <| UnknownContentType "InteractiveVideo"
-- This last case cannot actually occur
_ ->
problem <| GenericProblem
star =
succeed
(\x ->
if S.length x == 0 then
False
else type BranchingScenarioBloc
True = BranchingQuestionBranchingScenarioBloc (BlocRecord BranchingQuestionBloc)
) | CoursePresentationBranchingScenarioBloc (BlocRecord CoursePresentationBloc)
|= getChompedString (chompWhile ((==) '*')) | InteractiveVideoBranchingScenarioBloc (BlocRecord InteractiveVideoBloc)
tillEndOfLine = type CoursePresentationBloc
getChompedString <| chompWhile ((/=) '\n') = TrueFalseCoursePresentationBloc (BlocRecord TrueFalseBloc)
mySpaces = type TrueFalseBloc
chompWhile <| \x -> x == ' ' || x == '\t' = TrueFalseBloc BlocRecord ()
type BranchingQuestionBloc
= BranchingQuestionAlternativeBranchingQuestionBloc (BlocRecord BranchingQuestionAlternativeBloc)
{-
type alias BranchingQuestionAlternativeBloc =
BranchingScenarioBloc
-}
{-
branchingScenarioParser depth =
let
f title contentList =
BranchingScenarioH5P
{ nouveauBranchingScenario
| startScreen =
nouveauBranchingScenario.startScreen
|> withStartScreenSubtitle title
, content = [] -- TODO
}
in
succeed f
|= titleParser
|. blankLines
|= loop [] (contentsParser (depth + 1) BranchingScenarioContext)
-} type InteractiveVideoBloc
--|= loop ( [], 0 ) (branchingScenarioParserHelp (depth + 1)) = InteractiveVideoBloc BlocRecord ()
--|. blankLines
{- Dans une configuration de la forme :
*BranchingScenario Titre du cours
** BranchingQuestion Cxu ?
...
** CoursePresentation
...
Récupère tout ce qui se trouve au niveau ** sous la forme d'une liste headlineParser =
-} getChompedString <| chompWhile ((/=) '\n')
{-
branchingScenarioParserHelp depth ( contentList, contentId ) =
oneOf
[ let
f ( contents, id ) =
Loop ( contentList ++ contents, id + 1 )
in
succeed f
|= contentParser depth contentId
|. blankLines
, succeed (Done contentList)
]
-}
{-
contentParserBis depth contentId =
oneOf
[ backtrackable <| branchingQuestionParser depth contentId
, succeed (\x -> ( [ x ], contentId + 1 ))
|= oneOf
[ backtrackable <| coursePresentationParser depth
, trueFalseParser depth
]
--, problemBis "Oups" blocContentParser =
getChompedString
(succeed identity
|. chompWhile ((/=) '*')
|= getCol
|> andThen
(\col ->
if col > 1 then
oneOf
[ end EndOfFile
, succeed ()
|. token (Token "*" EndOfFile)
|. blocContentParser
] ]
-} else
{- succeed ()
)
-}
{-
{-| Ici branchList est un enregistrement forçant la liste à avoir au moins deux éléments
-}
branchingQuestionParser depth contentId =
let
f question ( branchList, id ) =
( branchList.first :: branchList.second :: branchList.others
, contentId + L.length branchList.others + 2
) )
in
succeed f
|. stars depth
|. keywordBis "BranchingQuestion"
|. mySpaces
|= questionParser
|. blankLines
-- Je dirais qu'il faut un contentId + 1 ici
|= loop ( [], contentId ) (branchingQuestionAlternativeParser (depth + 1))
{-| Ici branchList est une liste withStars parser depth =
-} succeed identity
branchingQuestionAlternativeParser depth ( branchList, contentId ) = |. symbol (Token (S.repeat depth "*") GenericProblem)
oneOf |= getChompedString (chompWhile ((==) '*'))
[ let |. atLeastOneSpace
f alternative ( alternativeList, id ) = |> andThen
case branchList of (\x ->
[] -> if S.length x == 0 then
-- TODO parser
Loop ( alternativeList, id )
_ -> else
-- TODO problem InconsistantStructure
Loop ( alternativeList, id )
in
succeed f
|. stars depth
|= alternativeAnswerParser
|= loop ( [], contentId ) (branchingQuestionAlternativeParserHelp (depth + 1))
, (succeed ()
|> P.map (\_ -> List.concat branchList)
) )
|> andThen
(\xx ->
case xx of
[] ->
problemBis "Un embranchement doit avoir des branches !"
x :: [] ->
problemBis "Un embranchement doit avoir au moins deux branches !"
x :: y :: zz -> atLeastOneSpace =
succeed () succeed ()
|> P.map (\_ -> Done ( { first = x, second = y, others = zz }, contentId )) |. token (Token " " MissingSpace)
) |. chompWhile
] <|
\x -> x == ' ' || x == '\t'
{-| Tout le travail reste à faire !
-}
branchingQuestionAlternativeParserHelp depth ( branchList, contentId ) =
oneOf
[ succeed
(Done
( [ [ CoursePresentationH5P (new coursePresentationField) ]
, [ TrueFalseH5P nouveauTrueFalse ]
]
, contentId
)
)
]
-}
{- {-
@ -1894,6 +1774,8 @@ type Problem
| ExpectingContentType | ExpectingContentType
| UnknownContentType String | UnknownContentType String
| InconsistantStructure | InconsistantStructure
| MissingSpace
| Missing String
deadEndsToStringBis errs = deadEndsToStringBis errs =
@ -1938,6 +1820,12 @@ showProblem prob =
InconsistantStructure -> InconsistantStructure ->
"La structure du document n'est pas consistante !\n" "La structure du document n'est pas consistante !\n"
MissingSpace ->
"Les '*' doivent être suivies d'une espace\n"
Missing contentType ->
"Est-ce qu'il ne manquerait pas un " ++ contentType ++ " ?\n"
_ -> _ ->
"Problème inconnu\n" "Problème inconnu\n"
@ -2025,6 +1913,24 @@ type H5pTree
= H5pTree Context String (List H5pTree) = H5pTree Context String (List H5pTree)
buildBranchingScenario title blocs =
let
build content =
new branchingScenarioField
|> with2 startScreenField startScreenSubtitleField title
|> with contentField content
|> BranchingScenarioH5P
in
fromBranchingScenario
{ content = R.constant []
, lastIdUsed = -1
, headline = title
}
blocs
|> .content
|> R.map build
toH5p : H5pTree -> R.Generator H5p toH5p : H5pTree -> R.Generator H5p
toH5p tree = toH5p tree =
case tree of case tree of
@ -2106,10 +2012,10 @@ type alias BranchingScenarioState =
fromBranchingScenario : fromBranchingScenario :
BranchingScenarioState BranchingScenarioState
-> List H5pTree -> List Bloc
-> BranchingScenarioState -> BranchingScenarioState
fromBranchingScenario state trees = fromBranchingScenario state blocs =
case trees of case blocs of
[] -> [] ->
{ state { state
| content = | content =
@ -2117,7 +2023,7 @@ fromBranchingScenario state trees =
R.map L.reverse state.content R.map L.reverse state.content
} }
tree :: treesTail -> bloc :: blocsTail ->
let let
buildContent subBuilder title contentType library subTrees = buildContent subBuilder title contentType library subTrees =
R.map2 R.map2
@ -2138,7 +2044,7 @@ fromBranchingScenario state trees =
|> with nextContentIdField (Just state.lastIdUsed) |> with nextContentIdField (Just state.lastIdUsed)
newState = newState =
case tree of case bloc of
H5pTree BranchingQuestionContext question subTrees -> H5pTree BranchingQuestionContext question subTrees ->
let let
content = content =
@ -2229,12 +2135,6 @@ fromBranchingQuestion state trees =
branchingQuestion = branchingQuestion =
R.map branchingQuestionHelp UUID.generator R.map branchingQuestionHelp UUID.generator
params =
BranchingQuestionBranchingScenarioContentTypeParams
{ alternatives = L.reverse state.alternatives
, question = state.question
}
branchingQuestionHelp uuid = branchingQuestionHelp uuid =
new contentField new contentField
|> with3 typeField metadataField titleField "" |> with3 typeField metadataField titleField ""
@ -2243,6 +2143,12 @@ fromBranchingQuestion state trees =
|> with2 typeField paramsField params |> with2 typeField paramsField params
|> with2 typeField subContentIdField (UUID.toString uuid) |> with2 typeField subContentIdField (UUID.toString uuid)
params =
BranchingQuestionBranchingScenarioContentTypeParams
{ alternatives = L.reverse state.alternatives
, question = state.question
}
content = content =
state.content state.content
|> R.map2 (::) branchingQuestion |> R.map2 (::) branchingQuestion

Loading…
Cancel
Save