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"}} />
|
|
|
|
|
|
|
|
{{did-update (fn dispatch "LOAD") src=src}}
|
|
|
|
|
|
|
|
{{#let (hash
|
|
|
|
data=data
|
|
|
|
error=error
|
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}}
|
|
|
|
<State @notMatches={{array "error" "disconnected"}}>
|
|
|
|
{{! 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>
|
|
|
|
|
|
|
|
<State @matches={{array "idle" "disconnected"}}>
|
|
|
|
|
|
|
|
<State @matches="disconnected">
|
|
|
|
{{#yield-slot name="disconnected" params=(block-params (component 'notification' after=(action dispatch "RESET")))}}
|
|
|
|
{{yield api}}
|
|
|
|
{{else}}
|
|
|
|
<Notification @sticky={{true}}>
|
|
|
|
<p data-notification role="alert" class="warning notification-update">
|
|
|
|
<strong>Warning!</strong>
|
|
|
|
An error was returned whilst loading this data, refresh to try again.
|
|
|
|
</p>
|
|
|
|
</Notification>
|
|
|
|
{{/yield-slot}}
|
|
|
|
</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}}
|
|
|
|
</StateChart>
|