From 0337be98f9dbd4c10acdf73af55648bdeb5c6489 Mon Sep 17 00:00:00 2001 From: eikek Date: Wed, 26 Jan 2022 21:21:55 +0100 Subject: [PATCH] Outline dashboard model --- modules/webapp/src/main/elm/Comp/BoxView.elm | 28 +++++++ .../src/main/elm/Comp/DashboardView.elm | 79 +++++++++++++++++++ modules/webapp/src/main/elm/Data/Box.elm | 12 +++ .../webapp/src/main/elm/Data/BoxContent.elm | 27 +++++++ .../webapp/src/main/elm/Data/Dashboard.elm | 10 +++ .../src/main/elm/Page/Dashboard/Data.elm | 16 +++- .../elm/Page/Dashboard/DefaultDashboard.elm | 57 +++++++++++++ .../src/main/elm/Page/Dashboard/Update.elm | 11 ++- .../src/main/elm/Page/Dashboard/View.elm | 7 +- 9 files changed, 240 insertions(+), 7 deletions(-) create mode 100644 modules/webapp/src/main/elm/Comp/BoxView.elm create mode 100644 modules/webapp/src/main/elm/Comp/DashboardView.elm create mode 100644 modules/webapp/src/main/elm/Data/Box.elm create mode 100644 modules/webapp/src/main/elm/Data/BoxContent.elm create mode 100644 modules/webapp/src/main/elm/Data/Dashboard.elm create mode 100644 modules/webapp/src/main/elm/Page/Dashboard/DefaultDashboard.elm diff --git a/modules/webapp/src/main/elm/Comp/BoxView.elm b/modules/webapp/src/main/elm/Comp/BoxView.elm new file mode 100644 index 00000000..b429cfe9 --- /dev/null +++ b/modules/webapp/src/main/elm/Comp/BoxView.elm @@ -0,0 +1,28 @@ +module Comp.BoxView exposing (..) + +import Data.Box exposing (Box) +import Data.Flags exposing (Flags) +import Html exposing (Html, div) + + +type alias Model = + {} + + +type Msg + = Dummy + + +init : Flags -> Box -> ( Model, Cmd Msg ) +init flags box = + ( {}, Cmd.none ) + + + +--- Update +--- View + + +view : Model -> Html Msg +view model = + div [] [] diff --git a/modules/webapp/src/main/elm/Comp/DashboardView.elm b/modules/webapp/src/main/elm/Comp/DashboardView.elm new file mode 100644 index 00000000..974d0675 --- /dev/null +++ b/modules/webapp/src/main/elm/Comp/DashboardView.elm @@ -0,0 +1,79 @@ +module Comp.DashboardView exposing (Model, Msg, init, view, viewBox) + +import Comp.BoxView +import Data.Box exposing (Box) +import Data.Dashboard exposing (Dashboard) +import Data.Flags exposing (Flags) +import Dict exposing (Dict) +import Html exposing (Html, div) +import Html.Attributes exposing (class) + + +type alias Model = + { dashboard : Dashboard + , boxModels : List Comp.BoxView.Model + } + + +type Msg + = BoxMsg Comp.BoxView.Msg + + +init : Flags -> Dashboard -> ( Model, Cmd Msg ) +init flags db = + let + ( boxModels, cmds ) = + List.map (Comp.BoxView.init flags) db.boxes + |> List.map (Tuple.mapSecond <| Cmd.map BoxMsg) + |> List.unzip + in + ( { dashboard = db + , boxModels = boxModels + } + , Cmd.batch cmds + ) + + + +--- View + + +view : Model -> Html Msg +view model = + div + [ class (gridStyle model.dashboard) + ] + (List.map viewBox model.boxModels) + + +viewBox : Comp.BoxView.Model -> Html Msg +viewBox box = + Html.map BoxMsg + (Comp.BoxView.view box) + + + +--- Helpers + + +gridStyle : Dashboard -> String +gridStyle db = + let + colStyle = + case db.columns of + 1 -> + "" + + 2 -> + "md:grid-cols-2" + + 3 -> + "md:grid-cols-3" + + 4 -> + "md:grid-cols-4" + + _ -> + "md:grid-cols-5" + in + "grid gap-4 grid-cols-1 " ++ colStyle diff --git a/modules/webapp/src/main/elm/Data/Box.elm b/modules/webapp/src/main/elm/Data/Box.elm new file mode 100644 index 00000000..1553b7d4 --- /dev/null +++ b/modules/webapp/src/main/elm/Data/Box.elm @@ -0,0 +1,12 @@ +module Data.Box exposing (Box) + +import Data.BoxContent exposing (BoxContent) + + +type alias Box = + { name : String + , visible : Bool + , decoration : Bool + , colspan : Int + , content : BoxContent + } diff --git a/modules/webapp/src/main/elm/Data/BoxContent.elm b/modules/webapp/src/main/elm/Data/BoxContent.elm new file mode 100644 index 00000000..82f4c8e1 --- /dev/null +++ b/modules/webapp/src/main/elm/Data/BoxContent.elm @@ -0,0 +1,27 @@ +module Data.BoxContent exposing (BoxContent(..), MessageData, QueryData, SummaryData) + +import Data.ItemArrange exposing (ItemArrange) + + +type BoxContent + = BoxUpload + | BoxMessage MessageData + | BoxQuery QueryData + | BoxSummary SummaryData + + +type alias MessageData = + { title : String + , body : String + } + + +type alias QueryData = + { query : String + , view : ItemArrange + } + + +type alias SummaryData = + { query : String + } diff --git a/modules/webapp/src/main/elm/Data/Dashboard.elm b/modules/webapp/src/main/elm/Data/Dashboard.elm new file mode 100644 index 00000000..9aae25d6 --- /dev/null +++ b/modules/webapp/src/main/elm/Data/Dashboard.elm @@ -0,0 +1,10 @@ +module Data.Dashboard exposing (Dashboard) + +import Data.Box exposing (Box) + + +type alias Dashboard = + { name : String + , columns : Int + , boxes : List Box + } diff --git a/modules/webapp/src/main/elm/Page/Dashboard/Data.elm b/modules/webapp/src/main/elm/Page/Dashboard/Data.elm index d93340a2..1b959891 100644 --- a/modules/webapp/src/main/elm/Page/Dashboard/Data.elm +++ b/modules/webapp/src/main/elm/Page/Dashboard/Data.elm @@ -15,6 +15,7 @@ module Page.Dashboard.Data exposing import Api import Comp.BookmarkChooser +import Comp.DashboardView import Comp.EquipmentManage import Comp.FolderManage import Comp.NotificationHookManage @@ -26,6 +27,7 @@ import Comp.SourceManage import Comp.TagManage import Data.Bookmarks exposing (AllBookmarks) import Data.Flags exposing (Flags) +import Page.Dashboard.DefaultDashboard as DefaultDashboard type alias SideMenuModel = @@ -41,12 +43,19 @@ type alias Model = init : Flags -> ( Model, Cmd Msg ) init flags = + let + ( dm, dc ) = + Comp.DashboardView.init flags DefaultDashboard.value + in ( { sideMenu = { bookmarkChooser = Comp.BookmarkChooser.init Data.Bookmarks.empty } - , content = NoContent + , content = Home dm } - , initCmd flags + , Cmd.batch + [ initCmd flags + , Cmd.map DashboardMsg dc + ] ) @@ -72,6 +81,7 @@ type Msg | EquipmentMsg Comp.EquipmentManage.Msg | TagMsg Comp.TagManage.Msg | FolderMsg Comp.FolderManage.Msg + | DashboardMsg Comp.DashboardView.Msg | InitNotificationHook | InitDashboard | InitPeriodicQuery @@ -85,7 +95,7 @@ type Msg type Content - = NoContent + = Home Comp.DashboardView.Model | Webhook Comp.NotificationHookManage.Model | PeriodicQuery Comp.PeriodicQueryTaskManage.Model | Source Comp.SourceManage.Model diff --git a/modules/webapp/src/main/elm/Page/Dashboard/DefaultDashboard.elm b/modules/webapp/src/main/elm/Page/Dashboard/DefaultDashboard.elm new file mode 100644 index 00000000..8f12acee --- /dev/null +++ b/modules/webapp/src/main/elm/Page/Dashboard/DefaultDashboard.elm @@ -0,0 +1,57 @@ +module Page.Dashboard.DefaultDashboard exposing (..) + +import Data.Box exposing (Box) +import Data.BoxContent exposing (BoxContent(..)) +import Data.Dashboard exposing (Dashboard) +import Data.ItemArrange + + +value : Dashboard +value = + { name = "Default" + , columns = 2 + , boxes = + [ messageBox + , newDocuments + , summary + ] + } + + +messageBox : Box +messageBox = + { name = "Welcome Message" + , visible = True + , decoration = False + , colspan = 2 + , content = + BoxMessage + { title = "Welcome to Docspell" + , body = "" + } + } + + +newDocuments : Box +newDocuments = + { name = "New Documents" + , visible = True + , decoration = True + , colspan = 1 + , content = + BoxQuery + { query = "inbox:yes" + , view = Data.ItemArrange.List + } + } + + +summary : Box +summary = + { name = "Summary" + , visible = True + , decoration = True + , colspan = 1 + , content = + BoxSummary { query = "" } + } diff --git a/modules/webapp/src/main/elm/Page/Dashboard/Update.elm b/modules/webapp/src/main/elm/Page/Dashboard/Update.elm index 6b5c277c..4b2d95a8 100644 --- a/modules/webapp/src/main/elm/Page/Dashboard/Update.elm +++ b/modules/webapp/src/main/elm/Page/Dashboard/Update.elm @@ -9,6 +9,7 @@ module Page.Dashboard.Update exposing (update) import Browser.Navigation as Nav import Comp.BookmarkChooser +import Comp.DashboardView import Comp.EquipmentManage import Comp.FolderManage import Comp.NotificationHookManage @@ -22,6 +23,7 @@ import Data.Flags exposing (Flags) import Messages.Page.Dashboard exposing (Texts) import Page exposing (Page(..)) import Page.Dashboard.Data exposing (..) +import Page.Dashboard.DefaultDashboard import Set @@ -56,7 +58,11 @@ update texts navKey flags msg model = ) InitDashboard -> - ( { model | content = NoContent }, Cmd.none, Sub.none ) + let + ( dm, dc ) = + Comp.DashboardView.init flags Page.Dashboard.DefaultDashboard.value + in + ( { model | content = Home dm }, Cmd.map DashboardMsg dc, Sub.none ) InitNotificationHook -> let @@ -235,6 +241,9 @@ update texts navKey flags msg model = _ -> unit model + DashboardMsg lm -> + unit model + unit : Model -> ( Model, Cmd Msg, Sub Msg ) unit m = diff --git a/modules/webapp/src/main/elm/Page/Dashboard/View.elm b/modules/webapp/src/main/elm/Page/Dashboard/View.elm index c2b6a5a6..31a87018 100644 --- a/modules/webapp/src/main/elm/Page/Dashboard/View.elm +++ b/modules/webapp/src/main/elm/Page/Dashboard/View.elm @@ -7,6 +7,7 @@ module Page.Dashboard.View exposing (viewContent, viewSidebar) +import Comp.DashboardView import Comp.EquipmentManage import Comp.FolderManage import Comp.NotificationHookManage @@ -20,7 +21,6 @@ import Data.Flags exposing (Flags) import Data.UiSettings exposing (UiSettings) import Html exposing (..) import Html.Attributes exposing (..) -import Html.Events exposing (onClick) import Messages.Page.Dashboard exposing (Texts) import Page.Dashboard.Data exposing (..) import Page.Dashboard.SideMenu as SideMenu @@ -46,8 +46,9 @@ viewContent texts flags settings model = , class S.content ] [ case model.content of - NoContent -> - div [] [] + Home m -> + Html.map DashboardMsg + (Comp.DashboardView.view m) Webhook m -> viewHookManage texts settings m