Skip to content

Commit 73747c4

Browse files
committed
Basic ui for addons
1 parent 7fdd78a commit 73747c4

33 files changed

Lines changed: 2881 additions & 13 deletions

modules/webapp/src/main/elm/Api.elm

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ module Api exposing
1818
, addShare
1919
, addTag
2020
, addTagsMultiple
21+
, addonRunConfigDelete
22+
, addonRunConfigGet
23+
, addonRunConfigSet
24+
, addonRunExistingItem
25+
, addonsDelete
26+
, addonsGetAll
27+
, addonsInstall
28+
, addonsUpdate
2129
, attachmentPreviewURL
2230
, bookmarkNameExists
2331
, cancelJob
@@ -211,6 +219,11 @@ module Api exposing
211219
, versionInfo
212220
)
213221

222+
import Api.Model.AddonList exposing (AddonList)
223+
import Api.Model.AddonRegister exposing (AddonRegister)
224+
import Api.Model.AddonRunConfig exposing (AddonRunConfig)
225+
import Api.Model.AddonRunConfigList exposing (AddonRunConfigList)
226+
import Api.Model.AddonRunExistingItem exposing (AddonRunExistingItem)
214227
import Api.Model.AttachmentMeta exposing (AttachmentMeta)
215228
import Api.Model.AuthResult exposing (AuthResult)
216229
import Api.Model.BasicResult exposing (BasicResult)
@@ -3156,6 +3169,99 @@ shareDownloadAllLink flags id =
31563169

31573170

31583171

3172+
--- Addons
3173+
3174+
3175+
addonsGetAll : Flags -> (Result Http.Error AddonList -> msg) -> Cmd msg
3176+
addonsGetAll flags receive =
3177+
Http2.authGet
3178+
{ url = flags.config.baseUrl ++ "/api/v1/sec/addon/archive"
3179+
, account = getAccount flags
3180+
, expect = Http.expectJson receive Api.Model.AddonList.decoder
3181+
}
3182+
3183+
3184+
addonsDelete : Flags -> String -> (Result Http.Error BasicResult -> msg) -> Cmd msg
3185+
addonsDelete flags addonId receive =
3186+
Http2.authDelete
3187+
{ url = flags.config.baseUrl ++ "/api/v1/sec/addon/archive/" ++ addonId
3188+
, account = getAccount flags
3189+
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
3190+
}
3191+
3192+
3193+
addonsInstall : Flags -> AddonRegister -> (Result Http.Error BasicResult -> msg) -> Cmd msg
3194+
addonsInstall flags addon receive =
3195+
Http2.authPost
3196+
{ url = flags.config.baseUrl ++ "/api/v1/sec/addon/archive"
3197+
, account = getAccount flags
3198+
, body = Http.jsonBody (Api.Model.AddonRegister.encode addon)
3199+
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
3200+
}
3201+
3202+
3203+
addonsUpdate : Flags -> String -> (Result Http.Error BasicResult -> msg) -> Cmd msg
3204+
addonsUpdate flags addonId receive =
3205+
Http2.authPut
3206+
{ url = flags.config.baseUrl ++ "/api/v1/sec/addon/archive/" ++ addonId
3207+
, account = getAccount flags
3208+
, body = Http.emptyBody
3209+
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
3210+
}
3211+
3212+
3213+
addonRunConfigGet : Flags -> (Result Http.Error AddonRunConfigList -> msg) -> Cmd msg
3214+
addonRunConfigGet flags receive =
3215+
Http2.authGet
3216+
{ url = flags.config.baseUrl ++ "/api/v1/sec/addon/run-config"
3217+
, account = getAccount flags
3218+
, expect = Http.expectJson receive Api.Model.AddonRunConfigList.decoder
3219+
}
3220+
3221+
3222+
addonRunConfigSet :
3223+
Flags
3224+
-> AddonRunConfig
3225+
-> (Result Http.Error BasicResult -> msg)
3226+
-> Cmd msg
3227+
addonRunConfigSet flags cfg receive =
3228+
if cfg.id == "" then
3229+
Http2.authPost
3230+
{ url = flags.config.baseUrl ++ "/api/v1/sec/addon/run-config"
3231+
, account = getAccount flags
3232+
, body = Http.jsonBody (Api.Model.AddonRunConfig.encode cfg)
3233+
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
3234+
}
3235+
3236+
else
3237+
Http2.authPut
3238+
{ url = flags.config.baseUrl ++ "/api/v1/sec/addon/run-config/" ++ cfg.id
3239+
, account = getAccount flags
3240+
, body = Http.jsonBody (Api.Model.AddonRunConfig.encode cfg)
3241+
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
3242+
}
3243+
3244+
3245+
addonRunConfigDelete : Flags -> String -> (Result Http.Error BasicResult -> msg) -> Cmd msg
3246+
addonRunConfigDelete flags id receive =
3247+
Http2.authDelete
3248+
{ url = flags.config.baseUrl ++ "/api/v1/sec/addon/run-config/" ++ id
3249+
, account = getAccount flags
3250+
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
3251+
}
3252+
3253+
3254+
addonRunExistingItem : Flags -> AddonRunExistingItem -> (Result Http.Error BasicResult -> msg) -> Cmd msg
3255+
addonRunExistingItem flags input receive =
3256+
Http2.authPost
3257+
{ url = flags.config.baseUrl ++ "/api/v1/sec/addon/run/existingitem"
3258+
, account = getAccount flags
3259+
, body = Http.jsonBody (Api.Model.AddonRunExistingItem.encode input)
3260+
, expect = Http.expectJson receive Api.Model.BasicResult.decoder
3261+
}
3262+
3263+
3264+
31593265
--- Helper
31603266

