Fix for symbol dialog

This commit is contained in:
piotrpekala7 2021-05-14 13:01:41 +02:00
parent c8f1a4d428
commit ca7b43a5c2
3 changed files with 12 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
import { Server } from '../../../../models/server';
import { Symbol } from '../../../../models/symbol';
import { SymbolService } from '../../../../services/symbol.service';
@ -18,7 +19,7 @@ export class SymbolsComponent implements OnInit {
isSelected: string = '';
searchText: string = '';
constructor(private symbolService: SymbolService) {}
constructor(private symbolService: SymbolService, private domSanitizer: DomSanitizer) {}
ngOnInit() {
this.isSelected = this.symbol;
@ -76,6 +77,11 @@ export class SymbolsComponent implements OnInit {
width=\"${imageToUpload.width}\">\n<image height=\"${imageToUpload.height}\" width=\"${imageToUpload.width}\" xlink:href=\"${image}\"/>\n</svg>`;
}
getImage(symbolFilename: string) {
let symbol = this.symbolService.get(symbolFilename);
return this.domSanitizer.bypassSecurityTrustUrl(`data:image/svg+xml;base64,${btoa(symbol.raw)}`);
}
getImageSourceForTemplate(symbol: string) {
return `${this.server.protocol}//${this.server.host}:${this.server.port}/v3/symbols/${symbol}/raw`;
}

View File

@ -2,6 +2,7 @@ import { Pipe, PipeTransform } from '@angular/core';
import { Console } from 'console';
import { Server } from '../models/server';
import { HttpServer } from '../services/http-server.service';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({
name: 'authImage'
@ -9,7 +10,8 @@ import { HttpServer } from '../services/http-server.service';
export class AuthImageFilter implements PipeTransform {
constructor(
private httpServer: HttpServer
private httpServer: HttpServer,
private domSanitizer: DomSanitizer
) {}
async transform(src: string, server: Server) {
@ -17,7 +19,7 @@ export class AuthImageFilter implements PipeTransform {
const imageBlob: Blob = await this.httpServer.getBlob(server, url).toPromise();
const reader = new FileReader();
return new Promise((resolve, reject) => {
reader.onloadend = () => resolve(reader.result as string);
reader.onloadend = () => resolve(this.domSanitizer.bypassSecurityTrustUrl(reader.result as string));
reader.readAsDataURL(imageBlob);
});
}