mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2024-12-19 13:07:52 +00:00
Importing symbols added
This commit is contained in:
parent
a879aab519
commit
2fe8cc72aa
@ -1,4 +1,21 @@
|
||||
<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/>
|
||||
<div class="wrapper">
|
||||
<div class="buttonWrapper" *ngFor="let symbol of symbols | filenamefilter: searchText">
|
||||
|
@ -8,6 +8,11 @@
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.menu {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.button {
|
||||
background: border-box;
|
||||
border-width: 0px;
|
||||
@ -36,3 +41,15 @@
|
||||
grid-row-gap: 3em;
|
||||
grid-column-gap: 1em;
|
||||
}
|
||||
|
||||
.radio-selection {
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
.mat-radio-button ~ .mat-radio-button {
|
||||
margin-left: 16px;
|
||||
}
|
||||
|
||||
.non-visible {
|
||||
display: none;
|
||||
}
|
||||
|
@ -24,14 +24,44 @@ export class SymbolsComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
this.isSelected = this.symbol;
|
||||
|
||||
this.symbolService.list(this.server).subscribe((symbols: Symbol[]) => {
|
||||
this.symbols = symbols;
|
||||
});
|
||||
this.loadSymbols();
|
||||
}
|
||||
|
||||
setSelected(symbol_id: string) {
|
||||
this.isSelected = symbol_id;
|
||||
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>`
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,10 @@ export class SymbolService {
|
||||
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[]> {
|
||||
const subscription = this.list(server).subscribe((symbols: Symbol[]) => {
|
||||
const streams = symbols.map(symbol => this.raw(server, symbol.symbol_id));
|
||||
|
Loading…
Reference in New Issue
Block a user