31613267

modules/webapp/src/main/elm/App/Update.elm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import Api
1414
import App.Data exposing (..)
1515
import Browser exposing (UrlRequest(..))
1616
import Browser.Navigation as Nav
17+
import Comp.AddonArchiveManage
1718
import Comp.DownloadAll
1819
import Data.AppEvent exposing (AppEvent(..))
1920
import Data.Environment as Env
@@ -345,6 +346,9 @@ updateWithSub msg model =
345346
Ok (JobsWaiting n) ->
346347
( { model | jobsWaiting = max 0 n }, Cmd.none, Sub.none )
347348

349+
Ok (AddonInstalled info) ->
350+
updateManageData (Page.ManageData.Data.AddonArchiveMsg <| Comp.AddonArchiveManage.addonInstallResult info) model
351+
348352
Err _ ->
349353
( model, Cmd.none, Sub.none )
350354

@@ -640,7 +644,7 @@ updateManageData : Page.ManageData.Data.Msg -> Model -> ( Model, Cmd Msg, Sub Ms
640644
updateManageData lmsg model =
641645
let
642646
( lm, lc, ls ) =
643-
Page.ManageData.Update.update model.flags lmsg model.manageDataModel
647+
Page.ManageData.Update.update model.flags model.uiSettings lmsg model.manageDataModel
644648
in
645649
( { model | manageDataModel = lm }
646650
, Cmd.map ManageDataMsg lc
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{-
2+
Copyright 2020 Eike K. & Contributors
3+
4+
SPDX-License-Identifier: AGPL-3.0-or-later
5+
-}
6+
7+
8+
module Comp.AddonArchiveForm exposing (Model, Msg, get, init, initWith, update, view)
9+
10+
import Api.Model.Addon exposing (Addon)
11+
import Comp.Basic as B
12+
import Data.Flags exposing (Flags)
13+
import Html exposing (..)
14+
import Html.Attributes exposing (..)
15+
import Html.Events exposing (onInput)
16+
import Messages.Comp.AddonArchiveForm exposing (Texts)
17+
import Styles as S
18+
import Util.Maybe
19+
20+
21+
type alias Model =
22+
{ addon : Addon
23+
, url : Maybe String
24+
}
25+
26+
27+
init : ( Model, Cmd Msg )
28+
init =
29+
( { addon = Api.Model.Addon.empty
30+
, url = Nothing
31+
}
32+
, Cmd.none
33+
)
34+
35+
36+
initWith : Addon -> ( Model, Cmd Msg )
37+
initWith a =
38+
( { addon = a
39+
, url = a.url
40+
}
41+
, Cmd.none
42+
)
43+
44+
45+
isValid : Model -> Bool
46+
isValid model =
47+
model.url /= Nothing
48+
49+
50+
get : Model -> Maybe Addon
51+
get model =
52+
let
53+
a =
54+
model.addon
55+
in
56+
if isValid model then
57+
Just
58+
{ a
59+
| url = model.url
60+
}
61+
62+
else
63+
Nothing
64+
65+
66+
type Msg
67+
= SetUrl String
68+
69+
70+
update : Flags -> Msg -> Model -> ( Model, Cmd Msg )
71+
update _ msg model =
72+
case msg of
73+
SetUrl url ->
74+
( { model | url = Util.Maybe.fromString url }, Cmd.none )
75+
76+
77+
78+
--- View
79+
80+
81+
view : Texts -> Model -> Html Msg
82+
view texts model =
83+
div
84+
[ class "flex flex-col" ]
85+
[ div [ class "mb-4" ]
86+
[ label
87+
[ class S.inputLabel
88+
]
89+
[ text texts.addonUrl
90+
, B.inputRequired
91+
]
92+
, input
93+
[ type_ "text"
94+
, placeholder texts.addonUrlPlaceholder
95+
, class S.textInput
96+
, classList [ ( "disabled", model.addon.id /= "" ) ]
97+
, value (model.url |> Maybe.withDefault "")
98+
, onInput SetUrl
99+
, disabled (model.addon.id /= "")
100+
]
101+
[]
102+
, span [ class "text-sm opacity-75" ]
103+
[ text texts.installInfoText
104+
]
105+
]
106+
]

0 commit comments

Comments
 (0)