2020-07-09 09:08:47 +00:00
|
|
|
{{yield}}
|
|
|
|
<StateChart @src={{chart}} as |State Guard Action dispatch state|>
|
|
|
|
<Ref @target={{this}} @name="dispatch" @value={{dispatch}} />
|
|
|
|
<Guard @name="loaded" @cond={{action "isLoaded"}} />
|
|
|
|
|
|
|
|
|
|
|
|
{{#let (hash
|
|
|
|
data=data
|
|
|
|
error=error
|
2021-12-01 11:33:33 +00:00
|
|
|
invalidate=(action "invalidate")
|
2020-07-17 13:42:45 +00:00
|
|
|
dispatchError=(queue (action (mut error) value="error.errors.firstObject") (action dispatch "ERROR"))
|
2020-07-09 09:08:47 +00:00
|
|
|
) as |api|}}
|
|
|
|
|
2020-07-17 13:42:45 +00:00
|
|
|
{{#yield-slot name="data"}}
|
|
|
|
{{yield api}}
|
|
|
|
{{else}}
|
|
|
|
{{! if we didn't specify any data}}
|
|
|
|
{{#if (not items)}}
|
|
|
|
{{! try and load the data if we aren't in an error state}}
|
2021-12-01 11:33:33 +00:00
|
|
|
<State @notMatches={{array "error" "disconnected" "invalidating"}}>
|
2020-07-17 13:42:45 +00:00
|
|
|
{{! but only if we only asked for a single load and we are in loading state}}
|
|
|
|
{{#if (and src (or (not once) (state-matches state "loading")))}}
|
|
|
|
<DataSource
|
|
|
|
@open={{open}}
|
|
|
|
@src={{src}}
|
|
|
|
@onchange={{queue (action "change" value="data") (action dispatch "SUCCESS")}}
|
|
|
|
@onerror={{api.dispatchError}}
|
|
|
|
/>
|
|
|
|
{{/if}}
|
|
|
|
</State>
|
|
|
|
{{/if}}
|
|
|
|
{{/yield-slot}}
|
2020-07-09 09:08:47 +00:00
|
|
|
|
|
|
|
<State @matches="loading">
|
|
|
|
{{#yield-slot name="loading"}}
|
|
|
|
{{yield api}}
|
|
|
|
{{else}}
|
2020-10-14 08:03:39 +00:00
|
|
|
<Consul::Loader />
|
2020-07-09 09:08:47 +00:00
|
|
|
{{/yield-slot}}
|
|
|
|
</State>
|
|
|
|
|
|
|
|
<State @matches="error">
|
|
|
|
{{#yield-slot name="error"}}
|
|
|
|
{{yield api}}
|
|
|
|
{{else}}
|
|
|
|
<ErrorState @error={{error}} />
|
|
|
|
{{/yield-slot}}
|
|
|
|
</State>
|
|
|
|
|
2021-12-01 11:33:33 +00:00
|
|
|
<State @matches={{array "idle" "disconnected" "invalidating"}}>
|
2020-07-09 09:08:47 +00:00
|
|
|
|
|
|
|
<State @matches="disconnected">
|
2022-01-04 14:55:32 +00:00
|
|
|
{{#if (not (eq error.status '401'))}}
|
2021-11-24 18:14:07 +00:00
|
|
|
{{#yield-slot name="disconnected" params=(block-params (action dispatch "RESET"))}}
|
2022-01-04 14:55:32 +00:00
|
|
|
{{yield api}}
|
2020-07-09 09:08:47 +00:00
|
|
|
{{else}}
|
2021-11-24 18:14:07 +00:00
|
|
|
<Notice
|
|
|
|
{{notification
|
|
|
|
sticky=true
|
|
|
|
}}
|
|
|
|
class="notification-update"
|
|
|
|
@type="warning"
|
|
|
|
as |notice|>
|
|
|
|
<notice.Header>
|
2020-07-09 09:08:47 +00:00
|
|
|
<strong>Warning!</strong>
|
2021-11-24 18:14:07 +00:00
|
|
|
</notice.Header>
|
|
|
|
<notice.Body>
|
|
|
|
<p>
|
|
|
|
An error was returned whilst loading this data, refresh to try again.
|
|
|
|
</p>
|
|
|
|
</notice.Body>
|
|
|
|
</Notice>
|
2020-07-09 09:08:47 +00:00
|
|
|
{{/yield-slot}}
|
2022-01-04 14:55:32 +00:00
|
|
|
{{/if}}
|
2020-07-09 09:08:47 +00:00
|
|
|
</State>
|
2021-02-19 16:42:16 +00:00
|
|
|
{{#if (eq error.status "403")}}
|
|
|
|
{{#yield-slot name="error"}}
|
|
|
|
{{yield api}}
|
|
|
|
{{else}}
|
|
|
|
<ErrorState @error={{error}} />
|
|
|
|
{{/yield-slot}}
|
|
|
|
{{else}}
|
|
|
|
<YieldSlot @name="loaded">
|
|
|
|
{{yield api}}
|
|
|
|
</YieldSlot>
|
|
|
|
{{/if}}
|
2020-07-09 09:08:47 +00:00
|
|
|
|
|
|
|
</State>
|
|
|
|
|
|
|
|
{{/let}}
|
2021-10-07 11:38:04 +00:00
|
|
|
{{did-update (fn dispatch "LOAD") src=src}}
|
2020-07-09 09:08:47 +00:00
|
|
|
</StateChart>
|