Add the save button on works
continuous-integration/drone/push Build is passing Details

pull/15/head
Colin FRIZOT 11 months ago
parent 3bd2c44bad
commit d71c510bb6

@ -1,4 +1,4 @@
import { Component, ViewChild } from '@angular/core'; import { Component, Input, ViewChild } from '@angular/core';
import { CodeExecutionService } from 'src/app/services/codeExecution.service'; import { CodeExecutionService } from 'src/app/services/codeExecution.service';
import { Compartment } from '@codemirror/state'; import { Compartment } from '@codemirror/state';
import { CodeMirrorComponent } from '@sandkasten/codemirror6-editor'; import { CodeMirrorComponent } from '@sandkasten/codemirror6-editor';
@ -38,6 +38,7 @@ import {
} from '@codemirror/autocomplete'; } from '@codemirror/autocomplete';
import { lintKeymap } from '@codemirror/lint'; import { lintKeymap } from '@codemirror/lint';
import { WorkService } from '../../services/work.service'; import { WorkService } from '../../services/work.service';
import { Work } from '../../models/work.model';
const basicSetup: Extension = (() => [ const basicSetup: Extension = (() => [
highlightActiveLineGutter(), highlightActiveLineGutter(),
@ -81,6 +82,7 @@ const basicSetup: Extension = (() => [
], ],
}) })
export class EditorComponent { export class EditorComponent {
@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é
readonly languages: LanguageDescription[] = LANGUAGES; readonly languages: LanguageDescription[] = LANGUAGES;
@ -142,6 +144,12 @@ export class EditorComponent {
protected workService: WorkService protected workService: WorkService
) {} ) {}
ngOnInit() {
if (this.currentWork) {
this.editorContent = this.currentWork.content;
}
}
// Efface le contenu de l'éditeur // Efface le contenu de l'éditeur
clear(): void { clear(): void {
this.editorContent = ''; this.editorContent = '';
@ -191,7 +199,13 @@ export class EditorComponent {
} }
shareButtonClicked() {} shareButtonClicked() {}
saveButtonClicked() {}
saveButtonClicked() {
this.workService.updateWork(
String(this.currentWork.id_work),
this.editorContent
);
}
protected readonly console = console; protected readonly console = console;
} }

@ -1,5 +1,9 @@
<div> <div class="work-list-detail">
<h4>{{ work.id_work }} - {{ work.title }}</h4> <h4 class="work-list-detail--title">{{ work.title }}</h4>
<span> WORK CONTENT : {{ work.content }}</span> <span class="work-list-detail--content">{{
<a [routerLink]="['/work/', work.id_work]">Edit Code</a> work.content | slice: 0 : 50
}}</span>
<button class="work-list-detail--btn" [routerLink]="['/work/', work.id_work]">
Edit Code
</button>
</div> </div>

@ -0,0 +1,26 @@
.work-list-detail {
background: lightgray;
width: fit-content;
padding: 2rem;
border-radius: 1rem;
display: flex;
flex-direction: column;
gap: 1rem;
&--title {
margin: 0;
font-size: 1.5rem;
font-weight: bold;
}
&--content {
}
&--btn {
width: fit-content;
padding: 0.5rem 1rem;
border: 1px solid black;
border-radius: 0.5rem;
}
}

@ -1,13 +1,14 @@
import { Component, Input } from '@angular/core'; import { Component, Input } from '@angular/core';
import { Work } from '../../models/work.model'; import { Work } from '../../models/work.model';
import { RouterLink } from '@angular/router'; import { RouterLink } from '@angular/router';
import { SlicePipe } from '@angular/common';
@Component({ @Component({
selector: 'app-work-list-detail', selector: 'app-work-list-detail',
standalone: true, standalone: true,
imports: [RouterLink], imports: [RouterLink, SlicePipe],
templateUrl: './work-list-detail.component.html', templateUrl: './work-list-detail.component.html',
styleUrl: './work-list-detail.component.css', styleUrl: './work-list-detail.component.scss',
}) })
export class WorkListDetailComponent { export class WorkListDetailComponent {
@Input() work!: Work; @Input() work!: Work;

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

@ -37,8 +37,7 @@ export class WorkComponent implements OnInit {
private route: ActivatedRoute, private route: ActivatedRoute,
private themeService: ThemeService, private themeService: ThemeService,
protected workService: WorkService protected workService: WorkService
) { ) {}
}
ngOnInit() { ngOnInit() {
this.themeService.isDarkTheme.subscribe((value) => { this.themeService.isDarkTheme.subscribe((value) => {

@ -6,8 +6,8 @@
</div> </div>
<h3>All Works</h3> <h3>All Works</h3>
<ul> <div class="all-works">
<li *ngFor="let work of works"> <div *ngFor="let work of works">
<app-work-list-detail [work]="work"></app-work-list-detail> <app-work-list-detail [work]="work"></app-work-list-detail>
</li> </div>
</ul> </div>

@ -0,0 +1,5 @@
.all-works {
display: flex;
flex-wrap: wrap;
gap: 2rem;
}

@ -10,7 +10,7 @@ import { WorkListDetailComponent } from '../work-list-detail/work-list-detail.co
standalone: true, standalone: true,
imports: [NgForOf, FormsModule, SlicePipe, WorkListDetailComponent], imports: [NgForOf, FormsModule, SlicePipe, WorkListDetailComponent],
templateUrl: './works-list.component.html', templateUrl: './works-list.component.html',
styleUrl: './works-list.component.css', styleUrl: './works-list.component.scss',
}) })
export class WorksListComponent { export class WorksListComponent {
works: Work[] = []; works: Work[] = [];

@ -55,4 +55,11 @@ export class WorkService {
this.http.post<any>(`${this.API_URL}/works`, body).subscribe(); this.http.post<any>(`${this.API_URL}/works`, body).subscribe();
} }
updateWork(id: string, code: string): void {
let body = {
newContent: code,
};
this.http.put<any>(`${this.API_URL}/works/${id}/content`, body).subscribe();
}
} }

Loading…
Cancel
Save