Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
733bb03
commit 351ad5e
Showing
8 changed files
with
237 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
BookStore-Angular-MongoDb/angular/src/app/book/create-book/create-book.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<div class="card"> | ||
<div class="card-body"> | ||
<form [formGroup]="form" (ngSubmit)="save()"> | ||
<div class="form-group"> | ||
<label for="author-id">Author</label><span> * </span> | ||
<select class="form-control" id="author-id" formControlName="authorId"> | ||
<option [ngValue]="null">Select author</option> | ||
<option [ngValue]="author.id" *ngFor="let author of authors$ | async"> | ||
{{ author.name }} | ||
</option> | ||
</select> | ||
</div> | ||
|
||
<div class="mt-2"> | ||
<label for="book-name">Name</label><span> * </span> | ||
<input type="text" id="book-name" class="form-control" formControlName="name" autofocus /> | ||
</div> | ||
|
||
<div class="mt-2"> | ||
<label for="book-price">Price</label><span> * </span> | ||
<input type="number" id="book-price" class="form-control" formControlName="price" /> | ||
</div> | ||
|
||
<div class="mt-2"> | ||
<label for="book-type">Type</label><span> * </span> | ||
<select class="form-control" id="book-type" formControlName="type"> | ||
<option [ngValue]="null">Select a book type</option> | ||
<option [ngValue]="type.value" *ngFor="let type of bookTypes"> | ||
{{ '::Enum:BookType.' + type.value | abpLocalization }} | ||
</option> | ||
</select> | ||
</div> | ||
|
||
<div class="mt-2"> | ||
<label>Publish date</label><span> * </span> | ||
<input | ||
#datepicker="ngbDatepicker" | ||
class="form-control" | ||
name="datepicker" | ||
formControlName="publishDate" | ||
ngbDatepicker | ||
(click)="datepicker.toggle()" | ||
/> | ||
</div> | ||
|
||
<div class="pt-2"> | ||
<button type="button" class="btn btn-secondary m-1" [routerLink]="['/books']"> | ||
{{ '::Cancel' | abpLocalization }} | ||
</button> | ||
|
||
<button class="btn btn-primary"> | ||
<i class="fa fa-check mr-1"></i> | ||
{{ '::Save' | abpLocalization }} | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> |
45 changes: 45 additions & 0 deletions
45
BookStore-Angular-MongoDb/angular/src/app/book/create-book/create-book.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Component, inject } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; | ||
import { map } from 'rxjs'; | ||
import { NgbDateNativeAdapter, NgbDateAdapter } from '@ng-bootstrap/ng-bootstrap'; | ||
import { BookService, bookTypeOptions } from '@proxy/books'; | ||
|
||
const { required } = Validators; | ||
|
||
@Component({ | ||
selector: 'app-create-book', | ||
templateUrl: './create-book.component.html', | ||
providers: [{ provide: NgbDateAdapter, useClass: NgbDateNativeAdapter }], | ||
}) | ||
export class CreateBookComponent { | ||
private readonly router = inject(Router); | ||
private readonly fb = inject(FormBuilder); | ||
private readonly bookService = inject(BookService); | ||
|
||
form: FormGroup; | ||
authors$ = this.bookService.getAuthorLookup().pipe(map(({ items }) => items)); | ||
bookTypes = bookTypeOptions; | ||
|
||
private buildForm() { | ||
this.form = this.fb.group({ | ||
authorId: [null, required], | ||
name: [null, required], | ||
type: [null, required], | ||
publishDate: [undefined, required], | ||
price: [null, required], | ||
}); | ||
} | ||
|
||
constructor() { | ||
this.buildForm(); | ||
} | ||
|
||
save() { | ||
if (this.form.invalid) return; | ||
|
||
this.bookService.create(this.form.value).subscribe(() => { | ||
this.router.navigate(['/books']); | ||
}); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
BookStore-Angular-MongoDb/angular/src/app/book/edit-book/edit-book.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<div class="card"> | ||
<div class="card-body"> | ||
<form *ngIf="form" [formGroup]="form" (ngSubmit)="save()"> | ||
<div class="form-group"> | ||
<label for="author-id">Author</label><span> * </span> | ||
<select class="form-control" id="author-id" formControlName="authorId"> | ||
<option [ngValue]="null">Select author</option> | ||
<option [ngValue]="author.id" *ngFor="let author of authors$ | async"> | ||
{{ author.name }} | ||
</option> | ||
</select> | ||
</div> | ||
|
||
<div class="mt-2"> | ||
<label for="book-name">Name</label><span> * </span> | ||
<input type="text" id="book-name" class="form-control" formControlName="name" autofocus /> | ||
</div> | ||
|
||
<div class="mt-2"> | ||
<label for="book-price">Price</label><span> * </span> | ||
<input type="number" id="book-price" class="form-control" formControlName="price" /> | ||
</div> | ||
|
||
<div class="mt-2"> | ||
<label for="book-type">Type</label><span> * </span> | ||
<select class="form-control" id="book-type" formControlName="type"> | ||
<option [ngValue]="null">Select a book type</option> | ||
<option [ngValue]="type.value" *ngFor="let type of bookTypes"> | ||
{{ '::Enum:BookType.' + type.value | abpLocalization }} | ||
</option> | ||
</select> | ||
</div> | ||
|
||
<div class="mt-2"> | ||
<label>Publish date</label><span> * </span> | ||
<input | ||
#datepicker="ngbDatepicker" | ||
class="form-control" | ||
name="datepicker" | ||
formControlName="publishDate" | ||
ngbDatepicker | ||
(click)="datepicker.toggle()" | ||
/> | ||
</div> | ||
|
||
<div class="pt-2"> | ||
<button type="button" class="btn btn-secondary m-1" [routerLink]="['/books']"> | ||
{{ '::Cancel' | abpLocalization }} | ||
</button> | ||
|
||
<button class="btn btn-primary"> | ||
<i class="fa fa-check mr-1"></i> | ||
{{ '::Save' | abpLocalization }} | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> |
Oops, something went wrong.