@@ -1,5 +1,6 @@
|
|
1 |
import { CommonModule } from '@angular/common';
|
2 |
import { NgModule } from '@angular/core';
|
|
|
3 |
|
4 |
import { AppRoutingModule } from './app-routing.module.one-app';
|
5 |
import { AppComponent } from './app.component';
|
@@ -18,6 +19,7 @@
|
|
18 |
],
|
19 |
imports: [
|
20 |
CommonModule,
|
|
|
21 |
AppRoutingModule
|
22 |
],
|
23 |
providers: [],
|
1 |
import { CommonModule } from '@angular/common';
|
2 |
import { NgModule } from '@angular/core';
|
3 |
+
import { HttpClientModule } from '@angular/common/http';
|
4 |
|
5 |
import { AppRoutingModule } from './app-routing.module.one-app';
|
6 |
import { AppComponent } from './app.component';
|
19 |
],
|
20 |
imports: [
|
21 |
CommonModule,
|
22 |
+
HttpClientModule,
|
23 |
AppRoutingModule
|
24 |
],
|
25 |
providers: [],
|
@@ -1,4 +1,4 @@
|
|
1 |
-
<div *ngIf="book">
|
2 |
<h1>{{ book.title }}</h1>
|
3 |
<h3 *ngIf="book.subtitle">{{ book.subtitle }}</h3>
|
4 |
<div class="ui divider"></div>
|
@@ -29,4 +29,12 @@
|
|
29 |
<img *ngFor="let thumbnail of book.thumbnails"
|
30 |
[src]="thumbnail.url">
|
31 |
</div>
|
|
|
|
|
|
|
|
|
32 |
</div>
|
|
|
|
|
|
|
|
1 |
+
<div *ngIf="book; else loading">
|
2 |
<h1>{{ book.title }}</h1>
|
3 |
<h3 *ngIf="book.subtitle">{{ book.subtitle }}</h3>
|
4 |
<div class="ui divider"></div>
|
29 |
<img *ngFor="let thumbnail of book.thumbnails"
|
30 |
[src]="thumbnail.url">
|
31 |
</div>
|
32 |
+
<button class="ui tiny red labeled icon button"
|
33 |
+
(click)="removeBook()">
|
34 |
+
<i class="remove icon"></i> Buch löschen
|
35 |
+
</button>
|
36 |
</div>
|
37 |
+
|
38 |
+
<ng-template #loading>
|
39 |
+
<div class="ui active centered inline loader"></div>
|
40 |
+
</ng-template>
|
@@ -1,5 +1,5 @@
|
|
1 |
import { Component, OnInit } from '@angular/core';
|
2 |
-
import { ActivatedRoute } from '@angular/router';
|
3 |
|
4 |
import { Book } from '../shared/book';
|
5 |
import { BookStoreService } from '../shared/book-store.service';
|
@@ -14,16 +14,24 @@
|
|
14 |
|
15 |
constructor(
|
16 |
private bs: BookStoreService,
|
|
|
17 |
private route: ActivatedRoute
|
18 |
) { }
|
19 |
|
20 |
ngOnInit(): void {
|
21 |
const params = this.route.snapshot.paramMap;
|
22 |
-
|
23 |
-
|
24 |
}
|
25 |
|
26 |
getRating(num: number) {
|
27 |
return new Array(num);
|
28 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
}
|
1 |
import { Component, OnInit } from '@angular/core';
|
2 |
+
import { ActivatedRoute, Router } from '@angular/router';
|
3 |
|
4 |
import { Book } from '../shared/book';
|
5 |
import { BookStoreService } from '../shared/book-store.service';
|
14 |
|
15 |
constructor(
|
16 |
private bs: BookStoreService,
|
17 |
+
private router: Router,
|
18 |
private route: ActivatedRoute
|
19 |
) { }
|
20 |
|
21 |
ngOnInit(): void {
|
22 |
const params = this.route.snapshot.paramMap;
|
23 |
+
this.bs.getSingle(params.get('isbn') || '')
|
24 |
+
.subscribe(b => this.book = b);
|
25 |
}
|
26 |
|
27 |
getRating(num: number) {
|
28 |
return new Array(num);
|
29 |
}
|
30 |
+
|
31 |
+
removeBook() {
|
32 |
+
if (this.book && confirm('Buch wirklich löschen?')) {
|
33 |
+
this.bs.remove(this.book.isbn)
|
34 |
+
.subscribe(res => this.router.navigate(['../'], { relativeTo: this.route }));
|
35 |
+
}
|
36 |
+
}
|
37 |
}
|
@@ -3,4 +3,10 @@
|
|
3 |
*ngFor="let b of books"
|
4 |
[book]="b"
|
5 |
[routerLink]="b.isbn"></bm-book-list-item>
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
</div>
|
3 |
*ngFor="let b of books"
|
4 |
[book]="b"
|
5 |
[routerLink]="b.isbn"></bm-book-list-item>
|
6 |
+
|
7 |
+
<div *ngIf="!books" class="ui active dimmer">
|
8 |
+
<div class="ui large text loader">Daten werden geladen...</div>
|
9 |
+
</div>
|
10 |
+
|
11 |
+
<p *ngIf="books && !books.length">Es wurden noch keine Bücher eingetragen.</p>
|
12 |
</div>
|
@@ -14,6 +14,6 @@
|
|
14 |
constructor(private bs: BookStoreService) { }
|
15 |
|
16 |
ngOnInit(): void {
|
17 |
-
this.
|
18 |
}
|
19 |
}
|
14 |
constructor(private bs: BookStoreService) { }
|
15 |
|
16 |
ngOnInit(): void {
|
17 |
+
this.bs.getAll().subscribe(res => this.books = res);
|
18 |
}
|
19 |
}
|
@@ -1,4 +1,6 @@
|
|
1 |
import { Injectable } from '@angular/core';
|
|
|
|
|
2 |
|
3 |
import { Book } from './book';
|
4 |
|
@@ -6,44 +8,24 @@
|
|
6 |
providedIn: 'root'
|
7 |
})
|
8 |
export class BookStoreService {
|
9 |
-
|
10 |
|
11 |
-
constructor() {
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
title: 'Angular',
|
16 |
-
authors: ['Ferdinand Malcher', 'Johannes Hoppe', 'Danny Koppenhagen'],
|
17 |
-
published: new Date(2020, 8, 1),
|
18 |
-
subtitle: 'Grundlagen, fortgeschrittene Themen und Best Practices',
|
19 |
-
rating: 5,
|
20 |
-
thumbnails: [{
|
21 |
-
url: 'https://ng-buch.de/angular-cover.jpg',
|
22 |
-
title: 'Buchcover'
|
23 |
-
}],
|
24 |
-
description: 'Lernen Sie Angular mit diesem Praxisbuch!'
|
25 |
-
},
|
26 |
-
{
|
27 |
-
isbn: '9783864905520',
|
28 |
-
title: 'React',
|
29 |
-
authors: ['Oliver Zeigermann', 'Nils Hartmann'],
|
30 |
-
published: new Date(2019, 11, 12),
|
31 |
-
subtitle: 'Grundlagen, fortgeschrittene Techniken und Praxistipps',
|
32 |
-
rating: 3,
|
33 |
-
thumbnails: [{
|
34 |
-
url: 'https://ng-buch.de/react-cover.jpg',
|
35 |
-
title: 'Buchcover'
|
36 |
-
}],
|
37 |
-
description: 'Das bewährte und umfassende Praxisbuch zu React.'
|
38 |
-
}
|
39 |
-
];
|
40 |
}
|
41 |
|
42 |
-
|
43 |
-
return this.
|
|
|
|
|
44 |
}
|
45 |
|
46 |
-
|
47 |
-
return this.
|
|
|
|
|
|
|
48 |
}
|
49 |
}
|
1 |
import { Injectable } from '@angular/core';
|
2 |
+
import { HttpClient } from '@angular/common/http';
|
3 |
+
import { Observable } from 'rxjs';
|
4 |
|
5 |
import { Book } from './book';
|
6 |
|
8 |
providedIn: 'root'
|
9 |
})
|
10 |
export class BookStoreService {
|
11 |
+
private api = 'https://api4.angular-buch.com';
|
12 |
|
13 |
+
constructor(private http: HttpClient) {}
|
14 |
+
|
15 |
+
getAll(): Observable<Book[]> {
|
16 |
+
return this.http.get<any[]>(`${this.api}/books`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
}
|
18 |
|
19 |
+
getSingle(isbn: string): Observable<Book> {
|
20 |
+
return this.http.get<any>(
|
21 |
+
`${this.api}/book/${isbn}`
|
22 |
+
);
|
23 |
}
|
24 |
|
25 |
+
remove(isbn: string): Observable<any> {
|
26 |
+
return this.http.delete(
|
27 |
+
`${this.api}/book/${isbn}`,
|
28 |
+
{ responseType: 'text' }
|
29 |
+
);
|
30 |
}
|
31 |
}
|