11<script >
2- import { onDestroy } from ' svelte' ;
2+ import { onMount , onDestroy } from ' svelte' ;
33 import { page } from ' $app/stores' ;
44 import { _ } from ' svelte-i18n' ;
55 import { Card , CardBody , Col , Row } from ' @sveltestrap/sveltestrap' ;
66 import HeadTitle from " $lib/common/HeadTitle.svelte" ;
77 import Breadcrumb from ' $lib/common/Breadcrumb.svelte' ;
88 import { globalMenuStore } from ' $lib/helpers/store' ;
99
10- /** @type {string } */
11- let embedUrl = ' ' ;
10+ /** @type {any } */
11+ let unsubscriber ;
1212
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+ });
1719 });
1820
1921 onDestroy (() => {
2022 unsubscriber? .();
2123 });
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+ }
2256< / script>
2357
2458< HeadTitle title= " {$_('Metrics')}" / >
2559< Breadcrumb title= " {$_('Agent')}" pagetitle= " {$_('Metrics')}" / >
2660
27- {#if embedUrl}
2861< Row>
2962 < Col lg= " 12" >
3063 < 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>
4265 < / Card>
4366 < / Col>
44- < / Row>
45- {/ if }
67+ < / Row>
0 commit comments