Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
janslifka committed Oct 8, 2024
1 parent a4be818 commit a0d93aa
Show file tree
Hide file tree
Showing 43 changed files with 1,276 additions and 30 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/wizard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ jobs:
- name: '[app] Install'
run: npm ci

- name: '[app] Test'
run: |
npm run test:$COMPONENT
# - name: '[app] Test'
# run: |
# npm run test:$COMPONENT

- name: '[app] Build'
run: |
Expand Down
32 changes: 32 additions & 0 deletions engine-shared/elm/Shared/Api/QuestionnaireFiles.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Shared.Api.QuestionnaireFiles exposing (getQuestionnaireFiles, postFile)

import File exposing (File)
import Http
import Shared.AbstractAppState exposing (AbstractAppState)
import Shared.Api exposing (ToMsg, jwtFetchFileWithData, jwtGet)
import Shared.Data.Pagination as Pagination exposing (Pagination)
import Shared.Data.PaginationQueryFilters exposing (PaginationQueryFilters)
import Shared.Data.PaginationQueryString as PaginationQueryString exposing (PaginationQueryString)
import Shared.Data.QuestionnaireFile as QuestionnaireFile exposing (QuestionnaireFile)
import Shared.Data.QuestionnaireFileSimple as QuestionnaireFileSimple exposing (QuestionnaireFileSimple)
import Uuid exposing (Uuid)


getQuestionnaireFiles : PaginationQueryFilters -> PaginationQueryString -> AbstractAppState a -> ToMsg (Pagination QuestionnaireFile) msg -> Cmd msg
getQuestionnaireFiles _ qs =
let
queryString =
PaginationQueryString.toApiUrl qs

url =
"/questionnaire-files" ++ queryString
in
jwtGet url (Pagination.decoder "questionnaireFiles" QuestionnaireFile.decoder)


postFile : Uuid -> File -> AbstractAppState a -> ToMsg QuestionnaireFileSimple msg -> Cmd msg
postFile questionnaireUuid file =
jwtFetchFileWithData ("/questionnaires/" ++ Uuid.toString questionnaireUuid ++ "/files")
[ Http.stringPart "fileName" (File.name file) ]
QuestionnaireFileSimple.decoder
file
18 changes: 16 additions & 2 deletions engine-shared/elm/Shared/Data/Event/AddQuestionEventData.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Shared.Data.Event.AddQuestionEventData exposing

import Json.Decode as D exposing (Decoder)
import Json.Encode as E
import Shared.Data.Event.AddQuestionFileEventData as AddQuestionFileEventData exposing (AddQuestionFileEventData)
import Shared.Data.Event.AddQuestionIntegrationEventData as AddQuestionIntegrationEventData exposing (AddQuestionIntegrationEventData)
import Shared.Data.Event.AddQuestionItemSelectEventData as AddQuestionItemSelectEventData exposing (AddQuestionItemSelectEventData)
import Shared.Data.Event.AddQuestionListEventData as AddQuestionListEventData exposing (AddQuestionListEventData)
Expand All @@ -27,6 +28,7 @@ type AddQuestionEventData
| AddQuestionIntegrationEvent AddQuestionIntegrationEventData
| AddQuestionMultiChoiceEvent AddQuestionMultiChoiceEventData
| AddQuestionItemSelectEvent AddQuestionItemSelectEventData
| AddQuestionFileEvent AddQuestionFileEventData


decoder : Decoder AddQuestionEventData
Expand All @@ -53,6 +55,9 @@ decoder =
"ItemSelectQuestion" ->
D.map AddQuestionItemSelectEvent AddQuestionItemSelectEventData.decoder

"FileQuestion" ->
D.map AddQuestionFileEvent AddQuestionFileEventData.decoder

_ ->
D.fail <| "Unknown question type: " ++ questionType
)
Expand All @@ -69,6 +74,7 @@ encode data =
AddQuestionIntegrationEventData.encode
AddQuestionMultiChoiceEventData.encode
AddQuestionItemSelectEventData.encode
AddQuestionFileEventData.encode
data
in
( "eventType", E.string "AddQuestionEvent" ) :: eventData
Expand Down Expand Up @@ -100,6 +106,9 @@ toQuestion questionUuid data =
AddQuestionItemSelectEvent eventData ->
AddQuestionItemSelectEventData.toQuestion questionUuid eventData

AddQuestionFileEvent eventData ->
AddQuestionFileEventData.toQuestion questionUuid eventData


getTypeString : AddQuestionEventData -> String
getTypeString =
Expand All @@ -110,11 +119,12 @@ getTypeString =
(always "Integration")
(always "MultiChoice")
(always "ItemSelect")
(always "File")


