oip-common 0.0.38 → 0.1.2

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.
@@ -1,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, inject, signal, computed, effect, ChangeDetectorRef, Component, Input, PLATFORM_ID, InjectionToken, HostBinding, EventEmitter, Output, ViewChild, Renderer2, SecurityContext, ChangeDetectionStrategy, Pipe } from '@angular/core';
2
+ import { Injectable, inject, InjectionToken, signal, computed, effect, ChangeDetectorRef, Component, Input, PLATFORM_ID, HostBinding, EventEmitter, Output, ViewChild, Renderer2, SecurityContext, ChangeDetectionStrategy, Pipe } from '@angular/core';
3
3
  import * as i2$6 from 'primeng/api';
4
4
  import { MessageService, ConfirmationService, PrimeIcons, SharedModule } from 'primeng/api';
5
5
  import { HttpErrorResponse, HttpClient as HttpClient$1, HttpHeaders } from '@angular/common/http';
@@ -197,6 +197,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
197
197
  args: [{ providedIn: 'root' }]
198
198
  }] });
199
199
 
200
+ const DEFAULT_OIP_FRONTEND_CONFIG = {
201
+ appMode: 'standalone',
202
+ apiBaseUrl: '',
203
+ notificationHubUrl: ''
204
+ };
205
+ const OIP_FRONTEND_CONFIG = new InjectionToken('OIP_FRONTEND_CONFIG', {
206
+ factory: () => DEFAULT_OIP_FRONTEND_CONFIG
207
+ });
208
+
200
209
  /**
201
210
  * BaseDataService provides a unified interface for sending HTTP requests
202
211
  * using Angular's HttpClient. It supports standard HTTP methods and automatic
@@ -205,12 +214,20 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.16", ngImpo
205
214
  class BaseDataService {
206
215
  constructor() {
207
216
  this.http = inject(HttpClient$1);
217
+ this.frontendConfig = inject(OIP_FRONTEND_CONFIG);
208
218
  }
209
219
  /**
210
220
  * Gets the base URL of the application from the HTML <base> tag.
211
221
  */
212
222
  get baseUrl() {
213
- return document.getElementsByTagName('base')[0].href;
223
+ return this.normalizeBaseUrl(this.frontendConfig.apiBaseUrl || document.getElementsByTagName('base')[0].href);
224
+ }
225
+ /**
226
+ * Builds a fully-qualified application URL based on frontend mode.
227
+ */
228
+ buildUrl(path) {
229
+ const normalizedPath = path.startsWith('/') ? path.substring(1) : path;
230
+ return `${this.baseUrl}${normalizedPath}`;
214
231
  }
215
232
  /**
216
233
  * Sends an HTTP request with the specified method and data.
@@ -258,6 +275,9 @@ class BaseDataService {
258
275
  const result = this.http.get(url, httpOptions);
259
276
  return lastValueFrom(result);
260
277
  }
278
+ normalizeBaseUrl(baseUrl) {
279
+ return baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`;
280
+ }
261
281
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: BaseDataService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
262
282
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: BaseDataService }); }
263
283
  }
@@ -1550,23 +1570,31 @@ class UserService {
1550
1570
  */
1551
1571
  get shortLabel() {
1552
1572
  const data = this.securityService.getCurrentUser();
1553
- return data ? data.given_name[0].toUpperCase() + data.family_name[0].toUpperCase() : '';
1573
+ const givenNameInitial = data?.given_name?.trim()?.[0];
1574
+ const familyNameInitial = data?.family_name?.trim()?.[0];
1575
+ return `${givenNameInitial ?? ''}${familyNameInitial ?? ''}`.toUpperCase();
1554
1576
  }
1555
1577
  get userName() {
1556
1578
  const data = this.securityService.getCurrentUser();
1557
- return `${data.given_name} ${data.family_name}`;
1579
+ return [data?.given_name, data?.family_name].filter(Boolean).join(' ');
1558
1580
  }
1559
1581
  /**
1560
1582
  * Initiates an HTTP request to fetch the user's photo based on their email,
1561
1583
  * and updates the `photo` and `photoLoaded` properties accordingly.
1562
1584
  */
