Skip to content

Commit

Permalink
fix: ocxSrc directive with external image url, ocx slots (#206)
Browse files Browse the repository at this point in the history
Co-authored-by: kim.tran <[email protected]>
  • Loading branch information
KimFFVII and kim.tran authored Apr 5, 2024
1 parent 70e9243 commit 562be36
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 24 deletions.
33 changes: 21 additions & 12 deletions libs/angular-accelerator/src/lib/directives/src.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ export class SrcDirective {
}
set ocxSrc(value: string | undefined) {
if (value && this._src !== value) {
this.httpClient.get(value, { responseType: 'blob' }).subscribe({
next: (blob) => {
const url = URL.createObjectURL(blob)
this.el.nativeElement.onload = () => {
URL.revokeObjectURL(url)
}
this.el.nativeElement.src = url
},
error: () => {
this.el.nativeElement.src = 'error'
},
})
try {
if (new URL(value, window.location.origin).origin === window.location.origin) {
this.httpClient.get(value, { responseType: 'blob' }).subscribe({
next: (blob) => {
const url = URL.createObjectURL(blob)
this.el.nativeElement.onload = () => {
URL.revokeObjectURL(url)
}
this.el.nativeElement.src = url
},
error: () => {
this.el.nativeElement.src = 'error'
},
})
} else {
this.el.nativeElement.src = value
}
} catch (error) {
console.log('Cannot parse URL ', value, error)
this.el.nativeElement.src = value
}
this._src = value
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Location } from '@angular/common'
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { Config } from '@onecx/integration-interface'
Expand All @@ -11,7 +12,9 @@ export class AppConfigService {

public init(baseUrl: string): Promise<void> {
return new Promise((resolve, reject) => {
const loadConfigPromise: Promise<Config> = firstValueFrom(this.http.get<Config>(baseUrl + 'assets/env.json'))
const loadConfigPromise: Promise<Config> = firstValueFrom(
this.http.get<Config>(Location.joinWithSlash(baseUrl, 'assets/env.json'))
)

loadConfigPromise
.then(async (config) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<ng-content></ng-content>
</div>
<div class="layout-topbar-actions-right">
<ocx-slot name="headerRight" class="layout-topbar-items"></ocx-slot>
<ul class="layout-topbar-items">
<!-- Only desktop: Actions (favorites, support, search, ...) as icon buttons -->
<ng-container *ocxIfBreakpoint="'desktop'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@
[menuButtonTitle]="menuButtonTitle"
(menuButtonClick)="onMenuButtonClick($event)"
>
<div class="horizontal">
<ocx-slot name="menu" *ngIf="isHorizontalMenuVisible()">Horizontal Menu</ocx-slot>
</div>
<ocx-slot name="horizontalMenu" *ngIf="isHorizontalMenuVisible()"></ocx-slot>

</ocx-shell-header>

<p-toast></p-toast>

<div class="menu-wrapper">
<div class="layout-menu-container" *ngIf="isStaticalMenuVisible()">
<ocx-slot name="menu">Vertical Menu</ocx-slot>
<ocx-slot name="menu"></ocx-slot>
</div>
</div>

<div class="layout-main">
<div class="layout-content relative">
<ocx-slot name="AnnouncementBanner">Announcement Banner</ocx-slot>
<ocx-slot name="subHeader"></ocx-slot>

<ng-content></ng-content>
<router-outlet></router-outlet>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
.horizontal {
display: flex;
flex-direction: row;
justify-content: flex-end;
align-items: center;
}

0 comments on commit 562be36

Please sign in to comment.