maca/postgrest-admin-preview/12.0.4

NOTE: the latest version is 15.0.0

Rerouted (regenerated, verified). Same repository and tag, but GitHub now builds the zip with different bytes, so it no longer matches the SHA-1 package.elm-lang.org recorded. The Lamdera package server serves a copy recovered from https://github.com/maca/postgrest-admin-preview.

What we checked: Rebuilt with git archive from commit 7cf1d70f7ffc of https://github.com/maca/postgrest-admin-preview (zip prefix maca-postgrest-admin-preview-7cf1d70/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 466b481a17567624454ed983961c03718d6f5e8c.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/maca/postgrest-admin-preview/zipball/12.0.4/

PostgRestAdmin.Config

Program configuration

type alias Config m msg =
Decoder (Config m msg)

PostgRestAdmin.application configuration params.

Init

init : Config m msg

PostgRestAdmin.application decoder with defaults.

main : PostgRestAdmin.Program Never Never
main =
    PostgRestAdmin.application Config.init

Basics

withHost : String -> Config m msg -> Config m msg

Specify the postgREST host.

  main : PostgRestAdmin.Program Never Never
  main =
      Config.init
          |> Config.withHost "http://localhost:3000"
          |> PostgRestAdmin.application

Alternatively the host can be specified using flags, configuring using withHost. Program flags take precedence.

  Elm.Main.init({
      flags: { host: "http://localhost:3000" }
  })
withFormFields : String -> List String -> Config m msg -> Config m msg

Specify which fields should be present in the the edit and create forms, overriding the table schema. By default a primary key field is not present in the forms.

  main : PostgRestAdmin.Program Never Never
  main =
      Config.init
          |> Config.withFormFields "posts" ["id", "title", "content"]
          |> PostgRestAdmin.application

Alternatively this parameter can be configured using flags, configuring using withFormFields. Program flags take precedence.

  Elm.Main.init({
      flags: { formFields: { posts: [ "id", "title", "content" ]} }
  })
String
-> List ( String, Record -> String -> String )
-> Config m msg
-> Config m msg

Specify a number of actions buttons to be shown in the detail page of a record along with Edit and Delete buttons.

withDetailActions expect a dict where the keys correspond with the name of a table and the values are a list of tuples, the first element of the tuple corresponds to the button text and the second is a function that takes the id of the resource and returns a url string.

  import Url.Builder as Url


  main : PostgRestAdmin.Program Never Never
  main =
      Config.init
          |> Config.withDetailActions "posts"
              [ ( "View Comments"
                , \_ id -> Url.absolute [ "posts", id, "comments" ] []
                )
              ]


      |> PostgRestAdmin.application
withTables : List String -> Config m msg -> Config m msg

Pass a list of table names to restrict the editable resources, also sets the order of the left resources menu.

  main : PostgRestAdmin.Program Never Never
  main =
      Config.init
          |> Config.withTables ["posts", "comments"]
          |> PostgRestAdmin.application

Alternatively the host can be specified using flags, configuring using withTables. Program flags take precedence.

  Elm.Main.init({
      tables: ["posts", "comments"]
  })

Auth

withFormAuth : FormAuth -> Config m msg -> Config m msg

Enable user credentials form and configure the parameters. Credentials are be used to obtain a JWT.

See FormAuth for configuration options.

  import PostgRestAdmin.Config.FormAuth as FormAuth


  main : PostgRestAdmin.Program Never Never
  main =
      Config.init
          |> Config.withFormAuth FormAuth.config
          |> PostgRestAdmin.application
withJwt : String -> Config m msg -> Config m msg

Set a JWT to authenticate postgREST requests. Even when using withFormAuth it's possible to set an initial JWT.

  main : PostgRestAdmin.Program Never Never
  main =
      Config.init
          |> Config.withJwt "8abf3a...9ac36d"
          |> PostgRestAdmin.application

Alternatively the token can be passed using flags, configuring using withJwt. Program flags take precedence.

  Elm.Main.init({
      flags: { jwt: sessionStorage.getItem("jwt") }
  })
withOnLogin : (String -> Cmd msg) -> Config m msg -> Config m msg

Callback triggered with a JWT string on successful login. Tipically used to persist the JWT to session storage.

      port loginSuccess : String -> Cmd msg


      main : PostgRestAdmin.Program Never Never
      main =
          Config.init
              |> Config.withOnLogin loginSuccess
              |> PostgRestAdmin.application

Elm init

    app = Elm.Main.init({
      flags: { jwt: sessionStorage.getItem("jwt") }
    })


    app.ports.loginSuccess.subscribe(jwt => {
      sessionStorage.setItem("jwt", jwt)
    });

Application mounting

{ init : Client -> Key -> ( model, Cmd msg )
, view : model -> Html msg
, update : msg -> model -> ( model, Cmd msg )
, subscriptions : model -> Sub msg
, onLogin : Client -> msg
}
-> Parser (msg -> msg) msg
-> Config model msg
-> Config model msg

Mount an application on a give path using Url.Parser. This is usefull if you want to override an existing page or add additional behaviour.

The component specification is similar to the specification for Browser.element, with the addition of onLogin param for which a msg should be provided to be sent on successful login.

Note that the type signature changes from PostgRestAdmin.Program Nothing Nothing. Model and Msg are defined by your application.

The url parser should map to a Msg to be used to update your application when navigating to this route built the parameters that the parser defines, you can use Url.Parser.oneOf to parse many routes.

main : PostgRestAdmin.Program Model Msg
main =
    Config.init
        |> Config.withMountPoint
            { view = view
            , update = update
            , init = init
            , onLogin = LoggedIn
            }
            (Parser.map MyPostLoadedMsg
                (s "posts" </> Parser.string </> s "comments")
            )
        |> PostgRestAdmin.application

The application is initialized with a Client you can use to perform requests.