aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/elm/DecodeFlags.elm54
-rw-r--r--src/client/elm/Main.elm73
-rw-r--r--src/client/elm/Model.elm19
-rw-r--r--src/client/static/elm.js68
4 files changed, 110 insertions, 104 deletions
diff --git a/src/client/elm/DecodeFlags.elm b/src/client/elm/DecodeFlags.elm
new file mode 100644
index 0000000..5acc4f9
--- /dev/null
+++ b/src/client/elm/DecodeFlags.elm
@@ -0,0 +1,54 @@
+module DecodeFlags exposing (Flags, init)
+
+import Json.Decode exposing (Decoder, andThen, fail, string, succeed)
+import Json.Decode.Pipeline exposing (decode, required)
+import Model exposing (..)
+
+
+type alias Flags =
+ Json.Decode.Value
+
+
+init : Flags -> ( Model, Cmd msg )
+init flags =
+ case Json.Decode.decodeValue decodeUsers flags of
+ Ok user ->
+ ( Model user, Cmd.none )
+
+ Err err ->
+ Debug.crash err
+
+
+decodeUsers : Decoder (List User)
+decodeUsers =
+ Json.Decode.list decodeUser
+
+
+decodeUser : Decoder User
+decodeUser =
+ decode User
+ |> required "type" decodeUserType
+ |> required "value" string
+
+
+decodeUserType : Json.Decode.Decoder UserType
+decodeUserType =
+ string
+ |> andThen
+ (\s ->
+ case s of
+ "s" ->
+ succeed Student
+
+ "c" ->
+ succeed Class
+
+ "t" ->
+ succeed Teacher
+
+ "r" ->
+ succeed Room
+
+ _ ->
+ fail ("What the f*ck is " ++ s ++ "?")
+ )
diff --git a/src/client/elm/Main.elm b/src/client/elm/Main.elm
index de1f1fe..e59889d 100644
--- a/src/client/elm/Main.elm
+++ b/src/client/elm/Main.elm
@@ -1,9 +1,8 @@
module Main exposing (..)
import Html exposing (..)
-import Json.Decode exposing (Decoder, andThen, fail, string, succeed)
-import Json.Decode.Pipeline exposing (decode, required)
-
+import Model exposing (Model)
+import DecodeFlags exposing (Flags, init)
main : Program Flags Model msg
main =
@@ -14,74 +13,6 @@ main =
, subscriptions = subscriptions
}
-
-type alias Flags =
- Json.Decode.Value
-
-
-type alias Model =
- { users : List User
- }
-
-
-type alias User =
- { type_ : UserType
- , value : String
- }
-
-
-type UserType
- = Class
- | Teacher
- | Room
- | Student
-
-
-init : Flags -> ( Model, Cmd msg )
-init flags =
- case Json.Decode.decodeValue decodeUsers flags of
- Ok user ->
- ( Model user, Cmd.none )
-
- Err err ->
- Debug.crash err
-
-
-decodeUsers : Decoder (List User)
-decodeUsers =
- Json.Decode.list decodeUser
-
-
-decodeUser : Decoder User
-decodeUser =
- decode User
- |> required "type" decodeUserType
- |> required "value" string
-
-
-decodeUserType : Json.Decode.Decoder UserType
-decodeUserType =
- string
- |> andThen
- (\s ->
- case s of
- "s" ->
- succeed Student
-
- "c" ->
- succeed Class
-
- "t" ->
- succeed Teacher
-
- "r" ->
- succeed Room
-
- _ ->
- fail ("What the f*ck is " ++ s ++ "?")
- )
-
-
update : msg -> Model -> ( Model, Cmd msg )
update msg model =
( model, Cmd.none )
diff --git a/src/client/elm/Model.elm b/src/client/elm/Model.elm
new file mode 100644
index 0000000..8f4c6a6
--- /dev/null
+++ b/src/client/elm/Model.elm
@@ -0,0 +1,19 @@
+module Model exposing (..)
+
+
+type alias Model =
+ { users : List User
+ }
+
+
+type alias User =
+ { type_ : UserType
+ , value : String
+ }
+
+
+type UserType
+ = Class
+ | Teacher
+ | Room
+ | Student
diff --git a/src/client/static/elm.js b/src/client/static/elm.js
index cbab2b5..99bf4cb 100644
--- a/src/client/static/elm.js
+++ b/src/client/static/elm.js
@@ -7875,41 +7875,31 @@ var _elm_lang$html$Html$summary = _elm_lang$html$Html$node('summary');
var _elm_lang$html$Html$menuitem = _elm_lang$html$Html$node('menuitem');
var _elm_lang$html$Html$menu = _elm_lang$html$Html$node('menu');
-var _user$project$Main$subscriptions = function (model) {
- return _elm_lang$core$Platform_Sub$none;
-};
-var _user$project$Main$view = function (model) {
- return _elm_lang$html$Html$text(
- _elm_lang$core$Basics$toString(model));
-};
-var _user$project$Main$update = F2(
- function (msg, model) {
- return {ctor: '_Tuple2', _0: model, _1: _elm_lang$core$Platform_Cmd$none};
- });
-var _user$project$Main$Model = function (a) {
+var _user$project$Model$Model = function (a) {
return {users: a};
};
-var _user$project$Main$User = F2(
+var _user$project$Model$User = F2(
function (a, b) {
return {type_: a, value: b};
});
-var _user$project$Main$Student = {ctor: 'Student'};
-var _user$project$Main$Room = {ctor: 'Room'};
-var _user$project$Main$Teacher = {ctor: 'Teacher'};
-var _user$project$Main$Class = {ctor: 'Class'};
-var _user$project$Main$decodeUserType = A2(
+var _user$project$Model$Student = {ctor: 'Student'};
+var _user$project$Model$Room = {ctor: 'Room'};
+var _user$project$Model$Teacher = {ctor: 'Teacher'};
+var _user$project$Model$Class = {ctor: 'Class'};
+
+var _user$project$DecodeFlags$decodeUserType = A2(
_elm_lang$core$Json_Decode$andThen,
function (s) {
var _p0 = s;
switch (_p0) {
case 's':
- return _elm_lang$core$Json_Decode$succeed(_user$project$Main$Student);
+ return _elm_lang$core$Json_Decode$succeed(_user$project$Model$Student);
case 'c':
- return _elm_lang$core$Json_Decode$succeed(_user$project$Main$Class);
+ return _elm_lang$core$Json_Decode$succeed(_user$project$Model$Class);
case 't':
- return _elm_lang$core$Json_Decode$succeed(_user$project$Main$Teacher);
+ return _elm_lang$core$Json_Decode$succeed(_user$project$Model$Teacher);
case 'r':
- return _elm_lang$core$Json_Decode$succeed(_user$project$Main$Room);
+ return _elm_lang$core$Json_Decode$succeed(_user$project$Model$Room);
default:
return _elm_lang$core$Json_Decode$fail(
A2(
@@ -7919,36 +7909,48 @@ var _user$project$Main$decodeUserType = A2(
}
},
_elm_lang$core$Json_Decode$string);
-var _user$project$Main$decodeUser = A3(
+var _user$project$DecodeFlags$decodeUser = A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'value',
_elm_lang$core$Json_Decode$string,
A3(
_NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$required,
'type',
- _user$project$Main$decodeUserType,
- _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$decode(_user$project$Main$User)));
-var _user$project$Main$decodeUsers = _elm_lang$core$Json_Decode$list(_user$project$Main$decodeUser);
-var _user$project$Main$init = function (flags) {
- var _p1 = A2(_elm_lang$core$Json_Decode$decodeValue, _user$project$Main$decodeUsers, flags);
+ _user$project$DecodeFlags$decodeUserType,
+ _NoRedInk$elm_decode_pipeline$Json_Decode_Pipeline$decode(_user$project$Model$User)));
+var _user$project$DecodeFlags$decodeUsers = _elm_lang$core$Json_Decode$list(_user$project$DecodeFlags$decodeUser);
+var _user$project$DecodeFlags$init = function (flags) {
+ var _p1 = A2(_elm_lang$core$Json_Decode$decodeValue, _user$project$DecodeFlags$decodeUsers, flags);
if (_p1.ctor === 'Ok') {
return {
ctor: '_Tuple2',
- _0: _user$project$Main$Model(_p1._0),
+ _0: _user$project$Model$Model(_p1._0),
_1: _elm_lang$core$Platform_Cmd$none
};
} else {
return _elm_lang$core$Native_Utils.crashCase(
- 'Main',
+ 'DecodeFlags',
{
- start: {line: 44, column: 5},
- end: {line: 49, column: 28}
+ start: {line: 14, column: 5},
+ end: {line: 19, column: 28}
},
_p1)(_p1._0);
}
};
+
+var _user$project$Main$subscriptions = function (model) {
+ return _elm_lang$core$Platform_Sub$none;
+};
+var _user$project$Main$view = function (model) {
+ return _elm_lang$html$Html$text(
+ _elm_lang$core$Basics$toString(model));
+};
+var _user$project$Main$update = F2(
+ function (msg, model) {
+ return {ctor: '_Tuple2', _0: model, _1: _elm_lang$core$Platform_Cmd$none};
+ });
var _user$project$Main$main = _elm_lang$html$Html$programWithFlags(
- {init: _user$project$Main$init, update: _user$project$Main$update, view: _user$project$Main$view, subscriptions: _user$project$Main$subscriptions})(_elm_lang$core$Json_Decode$value);
+ {init: _user$project$DecodeFlags$init, update: _user$project$Main$update, view: _user$project$Main$view, subscriptions: _user$project$Main$subscriptions})(_elm_lang$core$Json_Decode$value);
var Elm = {};
Elm['Main'] = Elm['Main'] || {};