getEntityVisibleName : AddQuestionEventData -> Maybe String
getEntityVisibleName =
Just << map .title .title .title .title .title .title
Just << map .title .title .title .title .title .title .title


map :
Expand All @@ -124,9 +134,10 @@ map :
-> (AddQuestionIntegrationEventData -> a)
-> (AddQuestionMultiChoiceEventData -> a)
-> (AddQuestionItemSelectEventData -> a)
-> (AddQuestionFileEventData -> a)
-> AddQuestionEventData
-> a
map optionsQuestion listQuestion valueQuestion integrationQuestion multiChoiceQuestion itemSelectQuestion question =
map optionsQuestion listQuestion valueQuestion integrationQuestion multiChoiceQuestion itemSelectQuestion fileQuestion question =
case question of
AddQuestionOptionsEvent data ->
optionsQuestion data
Expand All @@ -145,3 +156,6 @@ map optionsQuestion listQuestion valueQuestion integrationQuestion multiChoiceQu

AddQuestionItemSelectEvent data ->
itemSelectQuestion data

AddQuestionFileEvent data ->
fileQuestion data
66 changes: 66 additions & 0 deletions engine-shared/elm/Shared/Data/Event/AddQuestionFileEventData.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module Shared.Data.Event.AddQuestionFileEventData exposing
( AddQuestionFileEventData
, decoder
, encode
, toQuestion
)

import Json.Decode as D exposing (Decoder)
import Json.Decode.Pipeline as D
import Json.Encode as E
import Json.Encode.Extra as E
import Shared.Data.KnowledgeModel.Annotation as Annotation exposing (Annotation)
import Shared.Data.KnowledgeModel.Question exposing (Question(..))


type alias AddQuestionFileEventData =
{ title : String
, text : Maybe String
, requiredPhaseUuid : Maybe String
, maxSize : Maybe Int
, fileTypes : Maybe String
, tagUuids : List String
, annotations : List Annotation
}


decoder : Decoder AddQuestionFileEventData
decoder =
D.succeed AddQuestionFileEventData
|> D.required "title" D.string
|> D.required "text" (D.nullable D.string)
|> D.required "requiredPhaseUuid" (D.nullable D.string)
|> D.required "maxSize" (D.maybe D.int)
|> D.required "fileTypes" (D.maybe D.string)
|> D.required "tagUuids" (D.list D.string)
|> D.required "annotations" (D.list Annotation.decoder)


encode : AddQuestionFileEventData -> List ( String, E.Value )
encode data =
[ ( "questionType", E.string "FileQuestion" )
, ( "title", E.string data.title )
, ( "text", E.maybe E.string data.text )
, ( "requiredPhaseUuid", E.maybe E.string data.requiredPhaseUuid )
, ( "maxSize", E.maybe E.int data.maxSize )
, ( "fileTypes", E.maybe E.string data.fileTypes )
, ( "tagUuids", E.list E.string data.tagUuids )
, ( "annotations", E.list Annotation.encode data.annotations )
]


toQuestion : String -> AddQuestionFileEventData -> Question
toQuestion uuid data =
FileQuestion
{ uuid = uuid
, title = data.title
, text = data.text
, requiredPhaseUuid = data.requiredPhaseUuid
, tagUuids = data.tagUuids
, referenceUuids = []
, expertUuids = []
, annotations = data.annotations
}
{ maxSize = data.maxSize
, fileTypes = data.fileTypes
}
12 changes: 12 additions & 0 deletions engine-shared/elm/Shared/Data/Event/EditEventSetters.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Shared.Data.Event.EditEventSetters exposing
, setDescription
, setEmail
, setExpertUuids
, setFileTypes
, setFollowUpUuids
, setId
, setIntegrationUuid
Expand All @@ -19,6 +20,7 @@ module Shared.Data.Event.EditEventSetters exposing
, setLabel
, setListQuestionUuid
, setLogo
, setMaxSize
, setMetricMeasures
, setMetricUuids
, setName
Expand Down Expand Up @@ -104,6 +106,11 @@ setExpertUuids value data =
{ data | expertUuids = EventField.create value True }


setFileTypes : a -> { b | fileTypes : EventField a } -> { b | fileTypes : EventField a }
setFileTypes value data =
{ data | fileTypes = EventField.create value True }


setFollowUpUuids : a -> { b | followUpUuids : EventField a } -> { b | followUpUuids : EventField a }
setFollowUpUuids value data =
{ data | followUpUuids = EventField.create value True }
Expand Down Expand Up @@ -149,6 +156,11 @@ setLogo value data =
{ data | logo = EventField.create value True }


setMaxSize : a -> { b | maxSize : EventField a } -> { b | maxSize : EventField a }
setMaxSize value data =
{ data | maxSize = EventField.create value True }


