Work
continuous-integration/drone/push Build is passing Details

pull/15/head
Matis MAZINGUE 10 months ago
parent d71c510bb6
commit 2f9a8e182e

@ -53,7 +53,7 @@
</div> </div>
<div class="param-editor"> <div class="param-editor">
<button class="button-icon" type="button" (click)="addToDatabase()"> <button class="button-icon" type="button" (click)="addToDatabase()">
ADD BDD {{ 'Editor.Add' | translate }}
</button> </button>
</div> </div>
<div class="param-editor"> <div class="param-editor">
@ -62,10 +62,11 @@
type="button" type="button"
(click)="shareButtonClicked()" (click)="shareButtonClicked()"
[disabled]="isLoaded"> [disabled]="isLoaded">
{{ 'Work.Share' | translate }} {{ 'Editor.Share' | translate }}
</button> </button>
</div> </div>
<!-- TODO mettre le bouton save dans la page work-->
<!--TODO if userID de la session =! userID du work then btn-save.style(display : none) else btn-save.style(display : block)--> <!--TODO if userID de la session =! userID du work then btn-save.style(display : none) else btn-save.style(display : block)-->
<div class="param-editor"> <div class="param-editor">
<button <button
@ -73,7 +74,7 @@
type="button" type="button"
(click)="saveButtonClicked()" (click)="saveButtonClicked()"
[disabled]="isLoaded"> [disabled]="isLoaded">
{{ 'Work.Save' | translate }} {{ 'Editor.Save' | translate }}
</button> </button>
</div> </div>
</div> </div>
@ -92,11 +93,11 @@
<div class="param-editor"> <div class="param-editor">
<button <button
class="button-icon button-run" class="button-icon btn-run"
type="button" type="button"
(click)="onRunButtonClicked()" (click)="onRunButtonClicked()"
[disabled]="isLoaded"> [disabled]="isLoaded">
<div>RUN</div> <div style="margin-right: 10px">{{ 'Editor.Run' | translate }}</div>
<svg <svg
viewBox="0 0 16 16" viewBox="0 0 16 16"
xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg"

@ -1,3 +1,14 @@
@mixin btn-styles($bg-color, $font-color) {
background-color: $bg-color;
color: $font-color;
border: none;
color: white;
padding: 12px 16px;
font-size: 16px;
cursor: pointer;
border-radius: 10px;
}
#editor-bar-header { #editor-bar-header {
display: flex; display: flex;
align-items: center; align-items: center;
@ -26,20 +37,6 @@ svg {
cursor: pointer; cursor: pointer;
} }
.button-run {
display: flex;
align-items: center;
justify-content: space-between;
background-color: #04aa6d;
border: none;
color: white;
padding: 12px 16px;
font-size: 16px;
width: 100px;
cursor: pointer;
border-radius: 10px;
}
select { select {
background-color: #0000f0; background-color: #0000f0;
border: none; border: none;
@ -73,24 +70,18 @@ select {
height: 100%; height: 100%;
} }
// @mixin btn-styles($bg-color, $font-color) { .btn-run {
display: flex;
// background-color: $bg-color; align-items: center;
// color: $font-color; justify-content: space-between;
// border: none; @include btn-styles(#04aa6d, white);
// color: white; }
// padding: 12px 16px;
// font-size: 16px;
// width: 100px;
// cursor: pointer;
// border-radius: 10px;
// }
// .btn-save { .btn-share {
// @include btn-styles(green, white); @include btn-styles(rgb(41, 120, 184), white);
// } }
// .btn-save { .btn-save {
// @include btn-styles(red, white); @include btn-styles(rgb(49, 159, 49), white);
// } }

@ -82,6 +82,8 @@ const basicSetup: Extension = (() => [
], ],
}) })
export class EditorComponent { export class EditorComponent {
APP_URL = 'http://localhost:4200/'; // à retirer
@Input() currentWork!: Work; @Input() currentWork!: Work;
isLoaded: boolean = false; // Pour vérifier si le chargement est terminé isLoaded: boolean = false; // Pour vérifier si le chargement est terminé
@ -194,11 +196,28 @@ export class EditorComponent {
a.click(); a.click();
} }
addToDatabase() { addToDatabase() :string {
this.workService.postWorkCode(this.editorContent); return this.workService.postWork(this.editorContent, this.selectedLanguage.name, 1); // replace 1 by current_user's id
} }
shareButtonClicked() {} shareButtonClicked() {
const link = this.addToDatabase();
const url = `${this.APP_URL}/work/${link}`;
const ok = TranslateModule;
// Vérifiez si l'API clipboard est disponible
if (navigator.clipboard) {
navigator.clipboard.writeText(url).then(() => {
// Optionnel : Afficher un message à l'utilisateur
alert('URL copied to clipboard!');
}).catch(() => {
// Optionnel : Afficher un message d'erreur à l'utilisateur
alert('Failed to copy URL to clipboard.');
});
} else {
// Optionnel : Si l'API clipboard n'est pas disponible, afficher un message à l'utilisateur
alert('Clipboard API not available');
}
}
saveButtonClicked() { saveButtonClicked() {
this.workService.updateWork( this.workService.updateWork(

@ -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: string = ''; linkLastWork = ""; //peut-être à cast en string
@ViewChild('menuRef') menuRef!: ElementRef; @ViewChild('menuRef') menuRef!: ElementRef;
@Input() themeClass!: string; @Input() themeClass!: string;
@ -34,7 +34,8 @@ 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

@ -54,6 +54,6 @@ export class WorkComponent implements OnInit {
} }
onSubmit(form: NgForm) { onSubmit(form: NgForm) {
this.workService.postWork(form); this.workService.saveWork(form);
} }
} }

@ -31,6 +31,6 @@ export class WorksListComponent {
} }
onSubmit(form: NgForm) { onSubmit(form: NgForm) {
this.workService.postWork(form); this.workService.saveWork(form);
} }
} }

