summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-08-08 11:54:16 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-08-08 11:54:16 +0200 |
commit | 0e15e48cf698c6d146ec3a93f844f03509111c6a (patch) | |
tree | 4c2abb69f01d876afc21663e3b6277c412dc9dcd /src/login/src/Struct | |
parent | 9d0475892354be33fa250b33ff0fc858aedb957a (diff) |
Starting to work on the sign-{in,out,up} page.
Diffstat (limited to 'src/login/src/Struct')
-rw-r--r-- | src/login/src/Struct/Error.elm | 45 | ||||
-rw-r--r-- | src/login/src/Struct/Event.elm | 29 | ||||
-rw-r--r-- | src/login/src/Struct/Flags.elm | 42 | ||||
-rw-r--r-- | src/login/src/Struct/HelpRequest.elm | 11 | ||||
-rw-r--r-- | src/login/src/Struct/Model.elm | 85 | ||||
-rw-r--r-- | src/login/src/Struct/ServerReply.elm | 21 | ||||
-rw-r--r-- | src/login/src/Struct/UI.elm | 69 |
7 files changed, 302 insertions, 0 deletions
diff --git a/src/login/src/Struct/Error.elm b/src/login/src/Struct/Error.elm new file mode 100644 index 0000000..5f40c09 --- /dev/null +++ b/src/login/src/Struct/Error.elm @@ -0,0 +1,45 @@ +module Struct.Error exposing (Type, Mode(..), new, to_string) + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Mode = + IllegalAction + | Programming + | Unimplemented + | Networking + | Failure + +type alias Type = + { + mode: Mode, + message: String + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +new : Mode -> String -> Type +new mode str = + { + mode = mode, + message = str + } + +to_string : Type -> String +to_string e = + ( + (case e.mode of + Failure -> "The action failed: " + IllegalAction -> "Request discarded: " + Programming -> "Error in the program (please report): " + Unimplemented -> "Update discarded due to unimplemented feature: " + Networking -> "Error while conversing with the server: " + ) + ++ e.message + ) + diff --git a/src/login/src/Struct/Event.elm b/src/login/src/Struct/Event.elm new file mode 100644 index 0000000..b473475 --- /dev/null +++ b/src/login/src/Struct/Event.elm @@ -0,0 +1,29 @@ +module Struct.Event exposing (Type(..), attempted) + +-- Elm ------------------------------------------------------------------------- +import Http + +-- Map ------------------------------------------------------------------- +import Struct.Error +import Struct.ServerReply +import Struct.HelpRequest +import Struct.UI + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Type = + None + | Failed Struct.Error.Type + | RequestedHelp Struct.HelpRequest.Type + | SendSignInRequested + | SendSignUpRequested + | ServerReplied (Result Http.Error (List Struct.ServerReply.Type)) + | TabSelected Struct.UI.Tab + +attempted : (Result.Result err val) -> Type +attempted act = + case act of + (Result.Ok _) -> None + (Result.Err msg) -> + (Failed (Struct.Error.new Struct.Error.Failure (toString msg))) diff --git a/src/login/src/Struct/Flags.elm b/src/login/src/Struct/Flags.elm new file mode 100644 index 0000000..228d258 --- /dev/null +++ b/src/login/src/Struct/Flags.elm @@ -0,0 +1,42 @@ +module Struct.Flags exposing + ( + Type, + maybe_get_param + ) + +-- Elm ------------------------------------------------------------------------- +import List + +-- Map ------------------------------------------------------------------- +import Util.List + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = + { + user_id : String, + token : String, + url_params : (List (List String)) + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +maybe_get_param : String -> Type -> (Maybe String) +maybe_get_param param flags = + case + (Util.List.get_first + (\e -> ((List.head e) == (Just param))) + flags.url_params + ) + of + Nothing -> Nothing + (Just a) -> + case (List.tail a) of + Nothing -> Nothing + (Just b) -> (List.head b) diff --git a/src/login/src/Struct/HelpRequest.elm b/src/login/src/Struct/HelpRequest.elm new file mode 100644 index 0000000..86d442a --- /dev/null +++ b/src/login/src/Struct/HelpRequest.elm @@ -0,0 +1,11 @@ +module Struct.HelpRequest exposing (Type(..)) + +-- Elm ------------------------------------------------------------------------- + +-- Map ------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Type = + None diff --git a/src/login/src/Struct/Model.elm b/src/login/src/Struct/Model.elm new file mode 100644 index 0000000..787d6ba --- /dev/null +++ b/src/login/src/Struct/Model.elm @@ -0,0 +1,85 @@ +module Struct.Model exposing + ( + Type, + new, + invalidate, + reset, + clear_error + ) + +-- Elm ------------------------------------------------------------------------- + +-- Map ------------------------------------------------------------------- +import Struct.Error +import Struct.Flags +import Struct.HelpRequest +import Struct.UI + +import Util.Array + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = + { + help_request: Struct.HelpRequest.Type, + error: (Maybe Struct.Error.Type), + username: String, + password: String, + email: String, + player_id: String, + session_token: String, + ui: Struct.UI.Type + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +new : Struct.Flags.Type -> Type +new flags = + let + maybe_mode = (Struct.Flags.maybe_get_param "mode" flags) + model = + { + help_request = Struct.HelpRequest.None, + error = Nothing, + username = "", + password = "", + email = "", + player_id = flags.user_id, + session_token = flags.token, + ui = (Struct.UI.default) + } + in + case maybe_mode of + Nothing -> model + + (Just id) -> + {model | + ui = + (Struct.UI.set_displayed_tab + (Struct.UI.tab_from_string id) + model.ui + ) + } + +reset : Type -> Type +reset model = + {model | + help_request = Struct.HelpRequest.None, + error = Nothing, + ui = (Struct.UI.default) + } + +invalidate : Struct.Error.Type -> Type -> Type +invalidate err model = + {model | + error = (Just err) + } + +clear_error : Type -> Type +clear_error model = {model | error = Nothing} diff --git a/src/login/src/Struct/ServerReply.elm b/src/login/src/Struct/ServerReply.elm new file mode 100644 index 0000000..a8580dc --- /dev/null +++ b/src/login/src/Struct/ServerReply.elm @@ -0,0 +1,21 @@ +module Struct.ServerReply exposing (Type(..)) + +-- Elm ------------------------------------------------------------------------- + +-- Map ------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +type Type = + Okay + | SetSession (String, String) + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- diff --git a/src/login/src/Struct/UI.elm b/src/login/src/Struct/UI.elm new file mode 100644 index 0000000..53528f7 --- /dev/null +++ b/src/login/src/Struct/UI.elm @@ -0,0 +1,69 @@ +module Struct.UI exposing + ( + Type, + Tab(..), + default, + -- Tab + try_getting_displayed_tab, + set_displayed_tab, + reset_displayed_tab, + to_string, + tab_from_string, + get_all_tabs + ) + +-- Map ------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Tab = + SignInTab + | SignUpTab + | SignedInTab + +type alias Type = + { + displayed_tab : (Maybe Tab) + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +default : Type +default = + { + displayed_tab = Nothing + } + +-- Tab ------------------------------------------------------------------------- +try_getting_displayed_tab : Type -> (Maybe Tab) +try_getting_displayed_tab ui = ui.displayed_tab + +set_displayed_tab : Tab -> Type -> Type +set_displayed_tab tab ui = {ui | displayed_tab = (Just tab)} + +reset_displayed_tab : Type -> Type +reset_displayed_tab ui = {ui | displayed_tab = Nothing} + +to_string : Tab -> String +to_string tab = + case tab of + SignInTab -> "Sign In" + SignUpTab -> "Sign Up" + SignedInTab -> "Signed In" + +tab_from_string : String -> Tab +tab_from_string str = + case str of + "signin" -> SignInTab + "signup" -> SignUpTab + _ -> SignInTab + +get_all_tabs : (List Tab) +get_all_tabs = + [SignInTab, SignUpTab] |