1
1
<script >
2
- import { onDestroy } from ' svelte' ;
2
+ import { onMount , onDestroy } from ' svelte' ;
3
3
import { page } from ' $app/stores' ;
4
4
import { _ } from ' svelte-i18n' ;
5
5
import { Card , CardBody , Col , Row } from ' @sveltestrap/sveltestrap' ;
6
6
import HeadTitle from " $lib/common/HeadTitle.svelte" ;
7
7
import Breadcrumb from ' $lib/common/Breadcrumb.svelte' ;
8
8
import { globalMenuStore } from ' $lib/helpers/store' ;
9
9
10
- /** @type {string } */
11
- let embedUrl = ' ' ;
10
+ /** @type {any } */
11
+ let unsubscriber ;
12
12
13
- const unsubscriber = globalMenuStore .subscribe ((/** @type {import('$pluginTypes').PluginMenuDefModel[]} */ menu) => {
14
- const url = $page .url .pathname ;
15
- const pageInfo = menu .find (x => x .link === url) || null ;
16
- embedUrl = pageInfo? .embedUrl || ' ' ;
13
+ onMount (async () => {
14
+ unsubscriber = globalMenuStore .subscribe ((/** @type {import('$pluginTypes').PluginMenuDefModel[]} */ menu) => {
15
+ const url = $page .url .pathname ;
16
+ const data = menu .find (x => x .link === url)? .embeddingInfo || null ;
17
+ embed (data);
18
+ });
17
19
});
18
20
19
21
onDestroy (() => {
20
22
unsubscriber? .();
21
23
});
24
+
25
+
26
+ /** @param {import('$pluginTypes').EmbeddingInfoModel?} data */
27
+ function embed (data ) {
28
+ if (! data) return ;
29
+
30
+ if (data .scriptSrc ) {
31
+ const script = document .createElement (" script" );
32
+ script .id = data .source ;
33
+ script .src = data .scriptSrc ;
34
+ script .async = true ;
35
+
36
+ if (data .scriptType ) {
37
+ script .type = data .scriptType ;
38
+ }
39
+ document .head .appendChild (script);
40
+ }
41
+
42
+ const div = document .querySelector (' #agent-metrics-content' );
43
+ if (! data .url || ! div) return ;
44
+
45
+ if (data .htmlTag ) {
46
+ const elem = document .createElement (data .htmlTag );
47
+ elem .id = data .source ;
48
+ elem .style .width = ' 100%' ;
49
+ elem .style .height = ' 100%' ;
50
+ elem .style .justifyContent = ' center' ;
51
+ // @ts-ignore
52
+ elem .src = data .url ;
53
+ div .appendChild (elem);
54
+ }
55
+ }
22
56
< / script>
23
57
24
58
< HeadTitle title= " {$_('Metrics')}" / >
25
59
< Breadcrumb title= " {$_('Agent')}" pagetitle= " {$_('Metrics')}" / >
26
60
27
- {#if embedUrl}
28
61
< Row>
29
62
< Col lg= " 12" >
30
63
< Card>
31
- < CardBody>
32
- < iframe
33
- title= " agent-metrics"
34
- height= " 100%"
35
- width= " 100%"
36
- src= {embedUrl}
37
- frameborder= " 0"
38
- allowfullscreen
39
- >
40
- < / iframe>
41
- < / CardBody>
64
+ < CardBody id= " agent-metrics-content" >< / CardBody>
42
65
< / Card>
43
66
< / Col>
44
- < / Row>
45
- {/ if }
67
+ < / Row>
0 commit comments