Link work dans l'url + fonc get workbylink et getlinklastworkbyiduser
continuous-integration/drone/push Build is passing Details

(à faire côté serv)
pull/15/head
Matis MAZINGUE 11 months ago
parent dfaf146cd5
commit 8518c75b36

@ -9,9 +9,10 @@ import { TranslationService } from '../../services/translation.service';
import { ThemeService } from '../../services/theme.service'; import { ThemeService } from '../../services/theme.service';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { ReactiveFormsModule } from '@angular/forms'; import { ReactiveFormsModule } from '@angular/forms';
import { RouterLink, RouterLinkActive } from '@angular/router'; import { Router, RouterLink, RouterLinkActive } from '@angular/router';
import { NgClass, NgOptimizedImage } from '@angular/common'; import { NgClass, NgOptimizedImage } from '@angular/common';
import { WorkService } from '../../services/work.service'; import { WorkService } from '../../services/work.service';
import { Observable } from 'rxjs';
@Component({ @Component({
selector: 'app-header', selector: 'app-header',
@ -32,12 +33,18 @@ export class HeaderComponent {
version: string = '1.0'; version: string = '1.0';
isMenuOpen: boolean = false; isMenuOpen: boolean = false;
isCheck: boolean = false; isCheck: boolean = false;
linkLastWork: string = this.workService.getIdLastWorkByUserId("");
@ViewChild('menuRef') menuRef!: ElementRef; @ViewChild('menuRef') menuRef!: ElementRef;
@Input() themeClass!: string; @Input() themeClass!: string;
@Input() themeService!: ThemeService; @Input() themeService!: ThemeService;
// Instanciation du service pour les actions de traduction // Instanciation du service pour les actions de traduction
constructor(private translationService: TranslationService, private workService: WorkService) { } constructor(
private router: Router,
private translationService: TranslationService,
private workService: WorkService)
{ }
// Méthode pour changer la langue // Méthode pour changer la langue
onLanguageChange(event: Event) { onLanguageChange(event: Event) {
@ -65,8 +72,9 @@ export class HeaderComponent {
} }
} }
getLastWorkLink() : string { onLastWorkLink() : void {
return 'work/'.concat(this.workService.getIdLastWorkByUserId("")) const url = `/work/${this.linkLastWork}`;
this.router.navigateByUrl(url);
} }
} }

@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Router, RouterLink } from '@angular/router'; import { RouterLink, ActivatedRoute } from '@angular/router';
import { ThemeService } from '../../services/theme.service'; import { ThemeService } from '../../services/theme.service';
import { NgClass } from '@angular/common'; import { NgClass } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
@ -7,6 +7,7 @@ import {Work} from "../../models/work.model";
import {WorkService} from "../../services/work.service"; import {WorkService} from "../../services/work.service";
import {NgForOf} from "@angular/common"; import {NgForOf} from "@angular/common";
import {FormsModule, NgForm} from "@angular/forms"; import {FormsModule, NgForm} from "@angular/forms";
import { Observable } from 'rxjs';
@Component({ @Component({
selector: 'app-work', selector: 'app-work',
@ -27,9 +28,9 @@ export class WorkComponent implements OnInit {
themeClass!: string; themeClass!: string;
works: Work[] = []; works: Work[] = [];
workEnCours: Observable<Work> = new Observable();
constructor( constructor(
private router: Router, private route: ActivatedRoute,
private themeService: ThemeService, private themeService: ThemeService,
protected workService: WorkService protected workService: WorkService
) {} ) {}
@ -41,15 +42,12 @@ export class WorkComponent implements OnInit {
: (this.themeClass = 'light-theme'); : (this.themeClass = 'light-theme');
}); });
this.workService.getWorks().subscribe((response: Work[]) => this.works = response); this.workService.getWorks().subscribe((response: Work[]) => this.works = response);
const link = String(this.route.snapshot.paramMap.get('link'));
if (link) {
this.workEnCours = this.workService.getWorkByLink(link);
} }
// Si click sur "Work", on redirige vers la page des travaux
onContinue(): void {
this.router.navigateByUrl('/work');
} }
onSubmit(form: NgForm) { onSubmit(form: NgForm) {
this.workService.postWork(form); this.workService.postWork(form);
} }

@ -20,6 +20,16 @@ export class WorkService {
return this.http.get(`${this.API_URL}/works`); return this.http.get(`${this.API_URL}/works`);
} }
//je veux return un work en fonction d'un link passé en param
getWorkByLink(link: string): Observable<any> {
return this.http.get(`${this.API_URL}/work/${link}`);
}
//je veux return le link du dernier work d'un user (en l'occurence celui connecté)
getLinkLastWorkByIdUser(id_user: string): Observable<any> {
return this.http.get(`${this.API_URL}/work/${id_user}`);
}
postWork(form: NgForm): void { postWork(form: NgForm): void {
let body = {link: crypto.randomUUID(), id_user: 1, id_language: 1, code: form.value.content, saveDate: new Date()} let body = {link: crypto.randomUUID(), id_user: 1, id_language: 1, code: form.value.content, saveDate: new Date()}
this.http.post<any>(`${this.API_URL}/works`, body).subscribe(); this.http.post<any>(`${this.API_URL}/works`, body).subscribe();

Loading…
Cancel
Save