docspell/modules/webapp/src/main/elm/Comp/CustomFieldTable.elm
Eike Kettner dd935454c9 First version of new ui based on tailwind
This drops fomantic-ui as css toolkit and introduces tailwindcss. With
tailwind there are no predefined components, but it's very easy to
create those. So customizing the look&feel is much simpler, most of
the time no additional css is needed.

This requires a complete rewrite of the markup + styles. Luckily all
logic can be kept as is. The now old ui is not removed, it is still
available by using a request header `Docspell-Ui` with a value of `1`
for the old ui and `2` for the new ui.

Another addition is "dev mode", where docspell serves assets with a
no-cache header, to disable browser caching. This makes developing a
lot easier.
2021-02-14 01:46:13 +01:00

140 lines
3.2 KiB
Elm

module Comp.CustomFieldTable exposing
( Action(..)
, Model
, Msg
, init
, update
, view
, view2
)
import Api.Model.CustomField exposing (CustomField)
import Comp.Basic as B
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
import Styles as S
import Util.Time
type alias Model =
{}
type Msg
= EditItem CustomField
type Action
= NoAction
| EditAction CustomField
init : Model
init =
{}
update : Msg -> Model -> ( Model, Action )
update msg model =
case msg of
EditItem item ->
( model, EditAction item )
--- View
view : Model -> List CustomField -> Html Msg
view _ items =
div []
[ table [ class "ui very basic aligned table" ]
[ thead []
[ tr []
[ th [ class "collapsing" ] []
, th [] [ text "Name/Label" ]
, th [] [ text "Format" ]
, th [] [ text "#Usage" ]
, th [] [ text "Created" ]
]
]
, tbody []
(List.map viewItem items)
]
]
viewItem : CustomField -> Html Msg
viewItem item =
tr []
[ td [ class "collapsing" ]
[ a
[ href "#"
, class "ui basic small blue label"
, onClick (EditItem item)
]
[ i [ class "edit icon" ] []
, text "Edit"
]
]
, td []
[ text <| Maybe.withDefault item.name item.label
]
, td []
[ text item.ftype
]
, td []
[ String.fromInt item.usages
|> text
]
, td []
[ Util.Time.formatDateShort item.created
|> text
]
]
--- View2
view2 : Model -> List CustomField -> Html Msg
view2 _ items =
div []
[ table [ class S.tableMain ]
[ thead []
[ tr []
[ th [] []
, th [ class "text-left" ] [ text "Name/Label" ]
, th [ class "text-left" ] [ text "Format" ]
, th [ class "text-center hidden sm:table-cell" ] [ text "#Usage" ]
, th [ class "text-center hidden sm:table-cell" ] [ text "Created" ]
]
]
, tbody []
(List.map viewItem2 items)
]
]
viewItem2 : CustomField -> Html Msg
viewItem2 item =
tr [ class S.tableRow ]
[ B.editLinkTableCell (EditItem item)
, td [ class "text-left py-4 md:py-2 pr-2" ]
[ text <| Maybe.withDefault item.name item.label
]
, td [ class "text-left py-4 md:py-2 pr-2" ]
[ text item.ftype
]
, td [ class "text-center py-4 md:py-2 sm:pr-2 hidden sm:table-cell" ]
[ String.fromInt item.usages
|> text
]
, td [ class "text-center py-4 md:py-2 hidden sm:table-cell" ]
[ Util.Time.formatDateShort item.created
|> text
]
]