mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-23 02:48:26 +00:00
Initial outline for managing spaces
This commit is contained in:
154
modules/webapp/src/main/elm/Comp/SpaceDetail.elm
Normal file
154
modules/webapp/src/main/elm/Comp/SpaceDetail.elm
Normal file
@ -0,0 +1,154 @@
|
||||
module Comp.SpaceDetail exposing
|
||||
( Model
|
||||
, Msg
|
||||
, init
|
||||
, update
|
||||
, view
|
||||
)
|
||||
|
||||
import Api
|
||||
import Api.Model.BasicResult exposing (BasicResult)
|
||||
import Api.Model.IdName exposing (IdName)
|
||||
import Api.Model.SpaceDetail exposing (SpaceDetail)
|
||||
import Api.Model.User exposing (User)
|
||||
import Api.Model.UserList exposing (UserList)
|
||||
import Comp.FixedDropdown
|
||||
import Data.Flags exposing (Flags)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick, onInput)
|
||||
import Http
|
||||
import Util.Http
|
||||
import Util.Maybe
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ result : Maybe BasicResult
|
||||
, name : Maybe String
|
||||
, members : List IdName
|
||||
, users : List User
|
||||
, memberDropdown : Comp.FixedDropdown.Model IdName
|
||||
, selectedMember : Maybe IdName
|
||||
}
|
||||
|
||||
|
||||
type Msg
|
||||
= SetName String
|
||||
| MemberDropdownMsg (Comp.FixedDropdown.Msg IdName)
|
||||
|
||||
|
||||
init : List User -> SpaceDetail -> Model
|
||||
init users space =
|
||||
{ result = Nothing
|
||||
, name = Util.Maybe.fromString space.name
|
||||
, members = space.members
|
||||
, users = users
|
||||
, memberDropdown =
|
||||
Comp.FixedDropdown.initMap .name
|
||||
(makeOptions users space.members)
|
||||
, selectedMember = Nothing
|
||||
}
|
||||
|
||||
|
||||
makeOptions : List User -> List IdName -> List IdName
|
||||
makeOptions users members =
|
||||
let
|
||||
toIdName u =
|
||||
IdName u.id u.login
|
||||
|
||||
notMember idn =
|
||||
List.member idn members |> not
|
||||
in
|
||||
List.map toIdName users
|
||||
|> List.filter notMember
|
||||
|
||||
|
||||
|
||||
--- Update
|
||||
|
||||
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
update flags msg model =
|
||||
case msg of
|
||||
SetName str ->
|
||||
( { model | name = Util.Maybe.fromString str }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
MemberDropdownMsg lmsg ->
|
||||
let
|
||||
( mm, sel ) =
|
||||
Comp.FixedDropdown.update lmsg model.memberDropdown
|
||||
in
|
||||
( { model
|
||||
| memberDropdown = mm
|
||||
, selectedMember = sel
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
|
||||
|
||||
--- View
|
||||
|
||||
|
||||
view : Model -> Html Msg
|
||||
view model =
|
||||
div []
|
||||
[ div [ class "ui header" ]
|
||||
[ text "Name"
|
||||
]
|
||||
, div [ class "ui action input" ]
|
||||
[ input
|
||||
[ type_ "text"
|
||||
, onInput SetName
|
||||
, Maybe.withDefault "" model.name
|
||||
|> value
|
||||
]
|
||||
[]
|
||||
, button
|
||||
[ class "ui icon button"
|
||||
]
|
||||
[ i [ class "save icon" ] []
|
||||
]
|
||||
]
|
||||
, div [ class "ui header" ]
|
||||
[ text "Members"
|
||||
]
|
||||
, div [ class "ui form" ]
|
||||
[ div [ class "inline field" ]
|
||||
[ Html.map MemberDropdownMsg
|
||||
(Comp.FixedDropdown.view
|
||||
(Maybe.map makeItem model.selectedMember)
|
||||
model.memberDropdown
|
||||
)
|
||||
, button
|
||||
[ class "ui primary button"
|
||||
]
|
||||
[ text "Add"
|
||||
]
|
||||
]
|
||||
]
|
||||
, div
|
||||
[ class "ui list"
|
||||
]
|
||||
(List.map viewMember model.members)
|
||||
]
|
||||
|
||||
|
||||
makeItem : IdName -> Comp.FixedDropdown.Item IdName
|
||||
makeItem idn =
|
||||
Comp.FixedDropdown.Item idn idn.name
|
||||
|
||||
|
||||
viewMember : IdName -> Html Msg
|
||||
viewMember member =
|
||||
div
|
||||
[ class "item"
|
||||
]
|
||||
[ button
|
||||
[ class "ui primary icon button"
|
||||
]
|
||||
[ i [ class "delete icon" ] []
|
||||
]
|
||||
]
|
118
modules/webapp/src/main/elm/Comp/SpaceManage.elm
Normal file
118
modules/webapp/src/main/elm/Comp/SpaceManage.elm
Normal file
@ -0,0 +1,118 @@
|
||||
module Comp.SpaceManage exposing
|
||||
( Model
|
||||
, Msg
|
||||
, empty
|
||||
, init
|
||||
, update
|
||||
, view
|
||||
)
|
||||
|
||||
import Api
|
||||
import Api.Model.SpaceDetail exposing (SpaceDetail)
|
||||
import Api.Model.SpaceItem exposing (SpaceItem)
|
||||
import Api.Model.SpaceList exposing (SpaceList)
|
||||
import Api.Model.User exposing (User)
|
||||
import Api.Model.UserList exposing (UserList)
|
||||
import Comp.SpaceDetail
|
||||
import Comp.SpaceTable
|
||||
import Data.Flags exposing (Flags)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick, onInput)
|
||||
import Http
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ tableModel : Comp.SpaceTable.Model
|
||||
, detailModel : Maybe Comp.SpaceDetail.Model
|
||||
, spaces : List SpaceItem
|
||||
, users : List User
|
||||
, query : String
|
||||
, loading : Bool
|
||||
}
|
||||
|
||||
|
||||
type Msg
|
||||
= TableMsg Comp.SpaceTable.Msg
|
||||
| DetailMsg Comp.SpaceDetail.Msg
|
||||
| UserListResp (Result Http.Error UserList)
|
||||
| SpaceListResp (Result Http.Error SpaceList)
|
||||
| SpaceDetailResp (Result Http.Error SpaceDetail)
|
||||
| SetQuery String
|
||||
| InitNewSpace
|
||||
|
||||
|
||||
empty : Model
|
||||
empty =
|
||||
{ tableModel = Comp.SpaceTable.init
|
||||
, detailModel = Nothing
|
||||
, spaces = []
|
||||
, users = []
|
||||
, query = ""
|
||||
, loading = False
|
||||
}
|
||||
|
||||
|
||||
init : Flags -> ( Model, Cmd Msg )
|
||||
init flags =
|
||||
( empty
|
||||
, Cmd.batch
|
||||
[ Api.getUsers flags UserListResp
|
||||
, Api.getSpaces flags SpaceListResp
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
|
||||
--- Update
|
||||
|
||||
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
update flags msg model =
|
||||
( model, Cmd.none )
|
||||
|
||||
|
||||
|
||||
--- View
|
||||
|
||||
|
||||
view : Model -> Html Msg
|
||||
view model =
|
||||
div []
|
||||
[ div [ class "ui secondary menu" ]
|
||||
[ div [ class "horizontally fitted item" ]
|
||||
[ div [ class "ui icon input" ]
|
||||
[ input
|
||||
[ type_ "text"
|
||||
, onInput SetQuery
|
||||
, value model.query
|
||||
, placeholder "Search…"
|
||||
]
|
||||
[]
|
||||
, i [ class "ui search icon" ]
|
||||
[]
|
||||
]
|
||||
]
|
||||
, div [ class "right menu" ]
|
||||
[ div [ class "item" ]
|
||||
[ a
|
||||
[ class "ui primary button"
|
||||
, href "#"
|
||||
, onClick InitNewSpace
|
||||
]
|
||||
[ i [ class "plus icon" ] []
|
||||
, text "New Space"
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
, Html.map TableMsg (Comp.SpaceTable.view model.tableModel model.spaces)
|
||||
, div
|
||||
[ classList
|
||||
[ ( "ui dimmer", True )
|
||||
, ( "active", model.loading )
|
||||
]
|
||||
]
|
||||
[ div [ class "ui loader" ] []
|
||||
]
|
||||
]
|
89
modules/webapp/src/main/elm/Comp/SpaceTable.elm
Normal file
89
modules/webapp/src/main/elm/Comp/SpaceTable.elm
Normal file
@ -0,0 +1,89 @@
|
||||
module Comp.SpaceTable exposing
|
||||
( Action(..)
|
||||
, Model
|
||||
, Msg
|
||||
, init
|
||||
, update
|
||||
, view
|
||||
)
|
||||
|
||||
import Api.Model.SpaceItem exposing (SpaceItem)
|
||||
import Api.Model.SpaceList exposing (SpaceList)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick)
|
||||
import Util.Time
|
||||
|
||||
|
||||
type alias Model =
|
||||
{}
|
||||
|
||||
|
||||
type Msg
|
||||
= EditItem SpaceItem
|
||||
|
||||
|
||||
type Action
|
||||
= NoAction
|
||||
| EditAction SpaceItem
|
||||
|
||||
|
||||
init : Model
|
||||
init =
|
||||
{}
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Action )
|
||||
update msg model =
|
||||
case msg of
|
||||
EditItem item ->
|
||||
( model, EditAction item )
|
||||
|
||||
|
||||
view : Model -> List SpaceItem -> Html Msg
|
||||
view _ items =
|
||||
div []
|
||||
[ table [ class "ui very basic center aligned table" ]
|
||||
[ thead []
|
||||
[ th [ class "collapsing" ] []
|
||||
, th [] [ text "Name" ]
|
||||
, th [] [ text "Owner" ]
|
||||
, th [] [ text "Members" ]
|
||||
, th [] [ text "Created" ]
|
||||
]
|
||||
, tbody []
|
||||
(List.map viewItem items)
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
viewItem : SpaceItem -> 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 []
|
||||
[ code []
|
||||
[ text item.name
|
||||
]
|
||||
]
|
||||
, td []
|
||||
[ text item.owner.name
|
||||
]
|
||||
, td []
|
||||
[ String.fromInt item.members
|
||||
|> text
|
||||
]
|
||||
, td []
|
||||
[ Util.Time.formatDateShort item.created
|
||||
|> text
|
||||
]
|
||||
]
|
Reference in New Issue
Block a user