Skip to content
Snippets Groups Projects
Commit 1ad39887 authored by Jannik Wurche's avatar Jannik Wurche
Browse files

new file structure

parent 2391e27c
No related branches found
No related tags found
No related merge requests found
Pipeline #22157 failed
image: busybox
image: node:14
stages:
- build
......@@ -6,7 +6,6 @@ stages:
variables:
ELM_VERSION: "0.19.1"
NODE_IMAGE: "node:14"
before_script:
- apt-get update
......@@ -19,7 +18,8 @@ build:
stage: build
script:
- mkdir -p public
- elm make src/Main.elm --output=public/elm.js
- cp src/HTLM/index.html public/index.html
- elm make src/Elm/Main.elm --output=public/elm.js
artifacts:
paths:
- public
......
File moved
module Main exposing (main)
module Elm.Main exposing (main)
import Browser
import Html exposing (Html, div)
......@@ -40,16 +40,11 @@ toPathString : (Float, Float) -> String
toPathString (x, y) =
String.fromFloat x ++ "," ++ String.fromFloat y
toSvgCoord : (Float, Float) -> Int -> Int -> (Float, Float)
toSvgCoord (x, y) xMin yMax=
( x - toFloat xMin, toFloat yMax - y )
generatePath : (Float -> Float) -> ViewBox -> String
generatePath fn viewBox =
let
values = range viewBox.xMin viewBox.xMax 100
points = List.map (\x -> (x, fn x)) values
--pathString = List.map (\v -> toPathString (toSvgCoord v viewBox.xMin viewBox.yMax)) points
pathString = List.map (\v -> toPathString v) points
in
"M" ++ (pathString |> String.join " L ")
......
......@@ -4,13 +4,13 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Elm Websites</title>
<link rel="stylesheet" href="style/style.css">
<link rel="stylesheet" href="../CSS/style.css">
</head>
<body>
<div id="elm-container"></div>
<script src="elm.js"></script>
<script src="../../public/elm.js"></script>
<script>
var app = Elm.Main.init({
var app = Elm.Elm.Main.init({
node: document.getElementById('elm-container')
});
</script>
......
module Main2 exposing (..)
import Browser
import Html exposing (Html)
import Http
import Json.Decode exposing (Decoder, decodeString)
import Quiz exposing (Quiz, decodeQuiz)
import Question exposing (Question)
main =
Browser.element
{ init = init
, update = update
, subscriptions = subscriptions
, view = view
}
type alias Model =
{ quiz : Maybe Quiz
, error : Maybe String }
init : () -> (Model, Cmd Msg)
init _ =
(Model Nothing Nothing, Cmd.none)
type Msg
= LoadQuiz String
| QuizLoaded (Result Http.Error Quiz)
update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
LoadQuiz quizId ->
let
request =
Http.get
{ url = "http://localhost:3000/quizzes/" ++ quizId
, expect = Http.expectJson QuizLoaded decodeQuiz
}
in
(model, request)
QuizLoaded (Ok quiz) ->
({ model | quiz = Just quiz, error = Nothing }, Cmd.none)
QuizLoaded (Err _) ->
({ model | error = Just "Failed to load quiz" }, Cmd.none)
view : Model -> Html Msg
view model =
case model.quiz of
Nothing ->
div [] [ text "Loading..." ]
Just quiz ->
div []
[ h1 [] [ text quiz.title ]
, p [] [ text quiz.description ]
, div [] (List.map viewQuestion quiz.questions)
]
viewQuestion : Question -> Html Msg
viewQuestion question =
case question of
MultipleChoice q ->
div []
[ h3 [] [ text q.task ]
, ul [] (List.map (\choice -> li [] [ text choice ]) q.choices)
]
Input q ->
div []
[ h3 [] [ text q.task ]
, input [ type_ "text" ] []
]
TrueFalse q ->
div []
[ h3 [] [ text q.task ]
, ul []
[ li [] [ text "True" ]
, li [] [ text "False" ]
]
]
subscriptions : Model -> Sub Msg
subscriptions _ =
Sub.none
module Question exposing (..)
import Json.Decode exposing (Decoder, (:=), list, string, int, bool, field, oneOf, map4, map5, nullable, dict)
type Question
= MultipleChoice MCQQuestion
| Input InputQuestion
| TrueFalse TrueFalseQuestion
type alias MCQQuestion =
{ id : String
, task : String
, points : Int
, correctAnswer : String
, choices : List String
, resources : Maybe (Dict String String)
}
type alias InputQuestion =
{ id : String
, task : String
, points : Int
, correctAnswer : String
}
type alias TrueFalseQuestion =
{ id : String
, task : String
, points : Int
, correctAnswer : Bool
, choices : List Bool
}
decodeQuestion : Decoder Question
decodeQuestion =
oneOf
[ map5 MCQQuestion
(field "id" string)
(field "task" string)
(field "points" int)
(field "correctAnswer" string)
(field "choices" (list string))
|> map5 (field "resources" (nullable (dict string)))
|> map5 (MultipleChoice)
, map4 InputQuestion
(field "id" string)
(field "task" string)
(field "points" int)
(field "correctAnswer" string)
|> map4 (Input)
, map5 TrueFalseQuestion
(field "id" string)
(field "task" string)
(field "points" int)
(field "correctAnswer" bool)
(field "choices" (list bool))
|> map5 (TrueFalse)
]
decodeQuestions : Decoder (List Question)
decodeQuestions =
list decodeQuestion
module Quiz exposing (..)
import Json.Decode exposing (Decoder, (:=), list, string, field)
import Question exposing (decodeQuestions, Question)
type alias Quiz =
{ id : String
, title : String
, description : String
, questions : List Question
}
decodeQuiz : Decoder Quiz
decodeQuiz =
map4 Quiz
(field "id" string)
(field "title" string)
(field "description" string)
(field "questions" decodeQuestions)
decodeQuizzes : Decoder (List Quiz)
decodeQuizzes =
field "quizzes" (list decodeQuiz)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment