diff --git a/src/elm/Layouts/Default/Build.elm b/src/elm/Layouts/Default/Build.elm index 055b67bc2..b7990b4dc 100644 --- a/src/elm/Layouts/Default/Build.elm +++ b/src/elm/Layouts/Default/Build.elm @@ -18,7 +18,9 @@ import RemoteData exposing (WebData) import Route exposing (Route) import Route.Path import Shared +import Time import Utils.Errors +import Utils.Interval as Interval import Vela import View exposing (View) @@ -99,6 +101,7 @@ init props shared _ = type Msg = OnUrlChanged { from : Route (), to : Route () } | GetBuildResponse (Result (Http.Detailed.Error String) ( Http.Metadata, Vela.Build )) + | Tick { time : Time.Posix, interval : Interval.Interval } update : Props contentMsg -> Shared.Model -> Msg -> Model -> ( Model, Effect Msg ) @@ -139,10 +142,31 @@ update props shared msg model = , Effect.handleHttpError { httpError = error } ) + Tick options -> + ( model + , Effect.batch + [ Effect.getRepoBuildsShared + { pageNumber = Nothing + , perPage = Nothing + , maybeEvent = Nothing + , org = props.org + , repo = props.repo + } + , Effect.getBuild + { baseUrl = shared.velaAPI + , session = shared.session + , onResponse = GetBuildResponse + , org = props.org + , repo = props.repo + , buildNumber = props.buildNumber + } + ] + ) + subscriptions : Model -> Sub Msg subscriptions model = - Sub.none + Interval.tickEveryFiveSeconds Tick diff --git a/src/elm/Pages/Org_.elm b/src/elm/Pages/Org_.elm index 62309f637..10064bbb9 100644 --- a/src/elm/Pages/Org_.elm +++ b/src/elm/Pages/Org_.elm @@ -17,8 +17,10 @@ import RemoteData exposing (WebData) import Route exposing (Route) import Route.Path import Shared +import Time import Utils.Errors import Utils.Helpers as Util +import Utils.Interval as Interval import Vela import View exposing (View) @@ -27,7 +29,7 @@ page : Auth.User -> Shared.Model -> Route { org : String } -> Page Model Msg page user shared route = Page.new { init = init shared route - , update = update + , update = update shared route , subscriptions = subscriptions , view = view shared route } @@ -75,10 +77,11 @@ init shared route () = type Msg = GetOrgReposResponse (Result (Http.Detailed.Error String) ( Http.Metadata, List Vela.Repository )) + | Tick { time : Time.Posix, interval : Interval.Interval } -update : Msg -> Model -> ( Model, Effect Msg ) -update msg model = +update : Shared.Model -> Route { org : String } -> Msg -> Model -> ( Model, Effect Msg ) +update shared route msg model = case msg of GetOrgReposResponse response -> case response of @@ -92,6 +95,16 @@ update msg model = , Effect.handleHttpError { httpError = error } ) + Tick options -> + ( model + , Effect.getOrgRepos + { baseUrl = shared.velaAPI + , session = shared.session + , onResponse = GetOrgReposResponse + , org = route.params.org + } + ) + -- SUBSCRIPTIONS @@ -99,7 +112,7 @@ update msg model = subscriptions : Model -> Sub Msg subscriptions model = - Sub.none + Interval.tickEveryFiveSeconds Tick diff --git a/src/elm/Pages/Org_/Builds.elm b/src/elm/Pages/Org_/Builds.elm index a37620638..2be4287a7 100644 --- a/src/elm/Pages/Org_/Builds.elm +++ b/src/elm/Pages/Org_/Builds.elm @@ -22,8 +22,10 @@ import Page exposing (Page) import RemoteData exposing (WebData) import Route exposing (Route) import Shared +import Time import Utils.Errors import Utils.Helpers as Util +import Utils.Interval as Interval import Vela import View exposing (View) @@ -98,6 +100,7 @@ type Msg | OnEventQueryParameterChanged { from : Maybe String, to : Maybe String } | FilterByEvent (Maybe String) | ShowHideFullTimestamps + | Tick { time : Time.Posix, interval : Interval.Interval } update : Shared.Model -> Route { org : String } -> Msg -> Model -> ( Model, Effect Msg ) @@ -218,6 +221,19 @@ update shared route msg model = ShowHideFullTimestamps -> ( { model | showFullTimestamps = not model.showFullTimestamps }, Effect.none ) + Tick options -> + ( model + , Effect.getOrgBuilds + { baseUrl = shared.velaAPI + , session = shared.session + , onResponse = GetOrgBuildsResponse + , pageNumber = Dict.get "page" route.query |> Maybe.andThen String.toInt + , perPage = Dict.get "perPage" route.query |> Maybe.andThen String.toInt + , maybeEvent = Dict.get "event" route.query + , org = route.params.org + } + ) + -- SUBSCRIPTIONS @@ -225,7 +241,10 @@ update shared route msg model = subscriptions : Model -> Sub Msg subscriptions model = - Util.onMouseDownSubscription "build-actions" (List.length model.showActionsMenus > 0) (ShowHideActionsMenus Nothing) + Sub.batch + [ Util.onMouseDownSubscription "build-actions" (List.length model.showActionsMenus > 0) (ShowHideActionsMenus Nothing) + , Interval.tickEveryFiveSeconds Tick + ] diff --git a/src/elm/Pages/Org_/Repo_/Build_.elm b/src/elm/Pages/Org_/Repo_/Build_.elm index 20b82c8a0..e7994aac5 100644 --- a/src/elm/Pages/Org_/Repo_/Build_.elm +++ b/src/elm/Pages/Org_/Repo_/Build_.elm @@ -436,7 +436,7 @@ update shared route msg model = subscriptions : Model -> Sub Msg subscriptions model = - Interval.tickEveryOneSecond Tick + Interval.tickEveryFiveSeconds Tick diff --git a/src/elm/Pages/Org_/Repo_/Build_/Services.elm b/src/elm/Pages/Org_/Repo_/Build_/Services.elm index 6bbcb2466..e1fe64aea 100644 --- a/src/elm/Pages/Org_/Repo_/Build_/Services.elm +++ b/src/elm/Pages/Org_/Repo_/Build_/Services.elm @@ -436,7 +436,7 @@ update shared route msg model = subscriptions : Model -> Sub Msg subscriptions model = - Interval.tickEveryOneSecond Tick + Interval.tickEveryFiveSeconds Tick