parent
23a7316af1
commit
729f7f9a45
@ -1,132 +1,63 @@
|
|||||||
# ---> Node
|
.DS_STORE
|
||||||
# Logs
|
|
||||||
logs
|
|
||||||
*.log
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
lerna-debug.log*
|
|
||||||
.pnpm-debug.log*
|
|
||||||
|
|
||||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
|
||||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
|
||||||
|
|
||||||
# Runtime data
|
|
||||||
pids
|
|
||||||
*.pid
|
|
||||||
*.seed
|
|
||||||
*.pid.lock
|
|
||||||
|
|
||||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
|
||||||
lib-cov
|
|
||||||
|
|
||||||
# Coverage directory used by tools like istanbul
|
|
||||||
coverage
|
|
||||||
*.lcov
|
|
||||||
|
|
||||||
# nyc test coverage
|
|
||||||
.nyc_output
|
|
||||||
|
|
||||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
|
||||||
.grunt
|
|
||||||
|
|
||||||
# Bower dependency directory (https://bower.io/)
|
|
||||||
bower_components
|
|
||||||
|
|
||||||
# node-waf configuration
|
|
||||||
.lock-wscript
|
|
||||||
|
|
||||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
|
||||||
build/Release
|
|
||||||
|
|
||||||
# Dependency directories
|
|
||||||
node_modules/
|
|
||||||
jspm_packages/
|
|
||||||
|
|
||||||
# Snowpack dependency directory (https://snowpack.dev/)
|
|
||||||
web_modules/
|
|
||||||
|
|
||||||
# TypeScript cache
|
|
||||||
*.tsbuildinfo
|
|
||||||
|
|
||||||
# Optional npm cache directory
|
|
||||||
.npm
|
|
||||||
|
|
||||||
# Optional eslint cache
|
|
||||||
.eslintcache
|
|
||||||
|
|
||||||
# Optional stylelint cache
|
|
||||||
.stylelintcache
|
|
||||||
|
|
||||||
# Microbundle cache
|
|
||||||
.rpt2_cache/
|
|
||||||
.rts2_cache_cjs/
|
|
||||||
.rts2_cache_es/
|
|
||||||
.rts2_cache_umd/
|
|
||||||
|
|
||||||
# Optional REPL history
|
|
||||||
.node_repl_history
|
|
||||||
|
|
||||||
# Output of 'npm pack'
|
|
||||||
*.tgz
|
|
||||||
|
|
||||||
# Yarn Integrity file
|
|
||||||
.yarn-integrity
|
|
||||||
|
|
||||||
# dotenv environment variable files
|
|
||||||
.env
|
|
||||||
.env.development.local
|
|
||||||
.env.test.local
|
|
||||||
.env.production.local
|
|
||||||
.env.local
|
|
||||||
|
|
||||||
# parcel-bundler cache (https://parceljs.org/)
|
|
||||||
.cache
|
|
||||||
.parcel-cache
|
|
||||||
|
|
||||||
# Next.js build output
|
|
||||||
.next
|
|
||||||
out
|
|
||||||
|
|
||||||
# Nuxt.js build / generate output
|
|
||||||
.nuxt
|
|
||||||
dist
|
|
||||||
|
|
||||||
# Gatsby files
|
|
||||||
.cache/
|
|
||||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
|
||||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
|
||||||
# public
|
|
||||||
|
|
||||||
# vuepress build output
|
|
||||||
.vuepress/dist
|
|
||||||
|
|
||||||
# vuepress v2.x temp and cache directory
|
|
||||||
.temp
|
|
||||||
.cache
|
|
||||||
|
|
||||||
# Docusaurus cache and generated files
|
|
||||||
.docusaurus
|
|
||||||
|
|
||||||
# Serverless directories
|
|
||||||
.serverless/
|
|
||||||
|
|
||||||
# FuseBox cache
|
|
||||||
.fusebox/
|
|
||||||
|
|
||||||
# DynamoDB Local files
|
|
||||||
.dynamodb/
|
|
||||||
|
|
||||||
# TernJS port file
|
|
||||||
.tern-port
|
|
||||||
|
|
||||||
# Stores VSCode versions used for testing VSCode extensions
|
|
||||||
.vscode-test
|
|
||||||
|
|
||||||
# yarn v2
|
|
||||||
.yarn/cache
|
|
||||||
.yarn/unplugged
|
|
||||||
.yarn/build-state.yml
|
|
||||||
.yarn/install-state.gz
|
|
||||||
.pnp.*
|
|
||||||
|
|
||||||
|
/dist/
|
||||||
|
/bazel-out
|
||||||
|
/integration/bazel/bazel-*
|
||||||
|
*.log
|
||||||
|
/node_modules/
|
||||||
|
|
||||||
|
# CircleCI temporary file for cache key computation.
|
||||||
|
# See `save_month_to_file` in `.circleci/config.yml`.
|
||||||
|
month.txt
|
||||||
|
|
||||||
|
# Include when developing application packages.
|
||||||
|
pubspec.lock
|
||||||
|
.c9
|
||||||
|
.idea/
|
||||||
|
.devcontainer/*
|
||||||
|
!.devcontainer/README.md
|
||||||
|
!.devcontainer/recommended-devcontainer.json
|
||||||
|
!.devcontainer/recommended-Dockerfile
|
||||||
|
.settings/
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/settings.json
|
||||||
|
.vscode/tasks.json
|
||||||
|
*.swo
|
||||||
|
*.swp
|
||||||
|
modules/.settings
|
||||||
|
modules/.vscode
|
||||||
|
.vimrc
|
||||||
|
.nvimrc
|
||||||
|
|
||||||
|
# Don't check in secret files
|
||||||
|
*secret.js
|
||||||
|
|
||||||
|
# Ignore npm/yarn debug log
|
||||||
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
|
|
||||||
|
# build-analytics
|
||||||
|
.build-analytics
|
||||||
|
|
||||||
|
# rollup-test output
|
||||||
|
/modules/rollup-test/dist/
|
||||||
|
|
||||||
|
# User specific bazel settings
|
||||||
|
.bazelrc.user
|
||||||
|
|
||||||
|
# User specific ng-dev settings
|
||||||
|
.ng-dev.user*
|
||||||
|
|
||||||
|
.notes.md
|
||||||
|
baseline.json
|
||||||
|
|
||||||
|
# Ignore .history for the xyz.local-history VSCode extension
|
||||||
|
.history
|
||||||
|
|
||||||
|
# Husky
|
||||||
|
.husky/_
|
||||||
|
aio/content/examples/.DS_Store
|
||||||
|
|
||||||
|
|
||||||
|
# Ignore cache created with the Angular CLI.
|
||||||
|
.angular/
|
@ -0,0 +1,100 @@
|
|||||||
|
{
|
||||||
|
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||||
|
"version": 1,
|
||||||
|
"newProjectRoot": "projects",
|
||||||
|
"projects": {
|
||||||
|
"angular-tp1": {
|
||||||
|
"projectType": "application",
|
||||||
|
"schematics": {},
|
||||||
|
"root": "",
|
||||||
|
"sourceRoot": "src",
|
||||||
|
"prefix": "app",
|
||||||
|
"architect": {
|
||||||
|
"build": {
|
||||||
|
"builder": "@angular-devkit/build-angular:application",
|
||||||
|
"options": {
|
||||||
|
"outputPath": "dist/angular-tp1",
|
||||||
|
"index": "src/index.html",
|
||||||
|
"browser": "src/main.ts",
|
||||||
|
"polyfills": [
|
||||||
|
"zone.js"
|
||||||
|
],
|
||||||
|
"tsConfig": "tsconfig.app.json",
|
||||||
|
"assets": [
|
||||||
|
"src/favicon.ico",
|
||||||
|
"src/assets"
|
||||||
|
],
|
||||||
|
"styles": [
|
||||||
|
"@angular/material/prebuilt-themes/indigo-pink.css",
|
||||||
|
"src/styles.css"
|
||||||
|
],
|
||||||
|
"scripts": []
|
||||||
|
},
|
||||||
|
"configurations": {
|
||||||
|
"production": {
|
||||||
|
"budgets": [
|
||||||
|
{
|
||||||
|
"type": "initial",
|
||||||
|
"maximumWarning": "500kb",
|
||||||
|
"maximumError": "1mb"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "anyComponentStyle",
|
||||||
|
"maximumWarning": "2kb",
|
||||||
|
"maximumError": "4kb"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputHashing": "all"
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"optimization": false,
|
||||||
|
"extractLicenses": false,
|
||||||
|
"sourceMap": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultConfiguration": "production"
|
||||||
|
},
|
||||||
|
"serve": {
|
||||||
|
"builder": "@angular-devkit/build-angular:dev-server",
|
||||||
|
"configurations": {
|
||||||
|
"production": {
|
||||||
|
"buildTarget": "angular-tp1:build:production"
|
||||||
|
},
|
||||||
|
"development": {
|
||||||
|
"buildTarget": "angular-tp1:build:development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultConfiguration": "development"
|
||||||
|
},
|
||||||
|
"extract-i18n": {
|
||||||
|
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||||
|
"options": {
|
||||||
|
"buildTarget": "angular-tp1:build"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
|
"builder": "@angular-devkit/build-angular:karma",
|
||||||
|
"options": {
|
||||||
|
"polyfills": [
|
||||||
|
"zone.js",
|
||||||
|
"zone.js/testing"
|
||||||
|
],
|
||||||
|
"tsConfig": "tsconfig.spec.json",
|
||||||
|
"assets": [
|
||||||
|
"src/favicon.ico",
|
||||||
|
"src/assets"
|
||||||
|
],
|
||||||
|
"styles": [
|
||||||
|
"@angular/material/prebuilt-themes/indigo-pink.css",
|
||||||
|
"src/styles.css"
|
||||||
|
],
|
||||||
|
"scripts": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cli": {
|
||||||
|
"analytics": "b31500bf-2432-4ea2-87ed-39312b79e8d0"
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"name": "angular-tp1",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"scripts": {
|
||||||
|
"ng": "ng",
|
||||||
|
"start": "ng serve",
|
||||||
|
"build": "ng build",
|
||||||
|
"watch": "ng build --watch --configuration development",
|
||||||
|
"test": "ng test"
|
||||||
|
},
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@angular/animations": "^17.3.0",
|
||||||
|
"@angular/cdk": "^17.3.10",
|
||||||
|
"@angular/common": "^17.3.0",
|
||||||
|
"@angular/compiler": "^17.3.0",
|
||||||
|
"@angular/core": "^17.3.0",
|
||||||
|
"@angular/forms": "^17.3.0",
|
||||||
|
"@angular/material": "^17.3.10",
|
||||||
|
"@angular/platform-browser": "^17.3.0",
|
||||||
|
"@angular/platform-browser-dynamic": "^17.3.0",
|
||||||
|
"@angular/router": "^17.3.0",
|
||||||
|
"rxjs": "~7.8.0",
|
||||||
|
"tslib": "^2.3.0",
|
||||||
|
"zone.js": "~0.14.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@angular-devkit/build-angular": "^17.3.7",
|
||||||
|
"@angular/cli": "^17.3.7",
|
||||||
|
"@angular/compiler-cli": "^17.3.0",
|
||||||
|
"typescript": "~5.4.2"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
<app-book-menu></app-book-menu>
|
||||||
|
|
||||||
|
<router-outlet (activate)="onActivate($event)"></router-outlet>
|
@ -0,0 +1,9 @@
|
|||||||
|
import { ApplicationConfig, LOCALE_ID } from '@angular/core';
|
||||||
|
import { provideRouter } from '@angular/router';
|
||||||
|
|
||||||
|
import { routes } from './app.routes';
|
||||||
|
import { provideAnimationsAsync } from '@angular/platform-browser/animations/async';
|
||||||
|
|
||||||
|
export const appConfig: ApplicationConfig = {
|
||||||
|
providers: [provideRouter(routes), provideAnimationsAsync(), provideAnimationsAsync(), { provide: LOCALE_ID, useValue: 'fr-FR' }]
|
||||||
|
};
|
@ -0,0 +1,13 @@
|
|||||||
|
import { Routes } from '@angular/router';
|
||||||
|
import { BookListComponent } from './components/book-list/book-list.component';
|
||||||
|
import { BookFormComponent } from './components/book-form/book-form.component';
|
||||||
|
import { BookDetailComponent } from './components/book-detail/book-detail.component';
|
||||||
|
import { BookHomeComponent } from './components/book-home/book-home.component';
|
||||||
|
|
||||||
|
export const routes: Routes = [
|
||||||
|
{ path: '', component: BookHomeComponent },
|
||||||
|
{ path: 'books', component: BookListComponent },
|
||||||
|
{ path: 'book/add', component: BookFormComponent },
|
||||||
|
{ path: 'book/:id', component: BookDetailComponent },
|
||||||
|
{ path: '**', redirectTo: '', pathMatch: 'full' }
|
||||||
|
];
|
@ -0,0 +1,12 @@
|
|||||||
|
<div *ngIf="selectedBook">
|
||||||
|
<h2>{{selectedBook.title | uppercase}}</h2>
|
||||||
|
<div><span>id: </span>{{selectedBook.id}}</div>
|
||||||
|
<div>
|
||||||
|
<label for="book-author">Auteur : </label>
|
||||||
|
{{ selectedBook.author }}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="book-publicationDate">Date de publication : </label>
|
||||||
|
{{ selectedBook.publicationDate | date: 'EEEE d MMMM y' }}
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -0,0 +1,25 @@
|
|||||||
|
import { Component} from '@angular/core';
|
||||||
|
import { UpperCasePipe, DatePipe, NgIf} from '@angular/common';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
|
||||||
|
import { Book } from '../../models/book.model';
|
||||||
|
import { BookService } from '../../services/book-service';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
standalone: true,
|
||||||
|
selector: 'app-book-detail',
|
||||||
|
imports: [DatePipe, UpperCasePipe, NgIf],
|
||||||
|
templateUrl: './book-detail.component.html',
|
||||||
|
styles: ``
|
||||||
|
})
|
||||||
|
export class BookDetailComponent {
|
||||||
|
selectedBook!: Book | undefined;
|
||||||
|
|
||||||
|
constructor(protected bookService: BookService, private activatedRoute: ActivatedRoute) {}
|
||||||
|
|
||||||
|
ngOnInit(){
|
||||||
|
const id = this.activatedRoute.snapshot.params['id'];
|
||||||
|
this.selectedBook = this.bookService.getBookById(id);
|
||||||
|
console.log(this.selectedBook);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
<section>
|
||||||
|
<h2>Add book form</h2>
|
||||||
|
|
||||||
|
<form [formGroup]="bookForm">
|
||||||
|
<div>
|
||||||
|
<mat-form-field class="full-width">
|
||||||
|
<mat-label>Title</mat-label>
|
||||||
|
<input matInput type="text" formControlName="title" />
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<mat-form-field class="full-width">
|
||||||
|
<mat-label>Author</mat-label>
|
||||||
|
<input matInput type="text" formControlName="author" />
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<mat-form-field class="full-width">
|
||||||
|
<mat-label>Publication date</mat-label>
|
||||||
|
<input matInput [matDatepicker]="picker" type="text" formControlName="publicationDate" />
|
||||||
|
<mat-datepicker-toggle matIconSuffix [for]="picker"></mat-datepicker-toggle>
|
||||||
|
<mat-datepicker #picker></mat-datepicker>
|
||||||
|
</mat-form-field>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button mat-flat-button color="primary" type="button" (click)="addBook()">Add</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
@ -0,0 +1,49 @@
|
|||||||
|
import { Component, EventEmitter, Output } from '@angular/core';
|
||||||
|
|
||||||
|
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||||
|
import { Book } from '../../models/book.model';
|
||||||
|
|
||||||
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatNativeDateModule } from '@angular/material/core';
|
||||||
|
import { MatDatepickerModule } from '@angular/material/datepicker';
|
||||||
|
import { MatFormFieldModule } from '@angular/material/form-field';
|
||||||
|
import { MatInputModule } from '@angular/material/input';
|
||||||
|
import { MatMenuModule } from '@angular/material/menu';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-book-form',
|
||||||
|
standalone: true,
|
||||||
|
imports: [
|
||||||
|
MatFormFieldModule,
|
||||||
|
MatInputModule,
|
||||||
|
MatButtonModule,
|
||||||
|
MatMenuModule,
|
||||||
|
MatDatepickerModule,
|
||||||
|
MatNativeDateModule,
|
||||||
|
FormsModule,
|
||||||
|
ReactiveFormsModule
|
||||||
|
],
|
||||||
|
templateUrl: './book-form.component.html'
|
||||||
|
})
|
||||||
|
export class BookFormComponent {
|
||||||
|
@Output() addBookEvent = new EventEmitter<Book>();
|
||||||
|
|
||||||
|
book: Book = { id: 0, title: '', author: '', publicationDate: new Date() }
|
||||||
|
bookForm: FormGroup = new FormGroup({
|
||||||
|
title: new FormControl(this.book.title, Validators.required),
|
||||||
|
author: new FormControl(this.book.author, Validators.required),
|
||||||
|
publicationDate: new FormControl(this.book.publicationDate, Validators.required)
|
||||||
|
});
|
||||||
|
|
||||||
|
addBook() {
|
||||||
|
if (this.bookForm.invalid) {
|
||||||
|
console.log("ERREUR");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.book = this.bookForm.value;
|
||||||
|
|
||||||
|
this.addBookEvent.emit(this.book);
|
||||||
|
this.bookForm.reset();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
<h1>Bienvenue sur la page d'accueil du Book Shop</h1>
|
@ -0,0 +1,12 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-book-home',
|
||||||
|
standalone: true,
|
||||||
|
imports: [],
|
||||||
|
templateUrl: './book-home.component.html',
|
||||||
|
styles: ``
|
||||||
|
})
|
||||||
|
export class BookHomeComponent {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
<h2>Book list</h2>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li *ngFor="let book of books">
|
||||||
|
<a routerLink="/book/{{ book.id }}">{{ book.title }}</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
@ -0,0 +1,23 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { RouterModule } from '@angular/router';
|
||||||
|
import { NgFor, DatePipe } from '@angular/common';
|
||||||
|
|
||||||
|
import { Book } from '../../models/book.model';
|
||||||
|
import { BookService } from '../../services/book-service'
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-book-list',
|
||||||
|
standalone: true,
|
||||||
|
imports: [NgFor, DatePipe, RouterModule],
|
||||||
|
templateUrl: './book-list.component.html'
|
||||||
|
})
|
||||||
|
export class BookListComponent {
|
||||||
|
books: Book[] = [];
|
||||||
|
|
||||||
|
constructor(protected bookService: BookService){
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit(){
|
||||||
|
this.books = this.bookService.getAll();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
<button mat-button [matMenuTriggerFor]="menu">Menu</button>
|
||||||
|
<mat-menu #menu="matMenu">
|
||||||
|
<a mat-menu-item routerLink="/" routerLinkActive="active" ariaCurrentWhenActive="page">Accueil</a>
|
||||||
|
<a mat-menu-item routerLink="/books" routerLinkActive="active" ariaCurrentWhenActive="page">Liste des livres</a>
|
||||||
|
<a mat-menu-item routerLink="/book/add" routerLinkActive="active" ariaCurrentWhenActive="page">Ajouter un livre</a>
|
||||||
|
</mat-menu>
|
@ -0,0 +1,15 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { RouterModule } from '@angular/router';
|
||||||
|
|
||||||
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { MatMenuModule } from '@angular/material/menu';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-book-menu',
|
||||||
|
standalone: true,
|
||||||
|
imports: [RouterModule, MatButtonModule, MatMenuModule],
|
||||||
|
templateUrl: './book-menu.component.html'
|
||||||
|
})
|
||||||
|
export class BookMenuComponent {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
<p>Un formulaire reactive-driven avec affichage en console</p>
|
||||||
|
|
||||||
|
<form [formGroup]="bookForm">
|
||||||
|
<div>
|
||||||
|
<label for="title">Titre</label>
|
||||||
|
<input type="text" id="title" formControlName="title" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="author">Auteur</label>
|
||||||
|
<input type="text" id="author" formControlName="author" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="publicationDate">Date de publication</label>
|
||||||
|
<input type="picker" id="publicationDate" formControlName="publicationDate" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="button" (click)="addBook()">Add</button>
|
||||||
|
</form>
|
@ -0,0 +1,41 @@
|
|||||||
|
import { Component, EventEmitter, Output } from '@angular/core';
|
||||||
|
import { FormControl, FormBuilder, ReactiveFormsModule, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { Book } from '../../models/book.model';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-test-form-reactive',
|
||||||
|
standalone: true,
|
||||||
|
imports: [ReactiveFormsModule],
|
||||||
|
templateUrl: './test-form-reactive.component.html'
|
||||||
|
})
|
||||||
|
export class TestFormReactiveComponent {
|
||||||
|
@Output() addBookEvent = new EventEmitter<Book>();
|
||||||
|
|
||||||
|
constructor(private fb: FormBuilder) {
|
||||||
|
}
|
||||||
|
|
||||||
|
book: Book = { id: 0, title: '', author: '', publicationDate: new Date() }
|
||||||
|
bookForm: FormGroup = this.fb.group({
|
||||||
|
title: ['', [Validators.required]],
|
||||||
|
author: ['', [Validators.required]],
|
||||||
|
publicationDate: ['', [Validators.required]]
|
||||||
|
});
|
||||||
|
|
||||||
|
//VARIANTE POSSIBLE AVEC FORMGROUP
|
||||||
|
/*bookForm: FormGroup = new FormGroup({
|
||||||
|
title: new FormControl(this.book.title, Validators.required),
|
||||||
|
author: new FormControl(this.book.author, Validators.required),
|
||||||
|
publicationDate: new FormControl(this.book.publicationDate, Validators.required)
|
||||||
|
});*/
|
||||||
|
|
||||||
|
addBook() {
|
||||||
|
if(this.bookForm.invalid) {
|
||||||
|
console.log('Le formulaire reactive-driven est mal rempli');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.book = this.bookForm.value;
|
||||||
|
console.log('Résultat du formulaire reactive-driven : ', this.book);
|
||||||
|
// Envoyer un évènement au parent avec la variable remplie
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<p>Un formulaire template-driven avec affichage en console</p>
|
||||||
|
|
||||||
|
<form #bookForm="ngForm" (ngSubmit)="onSubmit()">
|
||||||
|
<div>
|
||||||
|
<label for="title">Titre</label>
|
||||||
|
<input type="text" id="title" name="title" [(ngModel)]="book.title" required />
|
||||||
|
<div>
|
||||||
|
</div>
|
||||||
|
<label for="author">Nom</label>
|
||||||
|
<input type="text" id="author" name="author" [(ngModel)]="book.author" required />
|
||||||
|
</div>
|
||||||
|
<input type="submit" [disabled]="bookForm.invalid" value="ENVOYER" />
|
||||||
|
</form>
|
@ -0,0 +1,20 @@
|
|||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-test-form-template',
|
||||||
|
standalone: true,
|
||||||
|
imports: [FormsModule],
|
||||||
|
templateUrl: './test-form-template.component.html'
|
||||||
|
})
|
||||||
|
export class TestFormTemplateComponent {
|
||||||
|
book = {
|
||||||
|
title: '',
|
||||||
|
author: ''
|
||||||
|
};
|
||||||
|
|
||||||
|
onSubmit() {
|
||||||
|
console.log('Résultat du formulaire template-driven : ', this.book);
|
||||||
|
// Envoyer un évènement au parent avec la variable remplie
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
import { Book } from "../models/book.model";
|
||||||
|
|
||||||
|
export const BOOKS: Book[] = [
|
||||||
|
{ id: 1, title: 'The Lord of the Rings - The Fellowship of the Ring', author: 'J.R.R. Tolkien', publicationDate: new Date('07/29/1954') },
|
||||||
|
{ id: 2, title: 'The Lord of the Rings - The Two Towers', author: 'J.R.R. Tolkien', publicationDate: new Date('11/11/1954') },
|
||||||
|
{ id: 3, title: 'The Lord of the Rings - The Return of the King', author: 'J.R.R. Tolkien', publicationDate: new Date('10/20/1955') },
|
||||||
|
{ id: 4, title: 'Dune', author: 'Frank Herbert', publicationDate: new Date('1965') },
|
||||||
|
{ id: 5, title: 'Dune Messiah', author: 'Frank Herbert', publicationDate: new Date('1969') },
|
||||||
|
{ id: 6, title: 'It', author: 'Stephen King', publicationDate: new Date('09/15/1986') },
|
||||||
|
{ id: 7, title: 'Do Androids Dream of Electric Sheep?', author: 'Philip K. Dick', publicationDate: new Date('1968') }
|
||||||
|
];
|
@ -0,0 +1,6 @@
|
|||||||
|
export interface Book {
|
||||||
|
id: number,
|
||||||
|
title: string,
|
||||||
|
author: string,
|
||||||
|
publicationDate: Date
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
||||||
|
import { Injectable } from "@angular/core";
|
||||||
|
import { BOOKS } from "../datas/books.stub";
|
||||||
|
import { Book } from "../models/book.model";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BookService {
|
||||||
|
private books: Book[];
|
||||||
|
private readonly bookApiUrl = 'https://66e8848bb17821a9d9dcf68c.mockapi.io/books';
|
||||||
|
|
||||||
|
public constructor(private http: HttpClient){
|
||||||
|
this.books = BOOKS;
|
||||||
|
|
||||||
|
this.http.get<Book[]>(this.bookApiUrl).subscribe(books => {
|
||||||
|
books.forEach(b => {
|
||||||
|
this.addBookToLocal(b);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public getAll(): Book[]{
|
||||||
|
return this.books;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getBookById(id: number): Book | undefined{
|
||||||
|
return this.books.find(b => b.id === id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public addBook(book: Book): void{
|
||||||
|
this.addBookToLocal(book);
|
||||||
|
this.addBookToApi(book);
|
||||||
|
}
|
||||||
|
|
||||||
|
private addBookToLocal(book: Book): void{
|
||||||
|
console.log('addBookToLocal', book);
|
||||||
|
if(book.id === 0){
|
||||||
|
book.id = Math.max(...this.books.map(b => b.id)) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const existedBook = this.books.find(b => b.title === book.title || b.id === Number(book.id));
|
||||||
|
if(existedBook)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.books.push(book);
|
||||||
|
}
|
||||||
|
|
||||||
|
private addBookToApi(book: Book): void{
|
||||||
|
this.http.post<Book>(this.bookApiUrl, book).subscribe();
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 15 KiB |
@ -0,0 +1,15 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>AngularTp1</title>
|
||||||
|
<base href="/">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
|
||||||
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<app-root></app-root>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,10 @@
|
|||||||
|
import { bootstrapApplication } from '@angular/platform-browser';
|
||||||
|
import { appConfig } from './app/app.config';
|
||||||
|
import { AppComponent } from './app/app.component';
|
||||||
|
import { registerLocaleData } from '@angular/common';
|
||||||
|
import * as fr from '@angular/common/locales/fr';
|
||||||
|
|
||||||
|
registerLocaleData(fr.default);
|
||||||
|
|
||||||
|
bootstrapApplication(AppComponent, appConfig)
|
||||||
|
.catch((err) => console.error(err));
|
@ -0,0 +1,4 @@
|
|||||||
|
/* You can add global styles to this file, and also import other style files */
|
||||||
|
|
||||||
|
html, body { height: 100%; }
|
||||||
|
body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; }
|
@ -0,0 +1,14 @@
|
|||||||
|
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./out-tsc/app",
|
||||||
|
"types": []
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/main.ts"
|
||||||
|
],
|
||||||
|
"include": [
|
||||||
|
"src/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||||
|
{
|
||||||
|
"compileOnSave": false,
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./dist/out-tsc",
|
||||||
|
"strict": true,
|
||||||
|
"noImplicitOverride": true,
|
||||||
|
"noPropertyAccessFromIndexSignature": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"sourceMap": true,
|
||||||
|
"declaration": false,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"moduleResolution": "node",
|
||||||
|
"importHelpers": true,
|
||||||
|
"target": "ES2022",
|
||||||
|
"module": "ES2022",
|
||||||
|
"useDefineForClassFields": false,
|
||||||
|
"lib": [
|
||||||
|
"ES2022",
|
||||||
|
"dom"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"angularCompilerOptions": {
|
||||||
|
"enableI18nLegacyMessageIdFormat": false,
|
||||||
|
"strictInjectionParameters": true,
|
||||||
|
"strictInputAccessModifiers": true,
|
||||||
|
"strictTemplates": true
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
||||||
|
{
|
||||||
|
"extends": "./tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./out-tsc/spec",
|
||||||
|
"types": [
|
||||||
|
"jasmine"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/**/*.spec.ts",
|
||||||
|
"src/**/*.d.ts"
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in new issue