Commit e6a75e46 authored by Janik Münzenberger's avatar Janik Münzenberger
Browse files

Preselect plant

parent 3f59154c
......@@ -6,12 +6,12 @@
<form #analysisForm="ngForm" class="row col-md-6 col-sm-12 mx-auto justify-content-center flex-column" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="crop_id">{{"ANALYSIS.SELECT_A_CROP" | translate}}</label>
<select id="crop_id" name="crop_id" class="custom-select mb-3" ngModel>
<option *ngFor="let plant of plants" [value]="plant._id">{{plant.name}}</option>
<select id="crop_id" name="crop_id" class="custom-select mb-3" [(ngModel)]="selected">
<option *ngFor="let plant of plants" [value]="plant._id" >{{plant.name}}</option>
</select>
</div>
<div class="custom-file mb-3">
<input type='file' (change)="onSelectFile($event)" accept="image/*" class="inputfile col-md-3" id="image_file" name="image_file"
<input autocomplete="photo" type='file' (change)="onSelectFile($event)" accept="image/*" class="inputfile col-md-3" id="image_file" name="image_file"
#image ngModel>
<label class="custom-file-label" for="image_file">{{"ANALYSIS.SELECT_IMAGE" | translate}}</label>
</div>
......@@ -21,7 +21,7 @@
<div *ngIf="showImage == true" class="form-group mt-2">
<label for="notification_email" class="col-form-label">{{"ANALYSIS.TO_EMAIL" | translate}}:</label>
<input type="email" id="notification_email" name="notification_email" class="form-control" [(ngModel)]="notification_email">
<input type="email" autocomplete="email" id="notification_email" name="notification_email" class="form-control" [(ngModel)]="notification_email">
</div>
<div *ngIf="showImage == true" class="mt-3 mx-auto">
<button type="button" type="submit" class="btn btn-primary btn-lg">{{"ANALYSIS.ANALYSE" | translate}}</button>
......
......@@ -3,7 +3,7 @@ import { PlantService } from '../../services/plant.service';
import { IPlant } from '../../model/IPlant';
import { FormGroup, FormControl, Validators, NgForm } from '@angular/forms';
import { AnalysisService } from '../../services/analysis.service';
import { Router } from '@angular/router';
import { Router, ActivatedRoute } from '@angular/router';
import { AuthService } from '../../services/auth.service';
import { UserService } from '../../services/user.service';
......@@ -19,6 +19,8 @@ export class AnalyseComponent implements OnInit {
notification_email: string = "";
plants: IPlant[] = [];
selected: number;
@ViewChild(NgForm) analysisForm:NgForm;
@ViewChild('image') image;
@ViewChild('loader') loader;
......@@ -26,7 +28,8 @@ export class AnalyseComponent implements OnInit {
constructor(private pService: PlantService,
private aService: AnalysisService,
public userService: UserService,
private router: Router) {
private router: Router,
private route: ActivatedRoute) {
}
......@@ -37,7 +40,14 @@ export class AnalyseComponent implements OnInit {
}
getPlants(){
this.pService.getAllPlants().then(plants => this.plants = plants);
this.pService.getAllPlants().then(plants => {
this.plants = plants;
this.route.queryParams.subscribe(params => {
let preselect = params["plant"];
if(preselect) this.selected = +preselect;
else this.selected = plants[0]._id;
})
});
}
......@@ -46,11 +56,11 @@ export class AnalyseComponent implements OnInit {
onSubmit(){
let element = this.image.nativeElement;
if(element.files && element.files[0]){
if(this.selected && element.files && element.files[0]){
this.startAnalysis();
const formData = new FormData();
formData.append('image_file', element.files[0]);
formData.append('crop_id', this.analysisForm.value.crop_id);
formData.append('crop_id', this.selected.toString());
formData.append('notification_email', this.notification_email);
this.aService.startAnalysis(formData)
.then(res => {
......@@ -78,4 +88,5 @@ export class AnalyseComponent implements OnInit {
}
}
}
......@@ -37,6 +37,6 @@ export class PlantdetailsComponent implements OnInit, OnDestroy {
}
onShowAnalyse() {
this.router.navigate(['/result']);
this.router.navigate(['/analyse'], {queryParams: {plant: this.plant._id}});
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment