Skip to content

Commit

Permalink
Add option to use a models pointlabels
Browse files Browse the repository at this point in the history
  • Loading branch information
haneslinger committed Sep 23, 2024
1 parent 54fe368 commit d845f47
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 6 deletions.
3 changes: 2 additions & 1 deletion buildingmotif-app/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {MatDialogModule} from '@angular/material/dialog';
import {MatStepperModule} from '@angular/material/stepper';
import { ShapeValidationComponent } from './shape-validation/shape-validation.component';
import {MatExpansionModule} from '@angular/material/expansion';
import { PointlabelParserComponent } from './pointlabel-parser/pointlabel-parser.component';
import { PointlabelParserComponent, DialogOverviewExampleDialog } from './pointlabel-parser/pointlabel-parser.component';
import {MatGridListModule} from '@angular/material/grid-list';

@NgModule({
Expand All @@ -59,6 +59,7 @@ import {MatGridListModule} from '@angular/material/grid-list';
ModelValidateComponent,
ShapeValidationComponent,
PointlabelParserComponent,
DialogOverviewExampleDialog,
],
imports: [
BrowserModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div mat-dialog-content>
<mat-form-field appearance="fill">
<mat-label>Models</mat-label>
<mat-select [(ngModel)]="data.selectedModelId">
<mat-option *ngFor="let model of models" [value]="model.id">
{{model.name}}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<div mat-dialog-actions>
<button mat-button (click)="onNoClick()">No Thanks</button>
<button mat-button [mat-dialog-close]="data.selectedModelId" cdkFocusInitial>Ok</button>
</div>
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<div class="container">
<div class="pointlabels">
<button mat-raised-button color="primary" (click)="openDialog()">Pick one</button>

<!-- Unparsed -->
<ngx-codemirror #codemirror [options]="codeMirrorOptions"
[formControl]="pointLabelsFormControl"></ngx-codemirror>
<ngx-codemirror #codemirror [options]="codeMirrorOptions" [formControl]="pointLabelsFormControl"></ngx-codemirror>
<button mat-raised-button color="primary" (click)="parse()">Parse</button>

<!-- Parsed -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, Inject } from '@angular/core';
import { FormControl } from '@angular/forms';
import { PointlabelParserService } from './pointlabel-parser.service'
import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { ModelSearchService } from '../model-search/model-search.service';
import { Model } from '../types';

export interface Token {
error?: string;
Expand Down Expand Up @@ -46,7 +49,7 @@ export class PointlabelParserComponent implements OnInit {
lint: true
};

constructor(private PointlabelParserService: PointlabelParserService,) {
constructor(private PointlabelParserService: PointlabelParserService, public dialog: MatDialog) {
}

ngOnInit(): void {
Expand All @@ -69,7 +72,7 @@ export class PointlabelParserComponent implements OnInit {
let fileReader = new FileReader();
fileReader.onload = (e: any) => {
// read file
const abbs: {s: string, type_name: string}[] = e.target.result.split(/\r?\n/).map((row: string) => {
const abbs: { s: string, type_name: string }[] = e.target.result.split(/\r?\n/).map((row: string) => {
const items = row.split(",")
return { s: items[0], type_name: items[1] }
})
Expand Down Expand Up @@ -102,6 +105,27 @@ export class PointlabelParserComponent implements OnInit {

}

openDialog(): void {
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
width: '250px',
data: { selectedModelId: null },
});

dialogRef.afterClosed().subscribe(result => {
if (result !== null && result !== undefined) {
this.PointlabelParserService.getPointNames(
result
)
.subscribe({
next: (data: string[]) => {
this.pointLabelsFormControl.setValue(JSON.stringify(data))
}, // success path
error: (error) => {
}, // error path
});
}
});
}

onHover(token: Token) {
this.workspace.highlightBlock(token.id)
Expand Down Expand Up @@ -159,3 +183,37 @@ export class PointlabelParserComponent implements OnInit {
}

}

export interface DialogData {
selectedModelId?: number;
}

@Component({
selector: 'dialog-overview-example-dialog',
templateUrl: 'dialog-overview-example-dialog.html',
providers: [ModelSearchService],
})
export class DialogOverviewExampleDialog implements OnInit {
models: Model[] = [];
constructor(
public dialogRef: MatDialogRef<DialogOverviewExampleDialog>,
@Inject(MAT_DIALOG_DATA) public data: DialogData,
private modelSearchService: ModelSearchService,
) { }

ngOnInit() {
this.modelSearchService.getAllModels()
.subscribe({
next: (data: Model[]) => this.models = data, // success path
error: (error) => { } // error path
});
}

onClick(): void {
this.dialogRef.close();
}

onNoClick(): void {
this.dialogRef.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export class PointlabelParserService {
);
}

getPointNames(id: number) {
return this.http.get<string[]>(`http://localhost:5000/models/${id}/point_names`)
.pipe(
retry(3), // retry a failed request up to 3 times
catchError(this.handleError) // then handle the error
);
}

private handleError(error: HttpErrorResponse) {
if (error.status === 0) {
// A client-side or network error occurred. Handle it accordingly.
Expand Down

0 comments on commit d845f47

Please sign in to comment.