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

pull/15/head
Colin FRIZOT 11 months ago
parent 90f83ec698
commit 0e97f37bff

@ -1,26 +1,29 @@
import { NgModule } from '@angular/core'; import {NgModule} from '@angular/core';
import { RouterModule, Routes } from '@angular/router'; import {RouterModule, Routes} from '@angular/router';
import { EditorComponent } from './components/editor/editor.component'; import {EditorComponent} from './components/editor/editor.component';
import { LandingPageComponent } from './components/landing-page/landing-page.component'; import {LandingPageComponent} from './components/landing-page/landing-page.component';
import { DocumentationComponent } from './components/documentation/documentation.component'; import {DocumentationComponent} from './components/documentation/documentation.component';
import { FormComponent } from './components/form/form.component'; import {FormComponent} from './components/form/form.component';
import { TermsOfServiceComponent } from './components/terms-of-service/terms-of-service.component'; import {TermsOfServiceComponent} from './components/terms-of-service/terms-of-service.component';
import { OurStoryComponent } from './components/our-story/our-story.component'; import {OurStoryComponent} from './components/our-story/our-story.component';
import { PrivacyPolicyComponent } from './components/privacy-policy/privacy-policy.component'; import {PrivacyPolicyComponent} from './components/privacy-policy/privacy-policy.component';
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: 'editor', component: EditorComponent }, {path: 'editor', component: EditorComponent},
{ path: 'documentation', component: DocumentationComponent }, {path: 'documentation', component: DocumentationComponent},
{ path: 'contact', component: FormComponent }, {path: 'contact', component: FormComponent},
{ path: 'our-story', component: OurStoryComponent }, {path: 'our-story', component: OurStoryComponent},
{ path: 'terms-of-service', component: TermsOfServiceComponent }, {path: 'terms-of-service', component: TermsOfServiceComponent},
{ path: 'privacy-policy', component: PrivacyPolicyComponent }, {path: 'privacy-policy', component: PrivacyPolicyComponent},
{path: 'works', component: WorksListComponent},
]; ];
@NgModule({ @NgModule({
imports: [RouterModule.forRoot(routes)], imports: [RouterModule.forRoot(routes)],
exports: [RouterModule], exports: [RouterModule],
}) })
export class AppRoutingModule {} export class AppRoutingModule {
}

