]>
Commit | Line | Data |
---|---|---|
39ae355f | 1 | import { Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core'; |
f67539c2 TL |
2 | |
3 | import { AlertPanelComponent } from '../components/alert-panel/alert-panel.component'; | |
4 | import { LoadingPanelComponent } from '../components/loading-panel/loading-panel.component'; | |
5 | import { LoadingStatus } from '../forms/cd-form'; | |
6 | ||
7 | @Directive({ | |
8 | selector: '[cdFormLoading]' | |
9 | }) | |
10 | export class FormLoadingDirective { | |
39ae355f | 11 | constructor(private templateRef: TemplateRef<any>, private viewContainer: ViewContainerRef) {} |
f67539c2 | 12 | |
39ae355f | 13 | @Input() set cdFormLoading(condition: LoadingStatus) { |
f67539c2 TL |
14 | let content: any; |
15 | ||
16 | this.viewContainer.clear(); | |
17 | ||
18 | switch (condition) { | |
19 | case LoadingStatus.Loading: | |
f67539c2 | 20 | content = this.resolveNgContent($localize`Loading form data...`); |
39ae355f | 21 | this.viewContainer.createComponent(LoadingPanelComponent, { projectableNodes: content }); |
f67539c2 TL |
22 | break; |
23 | case LoadingStatus.Ready: | |
24 | this.viewContainer.createEmbeddedView(this.templateRef); | |
25 | break; | |
26 | case LoadingStatus.Error: | |
f67539c2 | 27 | content = this.resolveNgContent($localize`Form data could not be loaded.`); |
39ae355f TL |
28 | const componentRef = this.viewContainer.createComponent(AlertPanelComponent, { |
29 | projectableNodes: content | |
30 | }); | |
f67539c2 TL |
31 | (<AlertPanelComponent>componentRef.instance).type = 'error'; |
32 | break; | |
33 | } | |
34 | } | |
35 | ||
36 | resolveNgContent(content: string) { | |
37 | const element = document.createTextNode(content); | |
38 | return [[element]]; | |
39 | } | |
40 | } |