mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-06 07:05:59 +00:00
Copy/paste form together
This commit is contained in:
parent
ad772c0c25
commit
9b30542974
@ -61,7 +61,7 @@ init key url flags =
|
|||||||
, loginModel = Page.Login.Data.emptyModel
|
, loginModel = Page.Login.Data.emptyModel
|
||||||
, manageDataModel = Page.ManageData.Data.emptyModel
|
, manageDataModel = Page.ManageData.Data.emptyModel
|
||||||
, collSettingsModel = Page.CollectiveSettings.Data.emptyModel
|
, collSettingsModel = Page.CollectiveSettings.Data.emptyModel
|
||||||
, userSettingsModel = Page.UserSettings.Data.emptyModel
|
, userSettingsModel = Page.UserSettings.Data.emptyModel flags
|
||||||
, queueModel = Page.Queue.Data.emptyModel
|
, queueModel = Page.Queue.Data.emptyModel
|
||||||
, registerModel = Page.Register.Data.emptyModel
|
, registerModel = Page.Register.Data.emptyModel
|
||||||
, uploadModel = Page.Upload.Data.emptyModel
|
, uploadModel = Page.Upload.Data.emptyModel
|
||||||
|
@ -323,7 +323,11 @@ initPage model page =
|
|||||||
model
|
model
|
||||||
|
|
||||||
UserSettingPage ->
|
UserSettingPage ->
|
||||||
updateQueue Page.Queue.Data.StopRefresh model
|
Util.Update.andThen1
|
||||||
|
[ updateQueue Page.Queue.Data.StopRefresh
|
||||||
|
, updateUserSettings Page.UserSettings.Data.Init
|
||||||
|
]
|
||||||
|
model
|
||||||
|
|
||||||
QueuePage ->
|
QueuePage ->
|
||||||
updateQueue Page.Queue.Data.Init model
|
updateQueue Page.Queue.Data.Init model
|
||||||
|
@ -6,37 +6,242 @@ module Comp.NotificationForm exposing
|
|||||||
, view
|
, view
|
||||||
)
|
)
|
||||||
|
|
||||||
|
import Api
|
||||||
|
import Api.Model.EmailSettingsList exposing (EmailSettingsList)
|
||||||
import Api.Model.NotificationSettings exposing (NotificationSettings)
|
import Api.Model.NotificationSettings exposing (NotificationSettings)
|
||||||
|
import Api.Model.Tag exposing (Tag)
|
||||||
|
import Api.Model.TagList exposing (TagList)
|
||||||
|
import Comp.Dropdown
|
||||||
|
import Comp.EmailInput
|
||||||
|
import Comp.IntField
|
||||||
import Data.Flags exposing (Flags)
|
import Data.Flags exposing (Flags)
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
|
import Html.Events exposing (onCheck, onClick, onInput)
|
||||||
|
import Http
|
||||||
|
import Util.Http
|
||||||
|
import Util.Tag
|
||||||
|
import Util.Update
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{ settings : NotificationSettings
|
{ settings : NotificationSettings
|
||||||
|
, connectionModel : Comp.Dropdown.Model String
|
||||||
|
, tagInclModel : Comp.Dropdown.Model Tag
|
||||||
|
, tagExclModel : Comp.Dropdown.Model Tag
|
||||||
|
, recipients : List String
|
||||||
|
, recipientsModel : Comp.EmailInput.Model
|
||||||
|
, remindDays : Maybe Int
|
||||||
|
, remindDaysModel : Comp.IntField.Model
|
||||||
|
, enabled : Bool
|
||||||
|
, timer : String
|
||||||
|
, formError : Maybe String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= Submit
|
= Submit
|
||||||
|
| TagIncMsg (Comp.Dropdown.Msg Tag)
|
||||||
|
| TagExcMsg (Comp.Dropdown.Msg Tag)
|
||||||
|
| ConnMsg (Comp.Dropdown.Msg String)
|
||||||
|
| ConnResp (Result Http.Error EmailSettingsList)
|
||||||
|
| RecipientMsg Comp.EmailInput.Msg
|
||||||
|
| GetTagsResp (Result Http.Error TagList)
|
||||||
|
| RemindDaysMsg Comp.IntField.Msg
|
||||||
|
| ToggleEnabled
|
||||||
|
| SetSchedule String
|
||||||
|
|
||||||
|
|
||||||
init : Model
|
initCmd : Flags -> Cmd Msg
|
||||||
init =
|
initCmd flags =
|
||||||
{ settings = Api.Model.NotificationSettings.empty
|
Cmd.batch
|
||||||
}
|
[ Api.getMailSettings flags "" ConnResp
|
||||||
|
, Api.getTags flags "" GetTagsResp
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
init : Flags -> ( Model, Cmd Msg )
|
||||||
|
init flags =
|
||||||
|
( { settings = Api.Model.NotificationSettings.empty
|
||||||
|
, connectionModel =
|
||||||
|
Comp.Dropdown.makeSingle
|
||||||
|
{ makeOption = \a -> { value = a, text = a }
|
||||||
|
, placeholder = "Select connection..."
|
||||||
|
}
|
||||||
|
, tagInclModel = Util.Tag.makeDropdownModel
|
||||||
|
, tagExclModel = Util.Tag.makeDropdownModel
|
||||||
|
, recipients = []
|
||||||
|
, recipientsModel = Comp.EmailInput.init
|
||||||
|
, remindDays = Just 1
|
||||||
|
, remindDaysModel = Comp.IntField.init (Just 1) Nothing True "Remind Days"
|
||||||
|
, enabled = False
|
||||||
|
, timer = "*-*-1/7 12:00"
|
||||||
|
, formError = Nothing
|
||||||
|
}
|
||||||
|
, initCmd flags
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||||
update flags msg model =
|
update flags msg model =
|
||||||
( model, Cmd.none )
|
case msg of
|
||||||
|
SetSchedule str ->
|
||||||
|
( { model | timer = str }, Cmd.none )
|
||||||
|
|
||||||
|
RecipientMsg m ->
|
||||||
|
let
|
||||||
|
( em, ec, rec ) =
|
||||||
|
Comp.EmailInput.update flags model.recipients m model.recipientsModel
|
||||||
|
in
|
||||||
|
( { model | recipients = rec, recipientsModel = em }
|
||||||
|
, Cmd.map RecipientMsg ec
|
||||||
|
)
|
||||||
|
|
||||||
|
ConnMsg m ->
|
||||||
|
let
|
||||||
|
( cm, _ ) =
|
||||||
|
-- dropdown doesn't use cmd!!
|
||||||
|
Comp.Dropdown.update m model.connectionModel
|
||||||
|
in
|
||||||
|
( { model | connectionModel = cm }, Cmd.none )
|
||||||
|
|
||||||
|
ConnResp (Ok list) ->
|
||||||
|
let
|
||||||
|
names =
|
||||||
|
List.map .name list.items
|
||||||
|
|
||||||
|
cm =
|
||||||
|
Comp.Dropdown.makeSingleList
|
||||||
|
{ makeOption = \a -> { value = a, text = a }
|
||||||
|
, placeholder = "Select Connection..."
|
||||||
|
, options = names
|
||||||
|
, selected = List.head names
|
||||||
|
}
|
||||||
|
in
|
||||||
|
( { model
|
||||||
|
| connectionModel = cm
|
||||||
|
, formError =
|
||||||
|
if names == [] then
|
||||||
|
Just "No E-Mail connections configured. Goto user settings to add one."
|
||||||
|
|
||||||
|
else
|
||||||
|
Nothing
|
||||||
|
}
|
||||||
|
, Cmd.none
|
||||||
|
)
|
||||||
|
|
||||||
|
ConnResp (Err err) ->
|
||||||
|
( { model | formError = Just (Util.Http.errorToString err) }, Cmd.none )
|
||||||
|
|
||||||
|
TagIncMsg m ->
|
||||||
|
let
|
||||||
|
( m2, c2 ) =
|
||||||
|
Comp.Dropdown.update m model.tagInclModel
|
||||||
|
in
|
||||||
|
( { model | tagInclModel = m2 }
|
||||||
|
, Cmd.map TagIncMsg c2
|
||||||
|
)
|
||||||
|
|
||||||
|
TagExcMsg m ->
|
||||||
|
let
|
||||||
|
( m2, c2 ) =
|
||||||
|
Comp.Dropdown.update m model.tagExclModel
|
||||||
|
in
|
||||||
|
( { model | tagExclModel = m2 }
|
||||||
|
, Cmd.map TagExcMsg c2
|
||||||
|
)
|
||||||
|
|
||||||
|
GetTagsResp (Ok tags) ->
|
||||||
|
let
|
||||||
|
tagList =
|
||||||
|
Comp.Dropdown.SetOptions tags.items
|
||||||
|
in
|
||||||
|
Util.Update.andThen1
|
||||||
|
[ update flags (TagIncMsg tagList)
|
||||||
|
, update flags (TagExcMsg tagList)
|
||||||
|
]
|
||||||
|
model
|
||||||
|
|
||||||
|
GetTagsResp (Err _) ->
|
||||||
|
( model, Cmd.none )
|
||||||
|
|
||||||
|
RemindDaysMsg m ->
|
||||||
|
let
|
||||||
|
( pm, val ) =
|
||||||
|
Comp.IntField.update m model.remindDaysModel
|
||||||
|
in
|
||||||
|
( { model
|
||||||
|
| remindDaysModel = pm
|
||||||
|
, remindDays = val
|
||||||
|
}
|
||||||
|
, Cmd.none
|
||||||
|
)
|
||||||
|
|
||||||
|
ToggleEnabled ->
|
||||||
|
( { model | enabled = not model.enabled }, Cmd.none )
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
( model, Cmd.none )
|
||||||
|
|
||||||
|
|
||||||
view : Model -> Html Msg
|
view : String -> Model -> Html Msg
|
||||||
view model =
|
view extraClasses model =
|
||||||
div
|
div
|
||||||
[ classList
|
[ classList
|
||||||
[ ( "ui form", True )
|
[ ( "ui form", True )
|
||||||
|
, ( extraClasses, True )
|
||||||
|
, ( "error", model.formError /= Nothing )
|
||||||
|
]
|
||||||
|
]
|
||||||
|
[ div [ class "inline field" ]
|
||||||
|
[ div [ class "ui checkbox" ]
|
||||||
|
[ input
|
||||||
|
[ type_ "checkbox"
|
||||||
|
, onCheck (\_ -> ToggleEnabled)
|
||||||
|
, checked model.enabled
|
||||||
|
]
|
||||||
|
[]
|
||||||
|
, label [] [ text "Enabled" ]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
, div [ class "required field" ]
|
||||||
|
[ label [] [ text "Send via" ]
|
||||||
|
, Html.map ConnMsg (Comp.Dropdown.view model.connectionModel)
|
||||||
|
]
|
||||||
|
, div [ class "required field" ]
|
||||||
|
[ label []
|
||||||
|
[ text "Recipient(s)"
|
||||||
|
]
|
||||||
|
, Html.map RecipientMsg
|
||||||
|
(Comp.EmailInput.view model.recipients model.recipientsModel)
|
||||||
|
]
|
||||||
|
, div [ class "field" ]
|
||||||
|
[ label [] [ text "Tags Include (and)" ]
|
||||||
|
, Html.map TagIncMsg (Comp.Dropdown.view model.tagInclModel)
|
||||||
|
]
|
||||||
|
, div [ class "field" ]
|
||||||
|
[ label [] [ text "Tags Exclude (or)" ]
|
||||||
|
, Html.map TagExcMsg (Comp.Dropdown.view model.tagExclModel)
|
||||||
|
]
|
||||||
|
, Html.map RemindDaysMsg
|
||||||
|
(Comp.IntField.view model.remindDays
|
||||||
|
"required field"
|
||||||
|
model.remindDaysModel
|
||||||
|
)
|
||||||
|
, div [ class "required field" ]
|
||||||
|
[ label [] [ text "Schedule" ]
|
||||||
|
, input
|
||||||
|
[ type_ "text"
|
||||||
|
, onInput SetSchedule
|
||||||
|
, value model.timer
|
||||||
|
]
|
||||||
|
[]
|
||||||
|
]
|
||||||
|
, div [ class "ui divider" ] []
|
||||||
|
, button
|
||||||
|
[ class "ui primary button"
|
||||||
|
, onClick Submit
|
||||||
|
]
|
||||||
|
[ text "Submit"
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
[]
|
|
||||||
|
@ -25,7 +25,7 @@ import Html exposing (..)
|
|||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events exposing (onCheck, onInput)
|
import Html.Events exposing (onCheck, onInput)
|
||||||
import Http
|
import Http
|
||||||
import Util.Maybe
|
import Util.Tag
|
||||||
import Util.Update
|
import Util.Update
|
||||||
|
|
||||||
|
|
||||||
@ -56,8 +56,8 @@ type alias Model =
|
|||||||
|
|
||||||
emptyModel : Model
|
emptyModel : Model
|
||||||
emptyModel =
|
emptyModel =
|
||||||
{ tagInclModel = makeTagModel
|
{ tagInclModel = Util.Tag.makeDropdownModel
|
||||||
, tagExclModel = makeTagModel
|
, tagExclModel = Util.Tag.makeDropdownModel
|
||||||
, directionModel =
|
, directionModel =
|
||||||
Comp.Dropdown.makeSingleList
|
Comp.Dropdown.makeSingleList
|
||||||
{ makeOption =
|
{ makeOption =
|
||||||
@ -130,23 +130,6 @@ type Msg
|
|||||||
| ResetForm
|
| ResetForm
|
||||||
|
|
||||||
|
|
||||||
makeTagModel : Comp.Dropdown.Model Tag
|
|
||||||
makeTagModel =
|
|
||||||
Comp.Dropdown.makeModel
|
|
||||||
{ multiple = True
|
|
||||||
, searchable = \n -> n > 4
|
|
||||||
, makeOption = \tag -> { value = tag.id, text = tag.name }
|
|
||||||
, labelColor =
|
|
||||||
\tag ->
|
|
||||||
if Util.Maybe.nonEmpty tag.category then
|
|
||||||
"basic blue"
|
|
||||||
|
|
||||||
else
|
|
||||||
""
|
|
||||||
, placeholder = "Choose a tag…"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
getDirection : Model -> Maybe Direction
|
getDirection : Model -> Maybe Direction
|
||||||
getDirection model =
|
getDirection model =
|
||||||
let
|
let
|
||||||
|
@ -8,6 +8,7 @@ module Page.UserSettings.Data exposing
|
|||||||
import Comp.ChangePasswordForm
|
import Comp.ChangePasswordForm
|
||||||
import Comp.EmailSettingsManage
|
import Comp.EmailSettingsManage
|
||||||
import Comp.NotificationForm
|
import Comp.NotificationForm
|
||||||
|
import Data.Flags exposing (Flags)
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
@ -18,12 +19,12 @@ type alias Model =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
emptyModel : Model
|
emptyModel : Flags -> Model
|
||||||
emptyModel =
|
emptyModel flags =
|
||||||
{ currentTab = Nothing
|
{ currentTab = Nothing
|
||||||
, changePassModel = Comp.ChangePasswordForm.emptyModel
|
, changePassModel = Comp.ChangePasswordForm.emptyModel
|
||||||
, emailSettingsModel = Comp.EmailSettingsManage.emptyModel
|
, emailSettingsModel = Comp.EmailSettingsManage.emptyModel
|
||||||
, notificationModel = Comp.NotificationForm.init
|
, notificationModel = Tuple.first (Comp.NotificationForm.init flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -38,3 +39,4 @@ type Msg
|
|||||||
| ChangePassMsg Comp.ChangePasswordForm.Msg
|
| ChangePassMsg Comp.ChangePasswordForm.Msg
|
||||||
| EmailSettingsMsg Comp.EmailSettingsManage.Msg
|
| EmailSettingsMsg Comp.EmailSettingsManage.Msg
|
||||||
| NotificationMsg Comp.NotificationForm.Msg
|
| NotificationMsg Comp.NotificationForm.Msg
|
||||||
|
| Init
|
||||||
|
@ -10,6 +10,14 @@ import Page.UserSettings.Data exposing (..)
|
|||||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||||
update flags msg model =
|
update flags msg model =
|
||||||
case msg of
|
case msg of
|
||||||
|
Init ->
|
||||||
|
let
|
||||||
|
cmd =
|
||||||
|
Cmd.map NotificationMsg
|
||||||
|
(Tuple.second (Comp.NotificationForm.init flags))
|
||||||
|
in
|
||||||
|
( model, cmd )
|
||||||
|
|
||||||
SetTab t ->
|
SetTab t ->
|
||||||
let
|
let
|
||||||
m =
|
m =
|
||||||
@ -28,8 +36,12 @@ update flags msg model =
|
|||||||
( m, Cmd.none )
|
( m, Cmd.none )
|
||||||
|
|
||||||
NotificationTab ->
|
NotificationTab ->
|
||||||
-- todo: get initial settings
|
let
|
||||||
( m, Cmd.none )
|
initCmd =
|
||||||
|
Cmd.map NotificationMsg
|
||||||
|
(Tuple.second (Comp.NotificationForm.init flags))
|
||||||
|
in
|
||||||
|
( m, initCmd )
|
||||||
in
|
in
|
||||||
( m2, cmd )
|
( m2, cmd )
|
||||||
|
|
||||||
|
@ -88,5 +88,16 @@ viewNotificationForm model =
|
|||||||
[ text "Notification"
|
[ text "Notification"
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
, Html.map NotificationMsg (Comp.NotificationForm.view model.notificationModel)
|
, p []
|
||||||
|
[ text "Docspell can notify you once the due dates of your items come closer. "
|
||||||
|
, text "Notification is done via e-mail. You need to provide a connection in "
|
||||||
|
, text "your e-mail settings."
|
||||||
|
]
|
||||||
|
, p []
|
||||||
|
[ text "Each time this is executed, docspell finds all items that are due in "
|
||||||
|
, em [] [ text "Remind Days" ]
|
||||||
|
, text " days."
|
||||||
|
]
|
||||||
|
, Html.map NotificationMsg
|
||||||
|
(Comp.NotificationForm.view "segment" model.notificationModel)
|
||||||
]
|
]
|
||||||
|
22
modules/webapp/src/main/elm/Util/Tag.elm
Normal file
22
modules/webapp/src/main/elm/Util/Tag.elm
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
module Util.Tag exposing (makeDropdownModel)
|
||||||
|
|
||||||
|
import Api.Model.Tag exposing (Tag)
|
||||||
|
import Comp.Dropdown
|
||||||
|
import Util.Maybe
|
||||||
|
|
||||||
|
|
||||||
|
makeDropdownModel : Comp.Dropdown.Model Tag
|
||||||
|
makeDropdownModel =
|
||||||
|
Comp.Dropdown.makeModel
|
||||||
|
{ multiple = True
|
||||||
|
, searchable = \n -> n > 4
|
||||||
|
, makeOption = \tag -> { value = tag.id, text = tag.name }
|
||||||
|
, labelColor =
|
||||||
|
\tag ->
|
||||||
|
if Util.Maybe.nonEmpty tag.category then
|
||||||
|
"basic blue"
|
||||||
|
|
||||||
|
else
|
||||||
|
""
|
||||||
|
, placeholder = "Choose a tag…"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user