From 6ea906f80f596a6eb2011e2d4de935ada173e07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Tue, 26 May 2020 19:10:25 +0200 Subject: [PATCH] =?UTF-8?q?Un=20d=C3=A9but=20d'ajout=20pour=20uploader=20d?= =?UTF-8?q?es=20images?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Front/skydivelogs-app/src/app/app.module.ts | 4 ++ .../list-of-images.component.css | 0 .../list-of-images.component.html | 18 ++++++ .../list-of-images.component.spec.ts | 25 ++++++++ .../list-of-images.component.ts | 63 +++++++++++++++++++ .../user-profile/user-profile.component.html | 2 + Front/skydivelogs-app/src/models/image.ts | 19 ++++++ .../src/services/image.service.ts | 34 ++++++++++ 8 files changed, 165 insertions(+) create mode 100644 Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.css create mode 100644 Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.html create mode 100644 Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.spec.ts create mode 100644 Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.ts create mode 100644 Front/skydivelogs-app/src/models/image.ts create mode 100644 Front/skydivelogs-app/src/services/image.service.ts diff --git a/Front/skydivelogs-app/src/app/app.module.ts b/Front/skydivelogs-app/src/app/app.module.ts index 8f0c46c..75b9502 100644 --- a/Front/skydivelogs-app/src/app/app.module.ts +++ b/Front/skydivelogs-app/src/app/app.module.ts @@ -32,6 +32,7 @@ import { StatsService } from "../services/stats.service"; import { ServiceComm } from "../services/service-comm.service"; import { RequestCache } from "../services/request-cache.service"; import { AuthGuardService } from "../services/auth-guard.service"; +import { ImageService } from "../services/image.service"; import { BrowserAnimationsModule } from "@angular/platform-browser/animations"; import { FormsModule, ReactiveFormsModule } from "@angular/forms"; @@ -57,6 +58,7 @@ import { CachingInterceptor } from "../interceptor/caching.interceptor"; import { JwtAuthInterceptor } from "../interceptor/jwt-auth.interceptor"; import { ErrorInterceptor } from "../interceptor/error.interceptor"; import { UserProfileComponent } from "./user-profile/user-profile.component"; +import { ListOfImagesComponent } from "./list-of-images/list-of-images.component"; const appRoutes: Routes = [ { path: "", component: DefaultComponent, canActivate: [AuthGuardService] }, @@ -126,6 +128,7 @@ const appRoutes: Routes = [ CreateUserComponent, LoginUserComponent, UserProfileComponent, + ListOfImagesComponent, ], imports: [ RouterModule.forRoot( @@ -156,6 +159,7 @@ const appRoutes: Routes = [ ], exports: [HttpClientModule], providers: [ + ImageService, AircraftService, DropzoneService, GearService, diff --git a/Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.css b/Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.css new file mode 100644 index 0000000..e69de29 diff --git a/Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.html b/Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.html new file mode 100644 index 0000000..563101a --- /dev/null +++ b/Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.html @@ -0,0 +1,18 @@ +
+

+ + +

+

+ + Comment about the image + + +

+ + +
diff --git a/Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.spec.ts b/Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.spec.ts new file mode 100644 index 0000000..a5dcc11 --- /dev/null +++ b/Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ListOfImagesComponent } from './list-of-images.component'; + +describe('ListOfImagesComponent', () => { + let component: ListOfImagesComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ListOfImagesComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ListOfImagesComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); 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 new file mode 100644 index 0000000..5c98b2b --- /dev/null +++ b/Front/skydivelogs-app/src/app/list-of-images/list-of-images.component.ts @@ -0,0 +1,63 @@ +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"; + +@Component({ + selector: "app-list-of-images", + templateUrl: "./list-of-images.component.html", + styleUrls: ["./list-of-images.component.css"], +}) +export class ListOfImagesComponent implements OnInit { + public imgForm: FormGroup; + private selectedFile: File; + public dataSourceTable: MatTableDataSource; + public resultsLength = 0; + @ViewChild(MatPaginator, { static: true }) paginator: MatPaginator; + + constructor( + private serviceApi: ImageService, + private serviceComm: ServiceComm + ) {} + + ngOnInit(): void { + this.serviceComm.refreshRequest.subscribe((action) => { + if (action === AddAction.Gear) { + this.getListOfImages(); + } + }); + this.getListOfImages(); + + this.imgForm = new FormGroup({ + comment: new FormControl("", Validators.required), + image: new FormControl("", Validators.required), + }); + } + + getListOfImages() { + this.serviceApi.getListOfImages().subscribe((data) => { + setTimeout(() => { + this.dataSourceTable = new MatTableDataSource(data); + this.dataSourceTable.paginator = this.paginator; + this.resultsLength = data.length; + }, 500); + }); + } + + onFileChanged(event) { + this.selectedFile = event.target.files[0]; + } + + onSubmit(formData) { + if (this.imgForm.invalid) { + return; + } + + this.serviceApi.AddImage(formData.comment, this.selectedFile); + } +} diff --git a/Front/skydivelogs-app/src/app/user-profile/user-profile.component.html b/Front/skydivelogs-app/src/app/user-profile/user-profile.component.html index 517efbc..ab68605 100644 --- a/Front/skydivelogs-app/src/app/user-profile/user-profile.component.html +++ b/Front/skydivelogs-app/src/app/user-profile/user-profile.component.html @@ -40,4 +40,6 @@ + + diff --git a/Front/skydivelogs-app/src/models/image.ts b/Front/skydivelogs-app/src/models/image.ts new file mode 100644 index 0000000..286eefb --- /dev/null +++ b/Front/skydivelogs-app/src/models/image.ts @@ -0,0 +1,19 @@ +export class ImageReq { + constructor(data: any) { + Object.assign(this, data); + } + + public id: number; + public comment: string; + public data: string; +} + +export class ImageResp { + constructor(data: any) { + Object.assign(this, data); + } + + public id: number; + public comment: string; + public data: string; +} diff --git a/Front/skydivelogs-app/src/services/image.service.ts b/Front/skydivelogs-app/src/services/image.service.ts new file mode 100644 index 0000000..b9811f9 --- /dev/null +++ b/Front/skydivelogs-app/src/services/image.service.ts @@ -0,0 +1,34 @@ +import { Injectable } from "@angular/core"; +import { HttpClient } from "@angular/common/http"; +import { Observable } from "rxjs"; + +import { ImageResp, ImageReq } from "../models/Image"; + +import { BaseService } from "./base.service"; + +@Injectable() +export class ImageService extends BaseService { + constructor(private http: HttpClient) { + super(); + } + + public getListOfImages(): Observable> { + return this.http.get>(`${this.apiUrl}/Image`, { + headers: this.headers, + }); + } + + public AddImage(commentImg: string, dataImg: File) { + const bodyNewImage: ImageReq = { + id: 0, + comment: commentImg, + data: dataImg.type, + }; + + this.http + .post(`${this.apiUrl}/Image`, bodyNewImage, { + headers: this.headers, + }) + .subscribe((data) => console.log(data)); + } +}