diff --git a/Back/skydiveLogs-api.Business/JumpService.cs b/Back/skydiveLogs-api.Business/JumpService.cs index 91322f2..01d8b82 100644 --- a/Back/skydiveLogs-api.Business/JumpService.cs +++ b/Back/skydiveLogs-api.Business/JumpService.cs @@ -39,7 +39,7 @@ namespace skydiveLogs_api.Business jump.JumpType = selectedJumpType; jump.DropZone = selectedDropZone; jump.Gear = selectedGear; - jump.UserId = connectedUser.Id; + jump.User = connectedUser; _jumpRepository.Add(jump); } @@ -51,7 +51,7 @@ namespace skydiveLogs_api.Business public IEnumerable GetAllJumps(User connectedUser) { - return _jumpRepository.GetAll(connectedUser.Id); + return _jumpRepository.GetAll(connectedUser); } public Jump GetJumpById(int id) diff --git a/Back/skydiveLogs-api.Data/ImageRepository.cs b/Back/skydiveLogs-api.Data/ImageRepository.cs index 903afd9..3c6fcee 100644 --- a/Back/skydiveLogs-api.Data/ImageRepository.cs +++ b/Back/skydiveLogs-api.Data/ImageRepository.cs @@ -19,7 +19,15 @@ namespace skydiveLogs_api.Data public IEnumerable GetAll() { - return _col.FindAll().ToList(); + throw new System.NotImplementedException(); + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.User) + .Query() + .Where(j => j.User == user) + .ToList(); } public Image GetById(int id) diff --git a/Back/skydiveLogs-api.Data/Interface/IImageRepository.cs b/Back/skydiveLogs-api.Data/Interface/IImageRepository.cs index 141bc2f..b0d275c 100644 --- a/Back/skydiveLogs-api.Data/Interface/IImageRepository.cs +++ b/Back/skydiveLogs-api.Data/Interface/IImageRepository.cs @@ -1,9 +1,11 @@ -using skydiveLogs_api.Model; +using System.Collections.Generic; +using skydiveLogs_api.Model; namespace skydiveLogs_api.Data.Interface { public interface IImageRepository : IRepository { + IEnumerable GetAll(User user); } } diff --git a/Back/skydiveLogs-api.Data/Interface/IJumpRepository.cs b/Back/skydiveLogs-api.Data/Interface/IJumpRepository.cs index 8ed49ab..e3ecd8e 100644 --- a/Back/skydiveLogs-api.Data/Interface/IJumpRepository.cs +++ b/Back/skydiveLogs-api.Data/Interface/IJumpRepository.cs @@ -5,7 +5,7 @@ namespace skydiveLogs_api.Data.Interface { public interface IJumpRepository : IRepository { - IEnumerable GetAll(int userId); + IEnumerable GetAll(User user); } } diff --git a/Back/skydiveLogs-api.Data/JumpRepository.cs b/Back/skydiveLogs-api.Data/JumpRepository.cs index c0c4447..1ae7c6e 100644 --- a/Back/skydiveLogs-api.Data/JumpRepository.cs +++ b/Back/skydiveLogs-api.Data/JumpRepository.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Linq; using LiteDB; @@ -17,14 +16,15 @@ namespace skydiveLogs_api.Data _col = _dataProvider.CollOfJump; } - public IEnumerable GetAll(int userId) + public IEnumerable GetAll(User user) { return _col.Include(x => x.Aircraft) .Include(x => x.DropZone) .Include(x => x.Gear) .Include(x => x.JumpType) - .FindAll() - .Where(j => j.UserId == userId) + .Include(x => x.User) + .Query() + .Where(j => j.User == user) .ToList(); } diff --git a/Back/skydiveLogs-api.Data/LiteDbProvider.cs b/Back/skydiveLogs-api.Data/LiteDbProvider.cs index 7ad3405..fd8d29b 100644 --- a/Back/skydiveLogs-api.Data/LiteDbProvider.cs +++ b/Back/skydiveLogs-api.Data/LiteDbProvider.cs @@ -14,6 +14,7 @@ namespace skydiveLogs_api.Data BsonMapper.Global.Entity().DbRef(x => x.Aircraft, "Aircraft"); BsonMapper.Global.Entity().DbRef(x => x.DropZone, "DropZone"); BsonMapper.Global.Entity().DbRef(x => x.Gear, "Gear"); + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); BsonMapper.Global.Entity().DbRef(x => x.User, "User"); } diff --git a/Back/skydiveLogs-api.Model/Aircraft.cs b/Back/skydiveLogs-api.Model/Aircraft.cs index a1d8703..57760da 100644 --- a/Back/skydiveLogs-api.Model/Aircraft.cs +++ b/Back/skydiveLogs-api.Model/Aircraft.cs @@ -5,5 +5,7 @@ public int Id { get; set; } public string Name { get; set; } + + public string ImageData { get; set; } } } diff --git a/Back/skydiveLogs-api.Model/Jump.cs b/Back/skydiveLogs-api.Model/Jump.cs index 7641314..244fc27 100644 --- a/Back/skydiveLogs-api.Model/Jump.cs +++ b/Back/skydiveLogs-api.Model/Jump.cs @@ -14,7 +14,7 @@ namespace skydiveLogs_api.Model public Gear Gear { get; set; } - public int UserId { get; set; } + public User User { get; set; } public int ExitAltitude { get; set; } diff --git a/Back/skydiveLogs-api/Data/JumpsDb-log.db b/Back/skydiveLogs-api/Data/JumpsDb-log.db deleted file mode 100644 index e135b20..0000000 Binary files a/Back/skydiveLogs-api/Data/JumpsDb-log.db and /dev/null differ diff --git a/Back/skydiveLogs-api/Data/JumpsDb.db b/Back/skydiveLogs-api/Data/JumpsDb.db index 60e9773..c0e6daa 100644 Binary files a/Back/skydiveLogs-api/Data/JumpsDb.db and b/Back/skydiveLogs-api/Data/JumpsDb.db differ diff --git a/Back/skydiveLogs-api/DataContract/AircraftReq.cs b/Back/skydiveLogs-api/DataContract/AircraftReq.cs index 118c467..cd68eed 100644 --- a/Back/skydiveLogs-api/DataContract/AircraftReq.cs +++ b/Back/skydiveLogs-api/DataContract/AircraftReq.cs @@ -5,5 +5,7 @@ public int Id { get; set; } public string Name { get; set; } + + public string ImageData { get; set; } } } diff --git a/Back/skydiveLogs-api/DataContract/AircraftResp.cs b/Back/skydiveLogs-api/DataContract/AircraftResp.cs index b5c6261..b4b135e 100644 --- a/Back/skydiveLogs-api/DataContract/AircraftResp.cs +++ b/Back/skydiveLogs-api/DataContract/AircraftResp.cs @@ -5,5 +5,7 @@ public int Id { get; set; } public string Name { get; set; } + + public string ImageData { get; set; } } } diff --git a/Front/skydivelogs-app/src/app/list-of-aircrafts/list-of-aircrafts.component.ts b/Front/skydivelogs-app/src/app/list-of-aircrafts/list-of-aircrafts.component.ts index 168d982..e29abbf 100644 --- a/Front/skydivelogs-app/src/app/list-of-aircrafts/list-of-aircrafts.component.ts +++ b/Front/skydivelogs-app/src/app/list-of-aircrafts/list-of-aircrafts.component.ts @@ -1,21 +1,21 @@ -import { Component, OnInit, ViewChild } from "@angular/core"; -import { MatPaginator } from "@angular/material/paginator"; -import { MatTableDataSource } from "@angular/material/table"; -import { MatDialog } from "@angular/material/dialog"; +import { Component, OnInit, ViewChild } from '@angular/core'; +import { MatPaginator } from '@angular/material/paginator'; +import { MatTableDataSource } from '@angular/material/table'; +import { MatDialog } from '@angular/material/dialog'; -import { AircraftResp } from "../../models/aircraft"; -import { AircraftService } from "../../services/aircraft.service"; -import { ServiceComm } from "../../services/service-comm.service"; -import { NewAircraftComponent } from "../new-aircraft/new-aircraft.component"; -import { AddAction } from "../../models/add-action.enum"; +import { AircraftResp } from '../../models/aircraft'; +import { AircraftService } from '../../services/aircraft.service'; +import { ServiceComm } from '../../services/service-comm.service'; +import { NewAircraftComponent } from '../new-aircraft/new-aircraft.component'; +import { AddAction } from '../../models/add-action.enum'; @Component({ - selector: "app-list-of-aircrafts", - templateUrl: "./list-of-aircrafts.component.html", - styleUrls: ["./list-of-aircrafts.component.css"] + selector: 'app-list-of-aircrafts', + templateUrl: './list-of-aircrafts.component.html', + styleUrls: ['./list-of-aircrafts.component.css'] }) export class ListOfAircraftsComponent implements OnInit { - public displayedColumns: Array = ["id", "name"]; + public displayedColumns: Array = ['id', 'name']; public dataSourceTable: MatTableDataSource; public resultsLength = 0; @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; @@ -24,7 +24,7 @@ export class ListOfAircraftsComponent implements OnInit { private serviceApi: AircraftService, private serviceComm: ServiceComm, public dialog: MatDialog - ) {} + ) { } ngOnInit() { this.serviceComm.refreshRequest.subscribe(action => { @@ -33,7 +33,7 @@ export class ListOfAircraftsComponent implements OnInit { this.getListOfAircrafts(); } }); - this.serviceComm.UpdatedComponentTitle("List of aircrafts"); + this.serviceComm.UpdatedComponentTitle('List of aircrafts'); this.getListOfAircrafts(); } diff --git a/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.html b/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.html index c704e07..3ea27e3 100644 --- a/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.html +++ b/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.html @@ -4,12 +4,12 @@ - - + @@ -39,10 +42,7 @@ - - - - + diff --git a/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.ts b/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.ts index ce8e8e9..82b2b9f 100644 --- a/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.ts +++ b/Front/skydivelogs-app/src/app/list-of-dzs/list-of-dzs.component.ts @@ -1,27 +1,26 @@ -import { Component, OnInit, ViewChild } from "@angular/core"; -import { MatPaginator } from "@angular/material/paginator"; -import { MatTableDataSource } from "@angular/material/table"; -import { MatDialog } from "@angular/material/dialog"; +import { Component, OnInit, ViewChild } from '@angular/core'; +import { MatPaginator } from '@angular/material/paginator'; +import { MatTableDataSource } from '@angular/material/table'; +import { MatDialog } from '@angular/material/dialog'; -import { AddAction } from "../../models/add-action.enum"; -import { DropZoneResp } from "../../models/dropzone"; -import { DropzoneService } from "../../services/dropzone.service"; -import { ServiceComm } from "../../services/service-comm.service"; -import { NewDropZoneComponent } from "../new-drop-zone/new-drop-zone.component"; +import { AddAction } from '../../models/add-action.enum'; +import { DropZoneResp } from '../../models/dropzone'; +import { DropzoneService } from '../../services/dropzone.service'; +import { ServiceComm } from '../../services/service-comm.service'; +import { NewDropZoneComponent } from '../new-drop-zone/new-drop-zone.component'; @Component({ - selector: "app-list-of-dzs", - templateUrl: "./list-of-dzs.component.html", - styleUrls: ["./list-of-dzs.component.css"], + selector: 'app-list-of-dzs', + templateUrl: './list-of-dzs.component.html', + styleUrls: ['./list-of-dzs.component.css'], }) export class ListOfDzsComponent implements OnInit { public displayedColumns: Array = [ - "isfavorite", - "id", - "name", - "address", - "email", - "type", + 'isfavorite', + 'id', + 'name', + 'address', + 'type', ]; public dataSourceTable: MatTableDataSource; public resultsLength = 0; @@ -31,7 +30,7 @@ export class ListOfDzsComponent implements OnInit { private serviceApi: DropzoneService, private serviceComm: ServiceComm, public dialog: MatDialog - ) {} + ) { } ngOnInit() { this.serviceComm.refreshRequest.subscribe((action) => { @@ -40,7 +39,7 @@ export class ListOfDzsComponent implements OnInit { this.getListOfDropZones(); } }); - this.serviceComm.UpdatedComponentTitle("List of DZs"); + this.serviceComm.UpdatedComponentTitle('List of DZs'); this.getListOfDropZones(); } @@ -73,8 +72,8 @@ export class ListOfDzsComponent implements OnInit { openDialogToAdd() { this.dialog.open(NewDropZoneComponent, { - height: "400px", - width: "600px", + height: '400px', + width: '600px', }); } } diff --git a/Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.ts b/Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.ts index bae6876..63164e9 100644 --- a/Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.ts +++ b/Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.ts @@ -1,31 +1,31 @@ -import { Component, OnInit, ViewChild } from "@angular/core"; -import { FormGroup, FormControl, Validators } from "@angular/forms"; -import { MatTableDataSource } from "@angular/material/table"; -import { MatPaginator } from "@angular/material/paginator"; +import { Component, OnInit, ViewChild } from '@angular/core'; +import { FormGroup, FormControl, Validators } from '@angular/forms'; +import { MatTableDataSource } from '@angular/material/table'; +import { MatPaginator } from '@angular/material/paginator'; -import { ImageService } from "../../services/image.service"; -import { ServiceComm } from "../../services/service-comm.service"; -import { ImageResp } from "../../models/Image"; -import { AddAction } from "../../models/add-action.enum"; +import { ImageService } from '../../services/image.service'; +import { ServiceComm } from '../../services/service-comm.service'; +import { ImageResp } from '../../models/Image'; +import { AddAction } from '../../models/add-action.enum'; @Component({ - selector: "app-list-of-images", - templateUrl: "./list-of-images.component.html", - styleUrls: ["./list-of-images.component.css"], + selector: 'app-list-of-images', + templateUrl: './list-of-images.component.html', + styleUrls: ['./list-of-images.component.css'], }) export class ListOfImagesComponent implements OnInit { - public displayedColumns: Array = ["comment", "data"]; + public displayedColumns: Array = ['comment', 'data']; public imgForm: FormGroup; public imageError: string; + private selectedFile: string; public dataSourceTable: MatTableDataSource; public resultsLength = 0; - private selectedFile: string; @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; constructor( private serviceApi: ImageService, private serviceComm: ServiceComm - ) {} + ) { } ngOnInit(): void { this.serviceComm.refreshRequest.subscribe((action) => { @@ -36,8 +36,8 @@ export class ListOfImagesComponent implements OnInit { this.getListOfImages(); this.imgForm = new FormGroup({ - comment: new FormControl("", Validators.required), - image: new FormControl("", Validators.required), + comment: new FormControl('', Validators.required), + image: new FormControl('', Validators.required), }); } @@ -52,16 +52,16 @@ export class ListOfImagesComponent implements OnInit { } public onFileChanged(fileInput: any) { - var file = fileInput.dataTransfer + const file = fileInput.dataTransfer ? fileInput.dataTransfer.files[0] : fileInput.target.files[0]; - const allowed_types = ["image/png", "image/jpeg"]; + const allowed_types = ['image/png', 'image/jpeg']; const max_size = 20971520; if (!allowed_types.includes(file.type)) { - this.imageError = "Only Images are allowed ( JPG | PNG )"; + this.imageError = 'Only Images are allowed ( JPG | PNG )'; } else if (file.size > max_size) { - this.imageError = "Maximum size allowed is " + max_size / 1000 + "Mb"; + this.imageError = 'Maximum size allowed is ' + max_size / 1000 + 'Mb'; } else { const reader = new FileReader(); reader.onload = this.checkAndExtractDataToBase64.bind(this); @@ -76,16 +76,16 @@ export class ListOfImagesComponent implements OnInit { const image = new Image(); image.src = e.target.result; image.onload = (rs) => { - const img_height = rs.currentTarget["height"]; - const img_width = rs.currentTarget["width"]; + const img_height = rs.currentTarget['height']; + const img_width = rs.currentTarget['width']; if (img_height > max_height && img_width > max_width) { this.imageError = - "Maximum dimentions allowed " + max_height + "*" + max_width + "px"; + 'Maximum dimentions allowed ' + max_height + '*' + max_width + 'px'; } else { const imgBase64Path = e.target.result; this.selectedFile = imgBase64Path; - this.imageError = "OK"; + this.imageError = 'OK'; } }; } diff --git a/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.html b/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.html index bc47a54..b15b645 100644 --- a/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.html +++ b/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.html @@ -1,6 +1,13 @@
- favorite + + favorite favorite_border + (click)="setToFavorite(element)" style="cursor: pointer;">favorite_border link @@ -18,6 +18,9 @@ target="_blank"> map + + mail_outline + E-mail{{element.email}}Type {{element.type}}
+ + + + + diff --git a/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.ts b/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.ts index a25a4d8..6c23a4d 100644 --- a/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.ts +++ b/Front/skydivelogs-app/src/app/list-of-jumps/list-of-jumps.component.ts @@ -1,26 +1,26 @@ -import { Component, OnInit, ViewChild } from "@angular/core"; -import { MatPaginator } from "@angular/material/paginator"; -import { MatTableDataSource } from "@angular/material/table"; +import { Component, OnInit, ViewChild } from '@angular/core'; +import { MatPaginator } from '@angular/material/paginator'; +import { MatTableDataSource } from '@angular/material/table'; -import { Observable } from "rxjs"; -import { JumpResp } from "../../models/jump"; -import { JumpService } from "../../services/jump.service"; -import { ServiceComm } from "../../services/service-comm.service"; +import { Observable } from 'rxjs'; +import { JumpResp } from '../../models/jump'; +import { JumpService } from '../../services/jump.service'; +import { ServiceComm } from '../../services/service-comm.service'; @Component({ - selector: "app-list-of-jumps", - templateUrl: "./list-of-jumps.component.html", - styleUrls: ["./list-of-jumps.component.css"] + selector: 'app-list-of-jumps', + templateUrl: './list-of-jumps.component.html', + styleUrls: ['./list-of-jumps.component.css'] }) export class ListOfJumpsComponent implements OnInit { public listOfJumps: Observable>; public displayedColumns: Array = [ - "id", - "jumpDate", - "jumpType", - "aircraft", - "dropZone", - "gear" + 'infos', + 'id', + 'jumpDate', + 'jumpType', + 'aircraft', + 'dropZone' ]; public dataSourceTable; public resultsLength = 0; @@ -29,10 +29,10 @@ export class ListOfJumpsComponent implements OnInit { constructor( private serviceApi: JumpService, private serviceComm: ServiceComm - ) {} + ) { } ngOnInit() { - this.serviceComm.UpdatedComponentTitle("List of jumps"); + this.serviceComm.UpdatedComponentTitle('List of jumps'); this.getListOfJumps(); } diff --git a/Front/skydivelogs-app/src/app/login-user/login-user.component.html b/Front/skydivelogs-app/src/app/login-user/login-user.component.html index 3add5bb..35d6714 100644 --- a/Front/skydivelogs-app/src/app/login-user/login-user.component.html +++ b/Front/skydivelogs-app/src/app/login-user/login-user.component.html @@ -2,8 +2,8 @@

Username - + Username is required @@ -16,7 +16,7 @@ Password + [ngClass]="{ 'is-invalid': submitted && formCtrls.password.errors }"> Password is required diff --git a/Front/skydivelogs-app/src/app/login-user/login-user.component.ts b/Front/skydivelogs-app/src/app/login-user/login-user.component.ts index 105fe20..6bbe913 100644 --- a/Front/skydivelogs-app/src/app/login-user/login-user.component.ts +++ b/Front/skydivelogs-app/src/app/login-user/login-user.component.ts @@ -1,22 +1,24 @@ -import { Component, OnInit } from "@angular/core"; -import { Router, ActivatedRoute } from "@angular/router"; -import { FormBuilder, FormGroup, Validators } from "@angular/forms"; +import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core'; +import { Router, ActivatedRoute } from '@angular/router'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { MatInput } from '@angular/material/input'; -import { first } from "rxjs/operators"; +import { first } from 'rxjs/operators'; -import { AuthenticationService } from "../../services/authentication.service"; +import { AuthenticationService } from '../../services/authentication.service'; @Component({ - selector: "app-login-user", - templateUrl: "./login-user.component.html", - styleUrls: ["./login-user.component.css"] + selector: 'app-login-user', + templateUrl: './login-user.component.html', + styleUrls: ['./login-user.component.css'] }) -export class LoginUserComponent implements OnInit { +export class LoginUserComponent implements OnInit, AfterViewInit { loginForm: FormGroup; loading = false; submitted = false; returnUrl: string; - error = ""; + error = ''; + @ViewChild('username') userNameInput: MatInput; constructor( private formBuilder: FormBuilder, @@ -26,26 +28,31 @@ export class LoginUserComponent implements OnInit { ) { // redirect to home if already logged in if (this.authenticationService.currentUserValue) { - this.router.navigate(["/"]); + this.router.navigate(['/']); } } + ngAfterViewInit() { + this.userNameInput.focus(); + } + ngOnInit() { this.loginForm = this.formBuilder.group( { - username: ["", [Validators.required, Validators.minLength(3)]], + username: ['', [Validators.required, Validators.minLength(3)]], password: [ - "", + '', [ Validators.required /*, Validators.pattern("^[A-Za-z0-9_-]{8,15}$")*/ ] ] }, - { updateOn: "blur" } + { updateOn: 'blur' } ); // get return url from route parameters or default to '/' - this.returnUrl = this.route.snapshot.queryParams["returnUrl"] || "/"; + this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/'; + } get formCtrls() { diff --git a/Front/skydivelogs-app/src/app/login/login.component.html b/Front/skydivelogs-app/src/app/login/login.component.html index 17930f4..4307049 100644 --- a/Front/skydivelogs-app/src/app/login/login.component.html +++ b/Front/skydivelogs-app/src/app/login/login.component.html @@ -5,10 +5,10 @@ - + - + diff --git a/Front/skydivelogs-app/src/app/new-aircraft/new-aircraft.component.html b/Front/skydivelogs-app/src/app/new-aircraft/new-aircraft.component.html index d27c2a0..3db76cd 100644 --- a/Front/skydivelogs-app/src/app/new-aircraft/new-aircraft.component.html +++ b/Front/skydivelogs-app/src/app/new-aircraft/new-aircraft.component.html @@ -6,6 +6,10 @@

+

+ +

diff --git a/Front/skydivelogs-app/src/app/new-aircraft/new-aircraft.component.ts b/Front/skydivelogs-app/src/app/new-aircraft/new-aircraft.component.ts index e6b58be..5220310 100644 --- a/Front/skydivelogs-app/src/app/new-aircraft/new-aircraft.component.ts +++ b/Front/skydivelogs-app/src/app/new-aircraft/new-aircraft.component.ts @@ -1,16 +1,18 @@ -import { Component, OnInit } from "@angular/core"; -import { FormControl, FormGroup, Validators } from "@angular/forms"; -import { AircraftService } from "../../services/aircraft.service"; -import { ServiceComm } from "../../services/service-comm.service"; -import { AddAction } from "../../models/add-action.enum"; +import { Component, OnInit } from '@angular/core'; +import { FormControl, FormGroup, Validators } from '@angular/forms'; +import { AircraftService } from '../../services/aircraft.service'; +import { ServiceComm } from '../../services/service-comm.service'; +import { AddAction } from '../../models/add-action.enum'; @Component({ - selector: "app-new-aircraft", - templateUrl: "./new-aircraft.component.html", - styleUrls: ["./new-aircraft.component.css"] + selector: 'app-new-aircraft', + templateUrl: './new-aircraft.component.html', + styleUrls: ['./new-aircraft.component.css'] }) export class NewAircraftComponent implements OnInit { public addForm: FormGroup; + public imageError: string; + private selectedFile: string; constructor( private serviceComm: ServiceComm, @@ -18,16 +20,59 @@ export class NewAircraftComponent implements OnInit { ) { this.addForm = new FormGroup( { - aircraftName: new FormControl("", Validators.required) + aircraftName: new FormControl('', Validators.required) }, - { updateOn: "blur" } + { updateOn: 'blur' } ); } - ngOnInit() {} + ngOnInit() { } onSubmit(formData) { - this.serviceApi.AddAircraft(formData.aircraftName); + if (formData.invalid) { + return; + } + + this.serviceApi.AddAircraft(formData.aircraftName, this.selectedFile); this.serviceComm.RefreshData(AddAction.Aircraft); } + + public onFileChanged(fileInput: any) { + const file = fileInput.dataTransfer + ? fileInput.dataTransfer.files[0] + : fileInput.target.files[0]; + const allowed_types = ['image/png', 'image/jpeg']; + const max_size = 20971520; + + if (!allowed_types.includes(file.type)) { + this.imageError = 'Only Images are allowed ( JPG | PNG )'; + } else if (file.size > max_size) { + this.imageError = 'Maximum size allowed is ' + max_size / 1000 + 'Mb'; + } else { + const reader = new FileReader(); + reader.onload = this.checkAndExtractDataToBase64.bind(this); + reader.readAsDataURL(fileInput.target.files[0]); + } + } + + private checkAndExtractDataToBase64(e: any) { + const max_height = 15200; + const max_width = 25600; + + const image = new Image(); + image.src = e.target.result; + image.onload = (rs) => { + const img_height = rs.currentTarget['height']; + const img_width = rs.currentTarget['width']; + + if (img_height > max_height && img_width > max_width) { + this.imageError = + 'Maximum dimentions allowed ' + max_height + '*' + max_width + 'px'; + } else { + const imgBase64Path = e.target.result; + this.selectedFile = imgBase64Path; + this.imageError = 'OK'; + } + }; + } } diff --git a/Front/skydivelogs-app/src/app/new-jump/new-jump.component.html b/Front/skydivelogs-app/src/app/new-jump/new-jump.component.html index 03f1d8b..a1871da 100644 --- a/Front/skydivelogs-app/src/app/new-jump/new-jump.component.html +++ b/Front/skydivelogs-app/src/app/new-jump/new-jump.component.html @@ -37,8 +37,8 @@ {{dropZone.name}} - favorite DZ + + favorite
+ info + ID {{element.id}}