diff --git a/src/elm/Components/Form.elm b/src/elm/Components/Form.elm index dd47eaeb9..2077c9a5b 100644 --- a/src/elm/Components/Form.elm +++ b/src/elm/Components/Form.elm @@ -9,6 +9,7 @@ import Html exposing (Html, br, button, div, em, h2, h3, input, label, p, sectio import Html.Attributes exposing (checked, class, classList, disabled, for, id, placeholder, rows, type_, value, wrap) import Html.Events exposing (onCheck, onClick, onInput) import Maybe.Extra +import Shared import Utils.Helpers as Util import Vela @@ -164,97 +165,95 @@ viewButton { msg, text_, classList_, disabled_ } = {-| viewAllowEvents : takes model and repo and renders the settings category for updating repo webhook events -} viewAllowEvents : - ({ a | allow_events : Maybe Vela.AllowEvents } -> String -> Bool -> msg) - -> Maybe Vela.AllowEvents - -> { a | allow_events : Maybe Vela.AllowEvents } + Shared.Model + -> + { msg : { allow_events : Vela.AllowEvents, event : String } -> Bool -> msg + , allow_events : Vela.AllowEvents + , disabled_ : Bool + } -> List (Html msg) -viewAllowEvents msg allowEvents repo = - case allowEvents of - Just events -> - [ div [ class "form-controls", class "-two-col" ] - [ viewCheckbox - { title = "Push" - , subtitle = Nothing - , field = "allow_push_branch" - , state = events.push.branch - , msg = msg repo "allow_push_branch" - , disabled_ = False - } - , viewCheckbox - { title = "Tag" - , subtitle = Nothing - , field = "allow_push_tag" - , state = events.push.tag - , msg = msg repo "allow_push_tag" - , disabled_ = False - } - ] - , h3 [ class "settings-subtitle" ] [ text "Pull Request" ] - , div [ class "form-controls", class "-two-col" ] - [ viewCheckbox - { title = "Opened" - , subtitle = Nothing - , field = "allow_pull_opened" - , state = events.pull.opened - , msg = msg repo "allow_pull_opened" - , disabled_ = False - } - , viewCheckbox - { title = "Synchronize" - , subtitle = Nothing - , field = "allow_pull_synchronize" - , state = events.pull.synchronize - , msg = msg repo "allow_pull_synchronize" - , disabled_ = False - } - , viewCheckbox - { title = "Edited" - , subtitle = Nothing - , field = "allow_pull_edited" - , state = events.pull.edited - , msg = msg repo "allow_pull_edited" - , disabled_ = False - } - , viewCheckbox - { title = "Reopened" - , subtitle = Nothing - , field = "allow_pull_reopened" - , state = events.pull.reopened - , msg = msg repo "allow_pull_reopened" - , disabled_ = False - } - ] - , h3 [ class "settings-subtitle" ] [ text "Deployments" ] - , div [ class "form-controls", class "-two-col" ] - [ viewCheckbox - { title = "Created" - , subtitle = Nothing - , field = "allow_deploy_created" - , state = events.deploy.created - , msg = msg repo "allow_deploy_created" - , disabled_ = False - } - ] - , h3 [ class "settings-subtitle" ] [ text "Comment" ] - , div [ class "form-controls", class "-two-col" ] - [ viewCheckbox - { title = "Created" - , subtitle = Nothing - , field = "allow_comment_created" - , state = events.comment.created - , msg = msg repo "allow_comment_created" - , disabled_ = False - } - , viewCheckbox - { title = "Edited" - , subtitle = Nothing - , field = "allow_comment_edited" - , state = events.comment.edited - , msg = msg repo "allow_comment_edited" - , disabled_ = False - } - ] - ] - - Nothing -> - [] +viewAllowEvents shared { msg, allow_events } = + [ div [ class "form-controls", class "-two-col" ] + [ viewCheckbox + { title = "Push" + , subtitle = Nothing + , field = "allow_push_branch" + , state = allow_events.push.branch + , msg = msg { allow_events = allow_events, event = "allow_push_branch" } + , disabled_ = False + } + , viewCheckbox + { title = "Tag" + , subtitle = Nothing + , field = "allow_push_tag" + , state = allow_events.push.tag + , msg = msg { allow_events = allow_events, event = "allow_push_tag" } + , disabled_ = False + } + ] + , h3 [ class "settings-subtitle" ] [ text "Pull Request" ] + , div [ class "form-controls", class "-two-col" ] + [ viewCheckbox + { title = "Opened" + , subtitle = Nothing + , field = "allow_pull_opened" + , state = allow_events.pull.opened + , msg = msg { allow_events = allow_events, event = "allow_pull_opened" } + , disabled_ = False + } + , viewCheckbox + { title = "Synchronize" + , subtitle = Nothing + , field = "allow_pull_synchronize" + , state = allow_events.pull.synchronize + , msg = msg { allow_events = allow_events, event = "allow_pull_synchronize" } + , disabled_ = False + } + , viewCheckbox + { title = "Edited" + , subtitle = Nothing + , field = "allow_pull_edited" + , state = allow_events.pull.edited + , msg = msg { allow_events = allow_events, event = "allow_pull_edited" } + , disabled_ = False + } + , viewCheckbox + { title = "Reopened" + , subtitle = Nothing + , field = "allow_pull_reopened" + , state = allow_events.pull.reopened + , msg = msg { allow_events = allow_events, event = "allow_pull_reopened" } + , disabled_ = False + } + ] + , h3 [ class "settings-subtitle" ] [ text "Deployments" ] + , div [ class "form-controls", class "-two-col" ] + [ viewCheckbox + { title = "Created" + , subtitle = Nothing + , field = "allow_deploy_created" + , state = allow_events.deploy.created + , msg = msg { allow_events = allow_events, event = "allow_deploy_created" } + , disabled_ = False + } + ] + , h3 [ class "settings-subtitle" ] [ text "Comment" ] + , div [ class "form-controls", class "-two-col" ] + [ viewCheckbox + { title = "Created" + , subtitle = Nothing + , field = "allow_comment_created" + , state = allow_events.comment.created + , msg = msg { allow_events = allow_events, event = "allow_comment_created" } + , disabled_ = False + } + , viewCheckbox + { title = "Edited" + , subtitle = Nothing + , field = "allow_comment_edited" + , state = allow_events.comment.edited + , msg = msg { allow_events = allow_events, event = "allow_comment_edited" } + , disabled_ = False + } + ] + ] diff --git a/src/elm/Components/SecretForm.elm b/src/elm/Components/SecretForm.elm index 56cbd3c56..0fb67dcb8 100644 --- a/src/elm/Components/SecretForm.elm +++ b/src/elm/Components/SecretForm.elm @@ -34,92 +34,36 @@ import Html.Attributes import Html.Events exposing (onClick) import Shared import Utils.Helpers as Util +import Vela -- VIEW -viewEventsSelect : +viewAllowEventsSelect : Shared.Model -> - { msg : String -> Bool -> msg - , events : List String + { msg : { allow_events : Vela.AllowEvents, event : String } -> Bool -> msg + , allow_events : Vela.AllowEvents , disabled_ : Bool } -> Html msg -viewEventsSelect shared { msg, events, disabled_ } = - let - schedulesAllowed = - Util.checkScheduleAllowlist "org" "repo" shared.velaScheduleAllowlist - in +viewAllowEventsSelect shared props = section [] [ div [ for "events-select" ] - [ strong [] [ text "Limit to Events" ] - , span [ class "field-description" ] + ([ strong [] [ text "Limit to Events" ] + , span [ class "field-description" ] [ text "( " , em [] [ text "at least one event must be selected" ] , text " )" ] - , viewPullRequestWarning - ] - , div - [ class "form-controls" - , class "-stack" - ] - [ Components.Form.viewCheckbox - { title = "Push" - , subtitle = Nothing - , field = "push" - , state = List.member "push" events - , msg = msg "push" - , disabled_ = disabled_ - } - , Components.Form.viewCheckbox - { title = "Pull Request" - , subtitle = Nothing - , field = "pull_request" - , state = List.member "pull_request" events - , msg = msg "pull_request" - , disabled_ = disabled_ - } - , Components.Form.viewCheckbox - { title = "Tag" - , subtitle = Nothing - , field = "tag" - , state = List.member "tag" events - , msg = msg "tag" - , disabled_ = disabled_ - } - , Components.Form.viewCheckbox - { title = "Comment" - , subtitle = Nothing - , field = "comment" - , state = List.member "comment" events - , msg = msg "comment" - , disabled_ = disabled_ - } - , Components.Form.viewCheckbox - { title = "Deployment" - , subtitle = Nothing - , field = "deployment" - , state = List.member "deployment" events - , msg = msg "deployment" - , disabled_ = disabled_ - } - , if schedulesAllowed then - Components.Form.viewCheckbox - { title = "Schedule" - , subtitle = Nothing - , field = "schedule" - , state = List.member "schedule" events - , msg = msg "schedule" - , disabled_ = disabled_ - } - - else - text "" - ] + , viewPullRequestWarning + ] + ++ Components.Form.viewAllowEvents + shared + props + ) ] diff --git a/src/elm/Components/Secrets.elm b/src/elm/Components/Secrets.elm index 5076a4fa9..d3de31faa 100644 --- a/src/elm/Components/Secrets.elm +++ b/src/elm/Components/Secrets.elm @@ -219,6 +219,41 @@ addKey secret = { secret | key = secret.org ++ "/" ++ secret.repo ++ "/" ++ secret.name } +appendLabel : Bool -> String -> List String -> List String +appendLabel enabled label inList = + inList + ++ (if enabled then + [ label ] + + else + [] + ) + + +allowEventsToList : Vela.AllowEvents -> List String +allowEventsToList events = + [ ( events.push.branch, "push" ) + , ( events.push.tag, "tag" ) + , ( events.pull.opened, "pull_request:opened" ) + , ( events.pull.synchronize, "pull_request:synchronize" ) + , ( events.pull.edited, "pull_request:edited" ) + , ( events.pull.reopened, "pull_request:reopened" ) + , ( events.deploy.created, "deployment" ) + , ( events.comment.created, "comment:created" ) + , ( events.comment.edited, "comment:edited" ) + , ( events.schedule.run, "schedule" ) + ] + |> List.map + (\( enabled, label ) -> + if enabled then + Just label + + else + Nothing + ) + |> List.filterMap identity + + {-| viewSecret : takes secret and secret type and renders a table row -} viewSecret : String -> Vela.SecretType -> (String -> msg) -> Vela.Secret -> Html msg @@ -256,7 +291,8 @@ viewSecret engine type_ copyMsg secret = , scope "row" , class "break-word" ] - [ Components.Table.viewListCell secret.events "no events" [ ( "secret-event", True ) ] ] + [ Components.Table.viewListCell (allowEventsToList secret.allow_events) "no events" [] + ] , td [ attribute "data-label" "images" , scope "row" diff --git a/src/elm/Pages/Org_/Repo_/Settings.elm b/src/elm/Pages/Org_/Repo_/Settings.elm index bf8c55645..f306d7fcb 100644 --- a/src/elm/Pages/Org_/Repo_/Settings.elm +++ b/src/elm/Pages/Org_/Repo_/Settings.elm @@ -105,7 +105,7 @@ type Msg | RepairRepoResponse (Result (Http.Detailed.Error String) ( Http.Metadata, String )) | ChownRepo { repo : Vela.Repository } | ChownRepoResponse (Result (Http.Detailed.Error String) ( Http.Metadata, String )) - | AllowEventsUpdate Vela.Repository String Bool + | AllowEventsUpdate { allow_events : Vela.AllowEvents, event : String } Bool | AccessUpdate String | ForkPolicyUpdate String | BuildLimitOnInput String @@ -386,12 +386,12 @@ update shared route msg model = , Effect.handleHttpError { httpError = error } ) - AllowEventsUpdate repo event val -> + AllowEventsUpdate options val -> let payload = { defaultRepoPayload | allow_events = - (Vela.setAllowEvents repo event val).allow_events + Just (Vela.setAllowEvents options options.event val).allow_events } body = @@ -628,7 +628,12 @@ view shared route model = , em [] [ text "Active repositories must have at least one event enabled." ] ] ] - ++ Components.Form.viewAllowEvents AllowEventsUpdate repo.allow_events repo + ++ Components.Form.viewAllowEvents + shared + { msg = AllowEventsUpdate + , allow_events = repo.allow_events + , disabled_ = False + } ) , viewAccess repo AccessUpdate , viewForkPolicy repo ForkPolicyUpdate @@ -646,109 +651,6 @@ view shared route model = } -{-| viewAllowEvents : takes repo and renders the settings category for updating repo webhook events --} -viewAllowEvents : Vela.Repository -> Html Msg -viewAllowEvents repo = - case repo.allow_events of - Just allowEvents -> - section [ class "settings", Util.testAttribute "repo-settings-events" ] - [ h2 [ class "settings-title" ] [ text "Webhook Events" ] - , p [ class "settings-description" ] - [ text "Control which events on Git will trigger Vela pipelines." - , br [] [] - , em [] [ text "Active repositories must have at least one event enabled." ] - ] - , h3 [ class "settings-subtitle" ] [ text "Push" ] - , div [ class "form-controls", class "-two-col" ] - [ Components.Form.viewCheckbox - { title = "Push" - , subtitle = Nothing - , field = "allow_push_branch" - , state = allowEvents.push.branch - , msg = AllowEventsUpdate repo "allow_push_branch" - , disabled_ = False - } - , Components.Form.viewCheckbox - { title = "Tag" - , subtitle = Nothing - , field = "allow_push_tag" - , state = allowEvents.push.tag - , msg = AllowEventsUpdate repo "allow_push_tag" - , disabled_ = False - } - ] - , h3 [ class "settings-subtitle" ] [ text "Pull Request" ] - , div [ class "form-controls", class "-two-col" ] - [ Components.Form.viewCheckbox - { title = "Opened" - , subtitle = Nothing - , field = "allow_pull_opened" - , state = allowEvents.pull.opened - , msg = AllowEventsUpdate repo "allow_pull_opened" - , disabled_ = False - } - , Components.Form.viewCheckbox - { title = "Synchronize" - , subtitle = Nothing - , field = "allow_pull_synchronize" - , state = allowEvents.pull.synchronize - , msg = AllowEventsUpdate repo "allow_pull_synchronize" - , disabled_ = False - } - , Components.Form.viewCheckbox - { title = "Edited" - , subtitle = Nothing - , field = "allow_pull_edited" - , state = allowEvents.pull.edited - , msg = AllowEventsUpdate repo "allow_pull_edited" - , disabled_ = False - } - , Components.Form.viewCheckbox - { title = "Reopened" - , subtitle = Nothing - , field = "allow_pull_reopened" - , state = allowEvents.pull.reopened - , msg = AllowEventsUpdate repo "allow_pull_reopened" - , disabled_ = False - } - ] - , h3 [ class "settings-subtitle" ] [ text "Deployments" ] - , div [ class "form-controls", class "-two-col" ] - [ Components.Form.viewCheckbox - { title = "Created" - , subtitle = Nothing - , field = "allow_deploy_created" - , state = allowEvents.deploy.created - , msg = AllowEventsUpdate repo "allow_deploy_created" - , disabled_ = False - } - ] - , h3 [ class "settings-subtitle" ] [ text "Comment" ] - , div [ class "form-controls", class "-two-col" ] - [ Components.Form.viewCheckbox - { title = "Created" - , subtitle = Nothing - , field = "allow_comment_created" - , state = allowEvents.comment.created - , msg = AllowEventsUpdate repo "allow_comment_created" - , disabled_ = False - } - , Components.Form.viewCheckbox - { title = "Edited" - , subtitle = Nothing - , field = "allow_comment_edited" - , state = allowEvents.comment.edited - , msg = AllowEventsUpdate repo "allow_comment_edited" - , disabled_ = False - } - ] - ] - - Nothing -> - text "" - - {-| viewAccess : takes model and repo and renders the settings category for updating repo access -} viewAccess : Vela.Repository -> (String -> msg) -> Html msg diff --git a/src/elm/Pages/Secrets/Engine_/Org/Org_/Add.elm b/src/elm/Pages/Secrets/Engine_/Org/Org_/Add.elm index 8ea190d53..c22f1db3a 100644 --- a/src/elm/Pages/Secrets/Engine_/Org/Org_/Add.elm +++ b/src/elm/Pages/Secrets/Engine_/Org/Org_/Add.elm @@ -63,7 +63,7 @@ toLayout user route model = type alias Model = { name : String , value : String - , events : List String + , allow_events : Vela.AllowEvents , images : List String , image : String , allowCommand : Bool @@ -74,7 +74,7 @@ init : Shared.Model -> () -> ( Model, Effect Msg ) init shared () = ( { name = "" , value = "" - , events = [ "push" ] + , allow_events = Vela.defaultAllowEvents , images = [] , image = "" , allowCommand = True @@ -93,10 +93,10 @@ type Msg | NameOnInput String | ValueOnInput String | ImageOnInput String - | EventOnCheck String Bool | AddImage String | RemoveImage String | AllowCommandsOnClick String + | AllowEventsUpdate { allow_events : Vela.AllowEvents, event : String } Bool | SubmitForm @@ -134,22 +134,6 @@ update shared route msg model = , Effect.none ) - EventOnCheck event val -> - let - updatedEvents = - if val then - model.events - |> List.append [ event ] - |> List.Extra.unique - - else - model.events - |> List.filter ((/=) event) - in - ( { model | events = updatedEvents } - , Effect.none - ) - AddImage image -> ( { model | images = @@ -176,6 +160,11 @@ update shared route msg model = , Effect.none ) + AllowEventsUpdate options val -> + ( Vela.setAllowEvents model options.event val + , Effect.none + ) + SubmitForm -> let payload = @@ -186,9 +175,9 @@ update shared route msg model = , team = Nothing , name = Util.stringToMaybe model.name , value = Util.stringToMaybe model.value - , events = Just model.events , images = Just model.images , allowCommand = Just model.allowCommand + , allow_events = Just model.allow_events } body = @@ -251,9 +240,10 @@ view shared route model = , msg = ValueOnInput , disabled_ = False } - , Components.SecretForm.viewEventsSelect shared - { msg = EventOnCheck - , events = model.events + , Components.SecretForm.viewAllowEventsSelect + shared + { msg = AllowEventsUpdate + , allow_events = model.allow_events , disabled_ = False } , Components.SecretForm.viewImagesInput diff --git a/src/elm/Pages/Secrets/Engine_/Org/Org_/Edit_.elm b/src/elm/Pages/Secrets/Engine_/Org/Org_/Edit_.elm index 3e4a3fd1f..f9d26deba 100644 --- a/src/elm/Pages/Secrets/Engine_/Org/Org_/Edit_.elm +++ b/src/elm/Pages/Secrets/Engine_/Org/Org_/Edit_.elm @@ -66,10 +66,10 @@ type alias Model = { secret : WebData Vela.Secret , name : String , value : String - , events : List String , images : List String , image : String , allowCommand : Bool + , allow_events : Vela.AllowEvents , confirmingDelete : Bool } @@ -79,10 +79,10 @@ init shared route () = ( { secret = RemoteData.Loading , name = "" , value = "" - , events = [ "push" ] , images = [] , image = "" , allowCommand = True + , allow_events = Vela.defaultAllowEvents , confirmingDelete = False } , Effect.getOrgSecret @@ -108,10 +108,10 @@ type Msg | NameOnInput String | ValueOnInput String | ImageOnInput String - | EventOnCheck String Bool | AddImage String | RemoveImage String | AllowCommandsOnClick String + | AllowEventsUpdate { allow_events : Vela.AllowEvents, event : String } Bool | SubmitForm | ClickDelete | CancelDelete @@ -128,7 +128,7 @@ update shared route msg model = ( { model | secret = RemoteData.succeed secret , name = secret.name - , events = secret.events + , allow_events = secret.allow_events , images = secret.images , allowCommand = secret.allowCommand } @@ -192,22 +192,6 @@ update shared route msg model = , Effect.none ) - EventOnCheck event val -> - let - updatedEvents = - if val then - model.events - |> List.append [ event ] - |> List.Extra.unique - - else - model.events - |> List.filter ((/=) event) - in - ( { model | events = updatedEvents } - , Effect.none - ) - AddImage image -> ( { model | images = @@ -234,6 +218,11 @@ update shared route msg model = , Effect.none ) + AllowEventsUpdate options val -> + ( Vela.setAllowEvents model options.event val + , Effect.none + ) + SubmitForm -> let payload = @@ -244,9 +233,9 @@ update shared route msg model = , team = Nothing , name = Util.stringToMaybe model.name , value = Util.stringToMaybe model.value - , events = Just model.events , images = Just model.images , allowCommand = Just model.allowCommand + , allow_events = Just model.allow_events } body = @@ -332,10 +321,11 @@ view shared route model = , msg = ValueOnInput , disabled_ = not <| RemoteData.isSuccess model.secret } - , Components.SecretForm.viewEventsSelect shared - { msg = EventOnCheck - , events = model.events - , disabled_ = not <| RemoteData.isSuccess model.secret + , Components.SecretForm.viewAllowEventsSelect + shared + { msg = AllowEventsUpdate + , allow_events = model.allow_events + , disabled_ = False } , Components.SecretForm.viewImagesInput { onInput_ = ImageOnInput diff --git a/src/elm/Pages/Secrets/Engine_/Repo/Org_/Repo_/Add.elm b/src/elm/Pages/Secrets/Engine_/Repo/Org_/Repo_/Add.elm index d490a6397..3f070cc4f 100644 --- a/src/elm/Pages/Secrets/Engine_/Repo/Org_/Repo_/Add.elm +++ b/src/elm/Pages/Secrets/Engine_/Repo/Org_/Repo_/Add.elm @@ -64,7 +64,7 @@ toLayout user route model = type alias Model = { name : String , value : String - , allow_events : Maybe Vela.AllowEvents + , allow_events : Vela.AllowEvents , images : List String , image : String , allowCommand : Bool @@ -75,7 +75,7 @@ init : Shared.Model -> () -> ( Model, Effect Msg ) init shared () = ( { name = "" , value = "" - , allow_events = Just Vela.defaultAllowEventsPayload + , allow_events = Vela.defaultAllowEvents , images = [] , image = "" , allowCommand = True @@ -94,10 +94,10 @@ type Msg | NameOnInput String | ValueOnInput String | ImageOnInput String - | AllowEventsUpdate { allow_events : Maybe Vela.AllowEvents } String Bool | AddImage String | RemoveImage String | AllowCommandsOnClick String + | AllowEventsUpdate { allow_events : Vela.AllowEvents, event : String } Bool | SubmitForm @@ -135,12 +135,6 @@ update shared route msg model = , Effect.none ) - - AllowEventsUpdate allowedEvents event val -> - ( (Vela.setAllowEvents model event val) - , Effect.none - ) - AddImage image -> ( { model | images = @@ -167,6 +161,11 @@ update shared route msg model = , Effect.none ) + AllowEventsUpdate options val -> + ( Vela.setAllowEvents model options.event val + , Effect.none + ) + SubmitForm -> let payload = @@ -177,10 +176,9 @@ update shared route msg model = , team = Nothing , name = Util.stringToMaybe model.name , value = Util.stringToMaybe model.value - , events = Just [] , images = Just model.images , allowCommand = Just model.allowCommand - , allow_events = model.allow_events + , allow_events = Just model.allow_events } body = @@ -244,17 +242,12 @@ view shared route model = , msg = ValueOnInput , disabled_ = False } - , Html.span [] <| - Components.Form.viewAllowEvents - AllowEventsUpdate - model.allow_events - { allow_events = model.allow_events } - - -- , Components.SecretForm.viewEventsSelect shared - -- { msg = EventOnCheck - -- , events = model.events - -- , disabled_ = False - -- } + , Components.SecretForm.viewAllowEventsSelect + shared + { msg = AllowEventsUpdate + , allow_events = model.allow_events + , disabled_ = False + } , Components.SecretForm.viewImagesInput { onInput_ = ImageOnInput , addImage = AddImage diff --git a/src/elm/Pages/Secrets/Engine_/Repo/Org_/Repo_/Edit_.elm b/src/elm/Pages/Secrets/Engine_/Repo/Org_/Repo_/Edit_.elm index 5d84f69e7..e8f71fdc9 100644 --- a/src/elm/Pages/Secrets/Engine_/Repo/Org_/Repo_/Edit_.elm +++ b/src/elm/Pages/Secrets/Engine_/Repo/Org_/Repo_/Edit_.elm @@ -67,7 +67,7 @@ type alias Model = { secret : WebData Vela.Secret , name : String , value : String - , allow_events : Maybe Vela.AllowEvents + , allow_events : Vela.AllowEvents , images : List String , image : String , allowCommand : Bool @@ -80,7 +80,7 @@ init shared route () = ( { secret = RemoteData.Loading , name = "" , value = "" - , allow_events = Just Vela.defaultAllowEventsPayload + , allow_events = Vela.defaultAllowEvents , images = [] , image = "" , allowCommand = True @@ -110,10 +110,10 @@ type Msg | DeleteSecretResponse (Result (Http.Detailed.Error String) ( Http.Metadata, String )) | ValueOnInput String | ImageOnInput String - -- | EventOnCheck String Bool | AddImage String | RemoveImage String | AllowCommandsOnClick String + | AllowEventsUpdate { allow_events : Vela.AllowEvents, event : String } Bool | SubmitForm | ClickDelete | CancelDelete @@ -135,8 +135,6 @@ update shared route msg model = , name = secret.name , images = secret.images , allowCommand = secret.allowCommand - - -- todo: fill allowed_events? , allow_events = secret.allow_events } , Effect.none @@ -195,22 +193,6 @@ update shared route msg model = , Effect.none ) - -- EventOnCheck event val -> - -- let - -- updatedEvents = - -- if val then - -- model.events - -- |> List.append [ event ] - -- |> List.Extra.unique - - -- else - -- model.events - -- |> List.filter ((/=) event) - -- in - -- ( { model | events = updatedEvents } - -- , Effect.none - -- ) - AddImage image -> ( { model | images = @@ -237,6 +219,11 @@ update shared route msg model = , Effect.none ) + AllowEventsUpdate options val -> + ( Vela.setAllowEvents model options.event val + , Effect.none + ) + SubmitForm -> let payload = @@ -247,8 +234,7 @@ update shared route msg model = , team = Nothing , name = Util.stringToMaybe model.name , value = Util.stringToMaybe model.value - -- , events = Just model.events - , allow_events = model.allow_events + , allow_events = Just model.allow_events , images = Just model.images , allowCommand = Just model.allowCommand } @@ -338,12 +324,12 @@ view shared route model = , msg = ValueOnInput , disabled_ = not <| RemoteData.isSuccess model.secret } - - -- , Components.SecretForm.viewEventsSelect shared - -- { msg = EventOnCheck - -- , events = model.events - -- , disabled_ = not <| RemoteData.isSuccess model.secret - -- } + , Components.SecretForm.viewAllowEventsSelect + shared + { msg = AllowEventsUpdate + , allow_events = model.allow_events + , disabled_ = False + } , Components.SecretForm.viewImagesInput { onInput_ = ImageOnInput , addImage = AddImage diff --git a/src/elm/Pages/Secrets/Engine_/Shared/Org_/Team_/Add.elm b/src/elm/Pages/Secrets/Engine_/Shared/Org_/Team_/Add.elm index 21743733f..32ce63b3a 100644 --- a/src/elm/Pages/Secrets/Engine_/Shared/Org_/Team_/Add.elm +++ b/src/elm/Pages/Secrets/Engine_/Shared/Org_/Team_/Add.elm @@ -66,10 +66,10 @@ type alias Model = { team : String , name : String , value : String - , events : List String , images : List String , image : String , allowCommand : Bool + , allow_events : Vela.AllowEvents } @@ -83,10 +83,10 @@ init shared route () = Maybe.withDefault route.params.team <| Url.percentDecode route.params.team , name = "" , value = "" - , events = [ "push" ] , images = [] , image = "" , allowCommand = True + , allow_events = Vela.defaultAllowEvents } , Effect.none ) @@ -103,10 +103,10 @@ type Msg | NameOnInput String | ValueOnInput String | ImageOnInput String - | EventOnCheck String Bool | AddImage String | RemoveImage String | AllowCommandsOnClick String + | AllowEventsUpdate { allow_events : Vela.AllowEvents, event : String } Bool | SubmitForm @@ -149,22 +149,6 @@ update shared route msg model = , Effect.none ) - EventOnCheck event val -> - let - updatedEvents = - if val then - model.events - |> List.append [ event ] - |> List.Extra.unique - - else - model.events - |> List.filter ((/=) event) - in - ( { model | events = updatedEvents } - , Effect.none - ) - AddImage image -> ( { model | images = @@ -191,6 +175,11 @@ update shared route msg model = , Effect.none ) + AllowEventsUpdate options val -> + ( Vela.setAllowEvents model options.event val + , Effect.none + ) + SubmitForm -> let payload = @@ -201,7 +190,7 @@ update shared route msg model = , team = Just model.team , name = Util.stringToMaybe model.name , value = Util.stringToMaybe model.value - , events = Just model.events + , allow_events = Just model.allow_events , images = Just model.images , allowCommand = Just model.allowCommand } @@ -279,9 +268,10 @@ view shared route model = , msg = ValueOnInput , disabled_ = False } - , Components.SecretForm.viewEventsSelect shared - { msg = EventOnCheck - , events = model.events + , Components.SecretForm.viewAllowEventsSelect + shared + { msg = AllowEventsUpdate + , allow_events = model.allow_events , disabled_ = False } , Components.SecretForm.viewImagesInput diff --git a/src/elm/Pages/Secrets/Engine_/Shared/Org_/Team_/Edit_.elm b/src/elm/Pages/Secrets/Engine_/Shared/Org_/Team_/Edit_.elm index 849035b24..88ac42304 100644 --- a/src/elm/Pages/Secrets/Engine_/Shared/Org_/Team_/Edit_.elm +++ b/src/elm/Pages/Secrets/Engine_/Shared/Org_/Team_/Edit_.elm @@ -67,10 +67,10 @@ type alias Model = { secret : WebData Vela.Secret , name : String , value : String - , events : List String , images : List String , image : String , allowCommand : Bool + , allow_events : Vela.AllowEvents , confirmingDelete : Bool } @@ -80,10 +80,10 @@ init shared route () = ( { secret = RemoteData.Loading , name = "" , value = "" - , events = [ "push" ] , images = [] , image = "" , allowCommand = True + , allow_events = Vela.defaultAllowEvents , confirmingDelete = False } , Effect.getSharedSecret @@ -110,10 +110,10 @@ type Msg | DeleteSecretResponse (Result (Http.Detailed.Error String) ( Http.Metadata, String )) | ValueOnInput String | ImageOnInput String - | EventOnCheck String Bool | AddImage String | RemoveImage String | AllowCommandsOnClick String + | AllowEventsUpdate { allow_events : Vela.AllowEvents, event : String } Bool | SubmitForm | ClickDelete | CancelDelete @@ -133,9 +133,9 @@ update shared route msg model = ( { model | secret = RemoteData.succeed secret , name = secret.name - , events = secret.events , images = secret.images , allowCommand = secret.allowCommand + , allow_events = secret.allow_events } , Effect.none ) @@ -193,22 +193,6 @@ update shared route msg model = , Effect.none ) - EventOnCheck event val -> - let - updatedEvents = - if val then - model.events - |> List.append [ event ] - |> List.Extra.unique - - else - model.events - |> List.filter ((/=) event) - in - ( { model | events = updatedEvents } - , Effect.none - ) - AddImage image -> ( { model | images = @@ -235,6 +219,11 @@ update shared route msg model = , Effect.none ) + AllowEventsUpdate options val -> + ( Vela.setAllowEvents model options.event val + , Effect.none + ) + SubmitForm -> let payload = @@ -245,9 +234,9 @@ update shared route msg model = , team = Just route.params.team , name = Util.stringToMaybe model.name , value = Util.stringToMaybe model.value - , events = Just model.events , images = Just model.images , allowCommand = Just model.allowCommand + , allow_events = Just model.allow_events } body = @@ -335,10 +324,11 @@ view shared route model = , msg = ValueOnInput , disabled_ = not <| RemoteData.isSuccess model.secret } - , Components.SecretForm.viewEventsSelect shared - { msg = EventOnCheck - , events = model.events - , disabled_ = not <| RemoteData.isSuccess model.secret + , Components.SecretForm.viewAllowEventsSelect + shared + { msg = AllowEventsUpdate + , allow_events = model.allow_events + , disabled_ = False } , Components.SecretForm.viewImagesInput { onInput_ = ImageOnInput diff --git a/src/elm/Vela.elm b/src/elm/Vela.elm index 4e762386d..bb7633e15 100644 --- a/src/elm/Vela.elm +++ b/src/elm/Vela.elm @@ -67,7 +67,7 @@ module Vela exposing , decodeServices , decodeSourceRepositories , decodeSteps - , defaultAllowEventsPayload + , defaultAllowEvents , defaultDeploymentPayload , defaultRepoPayload , defaultSchedulePayload @@ -204,7 +204,21 @@ type alias SourceRepositories = buildEnableRepoPayload : Repository -> EnableRepoPayload buildEnableRepoPayload repo = - EnableRepoPayload repo.org repo.name repo.full_name repo.link repo.clone repo.private repo.trusted repo.active repo.allow_pull repo.allow_push repo.allow_deploy repo.allow_tag repo.allow_comment repo.allow_events + EnableRepoPayload + repo.org + repo.name + repo.full_name + repo.link + repo.clone + repo.private + repo.trusted + repo.active + repo.allow_pull + repo.allow_push + repo.allow_deploy + repo.allow_tag + repo.allow_comment + repo.allow_events encodeEnableRepository : EnableRepoPayload -> Json.Encode.Value @@ -223,7 +237,7 @@ encodeEnableRepository repo = , ( "allow_deploy", Json.Encode.bool <| repo.allow_deploy ) , ( "allow_tag", Json.Encode.bool <| repo.allow_tag ) , ( "allow_comment", Json.Encode.bool <| repo.allow_comment ) - , ( "allow_events", encodeOptional encodeAllowEvents repo.allow_events ) + , ( "allow_events", encodeAllowEvents repo.allow_events ) ] @@ -291,7 +305,7 @@ type alias EnableRepoPayload = , allow_deploy : Bool , allow_tag : Bool , allow_comment : Bool - , allow_events : Maybe AllowEventsPayload + , allow_events : AllowEventsPayload } @@ -344,7 +358,7 @@ type alias Repository = , allow_deploy : Bool , allow_tag : Bool , allow_comment : Bool - , allow_events : Maybe AllowEvents + , allow_events : AllowEvents , enabled : Enabled , pipeline_type : String } @@ -374,7 +388,7 @@ decodeRepository = |> optional "allow_deploy" bool False |> optional "allow_tag" bool False |> optional "allow_comment" bool False - |> optional "allow_events" (Json.Decode.maybe decodeAllowEvents) Nothing + |> optional "allow_events" decodeAllowEvents defaultAllowEvents -- "enabled" |> optional "active" enabledDecoder Disabled |> optional "pipeline_type" string "" @@ -446,10 +460,10 @@ defaultRepoPayload = setAllowEvents : - { a | allow_events : Maybe AllowEvents } + { a | allow_events : AllowEvents } -> String -> Bool - -> { a | allow_events : Maybe AllowEventsPayload } + -> { a | allow_events : AllowEventsPayload } setAllowEvents payload field val = let events = @@ -461,47 +475,47 @@ setAllowEvents payload field val = case field of "allow_push_branch" -> { payload - | allow_events = Just { events | push = { push | branch = val } } + | allow_events = { events | push = { push | branch = val } } } "allow_push_tag" -> { payload - | allow_events = Just { events | push = { push | tag = val } } + | allow_events = { events | push = { push | tag = val } } } "allow_pull_opened" -> { payload - | allow_events = Just { events | pull = { pull | opened = val } } + | allow_events = { events | pull = { pull | opened = val } } } "allow_pull_synchronize" -> { payload - | allow_events = Just { events | pull = { pull | synchronize = val } } + | allow_events = { events | pull = { pull | synchronize = val } } } "allow_pull_edited" -> { payload - | allow_events = Just { events | pull = { pull | edited = val } } + | allow_events = { events | pull = { pull | edited = val } } } "allow_pull_reopened" -> { payload - | allow_events = Just { events | pull = { pull | reopened = val } } + | allow_events = { events | pull = { pull | reopened = val } } } "allow_deploy_created" -> { payload - | allow_events = Just { events | deploy = { deploy | created = val } } + | allow_events = { events | deploy = { deploy | created = val } } } "allow_comment_created" -> { payload - | allow_events = Just { events | comment = { comment | created = val } } + | allow_events = { events | comment = { comment | created = val } } } "allow_comment_edited" -> { payload - | allow_events = Just { events | comment = { comment | edited = val } } + | allow_events = { events | comment = { comment | edited = val } } } _ -> @@ -513,6 +527,7 @@ type alias AllowEventsPayload = , pull : PullActions , deploy : DeployActions , comment : CommentActions + , schedule : ScheduleActions } @@ -541,16 +556,22 @@ type alias CommentActions = } +type alias ScheduleActions = + { run : Bool + } + + type alias AllowEvents = { push : PushActions , pull : PullActions , deploy : DeployActions , comment : CommentActions + , schedule : ScheduleActions } -defaultAllowEventsPayload : AllowEventsPayload -defaultAllowEventsPayload = +defaultAllowEvents : AllowEventsPayload +defaultAllowEvents = { push = { branch = False , tag = False @@ -568,21 +589,20 @@ defaultAllowEventsPayload = { created = False , edited = False } + , schedule = + { run = False + } } -toAllowEventsPayload : { a | allow_events : Maybe AllowEvents } -> AllowEventsPayload -toAllowEventsPayload resource = - case resource.allow_events of - Nothing -> - defaultAllowEventsPayload - - Just events -> - AllowEventsPayload - (defaultPushActions (Just events.push)) - (defaultPullActions (Just events.pull)) - (defaultDeployActions (Just events.deploy)) - (defaultCommentActions (Just events.comment)) +toAllowEventsPayload : { a | allow_events : AllowEvents } -> AllowEventsPayload +toAllowEventsPayload { allow_events } = + AllowEventsPayload + (defaultPushActions (Just allow_events.push)) + (defaultPullActions (Just allow_events.pull)) + (defaultDeployActions (Just allow_events.deploy)) + (defaultCommentActions (Just allow_events.comment)) + (defaultScheduleActions (Just allow_events.schedule)) defaultPushActions : Maybe PushActions -> PushActions @@ -625,6 +645,16 @@ defaultCommentActions commentActions = CommentActions comment.created comment.edited +defaultScheduleActions : Maybe ScheduleActions -> ScheduleActions +defaultScheduleActions scheduleActions = + case scheduleActions of + Nothing -> + ScheduleActions False + + Just schedule -> + ScheduleActions schedule.run + + decodePushActions : Decoder PushActions decodePushActions = Json.Decode.succeed PushActions @@ -654,6 +684,12 @@ decodeCommentActions = |> required "edited" bool +decodeScheduleActions : Decoder ScheduleActions +decodeScheduleActions = + Json.Decode.succeed ScheduleActions + |> required "run" bool + + decodeAllowEvents : Decoder AllowEvents decodeAllowEvents = Json.Decode.succeed AllowEvents @@ -661,6 +697,7 @@ decodeAllowEvents = |> required "pull_request" decodePullActions |> required "deployment" decodeDeployActions |> required "comment" decodeCommentActions + |> required "schedule" decodeScheduleActions encodeAllowEvents : AllowEventsPayload -> Json.Encode.Value @@ -670,6 +707,7 @@ encodeAllowEvents events = , ( "pull_request", encodePullActions events.pull ) , ( "deployment", encodeDeployActions events.deploy ) , ( "comment", encodeCommentActions events.comment ) + , ( "schedule", encodeScheduleActions events.schedule ) ] @@ -706,6 +744,13 @@ encodeCommentActions comment = ] +encodeScheduleActions : ScheduleActions -> Json.Encode.Value +encodeScheduleActions schedule = + Json.Encode.object + [ ( "run", Json.Encode.bool <| schedule.run ) + ] + + -- PIPELINE @@ -1329,7 +1374,7 @@ type alias Secret = , images : List String , events : List String , allowCommand : Bool - , allow_events : Maybe AllowEvents + , allow_events : AllowEvents } @@ -1415,7 +1460,7 @@ decodeSecret = |> optional "images" (Json.Decode.list string) [] |> optional "events" (Json.Decode.list string) [] |> optional "allow_command" bool False - |> optional "allow_events" (Json.Decode.maybe decodeAllowEvents) Nothing + |> optional "allow_events" decodeAllowEvents defaultAllowEvents decodeSecrets : Decoder (List Secret) @@ -1461,7 +1506,6 @@ encodeSecretPayload secret = , ( "team", encodeOptional Json.Encode.string secret.team ) , ( "name", encodeOptional Json.Encode.string secret.name ) , ( "value", encodeOptional Json.Encode.string secret.value ) - , ( "events", encodeOptionalList Json.Encode.string secret.events ) , ( "images", encodeOptionalList Json.Encode.string secret.images ) , ( "allow_command", encodeOptional Json.Encode.bool secret.allowCommand ) , ( "allow_events", encodeOptional encodeAllowEvents secret.allow_events )