@ -25,7 +25,7 @@
style="display: none" style="display: none"
type="file" type="file"
id="fileInput" id="fileInput"
(change)="loadFromFile($event)" /> (change)="loadFromFile($event)"/>
</div> </div>
<div class="param-editor"> <div class="param-editor">
@ -41,16 +41,21 @@
stroke="#1C274C" stroke="#1C274C"
stroke-width="1.5" stroke-width="1.5"
stroke-linecap="round" stroke-linecap="round"
stroke-linejoin="round" /> stroke-linejoin="round"/>
<path <path
d="M12 3V16M12 16L16 11.625M12 16L8 11.625" d="M12 3V16M12 16L16 11.625M12 16L8 11.625"
stroke="#1C274C" stroke="#1C274C"
stroke-width="1.5" stroke-width="1.5"
stroke-linecap="round" stroke-linecap="round"
stroke-linejoin="round" /> stroke-linejoin="round"/>
</svg> </svg>
</button> </button>
</div> </div>
<div class="param-editor">
<button class="button-icon" type="button" (click)="addToDatabase()">
ADD BDD
</button>
</div>
</div> </div>
<div class="editor-section-bar-header"> <div class="editor-section-bar-header">
@if (errorMessage) { @if (errorMessage) {

@ -1,11 +1,11 @@
import { Component, ViewChild } from '@angular/core'; import {Component, 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';
import { LanguageDescription } from '@codemirror/language'; import {LanguageDescription} from '@codemirror/language';
import { CODE_DEFAULTS, LANGUAGES } from '../languages'; import {CODE_DEFAULTS, LANGUAGES} from '../languages';
import { SafeHTMLPipe } from '../../safe-html.pipe'; import {SafeHTMLPipe} from '../../safe-html.pipe';
import { ReactiveFormsModule, FormsModule } from '@angular/forms'; import {ReactiveFormsModule, FormsModule} from '@angular/forms';
import { import {
keymap, keymap,
highlightSpecialChars, highlightSpecialChars,
@ -18,7 +18,7 @@ import {
highlightActiveLineGutter, highlightActiveLineGutter,
gutter, gutter,
} from '@codemirror/view'; } from '@codemirror/view';
import { Extension, EditorState } from '@codemirror/state'; import {Extension, EditorState} from '@codemirror/state';
import { import {
defaultHighlightStyle, defaultHighlightStyle,
syntaxHighlighting, syntaxHighlighting,
@ -27,15 +27,16 @@ import {
foldGutter, foldGutter,
foldKeymap, foldKeymap,
} from '@codemirror/language'; } from '@codemirror/language';
import { defaultKeymap, history, historyKeymap } from '@codemirror/commands'; import {defaultKeymap, history, historyKeymap} from '@codemirror/commands';
import { searchKeymap, highlightSelectionMatches } from '@codemirror/search'; import {searchKeymap, highlightSelectionMatches} from '@codemirror/search';
import { import {
autocompletion, autocompletion,
completionKeymap, completionKeymap,
closeBrackets, closeBrackets,
closeBracketsKeymap, closeBracketsKeymap,
} from '@codemirror/autocomplete'; } from '@codemirror/autocomplete';
import { lintKeymap } from '@codemirror/lint'; import {lintKeymap} from '@codemirror/lint';
import {WorksService} from "../../services/works.service";
const basicSetup: Extension = (() => [ const basicSetup: Extension = (() => [
highlightActiveLineGutter(), highlightActiveLineGutter(),
@ -46,7 +47,7 @@ const basicSetup: Extension = (() => [
dropCursor(), dropCursor(),
EditorState.allowMultipleSelections.of(true), EditorState.allowMultipleSelections.of(true),
indentOnInput(), indentOnInput(),
syntaxHighlighting(defaultHighlightStyle, { fallback: true }), syntaxHighlighting(defaultHighlightStyle, {fallback: true}),
bracketMatching(), bracketMatching(),
closeBrackets(), closeBrackets(),
autocompletion(), autocompletion(),
@ -88,6 +89,7 @@ export class EditorComponent {
get selectedLanguage(): LanguageDescription { get selectedLanguage(): LanguageDescription {
return this._selectedLanguage; return this._selectedLanguage;
} }
set selectedLanguage(value: LanguageDescription) { set selectedLanguage(value: LanguageDescription) {
this._selectedLanguage = value; this._selectedLanguage = value;
if (value.name in CODE_DEFAULTS) { if (value.name in CODE_DEFAULTS) {
@ -100,10 +102,12 @@ export class EditorComponent {
}); });
}); });
} }
private _linesNumbers: boolean = true; private _linesNumbers: boolean = true;
get linesNumbers() { get linesNumbers() {
return this._linesNumbers; return this._linesNumbers;
} }
set linesNumbers(lines: boolean) { set linesNumbers(lines: boolean) {
this._linesNumbers = lines; this._linesNumbers = lines;
this.codemirror.editor?.dispatch({ this.codemirror.editor?.dispatch({
@ -131,7 +135,8 @@ export class EditorComponent {
this.languageCompartment.of(this.selectedLanguage.support!), this.languageCompartment.of(this.selectedLanguage.support!),
]; ];
constructor(private codeExecutionService: CodeExecutionService) {} constructor(private codeExecutionService: CodeExecutionService, protected workService: WorksService) {
}
// Efface le contenu de l'éditeur // Efface le contenu de l'éditeur
clear(): void { clear(): void {
@ -170,10 +175,16 @@ export class EditorComponent {
} }
saveToFile() { saveToFile() {
const blob = new Blob([this.editorContent], { type: 'text/plain' }); const blob = new Blob([this.editorContent], {type: 'text/plain'});
const a = document.createElement('a'); const a = document.createElement('a');
a.download = `code.${this.selectedLanguage.extensions![0]}`; a.download = `code.${this.selectedLanguage.extensions![0]}`;
a.href = URL.createObjectURL(blob); a.href = URL.createObjectURL(blob);
a.click(); a.click();
} }
addToDatabase() {
this.workService.postWorkCode(this.editorContent);
}
protected readonly console = console;
} }

@ -0,0 +1,21 @@
<h2>Works</h2>
<ul>
<li *ngFor="let work of works">
{{ work.id_work }} - {{ work.link }} - {{ work.content }}
</li>
</ul>
<form #addBookForm="ngForm" (ngSubmit)="onSubmit(addBookForm)">
<div class="form-group">
<label for="link">Link</label>
<input type="text" class="form-control" id="link" name="link" ngModel required>
</div>
<div class="form-group">
<label for="content">Content</label>
<input type="text" class="form-control" id="content" name="content" ngModel required>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { WorksListComponent } from './works-list.component';
describe('WorksListComponent', () => {
let component: WorksListComponent;
let fixture: ComponentFixture<WorksListComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [WorksListComponent]
})
.compileComponents();
fixture = TestBed.createComponent(WorksListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

@ -0,0 +1,30 @@
import {Component} from '@angular/core';
import {Work} from "../../models/work.model";
import {WorksService} from "../../services/works.service";
import {NgForOf} from "@angular/common";
import {FormsModule, NgForm} from "@angular/forms";
@Component({
selector: 'app-works-list',
standalone: true,
imports: [
NgForOf,
FormsModule
],
templateUrl: './works-list.component.html',
styleUrl: './works-list.component.css'
})
export class WorksListComponent {
works: Work[] = [];
constructor(protected workService: WorksService) {
}
ngOnInit() {
this.workService.getWorks().subscribe((response: Work[]) => this.works = response)
}
onSubmit(form: NgForm) {
this.workService.postWork(form);
}
}

@ -0,0 +1,7 @@
export interface Work {
id_work: number,
link: string,
user_id: number,
language_id: number,
content: string
}

@ -0,0 +1,32 @@
import {Injectable} from '@angular/core';
import {Work} from "../models/work.model";
import {HttpClient} from "@angular/common/http";
import {Observable} from "rxjs";
import {NgForm} from "@angular/forms";
@Injectable({
providedIn: 'root'
})
export class WorksService {
API_URL = 'http://127.0.0.1:3000'
private works: Work[] = [];
constructor(private http: HttpClient) {
}
getWorks(): Observable<any> {
return this.http.get(`${this.API_URL}/works`);
}
postWork(form: NgForm): void {
let body = {link: form.value.link, id_user: 1, id_language: 1, code: form.value.content}
this.http.post<any>(`${this.API_URL}/works`, body).subscribe();
}
postWorkCode(code: string): void {
let body = {link: 'TODO', id_user: 1, id_language: 1, code: code}
this.http.post<any>(`${this.API_URL}/works`, body).subscribe();
}
}
Loading…
Cancel
Save