Add the Works link management
continuous-integration/drone/push Build is passing Details

pull/15/head
Colin FRIZOT 11 months ago
parent 2f9a8e182e
commit 46fc613f6f

@ -12,7 +12,7 @@ import { WorksListComponent } from './components/works-list/works-list.component
// Toutes les routes de l'application sont définies ici // Toutes les routes de l'application sont définies ici
const routes: Routes = [ const routes: Routes = [
{ path: '', component: LandingPageComponent }, { path: '', component: LandingPageComponent },
{ path: 'work/:id', component: WorkComponent }, { path: 'work/:link', component: WorkComponent },
{ path: 'works', component: WorksListComponent }, { path: 'works', component: WorksListComponent },
{ path: 'editor', component: EditorComponent }, { path: 'editor', component: EditorComponent },
{ path: 'documentation', component: DocumentationComponent }, { path: 'documentation', component: DocumentationComponent },

@ -79,7 +79,6 @@ select {
.btn-share { .btn-share {
@include btn-styles(rgb(41, 120, 184), white); @include btn-styles(rgb(41, 120, 184), white);
} }
.btn-save { .btn-save {

@ -148,6 +148,9 @@ export class EditorComponent {
ngOnInit() { ngOnInit() {
if (this.currentWork) { if (this.currentWork) {
this.selectedLanguage = this.languages.find(
(lang) => lang.name === this.currentWork.language
)!;
this.editorContent = this.currentWork.content; this.editorContent = this.currentWork.content;
} }
} }
@ -196,8 +199,12 @@ export class EditorComponent {
a.click(); a.click();
} }
addToDatabase() :string { addToDatabase(): string {
return this.workService.postWork(this.editorContent, this.selectedLanguage.name, 1); // replace 1 by current_user's id return this.workService.postWork(
this.editorContent,
this.selectedLanguage.name,
1
); // replace 1 by current_user's id
} }
shareButtonClicked() { shareButtonClicked() {
@ -206,10 +213,13 @@ export class EditorComponent {
const ok = TranslateModule; const ok = TranslateModule;
// Vérifiez si l'API clipboard est disponible // Vérifiez si l'API clipboard est disponible
if (navigator.clipboard) { if (navigator.clipboard) {
navigator.clipboard.writeText(url).then(() => { navigator.clipboard
.writeText(url)
.then(() => {
// Optionnel : Afficher un message à l'utilisateur // Optionnel : Afficher un message à l'utilisateur
alert('URL copied to clipboard!'); alert('URL copied to clipboard!');
}).catch(() => { })
.catch(() => {
// Optionnel : Afficher un message d'erreur à l'utilisateur // Optionnel : Afficher un message d'erreur à l'utilisateur
alert('Failed to copy URL to clipboard.'); alert('Failed to copy URL to clipboard.');
}); });
@ -222,7 +232,8 @@ export class EditorComponent {
saveButtonClicked() { saveButtonClicked() {
this.workService.updateWork( this.workService.updateWork(
String(this.currentWork.id_work), String(this.currentWork.id_work),
this.editorContent this.editorContent,
this.selectedLanguage.name
); );
} }

@ -25,7 +25,7 @@ export class HeaderComponent {
version: string = '1.0'; version: string = '1.0';
isMenuOpen: boolean = false; isMenuOpen: boolean = false;
isCheck: boolean = false; isCheck: boolean = false;
linkLastWork = ""; //peut-être à cast en string linkLastWork = ''; //peut-être à cast en string
@ViewChild('menuRef') menuRef!: ElementRef; @ViewChild('menuRef') menuRef!: ElementRef;
@Input() themeClass!: string; @Input() themeClass!: string;
@ -34,8 +34,7 @@ export class HeaderComponent {
// Instanciation du service pour les actions de traduction // Instanciation du service pour les actions de traduction
constructor( constructor(
private router: Router, private router: Router,
private translationService: TranslationService, private translationService: TranslationService
) {} ) {}
// Méthode pour changer la langue // Méthode pour changer la langue

@ -3,7 +3,7 @@
<span class="work-list-detail--content">{{ <span class="work-list-detail--content">{{
work.content | slice: 0 : 50 work.content | slice: 0 : 50
}}</span> }}</span>
<button class="work-list-detail--btn" [routerLink]="['/work/', work.id_work]"> <button class="work-list-detail--btn" [routerLink]="['/work/', work.link]">
Edit Code Edit Code
</button> </button>
</div> </div>

@ -1,5 +1,4 @@
<div *ngIf="work"> <div *ngIf="work">
<h2>Works</h2> <h3>{{ work.title }}</h3>
<h3>CURRENT WORK ID - {{ work.id_work }}</h3>
<app-editor [currentWork]="work"></app-editor> <app-editor [currentWork]="work"></app-editor>
</div> </div>

@ -46,9 +46,9 @@ export class WorkComponent implements OnInit {
: (this.themeClass = 'light-theme'); : (this.themeClass = 'light-theme');
}); });
const work_id = String(this.route.snapshot.paramMap.get('id')); const work_link = String(this.route.snapshot.paramMap.get('link'));
this.workService.getWorkById(work_id).subscribe((response: Work) => { this.workService.getWorkByLink(work_link).subscribe((response: Work) => {
this.work = response as Work; this.work = response as Work;
}); });
} }

@ -2,7 +2,7 @@ export interface Work {
id_work: number; id_work: number;
link: string; link: string;
user_id: number; user_id: number;
language_id: number; language: string;
title: string; title: string;
content: string; content: string;
} }

@ -18,18 +18,8 @@ export class WorkService {
return this.http.get(`${this.API_URL}/works`); return this.http.get(`${this.API_URL}/works`);
} }
getWorkById(id: string): Observable<any> { getWorkByLink(link: string): Observable<any> {
return this.http.get(`${this.API_URL}/works/${id}`); return this.http.get(`${this.API_URL}/works/${link}`);
}
//je veux return les works d'un user id
getWorksByUserId(user_id: string): Observable<any> {
return this.http.get(`${this.API_URL}/works/${user_id}`);
}
//je veux return le link du dernier work d'un user (en l'occurence celui connecté)
getLastWorkByUserId(user_id: string): Observable<any> {
return this.http.get(`${this.API_URL}/works/last-work/${user_id}`);
} }
saveWork(form: NgForm): void { saveWork(form: NgForm): void {
@ -43,17 +33,18 @@ export class WorkService {
id_user: id_user, // tant que ça pas résolu -> je peux pas faire le share id_user: id_user, // tant que ça pas résolu -> je peux pas faire le share
link: crypto.randomUUID(), link: crypto.randomUUID(),
language: language, language: language,
title: 'Basic JS', title: `Basic ${language}`,
code: code code: code,
}; };
this.http.post<any>(`${this.API_URL}/works`, body).subscribe(); this.http.post<any>(`${this.API_URL}/works`, body).subscribe();
return body.link; return body.link;
} }
updateWork(id: string, code: string): void { updateWork(id: string, code: string, language: string): void {
let body = { let body = {
newContent: code, newContent: code,
language: language,
}; };
this.http.put<any>(`${this.API_URL}/works/${id}/content`, body).subscribe(); this.http.put<any>(`${this.API_URL}/works/${id}/content`, body).subscribe();
} }

Loading…
Cancel
Save