Skip to content

Commit

Permalink
Merge branch 'branches/rudder/8.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelGauthier committed Feb 7, 2025
2 parents 2ff077e + 5d7ab88 commit c63dbec
Show file tree
Hide file tree
Showing 19 changed files with 134 additions and 796 deletions.
3 changes: 1 addition & 2 deletions auth-backends/src/main/elm/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/http": "2.0.0",
"elm/json": "1.1.3",
"pablen/toasty": "1.2.0"
"elm/json": "1.1.3"
},
"indirect": {
"elm/bytes": "1.0.8",
Expand Down
71 changes: 12 additions & 59 deletions auth-backends/src/main/elm/sources/AuthBackends.elm
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
module AuthBackends exposing (AdminConfig, AuthConfig, ConfigOption, FileConfig, LdapConfig, Model, Msg(..), addTempToast, addToast, backendConfigOption, backendDescription, backendTitle, createDecodeErrorNotification, createErrorNotification, createSuccessNotification, decodeAdminConfig, decodeApiCurrentAuthConf, decodeConfigOption, decodeCurrentAuthConf, decodeFileConfig, decodeLdapConfig, defaultConfig, displayAdminConfig, displayAuthConfig, displayBackendId, displayFileConfig, displayLdapConfig, displayProvidConfig, getErrorMessage, getTargets, init, main, subscriptions, tempConfig, update, view)
port module AuthBackends exposing (AdminConfig, AuthConfig, ConfigOption, FileConfig, LdapConfig, Model, Msg(..), backendConfigOption, backendDescription, backendTitle, decodeAdminConfig, decodeApiCurrentAuthConf, decodeConfigOption, decodeCurrentAuthConf, decodeFileConfig, decodeLdapConfig, displayAdminConfig, displayAuthConfig, displayBackendId, displayFileConfig, displayLdapConfig, displayProvidConfig, getErrorMessage, getTargets, init, main, subscriptions, update, view)

import Html exposing (..)
import Browser
import Html.Attributes exposing (checked, class, style, type_)
import Html.Attributes exposing (class)
import Http exposing (..)
import Json.Decode as D exposing (Decoder, succeed)
import Json.Decode.Pipeline exposing (..)
import String
import Toasty
import Toasty.Defaults


------------------------------
-- PORTS
------------------------------


port errorNotification : String -> Cmd msg



Expand All @@ -32,7 +38,7 @@ init : { contextPath : String } -> ( Model, Cmd Msg )
init flags =
let
initModel =
Model flags.contextPath Nothing Toasty.initialState
Model flags.contextPath Nothing
in
( initModel
, getTargets initModel
Expand Down Expand Up @@ -99,14 +105,11 @@ type alias LdapConfig =
type alias Model =
{ contextPath : String
, currentConfig : Maybe AuthConfig -- from API
, toasties : Toasty.Stack Toasty.Defaults.Toast
}


type Msg
= GetCurrentAuthConfig (Result Error AuthConfig)
-- NOTIFICATIONS
| ToastyMsg (Toasty.Msg Toasty.Defaults.Toast)



Expand Down Expand Up @@ -218,10 +221,7 @@ update msg model =
newModel =
{ model | currentConfig = Nothing }
in
( newModel, Cmd.none ) |> createErrorNotification "Error while trying to fetch settings." err

ToastyMsg subMsg ->
Toasty.update defaultConfig ToastyMsg subMsg model
( newModel, errorNotification ("Error while trying to fetch settings: " ++ getErrorMessage err) )



Expand All @@ -243,7 +243,6 @@ view model =
in
div [ class "row" ]
[ content
, div [ class "toasties" ] [ Toasty.view defaultConfig Toasty.Defaults.view ToastyMsg model.toasties ]
]


Expand Down Expand Up @@ -398,49 +397,3 @@ getErrorMessage e =
str
in
errMessage


defaultConfig : Toasty.Config Msg
defaultConfig =
Toasty.Defaults.config
|> Toasty.delay 999999999
|> Toasty.containerAttrs
[ style "position" "fixed"
, style "top" "50px"
, style "right" "30px"
, style "width" "100%"
, style "max-width" "500px"
, style "list-style-type" "none"
, style "padding" "0"
, style "margin" "0"
]


tempConfig : Toasty.Config Msg
tempConfig =
defaultConfig |> Toasty.delay 3000


addTempToast : Toasty.Defaults.Toast -> ( Model, Cmd Msg ) -> ( Model, Cmd Msg )
addTempToast toast ( model, cmd ) =
Toasty.addToast tempConfig ToastyMsg toast ( model, cmd )


addToast : Toasty.Defaults.Toast -> ( Model, Cmd Msg ) -> ( Model, Cmd Msg )
addToast toast ( model, cmd ) =
Toasty.addToast defaultConfig ToastyMsg toast ( model, cmd )


createSuccessNotification : String -> ( Model, Cmd Msg ) -> ( Model, Cmd Msg )
createSuccessNotification message =
addTempToast (Toasty.Defaults.Success "Success!" message)


createErrorNotification : String -> Http.Error -> ( Model, Cmd Msg ) -> ( Model, Cmd Msg )
createErrorNotification message e =
addToast (Toasty.Defaults.Error "Error..." (message ++ " (" ++ getErrorMessage e ++ ")"))


createDecodeErrorNotification : String -> String -> ( Model, Cmd Msg ) -> ( Model, Cmd Msg )
createDecodeErrorNotification message e =
addToast (Toasty.Defaults.Error "Error..." (message ++ " (" ++ e ++ ")"))
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<title>Rudder - Authentication Backends</title>
<link rel="stylesheet" type="text/css" href="/toserve/authbackends/auth-backends.css" media="screen" data-lift="with-cached-resource">
<script src="/toserve/authbackends/rudder-authbackends.js" data-lift="with-cached-resource"></script>
<link rel="stylesheet" type="text/css" href="/toserve/authbackends/toasty.css" media="screen" data-lift="with-cached-resource">
</head_merge>


Expand All @@ -36,6 +35,9 @@ <h3 class="page-title">Authentication Backends Configuration</h3>
<script>
var node = document.getElementById("auth-backends-app");
var app = Elm.AuthBackends.init( { node : node, flags : { contextPath: contextPath}});
app.ports.errorNotification.subscribe(function (str) {
createErrorNotification(str)
});
</script>

</div>
Expand Down
139 changes: 0 additions & 139 deletions auth-backends/src/main/style/toasty.css

This file was deleted.

1 change: 0 additions & 1 deletion branding/src/main/elm/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"elm/html": "1.0.0",
"elm/http": "2.0.0",
"elm/json": "1.1.3",
"pablen/toasty": "1.2.0",
"simonh1000/elm-colorpicker": "2.0.3"
},
"indirect": {
Expand Down
46 changes: 30 additions & 16 deletions branding/src/main/elm/sources/Branding.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ import Color exposing (rgb255)
import DataTypes exposing (..)
import Html exposing (..)
import Html.Events exposing (keyCode, on)
import Http exposing (Error)
import Json.Decode as Decode
import JsonDecoder exposing (..)
import JsonEncoder exposing (..)
import Toasty
import Toasty.Defaults
import ColorPicker
import View exposing (..)
import Browser
Expand All @@ -19,7 +16,8 @@ import Task

--- PORTS ---
port applyCss : ( CssObj ) -> Cmd msg

port successNotification : String -> Cmd msg
port errorNotification : String -> Cmd msg

--- MODEL ---
defaultSettings : Settings
Expand All @@ -35,8 +33,7 @@ defaultSettings =
initSettings : { contextPath : String } -> ( Model, Cmd Msg )
initSettings initValues =
let
toasties = Toasty.initialState
model = Model initValues.contextPath ColorPicker.empty ColorPicker.empty defaultSettings toasties False
model = Model initValues.contextPath ColorPicker.empty ColorPicker.empty defaultSettings False
in
( model, ApiCall.getSettings model)

Expand Down Expand Up @@ -183,8 +180,7 @@ update msg model =
( newModel, Cmd.none )

Err err ->
( model, Cmd.none )
|> createErrorNotification "Error while trying to fetch settings." err
( model, errorNotification ("Error while trying to fetch settings: " ++ (getErrorMessage err) ++ "") )

SaveSettings result ->
case result of
Expand All @@ -205,19 +201,14 @@ update msg model =
cssObj = CssObj bgColor txtColor labelTxt --wideLogoEnable wideLogoData smallLogoEnable smallLogoData

in
( model, applyCss ( cssObj ) )
|> createSuccessNotification "Your changes have been saved."
( model, Cmd.batch[applyCss ( cssObj ), successNotification ""] )

Err err ->
( model, Cmd.none )
|> createErrorNotification "Error while trying to save changes." err
( model, errorNotification ("Error while trying to save changes: " ++ (getErrorMessage err) ++ ""))

SendSave ->
( model, ApiCall.saveSettings model )

ToastyMsg subMsg ->
Toasty.update defaultConfig ToastyMsg subMsg model

{-- LOGO UPLOAD & PREVIEW --}
ToggleLogo logoType->
let
Expand Down Expand Up @@ -285,11 +276,34 @@ update msg model =
newModel = { model | settings = newSettings }
in
(newModel, Cmd.none)

onKeyDown : (Int -> msg) -> Html.Attribute msg
onKeyDown tagger =
on "keydown" (Decode.map tagger keyCode)


getErrorMessage : Http.Error -> String
getErrorMessage e =
let
errMessage =
case e of
Http.BadStatus status ->
"Code " ++ String.fromInt status

Http.BadUrl str ->
"Invalid API url"

Http.Timeout ->
"It took too long to get a response"

Http.NetworkError ->
"Network error"

Http.BadBody str ->
str
in
errMessage

--- MAIN ---
subscriptions : Model -> Sub Msg
subscriptions model =
Expand Down
Loading

0 comments on commit c63dbec

Please sign in to comment.