Browse Source

Merge pull request #4744 from vvlladd28/bug/dashboard-logo/safe-url

UI: Add dashboard logo sanitizer url; Added dashboard logo cache
pull/4772/head
Igor Kulikov 5 years ago
committed by GitHub
parent
commit
9f58341ee1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts

19
ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts

@ -128,6 +128,7 @@ import {
DashboardImageDialogComponent,
DashboardImageDialogData, DashboardImageDialogResult
} from '@home/components/dashboard-page/dashboard-image-dialog.component';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
// @dynamic
@Component({
@ -211,7 +212,8 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
addingLayoutCtx: DashboardPageLayoutContext;
logo = 'assets/logo_title_white.svg';
private dashboardLogoCache: SafeUrl;
private defaultDashboardLogo = 'assets/logo_title_white.svg';
dashboardCtx: DashboardContext = {
instanceId: this.utils.guid(),
@ -312,7 +314,8 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
private ngZone: NgZone,
private overlay: Overlay,
private viewContainerRef: ViewContainerRef,
private cd: ChangeDetectorRef) {
private cd: ChangeDetectorRef,
private sanitizer: DomSanitizer) {
super(store);
}
@ -413,6 +416,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
private reset() {
this.dashboard = null;
this.dashboardConfiguration = null;
this.dashboardLogoCache = undefined;
this.prevDashboard = null;
this.widgetEditMode = false;
@ -570,8 +574,12 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
}
}
public get dashboardLogo(): string {
return this.dashboard.configuration.settings.dashboardLogoUrl || this.logo;
public get dashboardLogo(): SafeUrl {
if (!this.dashboardLogoCache) {
const logo = this.dashboard.configuration.settings.dashboardLogoUrl || this.defaultDashboardLogo;
this.dashboardLogoCache = this.sanitizer.bypassSecurityTrustUrl(logo);
}
return this.dashboardLogoCache;
}
public showRightLayoutSwitch(): boolean {
@ -702,6 +710,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
}).afterClosed().subscribe((data) => {
if (data) {
this.dashboard.configuration.settings = data.settings;
this.dashboardLogoCache = undefined;
const newGridSettings = data.gridSettings;
if (newGridSettings) {
const layout = this.dashboard.configuration.states[layoutKeys.state].layouts[layoutKeys.layout];
@ -855,11 +864,13 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
if (this.widgetEditMode) {
if (revert) {
this.dashboard = this.prevDashboard;
this.dashboardLogoCache = undefined;
}
} else {
this.resetHighlight();
if (revert) {
this.dashboard = this.prevDashboard;
this.dashboardLogoCache = undefined;
this.dashboardConfiguration = this.dashboard.configuration;
this.dashboardCtx.dashboardTimewindow = this.dashboardConfiguration.timewindow;
this.entityAliasesUpdated();

Loading…
Cancel
Save