@uxland/primary-shell 5.1.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/index.js +22726 -22470
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.umd.cjs +229 -174
  4. package/dist/index.umd.cjs.map +1 -1
  5. package/dist/primary/shell/src/UI/components/pdf-visor/pdf-selector/pdf-selector.d.ts +12 -0
  6. package/dist/primary/shell/src/UI/components/pdf-visor/pdf-selector/template.d.ts +3 -0
  7. package/dist/primary/shell/src/UI/components/pdf-visor/pdf-visor.d.ts +22 -0
  8. package/dist/primary/shell/src/UI/components/pdf-visor/utils.d.ts +1 -0
  9. package/dist/primary/shell/src/UI/components/poc-events-ecap/poc-events-ecap.d.ts +2 -0
  10. package/dist/primary/shell/src/api/api.d.ts +2 -0
  11. package/dist/primary/shell/src/api/pdf-viewer-manager/events.d.ts +5 -0
  12. package/dist/primary/shell/src/api/pdf-viewer-manager/pdf-viewer-manager.d.ts +27 -0
  13. package/dist/primary/shell/src/constants.d.ts +1 -0
  14. package/dist/primary/shell/src/locales.d.ts +10 -0
  15. package/package.json +1 -1
  16. package/src/UI/components/clinical-monitoring/styles.css +0 -1
  17. package/src/UI/components/index.ts +1 -0
  18. package/src/UI/components/pdf-visor/pdf-selector/pdf-selector.ts +40 -0
  19. package/src/UI/components/pdf-visor/pdf-selector/styles.css +24 -0
  20. package/src/UI/components/pdf-visor/pdf-selector/template.ts +37 -0
  21. package/src/UI/components/pdf-visor/pdf-visor.ts +124 -0
  22. package/src/UI/components/pdf-visor/styles.css +29 -0
  23. package/src/UI/components/pdf-visor/utils.ts +16 -0
  24. package/src/UI/components/poc-events-ecap/poc-events-ecap.ts +37 -7
  25. package/src/api/api.ts +7 -1
  26. package/src/api/pdf-viewer-manager/events.ts +5 -0
  27. package/src/api/pdf-viewer-manager/pdf-viewer-manager.ts +97 -0
  28. package/src/constants.ts +1 -0
  29. package/src/handle-views.ts +12 -7
  30. package/src/locales.ts +10 -0
@@ -0,0 +1,12 @@
1
+ import { LitElement } from 'lit';
2
+ import { IPdfDocument } from '../../../../../src/api/pdf-viewer-manager/pdf-viewer-manager';
3
+
4
+ export declare class PdfSelector extends LitElement {
5
+ render(): import('lit').TemplateResult<1>;
6
+ static styles: import('lit').CSSResult;
7
+ pdfList: IPdfDocument[];
8
+ activePdfs: IPdfDocument[];
9
+ removePdf(id: string): void;
10
+ setActivePdf(id: string): void;
11
+ openInNewWindow(pdf: IPdfDocument): void;
12
+ }
@@ -0,0 +1,3 @@
1
+ import { PdfSelector } from './pdf-selector';
2
+
3
+ export declare const template: (props: PdfSelector) => import('lit').TemplateResult<1>;
@@ -0,0 +1,22 @@
1
+ import { LitElement } from 'lit';
2
+ import { PrimariaApi } from '../../../api/api';
3
+ import { IPdfDocument } from '../../../api/pdf-viewer-manager/pdf-viewer-manager';
4
+
5
+ export declare class PdfVisor extends LitElement {
6
+ static styles: import('lit').CSSResult;
7
+ api: PrimariaApi;
8
+ pdfList: IPdfDocument[];
9
+ activePdfs: IPdfDocument[];
10
+ private subscriptions;
11
+ connectedCallback(): Promise<void>;
12
+ disconnectedCallback(): void;
13
+ private _initializePdfState;
14
+ private _getPdfSrc;
15
+ private _subscribeEvents;
16
+ private _unsubscribeEvents;
17
+ private _onPdfAdded;
18
+ private _onPdfDeleted;
19
+ private _removePdf;
20
+ private _updateActivePdfs;
21
+ render(): import('lit').TemplateResult<1>;
22
+ }
@@ -0,0 +1 @@
1
+ export declare const createUrlFromBase64: (b64: string, type?: string) => string | undefined;
@@ -2,6 +2,8 @@ import { LitElement } from 'lit';
2
2
 
