11<script >
2- import { onMount , onDestroy , afterUpdate } from ' svelte' ;
3- import { derived } from ' svelte/store' ;
4- import { page } from ' $app/stores' ;
52 import { _ } from ' svelte-i18n' ;
6- import { Card , CardBody , Col , Row } from ' @sveltestrap/sveltestrap' ;
73 import HeadTitle from " $lib/common/HeadTitle.svelte" ;
84 import Breadcrumb from ' $lib/common/Breadcrumb.svelte' ;
9- import { globalMenuStore } from ' $lib/helpers/store' ;
10-
11-
12- /** @type {any} */
13- let menuUnsubscribe;
5+ import EmbeddingPage from ' $lib/common/embedding/EmbeddingPage.svelte' ;
146
157 /** @type {string?} */
168 let label = ' ' ;
17-
18- /** @type {string} */
19- let curSlug = ' ' ;
20-
21- const slug = derived (page, $page => $page .params .reportType );
22-
23- const contentSubscribe = slug .subscribe (value => {
24- if (curSlug && curSlug !== value) {
25- location .reload ();
26- }
27- curSlug = value;
28- });
29-
30- onMount (async () => {
31- menuUnsubscribe = globalMenuStore .subscribe ((/** @type {import('$pluginTypes').PluginMenuDefModel[]} */ menu) => {
32- const url = getPathUrl ();
33- let found = menu .find (x => x .link === url);
34- label = found? .label || null ;
35- if (! found? .embeddingInfo ) {
36- const subFound = menu .find (x => !! x .subMenu ? .find (y => y .link === url));
37- found = subFound? .subMenu ? .find (x => x .link === url);
38- label = found? .label || null ;
39- }
40- embed (found? .embeddingInfo || null );
41- });
42- });
43-
44- onDestroy (() => {
45- menuUnsubscribe? .();
46- contentSubscribe? .();
47- });
48-
49-
50- /** @param {import('$pluginTypes').EmbeddingInfoModel?} data */
51- function embed (data ) {
52- if (! data) return ;
53-
54- if (data .scriptSrc ) {
55- const script = document .createElement (" script" );
56- script .id = data .source ;
57- script .src = data .scriptSrc ;
58- script .async = true ;
59-
60- if (data .scriptType ) {
61- script .type = data .scriptType ;
62- }
63- document .head .appendChild (script);
64- }
65-
66- const div = document .querySelector (' #agent-reporting-content' );
67- if (! data .url || ! div) return ;
68-
69- if (data .htmlTag ) {
70- const elem = document .createElement (data .htmlTag );
71- elem .id = data .source ;
72- elem .style .width = ' 100%' ;
73- elem .style .height = ' 100%' ;
74- elem .style .justifyContent = ' center' ;
75- // @ts-ignore
76- elem .src = data .url ;
77- div .appendChild (elem);
78- }
79- }
80-
81- const getPathUrl = () => {
82- const path = $page .url .pathname ;
83- return path? .startsWith (' /' ) ? path .substring (1 ) : path;
84- };
859 </script >
8610
87- < HeadTitle title= " {$_(label || 'Reporting')}" / >
11+ <HeadTitle title =" {$_ (label || ' Reporting' )}" addOn = " Reporting " />
8812<Breadcrumb title =" {$_ (' Agent' )}" pagetitle =" {$_ (label || ' Reporting' )}" />
8913
90- < Row>
91- < Col lg= " 12" >
92- < Card>
93- < CardBody id= " agent-reporting-content" >< / CardBody>
94- < / Card>
95- < / Col>
96- < / Row>
14+ <EmbeddingPage
15+ htmlTagId =" agent-reporting-content"
16+ slugName =" reportType"
17+ bind:label ={label }
18+ />
0 commit comments