@ -29,31 +29,26 @@ export class WorkService {
//je veux return le link du dernier work d'un user (en l'occurence celui connecté) //je veux return le link du dernier work d'un user (en l'occurence celui connecté)
getLastWorkByUserId(user_id: string): Observable<any> { getLastWorkByUserId(user_id: string): Observable<any> {
return this.http.get(`${this.API_URL}/works/user/${user_id}`); return this.http.get(`${this.API_URL}/works/last-work/${user_id}`);
} }
postWork(form: NgForm): void { saveWork(form: NgForm): void {
let body = { const code = form.value.content;
link: crypto.randomUUID(),
user_id: 1, this.http.post<any>(`${this.API_URL}/works/save`, code).subscribe();
id_language: 1,
code: form.value.content,
saveDate: new Date(),
};
this.http.post<any>(`${this.API_URL}/works`, body).subscribe();
} }
postWorkCode(code: string): void { postWork(code: string, language: string, id_user: number): string {
let body = { let body = {
id_user: id_user, // tant que ça pas résolu -> je peux pas faire le share
link: crypto.randomUUID(), link: crypto.randomUUID(),
id_user: 1, language: language,
id_language: 1,
code: code,
title: 'Basic JS', title: 'Basic JS',
date: '2024-06-14T13:35:24.756Z', 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;
} }
updateWork(id: string, code: string): void { updateWork(id: string, code: string): void {

@ -148,8 +148,10 @@
}, },
"Date": "This document was last updated on January 10, 2024" "Date": "This document was last updated on January 10, 2024"
}, },
"Work": { "Editor": {
"Share": "Share", "Share": "Share",
"Save": "Save" "Save": "Save",
"Run": "RUN",
"Add": "ADD BDD"
} }
} }

@ -148,8 +148,10 @@
}, },
"Date": "Ce document a été mis à jour pour la dernière fois le 10 janvier 2024." "Date": "Ce document a été mis à jour pour la dernière fois le 10 janvier 2024."
}, },
"Work": { "Editor": {
"Share": "Partager", "Share": "Partager",
"Save": "Sauvergarder" "Save": "Sauvergarder",
"Run": "EXECUTER",
"Add": "AJOUTER A LA BDD"
} }
} }

Loading…
Cancel
Save