Skip to content

Commit

Permalink
fix: make navigation work
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed May 5, 2024
1 parent f708fe2 commit 0215aa9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1 i18n="@@imagequeryHeading">Image description</h1>
<button
mat-flat-button
color="primary"
[disabled]="!imageForm.controls.file || uploading"
[disabled]="uploading"
(click)="upload()"
i18n="@@upload"
>
Expand Down
20 changes: 12 additions & 8 deletions frontend/src/angular/src/app/image-query/image-query.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { tap } from 'rxjs';
import { ImageService } from '../service/image.service';
import { ImageFile } from '../model/image-file';
import { FormControl, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms';
import { Router } from '@angular/router';

@Component({
selector: 'app-image-query',
Expand All @@ -36,7 +37,7 @@ export class ImageQueryComponent {
protected uploading = false;
protected result: ImageFile | null = null;

constructor(private imageService: ImageService, private destroyRef: DestroyRef) { }
constructor(private imageService: ImageService, private destroyRef: DestroyRef, private router: Router) { }

protected onFileInputChange($event: Event): void {
this.result = null;
Expand All @@ -52,17 +53,17 @@ export class ImageQueryComponent {

protected upload(): void {
//console.log(this.file);
if (!!this.imageForm.controls.file) {
if (!!this.imageForm.controls.file.value) {
this.result = null;
this.uploading = true;
const formData = new FormData();
const myFile = this.imageForm.controls.file.value;
formData.append('file', myFile as Blob, myFile?.name as string);
formData.append('query', this.imageForm.controls.query.value as unknown as string);
formData.append('type', (this.imageForm.controls.file.value as unknown as File)?.type);
console.log(formData);
console.log(this.imageForm.controls.file.value);
console.log(this.imageForm.controls.query.value);
//console.log(formData);
//console.log(this.imageForm.controls.file.value);
//console.log(this.imageForm.controls.query.value);
this.imageService
.postImageForm(formData)
.pipe(
Expand All @@ -74,12 +75,15 @@ export class ImageQueryComponent {
.subscribe((result) => {
this.uploading = false;
this.result = result;
console.log(result);
this.imageForm.controls.file.setValue(null);
//console.log(result);
});
}
} else if(!this.uploading && !!this.result) {
this.result = null;
}
}

protected cancel(): void {
console.log('cancel');
this.router.navigate(['/']);
}
}

0 comments on commit 0215aa9

Please sign in to comment.