Something went wrong. Try again.
Configurable leathercraft templates clt.pocka.jp
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204-- Copyright 2026 Shota FUJI---- This Source Code Form is subject to the terms of the Mozilla Public-- License, v. 2.0. If a copy of the MPL was not distributed with this-- file, You can obtain one at https://mozilla.org/MPL/2.0/.---- SPDX-License-Identifier: MPL-2.0
module Models.PWS01.QueryHealer exposing (Model, Msg, init, update, view)
import Dict exposing (Dict)import Dict.Anyimport Html exposing (..)import Html.Attributes exposing (..)import Html.LivingStandard exposing (..)import Models.PWS01.Parameters as Parametersimport Models.PWS01.Parameters.Key as Key exposing (Key)import Models.PWS01.Parameters.Parser as Parser exposing (Error(..))import Preferences exposing (DictKeyMode(..), Preferences)import Url exposing (Url)import Url.SearchParams as SearchParams
-- MODEL
type alias Model = { errors : Parser.Errors , searchParams : Dict String String , url : Url , preferences : Preferences }
init : Url -> Preferences -> Parser.Errors -> Modelinit url preferences errors = { errors = errors , searchParams = url.query |> Maybe.map SearchParams.parse |> Maybe.withDefault Dict.empty , url = url , preferences = preferences }
-- UPDATE
type Msg = NoOp
update : Msg -> Model -> ( Model, Cmd Msg )update msg model = case msg of NoOp -> ( model, Cmd.none )
-- VIEW
defaults : DictKeyMode -> Dict String Stringdefaults mode = Dict.union (Parameters.toDict mode Parameters.default) (Parameters.fallbackValues mode)
row : Model -> Key -> Error -> Html Msgrow { searchParams, url, preferences } key error = let setLinkText : String -> Html msg setLinkText value = text ("Set to \"" ++ value ++ "\". ")
withDefault = case Parameters.getKey key (defaults preferences.urlKeyMode) of Just value -> Dict.insert (Key.toString key) value searchParams
Nothing -> searchParams
defaultLink = a [ slot "action" , href (Url.toString { url | query = Just (SearchParams.build withDefault) }) ] [ setLinkText (Parameters.getKey key (defaults preferences.urlKeyMode) |> Maybe.withDefault "") , text "(default value)" ] in node "x-query-healer" [ role "listitem" ] (span [ slot "key" ] [ text (Key.toLabel key) ] :: (case error of MissingValue -> [ span [ slot "description" ] [ text "Parameter is missing" ] , defaultLink ]
BelowMin min -> let withMin = Dict.insert (Key.toString key) (String.fromFloat min) searchParams in [ span [ slot "description" ] [ text "Value is below the minimum." ] , defaultLink , a [ slot "action" , href (Url.toString { url | query = Just (SearchParams.build withMin) }) ] [ setLinkText (String.fromFloat min) , text "(minimum value)" ] ]
AboveMax max -> let withMax = Dict.insert (Key.toString key) (String.fromFloat max) searchParams in [ span [ slot "description" ] [ text "Value exceeds the maximum." ] , defaultLink , a [ slot "action" , href (Url.toString { url | query = Just (SearchParams.build withMax) }) ] [ setLinkText (String.fromFloat max) , text "(maximum value)" ] ]
NotALength -> [ span [ slot "description" ] [ text "Value is not a valid length value." ] , defaultLink ]
NotAnInt -> [ span [ slot "description" ] [ text "Value is not a valid integer." ] , defaultLink ]
NonexistentVariant _ -> [ span [ slot "description" ] [ text "Unrecognizable value." ] , defaultLink ]
UnsupportedParametersVersion _ -> [ span [ slot "description" ] [ text "Unsupported version." ] , defaultLink , a [ slot "action" , href (Url.toString { url | query = Just (SearchParams.build (Parameters.default |> Parameters.toDict preferences.urlKeyMode)) } ) ] [ text "Use default parameters" ] ] ) )
view : Model -> Html Msgview model = let { url, preferences } = model in node "x-error-page" [] [ h1 [ slot "title" ] [ text "Invalid Parameters" ] , p [ slot "description" ] [ text "This URL is not a valid URL for WWSTB." , text " Fix erroneous parameters or start with " , a [ href (Url.toString { url | query = Just (SearchParams.build (Parameters.default |> Parameters.toDict preferences.urlKeyMode)) } ) ] [ text "default parameters" ] , text "." ] , node "x-query-healer-items" [ role "list" ] (model.errors |> Dict.Any.toList |> List.map (\( key, error ) -> row model key error) ) ]