setMetricMeasures : a -> { b | metricMeasures : EventField a } -> { b | metricMeasures : EventField a }
setMetricMeasures value data =
{ data | metricMeasures = EventField.create value True }
Expand Down
25 changes: 23 additions & 2 deletions engine-shared/elm/Shared/Data/Event/EditQuestionEventData.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Shared.Data.Event.EditQuestionEventData exposing
import Dict
import Json.Decode as D exposing (Decoder)
import Json.Encode as E
import Shared.Data.Event.EditQuestionFileEventData as EditQuestionFileEventData exposing (EditQuestionFileEventData)
import Shared.Data.Event.EditQuestionIntegrationEventData as EditQuestionIntegrationEventData exposing (EditQuestionIntegrationEventData)
import Shared.Data.Event.EditQuestionItemSelectData as EditQuestionItemSelectEventData exposing (EditQuestionItemSelectEventData)
import Shared.Data.Event.EditQuestionListEventData as EditQuestionListEventData exposing (EditQuestionListEventData)
Expand All @@ -30,6 +31,7 @@ type EditQuestionEventData
| EditQuestionIntegrationEvent EditQuestionIntegrationEventData
| EditQuestionMultiChoiceEvent EditQuestionMultiChoiceEventData
| EditQuestionItemSelectEvent EditQuestionItemSelectEventData
| EditQuestionFileEvent EditQuestionFileEventData


decoder : Decoder EditQuestionEventData
Expand All @@ -56,6 +58,9 @@ decoder =
"ItemSelectQuestion" ->
D.map EditQuestionItemSelectEvent EditQuestionItemSelectEventData.decoder

"FileQuestion" ->
D.map EditQuestionFileEvent EditQuestionFileEventData.decoder

_ ->
D.fail <| "Unknown question type: " ++ questionType
)
Expand All @@ -72,6 +77,7 @@ encode data =
EditQuestionIntegrationEventData.encode
EditQuestionMultiChoiceEventData.encode
EditQuestionItemSelectEventData.encode
EditQuestionFileEventData.encode
data
in
( "eventType", E.string "EditQuestionEvent" ) :: eventData
Expand Down Expand Up @@ -129,6 +135,13 @@ apply event question =
{ listQuestionUuid = EventField.getValueWithDefault eventData.listQuestionUuid (Question.getListQuestionUuid question)
}

EditQuestionFileEvent eventData ->
FileQuestion
(applyCommonData eventData)
{ maxSize = EventField.getValueWithDefault eventData.maxSize (Question.getMaxSize question)
, fileTypes = EventField.getValueWithDefault eventData.fileTypes (Question.getFileTypes question)
}


getTypeString : EditQuestionEventData -> String
getTypeString =
Expand All @@ -139,11 +152,12 @@ getTypeString =
(always "Integration")
(always "MultiChoice")
(always "ItemSelect")
(always "File")


getEntityVisibleName : EditQuestionEventData -> Maybe String
getEntityVisibleName =
EventField.getValue << map .title .title .title .title .title .title
EventField.getValue << map .title .title .title .title .title .title .title


map :
Expand All @@ -153,9 +167,10 @@ map :
-> (EditQuestionIntegrationEventData -> a)
-> (EditQuestionMultiChoiceEventData -> a)
-> (EditQuestionItemSelectEventData -> a)
-> (EditQuestionFileEventData -> a)
-> EditQuestionEventData
-> a
map optionsQuestion listQuestion valueQuestion integrationQuestion multiChoiceQuestion itemSelectQuestion question =
map optionsQuestion listQuestion valueQuestion integrationQuestion multiChoiceQuestion itemSelectQuestion fileQuestion question =
case question of
EditQuestionOptionsEvent data ->
optionsQuestion data
Expand All @@ -175,6 +190,9 @@ map optionsQuestion listQuestion valueQuestion integrationQuestion multiChoiceQu
EditQuestionItemSelectEvent data ->
itemSelectQuestion data

EditQuestionFileEvent data ->
fileQuestion data


squash : EditQuestionEventData -> EditQuestionEventData -> EditQuestionEventData
squash old new =
Expand All @@ -197,5 +215,8 @@ squash old new =
( EditQuestionItemSelectEvent oldData, EditQuestionItemSelectEvent newData ) ->
EditQuestionItemSelectEvent (EditQuestionItemSelectEventData.squash oldData newData)

( EditQuestionFileEvent oldData, EditQuestionFileEvent newData ) ->
EditQuestionFileEvent (EditQuestionFileEventData.squash oldData newData)

_ ->
new
Loading

0 comments on commit a0d93aa

Please sign in to comment.