mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-05 22:55:58 +00:00
Adopt UI to allow multiple notification tasks
This commit is contained in:
parent
e51e84408b
commit
2c13f9307c
@ -9,12 +9,14 @@ module Api exposing
|
||||
, checkCalEvent
|
||||
, createImapSettings
|
||||
, createMailSettings
|
||||
, createNotifyDueItems
|
||||
, createScanMailbox
|
||||
, deleteAttachment
|
||||
, deleteEquip
|
||||
, deleteImapSettings
|
||||
, deleteItem
|
||||
, deleteMailSettings
|
||||
, deleteNotifyDueItems
|
||||
, deleteOrg
|
||||
, deletePerson
|
||||
, deleteScanMailbox
|
||||
@ -75,6 +77,7 @@ module Api exposing
|
||||
, startOnceNotifyDueItems
|
||||
, startOnceScanMailbox
|
||||
, submitNotifyDueItems
|
||||
, updateNotifyDueItems
|
||||
, updateScanMailbox
|
||||
, upload
|
||||
, uploadAmend
|
||||
@ -108,6 +111,7 @@ import Api.Model.ItemUploadMeta exposing (ItemUploadMeta)
|
||||
import Api.Model.JobQueueState exposing (JobQueueState)
|
||||
import Api.Model.MoveAttachment exposing (MoveAttachment)
|
||||
import Api.Model.NotificationSettings exposing (NotificationSettings)
|
||||
import Api.Model.NotificationSettingsList exposing (NotificationSettingsList)
|
||||
import Api.Model.OptionalDate exposing (OptionalDate)
|
||||
import Api.Model.OptionalId exposing (OptionalId)
|
||||
import Api.Model.OptionalText exposing (OptionalText)
|
||||
@ -216,6 +220,19 @@ getScanMailbox flags receive =
|
||||
--- NotifyDueItems
|
||||
|
||||
|
||||
deleteNotifyDueItems :
|
||||
Flags
|
||||
-> String
|
||||
-> (Result Http.Error BasicResult -> msg)
|
||||
-> Cmd msg
|
||||
deleteNotifyDueItems flags id receive =
|
||||
Http2.authDelete
|
||||
{ url = flags.config.baseUrl ++ "/api/v1/sec/usertask/notifydueitems/" ++ id
|
||||
, account = getAccount flags
|
||||
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
|
||||
}
|
||||
|
||||
|
||||
startOnceNotifyDueItems :
|
||||
Flags
|
||||
-> NotificationSettings
|
||||
@ -230,6 +247,46 @@ startOnceNotifyDueItems flags settings receive =
|
||||
}
|
||||
|
||||
|
||||
updateNotifyDueItems :
|
||||
Flags
|
||||
-> NotificationSettings
|
||||
-> (Result Http.Error BasicResult -> msg)
|
||||
-> Cmd msg
|
||||
updateNotifyDueItems flags settings receive =
|
||||
Http2.authPut
|
||||
{ url = flags.config.baseUrl ++ "/api/v1/sec/usertask/notifydueitems"
|
||||
, account = getAccount flags
|
||||
, body = Http.jsonBody (Api.Model.NotificationSettings.encode settings)
|
||||
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
|
||||
}
|
||||
|
||||
|
||||
createNotifyDueItems :
|
||||
Flags
|
||||
-> NotificationSettings
|
||||
-> (Result Http.Error BasicResult -> msg)
|
||||
-> Cmd msg
|
||||
createNotifyDueItems flags settings receive =
|
||||
Http2.authPost
|
||||
{ url = flags.config.baseUrl ++ "/api/v1/sec/usertask/notifydueitems"
|
||||
, account = getAccount flags
|
||||
, body = Http.jsonBody (Api.Model.NotificationSettings.encode settings)
|
||||
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
|
||||
}
|
||||
|
||||
|
||||
getNotifyDueItems :
|
||||
Flags
|
||||
-> (Result Http.Error NotificationSettingsList -> msg)
|
||||
-> Cmd msg
|
||||
getNotifyDueItems flags receive =
|
||||
Http2.authGet
|
||||
{ url = flags.config.baseUrl ++ "/api/v1/sec/usertask/notifydueitems"
|
||||
, account = getAccount flags
|
||||
, expect = Http.expectJson receive Api.Model.NotificationSettingsList.decoder
|
||||
}
|
||||
|
||||
|
||||
submitNotifyDueItems :
|
||||
Flags
|
||||
-> NotificationSettings
|
||||
@ -244,18 +301,6 @@ submitNotifyDueItems flags settings receive =
|
||||
}
|
||||
|
||||
|
||||
getNotifyDueItems :
|
||||
Flags
|
||||
-> (Result Http.Error NotificationSettings -> msg)
|
||||
-> Cmd msg
|
||||
getNotifyDueItems flags receive =
|
||||
Http2.authGet
|
||||
{ url = flags.config.baseUrl ++ "/api/v1/sec/usertask/notifydueitems"
|
||||
, account = getAccount flags
|
||||
, expect = Http.expectJson receive Api.Model.NotificationSettings.decoder
|
||||
}
|
||||
|
||||
|
||||
|
||||
--- CalEvent
|
||||
|
||||
|
@ -1,7 +1,9 @@
|
||||
module Comp.NotificationForm exposing
|
||||
( Model
|
||||
( Action(..)
|
||||
, Model
|
||||
, Msg
|
||||
, init
|
||||
, initWith
|
||||
, update
|
||||
, view
|
||||
)
|
||||
@ -16,6 +18,7 @@ import Comp.CalEventInput
|
||||
import Comp.Dropdown
|
||||
import Comp.EmailInput
|
||||
import Comp.IntField
|
||||
import Comp.YesNoDimmer
|
||||
import Data.CalEvent exposing (CalEvent)
|
||||
import Data.Flags exposing (Flags)
|
||||
import Data.UiSettings exposing (UiSettings)
|
||||
@ -45,9 +48,18 @@ type alias Model =
|
||||
, scheduleModel : Comp.CalEventInput.Model
|
||||
, formMsg : Maybe BasicResult
|
||||
, loading : Int
|
||||
, yesNoDelete : Comp.YesNoDimmer.Model
|
||||
}
|
||||
|
||||
|
||||
type Action
|
||||
= SubmitAction NotificationSettings
|
||||
| StartOnceAction NotificationSettings
|
||||
| CancelAction
|
||||
| DeleteAction String
|
||||
| NoAction
|
||||
|
||||
|
||||
type Msg
|
||||
= Submit
|
||||
| TagIncMsg (Comp.Dropdown.Msg Tag)
|
||||
@ -60,22 +72,63 @@ type Msg
|
||||
| ToggleEnabled
|
||||
| ToggleCapOverdue
|
||||
| CalEventMsg Comp.CalEventInput.Msg
|
||||
| SetNotificationSettings (Result Http.Error NotificationSettings)
|
||||
| SubmitResp (Result Http.Error BasicResult)
|
||||
| StartOnce
|
||||
| Cancel
|
||||
| RequestDelete
|
||||
| YesNoDeleteMsg Comp.YesNoDimmer.Msg
|
||||
|
||||
|
||||
initCmd : Flags -> Cmd Msg
|
||||
initCmd flags =
|
||||
Cmd.batch
|
||||
[ Api.getMailSettings flags "" ConnResp
|
||||
, Api.getTags flags "" GetTagsResp
|
||||
, Api.getNotifyDueItems flags SetNotificationSettings
|
||||
initWith : Flags -> NotificationSettings -> ( Model, Cmd Msg )
|
||||
initWith flags s =
|
||||
let
|
||||
( im, ic ) =
|
||||
init flags
|
||||
|
||||
smtp =
|
||||
Util.Maybe.fromString s.smtpConnection
|
||||
|> Maybe.map List.singleton
|
||||
|> Maybe.withDefault []
|
||||
|
||||
removeAction ( tm, _, tc ) =
|
||||
( tm, tc )
|
||||
|
||||
( nm, nc ) =
|
||||
Util.Update.andThen1
|
||||
[ update flags (ConnMsg (Comp.Dropdown.SetSelection smtp)) >> removeAction
|
||||
, update flags (TagIncMsg (Comp.Dropdown.SetSelection s.tagsInclude)) >> removeAction
|
||||
, update flags (TagExcMsg (Comp.Dropdown.SetSelection s.tagsExclude)) >> removeAction
|
||||
]
|
||||
im
|
||||
|
||||
newSchedule =
|
||||
Data.CalEvent.fromEvent s.schedule
|
||||
|> Maybe.withDefault Data.CalEvent.everyMonth
|
||||
|
||||
( sm, sc ) =
|
||||
Comp.CalEventInput.init flags newSchedule
|
||||
in
|
||||
( { nm
|
||||
| settings = s
|
||||
, recipients = s.recipients
|
||||
, remindDays = Just s.remindDays
|
||||
, enabled = s.enabled
|
||||
, capOverdue = s.capOverdue
|
||||
, schedule = Data.Validated.Unknown newSchedule
|
||||
, scheduleModel = sm
|
||||
, formMsg = Nothing
|
||||
, loading = im.loading
|
||||
, yesNoDelete = Comp.YesNoDimmer.emptyModel
|
||||
}
|
||||
, Cmd.batch
|
||||
[ nc
|
||||
, ic
|
||||
, Cmd.map CalEventMsg sc
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
init : Flags -> UiSettings -> ( Model, Cmd Msg )
|
||||
init flags settings =
|
||||
init : Flags -> ( Model, Cmd Msg )
|
||||
init flags =
|
||||
let
|
||||
initialSchedule =
|
||||
Data.Validated.Unknown Data.CalEvent.everyMonth
|
||||
@ -100,10 +153,12 @@ init flags settings =
|
||||
, schedule = initialSchedule
|
||||
, scheduleModel = sm
|
||||
, formMsg = Nothing
|
||||
, loading = 3
|
||||
, loading = 2
|
||||
, yesNoDelete = Comp.YesNoDimmer.emptyModel
|
||||
}
|
||||
, Cmd.batch
|
||||
[ initCmd flags
|
||||
[ Api.getMailSettings flags "" ConnResp
|
||||
, Api.getTags flags "" GetTagsResp
|
||||
, Cmd.map CalEventMsg sc
|
||||
]
|
||||
)
|
||||
@ -155,12 +210,13 @@ makeSettings model =
|
||||
model.schedule
|
||||
|
||||
|
||||
withValidSettings : (NotificationSettings -> Cmd Msg) -> Model -> ( Model, Cmd Msg )
|
||||
withValidSettings : (NotificationSettings -> Action) -> Model -> ( Model, Action, Cmd Msg )
|
||||
withValidSettings mkcmd model =
|
||||
case makeSettings model of
|
||||
Valid set ->
|
||||
( { model | formMsg = Nothing }
|
||||
, mkcmd set
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
Invalid errs _ ->
|
||||
@ -168,15 +224,19 @@ withValidSettings mkcmd model =
|
||||
errMsg =
|
||||
String.join ", " errs
|
||||
in
|
||||
( { model | formMsg = Just (BasicResult False errMsg) }, Cmd.none )
|
||||
( { model | formMsg = Just (BasicResult False errMsg) }
|
||||
, NoAction
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
Unknown _ ->
|
||||
( { model | formMsg = Just (BasicResult False "An unknown error occured") }
|
||||
, NoAction
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
update : Flags -> Msg -> Model -> ( Model, Action, Cmd Msg )
|
||||
update flags msg model =
|
||||
case msg of
|
||||
CalEventMsg lmsg ->
|
||||
@ -192,6 +252,7 @@ update flags msg model =
|
||||
, scheduleModel = cm
|
||||
, formMsg = Nothing
|
||||
}
|
||||
, NoAction
|
||||
, Cmd.map CalEventMsg cc
|
||||
)
|
||||
|
||||
@ -205,6 +266,7 @@ update flags msg model =
|
||||
, recipientsModel = em
|
||||
, formMsg = Nothing
|
||||
}
|
||||
, NoAction
|
||||
, Cmd.map RecipientMsg ec
|
||||
)
|
||||
|
||||
@ -217,6 +279,7 @@ update flags msg model =
|
||||
| connectionModel = cm
|
||||
, formMsg = Nothing
|
||||
}
|
||||
, NoAction
|
||||
, Cmd.map ConnMsg cc
|
||||
)
|
||||
|
||||
@ -246,6 +309,7 @@ update flags msg model =
|
||||
else
|
||||
Nothing
|
||||
}
|
||||
, NoAction
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
@ -254,6 +318,7 @@ update flags msg model =
|
||||
| formMsg = Just (BasicResult False (Util.Http.errorToString err))
|
||||
, loading = model.loading - 1
|
||||
}
|
||||
, NoAction
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
@ -266,6 +331,7 @@ update flags msg model =
|
||||
| tagInclModel = m2
|
||||
, formMsg = Nothing
|
||||
}
|
||||
, NoAction
|
||||
, Cmd.map TagIncMsg c2
|
||||
)
|
||||
|
||||
@ -278,6 +344,7 @@ update flags msg model =
|
||||
| tagExclModel = m2
|
||||
, formMsg = Nothing
|
||||
}
|
||||
, NoAction
|
||||
, Cmd.map TagExcMsg c2
|
||||
)
|
||||
|
||||
@ -285,18 +352,25 @@ update flags msg model =
|
||||
let
|
||||
tagList =
|
||||
Comp.Dropdown.SetOptions tags.items
|
||||
in
|
||||
|
||||
removeAction ( tm, _, tc ) =
|
||||
( tm, tc )
|
||||
|
||||
( m, c ) =
|
||||
Util.Update.andThen1
|
||||
[ update flags (TagIncMsg tagList)
|
||||
, update flags (TagExcMsg tagList)
|
||||
[ update flags (TagIncMsg tagList) >> removeAction
|
||||
, update flags (TagExcMsg tagList) >> removeAction
|
||||
]
|
||||
{ model | loading = model.loading - 1 }
|
||||
in
|
||||
( m, NoAction, c )
|
||||
|
||||
GetTagsResp (Err err) ->
|
||||
( { model
|
||||
| loading = model.loading - 1
|
||||
, formMsg = Just (BasicResult False (Util.Http.errorToString err))
|
||||
}
|
||||
, NoAction
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
@ -310,6 +384,7 @@ update flags msg model =
|
||||
, remindDays = val
|
||||
, formMsg = Nothing
|
||||
}
|
||||
, NoAction
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
@ -318,6 +393,7 @@ update flags msg model =
|
||||
| enabled = not model.enabled
|
||||
, formMsg = Nothing
|
||||
}
|
||||
, NoAction
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
@ -326,75 +402,49 @@ update flags msg model =
|
||||
| capOverdue = not model.capOverdue
|
||||
, formMsg = Nothing
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
SetNotificationSettings (Ok s) ->
|
||||
let
|
||||
smtp =
|
||||
Util.Maybe.fromString s.smtpConnection
|
||||
|> Maybe.map List.singleton
|
||||
|> Maybe.withDefault []
|
||||
|
||||
( nm, nc ) =
|
||||
Util.Update.andThen1
|
||||
[ update flags (ConnMsg (Comp.Dropdown.SetSelection smtp))
|
||||
, update flags (TagIncMsg (Comp.Dropdown.SetSelection s.tagsInclude))
|
||||
, update flags (TagExcMsg (Comp.Dropdown.SetSelection s.tagsExclude))
|
||||
]
|
||||
model
|
||||
|
||||
newSchedule =
|
||||
Data.CalEvent.fromEvent s.schedule
|
||||
|> Maybe.withDefault Data.CalEvent.everyMonth
|
||||
|
||||
( sm, sc ) =
|
||||
Comp.CalEventInput.init flags newSchedule
|
||||
in
|
||||
( { nm
|
||||
| settings = s
|
||||
, recipients = s.recipients
|
||||
, remindDays = Just s.remindDays
|
||||
, enabled = s.enabled
|
||||
, capOverdue = s.capOverdue
|
||||
, schedule = Data.Validated.Unknown newSchedule
|
||||
, scheduleModel = sm
|
||||
, formMsg = Nothing
|
||||
, loading = model.loading - 1
|
||||
}
|
||||
, Cmd.batch
|
||||
[ nc
|
||||
, Cmd.map CalEventMsg sc
|
||||
]
|
||||
)
|
||||
|
||||
SetNotificationSettings (Err err) ->
|
||||
( { model
|
||||
| formMsg = Just (BasicResult False (Util.Http.errorToString err))
|
||||
, loading = model.loading - 1
|
||||
}
|
||||
, NoAction
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
Submit ->
|
||||
withValidSettings
|
||||
(\set -> Api.submitNotifyDueItems flags set SubmitResp)
|
||||
SubmitAction
|
||||
model
|
||||
|
||||
StartOnce ->
|
||||
withValidSettings
|
||||
(\set -> Api.startOnceNotifyDueItems flags set SubmitResp)
|
||||
StartOnceAction
|
||||
model
|
||||
|
||||
SubmitResp (Ok res) ->
|
||||
( { model | formMsg = Just res }
|
||||
Cancel ->
|
||||
( model, CancelAction, Cmd.none )
|
||||
|
||||
RequestDelete ->
|
||||
let
|
||||
( ym, _ ) =
|
||||
Comp.YesNoDimmer.update
|
||||
Comp.YesNoDimmer.activate
|
||||
model.yesNoDelete
|
||||
in
|
||||
( { model | yesNoDelete = ym }
|
||||
, NoAction
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
SubmitResp (Err err) ->
|
||||
( { model
|
||||
| formMsg = Just (BasicResult False (Util.Http.errorToString err))
|
||||
}
|
||||
YesNoDeleteMsg lm ->
|
||||
let
|
||||
( ym, flag ) =
|
||||
Comp.YesNoDimmer.update lm model.yesNoDelete
|
||||
|
||||
act =
|
||||
if flag then
|
||||
DeleteAction model.settings.id
|
||||
|
||||
else
|
||||
NoAction
|
||||
in
|
||||
( { model | yesNoDelete = ym }
|
||||
, act
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
@ -426,7 +476,8 @@ view extraClasses settings model =
|
||||
, ( "success", isFormSuccess model )
|
||||
]
|
||||
]
|
||||
[ div
|
||||
[ Html.map YesNoDeleteMsg (Comp.YesNoDimmer.view model.yesNoDelete)
|
||||
, div
|
||||
[ classList
|
||||
[ ( "ui dimmer", True )
|
||||
, ( "active", model.loading > 0 )
|
||||
@ -550,6 +601,21 @@ view extraClasses settings model =
|
||||
]
|
||||
[ text "Submit"
|
||||
]
|
||||
, button
|
||||
[ class "ui secondary button"
|
||||
, onClick Cancel
|
||||
]
|
||||
[ text "Cancel"
|
||||
]
|
||||
, button
|
||||
[ classList
|
||||
[ ( "ui red button", True )
|
||||
, ( "hidden invisible", model.settings.id == "" )
|
||||
]
|
||||
, onClick RequestDelete
|
||||
]
|
||||
[ text "Delete"
|
||||
]
|
||||
, button
|
||||
[ class "ui right floated button"
|
||||
, onClick StartOnce
|
||||
|
93
modules/webapp/src/main/elm/Comp/NotificationList.elm
Normal file
93
modules/webapp/src/main/elm/Comp/NotificationList.elm
Normal file
@ -0,0 +1,93 @@
|
||||
module Comp.NotificationList exposing
|
||||
( Action(..)
|
||||
, Model
|
||||
, Msg
|
||||
, init
|
||||
, update
|
||||
, view
|
||||
)
|
||||
|
||||
import Api.Model.NotificationSettings exposing (NotificationSettings)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick)
|
||||
import Util.Html
|
||||
|
||||
|
||||
type alias Model =
|
||||
{}
|
||||
|
||||
|
||||
type Msg
|
||||
= EditSettings NotificationSettings
|
||||
|
||||
|
||||
type Action
|
||||
= NoAction
|
||||
| EditAction NotificationSettings
|
||||
|
||||
|
||||
init : Model
|
||||
init =
|
||||
{}
|
||||
|
||||
|
||||
update : Msg -> Model -> ( Model, Action )
|
||||
update msg model =
|
||||
case msg of
|
||||
EditSettings settings ->
|
||||
( model, EditAction settings )
|
||||
|
||||
|
||||
view : Model -> List NotificationSettings -> Html Msg
|
||||
view _ items =
|
||||
div []
|
||||
[ table [ class "ui very basic table" ]
|
||||
[ thead []
|
||||
[ th [ class "collapsing" ] []
|
||||
, th [ class "collapsing" ]
|
||||
[ i [ class "check icon" ] []
|
||||
]
|
||||
, th [] [ text "Connection" ]
|
||||
, th [] [ text "Recipients" ]
|
||||
, th [] [ text "Schedule" ]
|
||||
, th [] [ text "Remind Days" ]
|
||||
]
|
||||
, tbody []
|
||||
(List.map viewItem items)
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
viewItem : NotificationSettings -> Html Msg
|
||||
viewItem item =
|
||||
tr []
|
||||
[ td [ class "collapsing" ]
|
||||
[ a
|
||||
[ href "#"
|
||||
, class "ui basic small blue label"
|
||||
, onClick (EditSettings item)
|
||||
]
|
||||
[ i [ class "edit icon" ] []
|
||||
, text "Edit"
|
||||
]
|
||||
]
|
||||
, td [ class "collapsing" ]
|
||||
[ Util.Html.checkbox item.enabled
|
||||
]
|
||||
, td []
|
||||
[ text item.smtpConnection
|
||||
]
|
||||
, td []
|
||||
[ String.join ", " item.recipients |> text
|
||||
]
|
||||
, td []
|
||||
[ code []
|
||||
[ text item.schedule
|
||||
]
|
||||
]
|
||||
, td []
|
||||
[ String.fromInt item.remindDays
|
||||
|> text
|
||||
]
|
||||
]
|
243
modules/webapp/src/main/elm/Comp/NotificationManage.elm
Normal file
243
modules/webapp/src/main/elm/Comp/NotificationManage.elm
Normal file
@ -0,0 +1,243 @@
|
||||
module Comp.NotificationManage exposing
|
||||
( Model
|
||||
, Msg
|
||||
, init
|
||||
, update
|
||||
, view
|
||||
)
|
||||
|
||||
import Api
|
||||
import Api.Model.BasicResult exposing (BasicResult)
|
||||
import Api.Model.NotificationSettings exposing (NotificationSettings)
|
||||
import Api.Model.NotificationSettingsList exposing (NotificationSettingsList)
|
||||
import Comp.NotificationForm
|
||||
import Comp.NotificationList
|
||||
import Data.Flags exposing (Flags)
|
||||
import Data.UiSettings exposing (UiSettings)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick)
|
||||
import Http
|
||||
import Util.Http
|
||||
|
||||
|
||||
type alias Model =
|
||||
{ listModel : Comp.NotificationList.Model
|
||||
, detailModel : Maybe Comp.NotificationForm.Model
|
||||
, items : List NotificationSettings
|
||||
, result : Maybe BasicResult
|
||||
}
|
||||
|
||||
|
||||
type Msg
|
||||
= ListMsg Comp.NotificationList.Msg
|
||||
| DetailMsg Comp.NotificationForm.Msg
|
||||
| GetDataResp (Result Http.Error NotificationSettingsList)
|
||||
| NewTask
|
||||
| SubmitResp (Result Http.Error BasicResult)
|
||||
| DeleteResp (Result Http.Error BasicResult)
|
||||
|
||||
|
||||
initModel : Model
|
||||
initModel =
|
||||
{ listModel = Comp.NotificationList.init
|
||||
, detailModel = Nothing
|
||||
, items = []
|
||||
, result = Nothing
|
||||
}
|
||||
|
||||
|
||||
initCmd : Flags -> Cmd Msg
|
||||
initCmd flags =
|
||||
Api.getNotifyDueItems flags GetDataResp
|
||||
|
||||
|
||||
init : Flags -> ( Model, Cmd Msg )
|
||||
init flags =
|
||||
( initModel, initCmd flags )
|
||||
|
||||
|
||||
|
||||
--- Update
|
||||
|
||||
|
||||
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
|
||||
update flags msg model =
|
||||
case msg of
|
||||
GetDataResp (Ok res) ->
|
||||
( { model
|
||||
| items = res.items
|
||||
, result = Nothing
|
||||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
GetDataResp (Err err) ->
|
||||
( { model | result = Just (BasicResult False (Util.Http.errorToString err)) }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
ListMsg lm ->
|
||||
let
|
||||
( mm, action ) =
|
||||
Comp.NotificationList.update lm model.listModel
|
||||
|
||||
( detail, cmd ) =
|
||||
case action of
|
||||
Comp.NotificationList.NoAction ->
|
||||
( Nothing, Cmd.none )
|
||||
|
||||
Comp.NotificationList.EditAction settings ->
|
||||
let
|
||||
( dm, dc ) =
|
||||
Comp.NotificationForm.initWith flags settings
|
||||
in
|
||||
( Just dm, Cmd.map DetailMsg dc )
|
||||
in
|
||||
( { model
|
||||
| listModel = mm
|
||||
, detailModel = detail
|
||||
}
|
||||
, cmd
|
||||
)
|
||||
|
||||
DetailMsg lm ->
|
||||
case model.detailModel of
|
||||
Just dm ->
|
||||
let
|
||||
( mm, action, mc ) =
|
||||
Comp.NotificationForm.update flags lm dm
|
||||
|
||||
( model_, cmd_ ) =
|
||||
case action of
|
||||
Comp.NotificationForm.NoAction ->
|
||||
( { model | detailModel = Just mm }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
Comp.NotificationForm.SubmitAction settings ->
|
||||
( { model
|
||||
| detailModel = Just mm
|
||||
, result = Nothing
|
||||
}
|
||||
, if settings.id == "" then
|
||||
Api.createNotifyDueItems flags settings SubmitResp
|
||||
|
||||
else
|
||||
Api.updateNotifyDueItems flags settings SubmitResp
|
||||
)
|
||||
|
||||
Comp.NotificationForm.CancelAction ->
|
||||
( { model
|
||||
| detailModel = Nothing
|
||||
, result = Nothing
|
||||
}
|
||||
, initCmd flags
|
||||
)
|
||||
|
||||
Comp.NotificationForm.StartOnceAction settings ->
|
||||
( { model
|
||||
| detailModel = Just mm
|
||||
, result = Nothing
|
||||
}
|
||||
, Api.startOnceNotifyDueItems flags settings SubmitResp
|
||||
)
|
||||
|
||||
Comp.NotificationForm.DeleteAction id ->
|
||||
( { model
|
||||
| detailModel = Just mm
|
||||
, result = Nothing
|
||||
}
|
||||
, Api.deleteNotifyDueItems flags id DeleteResp
|
||||
)
|
||||
in
|
||||
( model_
|
||||
, Cmd.batch
|
||||
[ Cmd.map DetailMsg mc
|
||||
, cmd_
|
||||
]
|
||||
)
|
||||
|
||||
Nothing ->
|
||||
( model, Cmd.none )
|
||||
|
||||
NewTask ->
|
||||
let
|
||||
( mm, mc ) =
|
||||
Comp.NotificationForm.init flags
|
||||
in
|
||||
( { model | detailModel = Just mm }, Cmd.map DetailMsg mc )
|
||||
|
||||
SubmitResp (Ok res) ->
|
||||
( { model | result = Just res }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
SubmitResp (Err err) ->
|
||||
( { model | result = Just (BasicResult False (Util.Http.errorToString err)) }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
DeleteResp (Ok res) ->
|
||||
if res.success then
|
||||
( { model | result = Nothing, detailModel = Nothing }
|
||||
, initCmd flags
|
||||
)
|
||||
|
||||
else
|
||||
( { model | result = Just res }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
DeleteResp (Err err) ->
|
||||
( { model | result = Just (BasicResult False (Util.Http.errorToString err)) }
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
|
||||
|
||||
--- View
|
||||
|
||||
|
||||
view : UiSettings -> Model -> Html Msg
|
||||
view settings model =
|
||||
div []
|
||||
[ div [ class "ui menu" ]
|
||||
[ a
|
||||
[ class "link item"
|
||||
, href "#"
|
||||
, onClick NewTask
|
||||
]
|
||||
[ i [ class "add icon" ] []
|
||||
, text "New Task"
|
||||
]
|
||||
]
|
||||
, div
|
||||
[ classList
|
||||
[ ( "ui message", True )
|
||||
, ( "error", Maybe.map .success model.result == Just False )
|
||||
, ( "success", Maybe.map .success model.result == Just True )
|
||||
, ( "invisible hidden", model.result == Nothing )
|
||||
]
|
||||
]
|
||||
[ Maybe.map .message model.result
|
||||
|> Maybe.withDefault ""
|
||||
|> text
|
||||
]
|
||||
, case model.detailModel of
|
||||
Just msett ->
|
||||
viewForm settings msett
|
||||
|
||||
Nothing ->
|
||||
viewList model
|
||||
]
|
||||
|
||||
|
||||
viewForm : UiSettings -> Comp.NotificationForm.Model -> Html Msg
|
||||
viewForm settings model =
|
||||
Html.map DetailMsg (Comp.NotificationForm.view "segment" settings model)
|
||||
|
||||
|
||||
viewList : Model -> Html Msg
|
||||
viewList model =
|
||||
Html.map ListMsg (Comp.NotificationList.view model.listModel model.items)
|
@ -8,7 +8,6 @@ module Comp.ScanMailboxList exposing
|
||||
)
|
||||
|
||||
import Api.Model.ScanMailboxSettings exposing (ScanMailboxSettings)
|
||||
import Api.Model.ScanMailboxSettingsList exposing (ScanMailboxSettingsList)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (onClick)
|
||||
@ -41,7 +40,7 @@ update msg model =
|
||||
|
||||
|
||||
view : Model -> List ScanMailboxSettings -> Html Msg
|
||||
view model items =
|
||||
view _ items =
|
||||
div []
|
||||
[ table [ class "ui very basic table" ]
|
||||
[ thead []
|
||||
|
@ -8,7 +8,7 @@ module Page.UserSettings.Data exposing
|
||||
import Comp.ChangePasswordForm
|
||||
import Comp.EmailSettingsManage
|
||||
import Comp.ImapSettingsManage
|
||||
import Comp.NotificationForm
|
||||
import Comp.NotificationManage
|
||||
import Comp.ScanMailboxManage
|
||||
import Comp.UiSettingsManage
|
||||
import Data.Flags exposing (Flags)
|
||||
@ -20,7 +20,7 @@ type alias Model =
|
||||
, changePassModel : Comp.ChangePasswordForm.Model
|
||||
, emailSettingsModel : Comp.EmailSettingsManage.Model
|
||||
, imapSettingsModel : Comp.ImapSettingsManage.Model
|
||||
, notificationModel : Comp.NotificationForm.Model
|
||||
, notificationModel : Comp.NotificationManage.Model
|
||||
, scanMailboxModel : Comp.ScanMailboxManage.Model
|
||||
, uiSettingsModel : Comp.UiSettingsManage.Model
|
||||
}
|
||||
@ -36,7 +36,7 @@ init flags settings =
|
||||
, changePassModel = Comp.ChangePasswordForm.emptyModel
|
||||
, emailSettingsModel = Comp.EmailSettingsManage.emptyModel
|
||||
, imapSettingsModel = Comp.ImapSettingsManage.emptyModel
|
||||
, notificationModel = Tuple.first (Comp.NotificationForm.init flags settings)
|
||||
, notificationModel = Tuple.first (Comp.NotificationManage.init flags)
|
||||
, scanMailboxModel = Tuple.first (Comp.ScanMailboxManage.init flags)
|
||||
, uiSettingsModel = um
|
||||
}
|
||||
@ -57,7 +57,7 @@ type Msg
|
||||
= SetTab Tab
|
||||
| ChangePassMsg Comp.ChangePasswordForm.Msg
|
||||
| EmailSettingsMsg Comp.EmailSettingsManage.Msg
|
||||
| NotificationMsg Comp.NotificationForm.Msg
|
||||
| NotificationMsg Comp.NotificationManage.Msg
|
||||
| ImapSettingsMsg Comp.ImapSettingsManage.Msg
|
||||
| ScanMailboxMsg Comp.ScanMailboxManage.Msg
|
||||
| UiSettingsMsg Comp.UiSettingsManage.Msg
|
||||
|
@ -3,7 +3,7 @@ module Page.UserSettings.Update exposing (update)
|
||||
import Comp.ChangePasswordForm
|
||||
import Comp.EmailSettingsManage
|
||||
import Comp.ImapSettingsManage
|
||||
import Comp.NotificationForm
|
||||
import Comp.NotificationManage
|
||||
import Comp.ScanMailboxManage
|
||||
import Comp.UiSettingsManage
|
||||
import Data.Flags exposing (Flags)
|
||||
@ -41,7 +41,7 @@ update flags settings msg model =
|
||||
let
|
||||
initCmd =
|
||||
Cmd.map NotificationMsg
|
||||
(Tuple.second (Comp.NotificationForm.init flags settings))
|
||||
(Tuple.second (Comp.NotificationManage.init flags))
|
||||
in
|
||||
( m, initCmd, Sub.none )
|
||||
|
||||
@ -80,7 +80,7 @@ update flags settings msg model =
|
||||
NotificationMsg lm ->
|
||||
let
|
||||
( m2, c2 ) =
|
||||
Comp.NotificationForm.update flags lm model.notificationModel
|
||||
Comp.NotificationManage.update flags lm model.notificationModel
|
||||
in
|
||||
( { model | notificationModel = m2 }
|
||||
, Cmd.map NotificationMsg c2
|
||||
|
@ -3,7 +3,7 @@ module Page.UserSettings.View exposing (view)
|
||||
import Comp.ChangePasswordForm
|
||||
import Comp.EmailSettingsManage
|
||||
import Comp.ImapSettingsManage
|
||||
import Comp.NotificationForm
|
||||
import Comp.NotificationManage
|
||||
import Comp.ScanMailboxManage
|
||||
import Comp.UiSettingsManage
|
||||
import Data.UiSettings exposing (UiSettings)
|
||||
@ -42,7 +42,7 @@ view settings model =
|
||||
viewEmailSettings settings model
|
||||
|
||||
Just NotificationTab ->
|
||||
viewNotificationForm settings model
|
||||
viewNotificationManage settings model
|
||||
|
||||
Just ImapSettingsTab ->
|
||||
viewImapSettings settings model
|
||||
@ -127,8 +127,8 @@ viewChangePassword model =
|
||||
]
|
||||
|
||||
|
||||
viewNotificationForm : UiSettings -> Model -> List (Html Msg)
|
||||
viewNotificationForm settings model =
|
||||
viewNotificationManage : UiSettings -> Model -> List (Html Msg)
|
||||
viewNotificationManage settings model =
|
||||
[ h2 [ class "ui header" ]
|
||||
[ i [ class "ui bullhorn icon" ] []
|
||||
, div [ class "content" ]
|
||||
@ -147,7 +147,7 @@ viewNotificationForm settings model =
|
||||
, text " days and sends this list via e-mail."
|
||||
]
|
||||
, Html.map NotificationMsg
|
||||
(Comp.NotificationForm.view "segment" settings model.notificationModel)
|
||||
(Comp.NotificationManage.view settings model.notificationModel)
|
||||
]
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user