Skip to content

Commit 185bfaa

Browse files
authored
Merge pull request #323 from iceljc/features/refine-chat-window
add embedding
2 parents 9c6910d + 6b24a12 commit 185bfaa

File tree

2 files changed

+53
-22
lines changed

2 files changed

+53
-22
lines changed

src/lib/helpers/types/pluginTypes.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@
1616
* @property {string} label
1717
* @property {string} icon
1818
* @property {string} link
19-
* @property {string?} [embedUrl]
19+
* @property {EmbeddingInfoModel?} [embeddingInfo]
2020
* @property {boolean} isHeader
2121
*/
2222

23+
/**
24+
* @typedef {Object} EmbeddingInfoModel
25+
* @property {string} source
26+
* @property {string?} [scriptSrc]
27+
* @property {string?} [scriptType]
28+
* @property {string?} [url]
29+
* @property {string?} [htmlTag]
30+
*/
31+
2332
/**
2433
* @typedef {Object} PluginFilter
2534
* @property {import('$commonTypes').Pagination} pager - Pagination
+43-21
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,67 @@
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

Comments
 (0)