Importing symbols added

This commit is contained in:
Piotr Pekala 2019-09-03 08:22:55 -07:00
parent a879aab519
commit 2fe8cc72aa
4 changed files with 72 additions and 4 deletions

View File

@ -1,4 +1,21 @@
<mat-card> <mat-card>
<div class="menu">
<mat-radio-group aria-label="Select an option" class="radio-selection">
<mat-radio-button value="1">All symbols</mat-radio-button>
<mat-radio-button value="2">Built-in symbols</mat-radio-button>
<mat-radio-button value="2">Custom symbols</mat-radio-button>
</mat-radio-group>
<input
type="file"
accept=".svg, .bmp, .jpeg, .jpg, .gif, .png"
class="non-visible"
#file
(change)="uploadSymbolFile($event)"/>
<button mat-button (click)="file.click()">
<mat-icon>add</mat-icon>
Add symbol
</button>
</div><br/><br/>
<input matInput type="text" [(ngModel)]="searchText" placeholder="Search by filename"><br/><br/> <input matInput type="text" [(ngModel)]="searchText" placeholder="Search by filename"><br/><br/>
<div class="wrapper"> <div class="wrapper">
<div class="buttonWrapper" *ngFor="let symbol of symbols | filenamefilter: searchText"> <div class="buttonWrapper" *ngFor="let symbol of symbols | filenamefilter: searchText">

View File

@ -8,6 +8,11 @@
outline: none; outline: none;
} }
.menu {
display: flex;
justify-content: space-between;
}
.button { .button {
background: border-box; background: border-box;
border-width: 0px; border-width: 0px;
@ -36,3 +41,15 @@
grid-row-gap: 3em; grid-row-gap: 3em;
grid-column-gap: 1em; grid-column-gap: 1em;
} }
.radio-selection {
width: 90%;
}
.mat-radio-button ~ .mat-radio-button {
margin-left: 16px;
}
.non-visible {
display: none;
}

View File

@ -24,14 +24,44 @@ export class SymbolsComponent implements OnInit {
ngOnInit() { ngOnInit() {
this.isSelected = this.symbol; this.isSelected = this.symbol;
this.loadSymbols();
this.symbolService.list(this.server).subscribe((symbols: Symbol[]) => {
this.symbols = symbols;
});
} }
setSelected(symbol_id: string) { setSelected(symbol_id: string) {
this.isSelected = symbol_id; this.isSelected = symbol_id;
this.symbolChanged.emit(this.isSelected); this.symbolChanged.emit(this.isSelected);
} }
loadSymbols() {
this.symbolService.list(this.server).subscribe((symbols: Symbol[]) => {
this.symbols = symbols;
});
}
public uploadSymbolFile(event) {
this.readSymbolFile(event.target);
}
private readSymbolFile(symbolInput) {
let file: File = symbolInput.files[0];
let fileName = symbolInput.files[0].name;
let fileReader: FileReader = new FileReader();
let imageToUpload = new Image();
fileReader.onloadend = () => {
let image = fileReader.result;
let svg = this.createSvgFileForImage(image, imageToUpload);
this.symbolService.add(this.server, fileName, svg).subscribe(() => {
this.loadSymbols();
});
}
imageToUpload.onload = () => { fileReader.readAsDataURL(file) };
imageToUpload.src = window.URL.createObjectURL(file);
}
private createSvgFileForImage(image: string|ArrayBuffer, imageToUpload: HTMLImageElement) {
return `<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" height=\"${imageToUpload.height}\"
width=\"${imageToUpload.width}\">\n<image height=\"${imageToUpload.height}\" width=\"${imageToUpload.width}\" xlink:href=\"${image}\"/>\n</svg>`
}
} }

View File

@ -15,6 +15,10 @@ export class SymbolService {
return this.symbols.getValue().find((symbol: Symbol) => symbol.symbol_id === symbol_id); return this.symbols.getValue().find((symbol: Symbol) => symbol.symbol_id === symbol_id);
} }
add(server: Server, symbolName: string, symbol: string) {
return this.httpServer.post(server, `/symbols/${symbolName}/raw`, symbol)
}
load(server: Server): Observable<Symbol[]> { load(server: Server): Observable<Symbol[]> {
const subscription = this.list(server).subscribe((symbols: Symbol[]) => { const subscription = this.list(server).subscribe((symbols: Symbol[]) => {
const streams = symbols.map(symbol => this.raw(server, symbol.symbol_id)); const streams = symbols.map(symbol => this.raw(server, symbol.symbol_id));