1563
1585
  getUserPhoto() {
1564
- const url = `${this.baseDataService.baseUrl}api/user-profile/get-user-photo?email=${this.securityService.getCurrentUser().email}`;
1586
+ const email = this.securityService.getCurrentUser()?.email;
1587
+ if (!email) {
1588
+ this.photoLoaded = true;
1589
+ return;
1590
+ }
1591
+ const url = this.baseDataService.buildUrl(`api/user-profile/get-user-photo?email=${email}`);
1565
1592
  this.baseDataService.getBlob(url).then((data) => {
1566
1593
  this.createImageFromBlob(data);
1567
1594
  this.photoLoaded = true;
1568
1595
  }, (error) => {
1569
1596
  console.log(error);
1597
+ this.photoLoaded = false;
1570
1598
  });
1571
1599
  }
1572
1600
  /**
@@ -5896,6 +5924,7 @@ class NotificationService {
5896
5924
  constructor() {
5897
5925
  this.securityService = inject(SecurityService);
5898
5926
  this.msgService = inject(MsgService);
5927
+ this.frontendConfig = inject(OIP_FRONTEND_CONFIG);
5899
5928
  this.securityService.getAccessToken().subscribe((token) => {
5900
5929
  this.securityData = token;
5901
5930
  if (token) {
@@ -5905,7 +5934,7 @@ class NotificationService {
5905
5934
  }
5906
5935
  });
5907
5936
  this.connection = new signalR.HubConnectionBuilder()
5908
- .withUrl('/hubs/notification', {
5937
+ .withUrl(this.resolveHubUrl(), {
5909
5938
  accessTokenFactory: () => this.securityData,
5910
5939
  skipNegotiation: true,
5911
5940
  transport: signalR.HttpTransportType.WebSockets
@@ -5922,6 +5951,15 @@ class NotificationService {
5922
5951
  this.msgService.add(opt);
5923
5952
  });
5924
5953
  }
5954
+ resolveHubUrl() {
5955
+ if (this.frontendConfig.notificationHubUrl) {
5956
+ return this.frontendConfig.notificationHubUrl;
5957
+ }
5958
+ if (this.frontendConfig.apiBaseUrl) {
5959
+ return `${this.frontendConfig.apiBaseUrl.replace(/\/$/, '')}/hubs/notification`;
5960
+ }
5961
+ return '/hubs/notification';
5962
+ }
5925
5963
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: NotificationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
5926
5964
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.16", ngImport: i0, type: NotificationService, providedIn: 'root' }); }
5927
5965
  }
@@ -6060,5 +6098,5 @@ const httpLoaderAuthFactory = (httpClient) => {
6060
6098
  * Generated bundle index. Do not edit.
6061
6099
  */
6062
6100
 
6063
- export { AppConfiguratorComponent, AppFloatingConfiguratorComponent, AppLayoutComponent, AppModulesComponent, AppTopbar, AuthGuardService, BaseDataService, BaseModuleComponent, ConfigComponent, ContentType, DbMigrationComponent, DiscussionComponent, ErrorComponent, FooterComponent, HttpClient, KeycloakSecurityService, L10nService, LOGO_COMPONENT_TOKEN, LayoutService, LogoComponent, LogoService, MenuComponent, MenuService, MsgService, NotfoundComponent, NotificationService, ProfileComponent, SecurePipe, SecurityComponent, SecurityDataService, SecurityService, SecurityStorageService, SidebarComponent, TableFilterService, TopBarService, UnauthorizedComponent, UserService, httpLoaderAuthFactory, langIntercept, provideLogoComponent };
6101
+ export { AppConfiguratorComponent, AppFloatingConfiguratorComponent, AppLayoutComponent, AppModulesComponent, AppTopbar, AuthGuardService, BaseDataService, BaseModuleComponent, ConfigComponent, ContentType, DEFAULT_OIP_FRONTEND_CONFIG, DbMigrationComponent, DiscussionComponent, ErrorComponent, FooterComponent, HttpClient, KeycloakSecurityService, L10nService, LOGO_COMPONENT_TOKEN, LayoutService, LogoComponent, LogoService, MenuComponent, MenuService, MsgService, NotfoundComponent, NotificationService, OIP_FRONTEND_CONFIG, ProfileComponent, SecurePipe, SecurityComponent, SecurityDataService, SecurityService, SecurityStorageService, SidebarComponent, TableFilterService, TopBarService, UnauthorizedComponent, UserService, httpLoaderAuthFactory, langIntercept, provideLogoComponent };
6064
6102
  //# sourceMappingURL=oip-common.mjs.map