3
3
  export declare class PocEventsEcap extends LitElement {
4
4
  render(): import('lit').TemplateResult<1>;
5
+ sendPdfToViewer(): void;
6
+ getPDFS(): void;
5
7
  goToLinkOnEcap(): void;
6
8
  static styles: import('lit').CSSResult;
7
9
  }
@@ -8,6 +8,7 @@ import { EcapEventManager } from './ecap-event-manager/ecap-event-manager';
8
8
  import { PluginBusyManager } from './plugin-busy-manager/plugin-busy-manager';
9
9
  import { PrimariaInteractionService } from './interaction-service';
10
10
  import { PrimariaNotificationService } from './notification-service/notification-service';
11
+ import { PdfViewerManager } from './pdf-viewer-manager/pdf-viewer-manager';
11
12
 
12
13
  export interface PrimariaApi extends HarmonixApi {
13
14
  httpClient: HttpClient;
@@ -19,6 +20,7 @@ export interface PrimariaApi extends HarmonixApi {
19
20
  tokenManager: TokenManager;
20
21
  ecapEventManager: EcapEventManager;
21
22
  pluginBusyManager: PluginBusyManager;
23
+ pdfViewerManager: PdfViewerManager;
22
24
  }
23
25
  export declare const PrimariaRegionHost: any;
24
26
  /**
@@ -0,0 +1,5 @@
1
+ export declare const pdfViwerEvents: {
2
+ added: string;
3
+ showed: string;
4
+ deleted: string;
5
+ };
@@ -0,0 +1,27 @@
1
+ import { PrimariaBroker } from '../broker/primaria-broker';
2
+ import { PrimariaNotificationService } from '../notification-service/notification-service';
3
+ import { PrimariaRegionManager } from '../region-manager/region-manager';
4
+
5
+ export interface IPdfDocument {
6
+ pdfName: string;
7
+ id: string;
8
+ data: PdfData;
9
+ }
10
+ export interface PdfData {
11
+ url?: string;
12
+ b64?: string;
13
+ }
14
+ export declare class PdfViewerManager {
15
+ private broker;
16
+ private notificationService;
17
+ private regionManager;
18
+ constructor(broker: PrimariaBroker, notificationService: PrimariaNotificationService, regionManager: PrimariaRegionManager);
19
+ private pdfs;
20
+ private activePdf;
21
+ private hasBeenActivated;
22
+ add(pdfName: string, data: PdfData): void;
23
+ delete(pdfId: string): void;
24
+ getPdfs(): IPdfDocument[];
25
+ private registerNavButton;
26
+ }
27
+ export declare const createPdfViewerManager: (broker: PrimariaBroker, notificationService: PrimariaNotificationService, regionManager: PrimariaRegionManager) => PdfViewerManager;
@@ -1,3 +1,4 @@
1
1
  export declare const primariaShellId = "primaria-shell";
2
2
  export declare const clinicalMonitoringId = "clinical-monitoring";
3
3
  export declare const pocTestEventsId = "poc-events-ecap";
4
+ export declare const pdfViewerId = "pdf-viewer";
@@ -34,6 +34,16 @@ export declare const locales: {
34
34
  busyManager: {
35
35
  title: string;
36
36
  };
37
+ pdfManager: {
38
+ uploaded: string;
39
+ alreadyUploaded: string;
40
+ navButtonLabel: string;
41
+ missingData: string;
42
+ duplicatedSource: string;
43
+ };
44
+ pdfVisor: {
45
+ noPdfSelected: string;
46
+ };
37
47
  };
38
48
  };
39
49
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxland/primary-shell",
3
- "version": "5.1.0",
3
+ "version": "5.1.1",
4
4
  "description": "Primaria Shell",
5
5
  "author": "UXLand <dev@uxland.es>",
6
6
  "homepage": "https://github.com/uxland/harmonix/tree/app#readme",
@@ -12,7 +12,6 @@
12
12
  flex-direction: row;
13
13
 
14
14
  #widgets-sidebar-region {
15
- z-index: 1;
16
15
  width: 25%;
17
16
  border-left: 1px solid rgb(189, 189, 189);
18
17
  }
@@ -4,3 +4,4 @@ import "../shared-components";
4
4
  import "./shell-header/shell-header";
5
5
  import "./quick-actions-menu/quick-actions-menu";
6
6
  import "../../api/plugin-busy-manager/plugin-busy-list/component";
7
+ import "./pdf-visor/pdf-selector/pdf-selector";
@@ -0,0 +1,40 @@
1
+ import { LitElement, css, unsafeCSS } from "lit";
2
+ import { customElement, property } from "lit/decorators.js";
3
+ import { IPdfDocument } from "../../../../../src/api/pdf-viewer-manager/pdf-viewer-manager";
4
+ import { template } from "./template";
5
+ import styles from "./styles.css?inline";
6
+ import { createUrlFromBase64 } from "../utils";
7
+
8
+ @customElement("pdf-selector")
9
+ export class PdfSelector extends LitElement {
10
+ render() {
11
+ return template(this);
12
+ }
13
+
14
+ static styles = css`
15
+ ${unsafeCSS(styles)}
16
+ `;
17
+
18
+ @property({ type: Array })
19
+ pdfList: IPdfDocument[];
20
+
21
+ @property({ type: Array })
22
+ activePdfs: IPdfDocument[] = [];
23
+
24
+ removePdf(id: string) {
25
+ this.dispatchEvent(
26
+ new CustomEvent("pdf-removed", { detail: id, bubbles: true, composed: true }),
27
+ );
28
+ }
29
+
30
+ setActivePdf(id: string) {
31
+ this.dispatchEvent(
32
+ new CustomEvent("active-pdf-changed", { detail: id, bubbles: true, composed: true }),
33
+ );
34
+ }
35
+
36
+ openInNewWindow(pdf: IPdfDocument) {
37
+ const url = pdf.data.url ? pdf.data.url : createUrlFromBase64(pdf.data.b64 as string);
38
+ url && window.open(url);
39
+ }
40
+ }
@@ -0,0 +1,24 @@
1
+ :host {
2
+ width: 250px;
3
+ gap: 8px
4
+ }
5
+
6
+ .pdf-item{
7
+ display: flex;
8
+ align-items: flex-start;
9
+ padding: 8px;
10
+ gap:8px;
11
+ color:black;
12
+ border-bottom: 1px solid var(--color-neutral-100);
13
+ }
14
+
15
+ .header-icons{
16
+ display: flex;
17
+ gap: 8px;
18
+ }
19
+
20
+ .container{
21
+ gap: 8px;
22
+ display: flex;
23
+ flex-direction: column;
24
+ }
@@ -0,0 +1,37 @@
1
+ import { html } from "lit";
2
+ import { PdfSelector } from "./pdf-selector";
3
+ import { IPdfDocument } from "primary/shell/src/api/pdf-viewer-manager/pdf-viewer-manager";
4
+ import { repeat } from "lit/directives/repeat.js";
5
+
6
+ export const template = (props: PdfSelector) => {
7
+ const pdfitem = (pdf: IPdfDocument) => {
8
+ return html`
9
+ <div class="pdf-item">
10
+ <dss-checkbox @onChange=${() => props.setActivePdf(pdf.id)}>
11
+ <input
12
+ slot="input"
13
+ type="checkbox"
14
+ aria-label="Label"
15
+ .checked=${props.activePdfs.some((p) => p.id === pdf.id)}
16
+ >
17
+ </dss-checkbox>
18
+ <div class="container">
19
+ <div class="header-icons">
20
+ <dss-icon-button size="md" variant="error" icon="picture_as_pdf"></dss-icon-button>
21
+ <dss-icon-button size="md" variant="error" icon="close" @click=${() => props.removePdf(pdf.id)}></dss-icon-button>
22
+ <dss-icon-button size="md" icon="open_in_new" @click=${() => props.openInNewWindow(pdf)}></dss-icon-button>
23
+ </div>
24
+ <div class="data">
25
+ ${pdf.pdfName}
26
+ </div>
27
+ </div>
28
+ </div>
29
+ `;
30
+ };
31
+
32
+ return html`
33
+ <div>
34
+ ${repeat(props.pdfList, (pdf: IPdfDocument) => pdfitem(pdf))}
35
+ </div>
36
+ `;
37
+ };
@@ -0,0 +1,124 @@
1
+ import styles from "./styles.css?inline";
2
+ import { html, LitElement, css, unsafeCSS } from "lit";
3
+ import { customElement, property } from "lit/decorators.js";
4
+ import { BrokerDisposableHandler } from "../../../api/broker/primaria-broker";
5
+ import { PrimariaApi } from "../../../api/api";
6
+ import { TYPES } from "../../../../src/infrastructure/ioc/types";
7
+ import { lazyInject } from "../../../../src/infrastructure/ioc/container";
8
+ import { pdfViwerEvents } from "../../../../src/api/pdf-viewer-manager/events";
9
+ import { IPdfDocument } from "../../../api/pdf-viewer-manager/pdf-viewer-manager";
10
+ import { translate } from "../../../../src/locales";
11
+ import { createUrlFromBase64 } from "./utils";
12
+
13
+ @customElement("pdf-visor")
14
+ export class PdfVisor extends LitElement {
15
+ static styles = css`${unsafeCSS(styles)}`;
16
+
17
+ @lazyInject(TYPES.primaryApi)
18
+ api: PrimariaApi;
19
+
20
+ @property({ type: Array })
21
+ pdfList: IPdfDocument[] = [];
22
+
23
+ @property({ type: Array })
24
+ activePdfs: IPdfDocument[] = [];
25
+
26
+ private subscriptions: BrokerDisposableHandler[] = [];
27
+
28
+ async connectedCallback() {
29
+ super.connectedCallback();
30
+ this._initializePdfState();
31
+ this._subscribeEvents();
32
+ }
33
+
34
+ disconnectedCallback(): void {
35
+ super.disconnectedCallback();
36
+ this._unsubscribeEvents();
37
+ }
38
+
39
+ private _initializePdfState() {
40
+ const initialPdfs = this.api.pdfViewerManager.getPdfs?.() || [];
41
+ this.pdfList = [...initialPdfs];
42
+
43
+ if (initialPdfs.length === 1) {
44
+ this.activePdfs = [initialPdfs[0] as IPdfDocument];
45
+ } else if (initialPdfs.length >= 2) {
46
+ this.activePdfs = initialPdfs.slice(-2);
47
+ }
48
+ }
49
+
50
+ private _getPdfSrc(pdf: IPdfDocument) {
51
+ if (pdf.data.url) return pdf.data.url;
52
+ if (pdf.data.b64) return createUrlFromBase64(pdf.data.b64);
53
+ return "";
54
+ }
55
+
56
+ private _subscribeEvents() {
57
+ const subscriptions = [
58
+ this.api.broker.subscribe(pdfViwerEvents.added, (pdf: IPdfDocument) => this._onPdfAdded(pdf)),
59
+ this.api.broker.subscribe(pdfViwerEvents.deleted, ({ id }) => this._onPdfDeleted({ id })),
60
+ ];
61
+ subscriptions.forEach((s) => this.subscriptions.push(s));
62
+ }
63
+
64
+ private _unsubscribeEvents() {
65
+ this.subscriptions.forEach((s) => s.dispose());
66
+ }
67
+
68
+ private _onPdfAdded(pdf: IPdfDocument) {
69
+ this.pdfList = [...this.pdfList, pdf];
70
+ this._updateActivePdfs(pdf.id);
71
+ }
72
+
73
+ private _onPdfDeleted({ id }) {
74
+ this.pdfList = this.pdfList.filter((pdf) => pdf.id !== id);
75
+ this.activePdfs = this.activePdfs.filter((pdf) => pdf.id !== id);
76
+ this.requestUpdate();
77
+ }
78
+
79
+ private _removePdf(id: string) {
80
+ this.api.pdfViewerManager.delete(id);
81
+ this.activePdfs = this.activePdfs.filter((pdf) => pdf.id !== id);
82
+ }
83
+
84
+ private _updateActivePdfs(id: string) {
85
+ const isAlreadyActive = this.activePdfs.some((pdf) => pdf.id === id);
86
+ if (isAlreadyActive) {
87
+ this.activePdfs = this.activePdfs.filter((pdf) => pdf.id !== id);
88
+ } else {
89
+ const newPdf = this.pdfList.find((pdf) => pdf.id === id);
90
+ if (!newPdf) return;
91
+ if (this.activePdfs.length === 2) {
92
+ this.activePdfs = [this.activePdfs[1] as IPdfDocument, newPdf];
93
+ } else {
94
+ this.activePdfs = [...this.activePdfs, newPdf];
95
+ }
96
+ }
97
+ this.requestUpdate();
98
+ }
99
+
100
+ render() {
101
+ return html`
102
+ <div class="pdf-container">
103
+ ${
104
+ this.activePdfs.length > 0
105
+ ? this.activePdfs.map(
106
+ (pdf) =>
107
+ html`<iframe height="100%" src=${this._getPdfSrc(pdf)} frameborder="0"></iframe>`,
108
+ )
109
+ : html`
110
+ <div class="no-pdf">
111
+ <p>${translate("pdfVisor.noPdfSelected")}</p>
112
+ </div>
113
+ `
114
+ }
115
+ </div>
116
+ <pdf-selector
117
+ .pdfList=${this.pdfList}
118
+ .activePdfs=${this.activePdfs}
119
+ @pdf-removed=${(e: CustomEvent) => this._removePdf(e.detail)}
120
+ @active-pdf-changed=${(e: CustomEvent) => this._updateActivePdfs(e.detail)}
121
+ ></pdf-selector>
122
+ `;
123
+ }
124
+ }
@@ -0,0 +1,29 @@
1
+ :host {
2
+ min-height: 1px;
3
+ height: 100%;
4
+ width: 100%;
5
+ display: flex;
6
+ }
7
+
8
+ iframe {
9
+ border: none;
10
+ flex:1;
11
+ height: 100%;
12
+
13
+ }
14
+
15
+ .pdf-container {
16
+ display: flex;
17
+ justify-content: center;
18
+ align-items: center;
19
+ height: 100%;
20
+ flex: 1;
21
+ border: 1px solid #ccc;
22
+ }
23
+
24
+ .no-pdf {
25
+ text-align: center;
26
+ color: #666;
27
+ font-size: 1.2rem;
28
+ font-weight: bold;
29
+ }
@@ -0,0 +1,16 @@
1
+ function base64ToBlob(base64, type = "application/octet-stream") {
2
+ const binStr = window.atob(base64);
3
+ const len = binStr.length;
4
+ const arr = new Uint8Array(len);
5
+ for (let i = 0; i < len; i++) {
6
+ arr[i] = binStr.charCodeAt(i);
7
+ }
8
+ return new Blob([arr], { type: type });
9
+ }
10
+
11
+ export const createUrlFromBase64 = (b64: string, type?: string) => {
12
+ if (b64) {
13
+ const blob = base64ToBlob(b64, type || "application/pdf");
14
+ return URL.createObjectURL(blob);
15
+ }
16
+ };
@@ -22,19 +22,49 @@ export class PocEventsEcap extends LitElement {
22
22
 
23
23
  </form>
24
24
  <button @click=${(e) => this.goToLinkOnEcap()}>LLennçar event ecap</button>
25
- </div>`;
25
+ </div>
26
+
27
+ <form>
28
+ <label for="pdfName">PDF Name</label>
29
+ <input type="text" id="pdfName" name="pdfName" placeholder="pdfName">
30
+ <label for="url">URL</label>
31
+ <input type="text" id="url" name="url" placeholder="url">
32
+
33
+
34
+ </form>
35
+ <button @click=${(e) => this.sendPdfToViewer()}>Add PDF</button>
36
+
37
+
38
+ <button @click=${(e) => this.getPDFS()}>GET PDFs</button>
39
+ `;
26
40
  }
27
41
 
28
- goToLinkOnEcap() {
42
+ sendPdfToViewer() {
43
+ const pdfName = (this as any).shadowRoot?.getElementById("pdfName")?.value as string;
44
+ const fileName = (this as any).shadowRoot?.getElementById("url")?.value as string;
29
45
 
30
- const eventType = (this as any).shadowRoot?.getElementById("eventType")?.value;
31
- const accio = (this as any).shadowRoot?.getElementById("accio")?.value;
32
- const parameterName = (this as any).shadowRoot?.getElementById("parameterName")?.value;
33
- const parameterValue = (this as any).shadowRoot?.getElementById("parameterValue")?.value;
46
+ const data = fileName;
47
+
48
+ const pdf = { pdfName, data };
49
+ console.log("Añadiendo PDF:", pdf);
50
+
51
+ shellApi.pdfViewerManager.add(pdf);
52
+ }
53
+
54
+ getPDFS() {
55
+ const pdfs = shellApi.pdfViewerManager.getPdfs();
56
+ console.log(pdfs);
57
+ }
58
+
59
+ goToLinkOnEcap() {
60
+ const eventType = (this as any).shadowRoot?.getElementById("eventType")?.value;
61
+ const accio = (this as any).shadowRoot?.getElementById("accio")?.value;
62
+ const parameterName = (this as any).shadowRoot?.getElementById("parameterName")?.value;
63
+ const parameterValue = (this as any).shadowRoot?.getElementById("parameterValue")?.value;
34
64
 
35
65
  //sending data to parent window if opened inside iframe
36
66
  shellApi.ecapEventManager.publish(eventType, accio, {
37
- [parameterName]: parameterValue
67
+ [parameterName]: parameterValue,
38
68
  });
39
69
  }
40
70
 
package/src/api/api.ts CHANGED
@@ -22,8 +22,10 @@ import { PrimariaInteractionService } from "./interaction-service";
22
22
  import { ParimariaInteractionServiceImpl } from "./interaction-service/interaction-service-impl";
23
23
  import { PrimariaNotificationService } from "./notification-service/notification-service";
24
24
  import { PrimariaNotificationServiceImpl } from "./notification-service/notification.service-impl";
25
+ import { createPdfViewerManager, PdfViewerManager } from "./pdf-viewer-manager/pdf-viewer-manager";
25
26
 
26
27
  const broker = createBroker();
28
+
27
29
  export interface PrimariaApi extends HarmonixApi {
28
30
  httpClient: HttpClient;
29
31
  interactionService: PrimariaInteractionService;
@@ -34,6 +36,7 @@ export interface PrimariaApi extends HarmonixApi {
34
36
  tokenManager: TokenManager;
35
37
  ecapEventManager: EcapEventManager;
36
38
  pluginBusyManager: PluginBusyManager;
39
+ pdfViewerManager: PdfViewerManager;
37
40
  }
38
41
 
39
42
  const regionManager: IRegionManager = createRegionManager("primaria");
@@ -53,9 +56,11 @@ const notificationService = new PrimariaNotificationServiceImpl();
53
56
  export const primariaApiFactory: ApiFactory<PrimariaApi> = (
54
57
  pluginInfo: PluginInfo,
55
58
  ): PrimariaApi => {
59
+ const regionManagerProxy = createRegionManagerProxy(pluginInfo, regionManager, broker);
60
+
56
61
  return {
57
62
  pluginInfo: pluginInfo,
58
- regionManager: createRegionManagerProxy(pluginInfo, regionManager, broker),
63
+ regionManager: regionManagerProxy,
59
64
  httpClient: createHttpClient(tokenManager, broker),
60
65
  broker: broker,
61
66
  createLocaleManager: createLocaleManager(pluginInfo.pluginId) as any,
@@ -65,6 +70,7 @@ export const primariaApiFactory: ApiFactory<PrimariaApi> = (
65
70
  pluginBusyManager,
66
71
  interactionService,
67
72
  notificationService,
73
+ pdfViewerManager: createPdfViewerManager(broker, notificationService, regionManagerProxy),
68
74
  };
69
75
  };
70
76
 
@@ -0,0 +1,5 @@
1
+ export const pdfViwerEvents = {
2
+ added: "added_pdf",
3
+ showed: "showed_pdf",
4
+ deleted: "deleted_pdf",
5
+ };
@@ -0,0 +1,97 @@
1
+ import { translate } from "../../locales";
2
+ import { PrimariaNavItem } from "../../UI/shared-components/primaria-nav-item/primaria-nav-item";
3
+ import { PrimariaBroker } from "../broker/primaria-broker";
4
+ import { PrimariaNotificationService } from "../notification-service/notification-service";
5
+ import { shellRegions } from "../region-manager/regions";
6
+ import { pdfViwerEvents } from "./events";
7
+ import { pdfViewerId } from "../../constants";
8
+ import { PrimariaRegionManager } from "../region-manager/region-manager";
9
+ import { generateId } from "@primaria/plugins-core";
10
+
11
+ export interface IPdfDocument {
12
+ pdfName: string;
13
+ id: string;
14
+ data: PdfData;
15
+ }
16
+
17
+ export interface PdfData {
18
+ url?: string;
19
+ b64?: string;
20
+ }
21
+
22
+ export class PdfViewerManager {
23
+ constructor(
24
+ private broker: PrimariaBroker,
25
+ private notificationService: PrimariaNotificationService,
26
+ private regionManager: PrimariaRegionManager,
27
+ ) {}
28
+
29
+ private pdfs: IPdfDocument[] = [];
30
+ private activePdf: IPdfDocument | null = null;
31
+ private hasBeenActivated = false;
32
+
33
+ add(pdfName: string, data: PdfData) {
34
+ const id = generateId();
35
+ const pdf: IPdfDocument = { id, pdfName, data };
36
+
37
+ if (!data.url && !data.b64) {
38
+ this.notificationService.error(translate("pdfManager.missingData"));
39
+ return;
40
+ }
41
+ if (data.url && data.b64) {
42
+ this.notificationService.error(translate("pdfManager.duplicatedSource"));
43
+ return;
44
+ }
45
+ if (!this.hasBeenActivated) {
46
+ this.registerNavButton();
47
+ this.hasBeenActivated = true;
48
+ }
49
+ if (this.pdfs.some((p) => p.pdfName === pdf.pdfName)) {
50
+ this.notificationService.warning(translate("pdfManager.alreadyUploaded"));
51
+ } else {
52
+ this.pdfs.push(pdf as IPdfDocument);
53
+ this.broker.publish(pdfViwerEvents.added, pdf);
54
+
55
+ this.notificationService.success(translate("pdfManager.uploaded"));
56
+ }
57
+ }
58
+
59
+ delete(pdfId: string) {
60
+ this.pdfs = this.pdfs.filter((pdf) => pdf.id !== pdfId);
61
+
62
+ if (this.activePdf?.id === pdfId) {
63
+ this.activePdf = null;
64
+ }
65
+
66
+ this.broker.publish(pdfViwerEvents.deleted, { id: pdfId });
67
+ }
68
+
69
+ getPdfs(): IPdfDocument[] {
70
+ return this.pdfs;
71
+ }
72
+
73
+ private registerNavButton() {
74
+ this.regionManager.registerView(shellRegions.navigationMenu, {
75
+ id: pdfViewerId,
76
+ factory: () => {
77
+ const menuItem = new PrimariaNavItem({
78
+ icon: "picture_as_pdf",
79
+ label: translate("pdfManager.navButtonLabel"),
80
+ callbackFn: () => {
81
+ this.regionManager.activateMainView(pdfViewerId);
82
+ },
83
+ });
84
+ return Promise.resolve(menuItem);
85
+ },
86
+ });
87
+ }
88
+ }
89
+
90
+ const pdfViewerManager = (broker, interactionManager, regionManager) =>
91
+ new PdfViewerManager(broker, interactionManager, regionManager);
92
+
93
+ export const createPdfViewerManager = (
94
+ broker: PrimariaBroker,
95
+ notificationService: PrimariaNotificationService,
96
+ regionManager: PrimariaRegionManager,
97
+ ) => pdfViewerManager(broker, notificationService, regionManager);
package/src/constants.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export const primariaShellId = "primaria-shell";
2
2
  export const clinicalMonitoringId = "clinical-monitoring";
3
3
  export const pocTestEventsId = "poc-events-ecap";
4
+ export const pdfViewerId = "pdf-viewer";