+
+
+
+
+ Add New Book
+
+
+
+
+
+
diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/angular/ui/src/app/app.component.ts b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/angular/ui/src/app/app.component.ts
index 94718f34fc..773a8b22e0 100644
--- a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/angular/ui/src/app/app.component.ts
+++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/angular/ui/src/app/app.component.ts
@@ -24,10 +24,17 @@ export class AppComponent {
private password: String = '';
- principal: Principal = new Principal(true, []);
+ principal: Principal = new Principal(false, []);
+ // principal: Principal = new Principal(true, [new Authority("ROLE_ADMIN")]);
loginFailed: boolean = false;
+ booksToEdit: number[] = [];
+
+ newBooks: Book[] = [];
+ isAddNewBook: boolean = false;
+ newBook: Book = new Book(null, '', '');
+
constructor(private http: Http){}
ngOnInit(): void {
@@ -84,6 +91,7 @@ export class AppComponent {
let book1: Book = new Book(2, 'Michael Crichton', 'Jurassic Park');
let book2: Book = new Book(3, 'McLaughlin, Pollice, and West', 'Object Oriented Analysis And Design');
this.books.push(book, book1, book2);
+ this.books.forEach(book => this.newBooks.push(new Book(book.id, book.author, book.title)))
}
selectBook(book: Book) {
@@ -94,4 +102,54 @@ export class AppComponent {
this.selectedBook = null;
}
+ editBook(bookIndex: number) {
+ this.booksToEdit.push(bookIndex);
+ }
+
+ cancelEditBook(bookIndex: number) {
+ if (this.booksToEdit.indexOf(bookIndex) !== -1) {
+ this.booksToEdit.splice(this.booksToEdit.indexOf(bookIndex), 1); //remove the index of the book to edit
+ //get the original book
+ let bookCopy: Book = new Book(this.books[bookIndex].id, this.books[bookIndex].author, this.books[bookIndex].title);
+ this.newBooks.splice(bookIndex,1,bookCopy); //replace the edited book with the old book
+ }
+ }
+
+ saveBook(bookIndex: number, newBook: Book) {
+ console.log(newBook);
+
+ //save the book to the database
+
+ //update the current array of books
+ let book: Book = this.books.find(b => b.id === newBook.id);
+ book.title = newBook.title;
+ book.author = newBook.author;
+ this.booksToEdit.splice(this.booksToEdit.indexOf(bookIndex), 1); //remove the index of the book to edit
+ }
+
+ delete(bookIndex: number) {
+ if (this.selectedBook !== null && this.books[bookIndex].id === this.selectedBook.id) {this.selectedBook = null;}
+
+ this.books.splice(bookIndex, 1); //remove the book at this index;
+ this.newBooks.splice(bookIndex, 1); //remove the editing book at this index
+ }
+
+ activateAddNewBook() {
+ this.isAddNewBook = true;
+ this.newBook = new Book(null, '', '');
+ }
+
+ cancelAddBook() {
+ this.isAddNewBook = false;
+ }
+
+ addNewBook(newBook: Book, element: any) {
+ //write new book to db
+ //on success:
+ this.books.push(newBook);
+ this.newBooks.push(newBook);
+ this.newBook = new Book(null, '', '');
+ element.focus();
+ }
+
}
diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/angular/ui/src/app/app.module.ts b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/angular/ui/src/app/app.module.ts
index 90aba1d6ce..6ae983e57f 100644
--- a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/angular/ui/src/app/app.module.ts
+++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/angular/ui/src/app/app.module.ts
@@ -5,11 +5,13 @@ import {HttpModule} from "@angular/http";
import {AppComponent} from "./app.component";
import {NgbModule} from "@ng-bootstrap/ng-bootstrap";
import {RatingComponent} from "./rating/rating.component";
+import {ClickStopPropagationDirective} from "./click-stop-propagation.directive";
@NgModule({
declarations: [
AppComponent,
- RatingComponent
+ RatingComponent,
+ ClickStopPropagationDirective
],
imports: [
BrowserModule,
diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/angular/ui/src/app/click-stop-propagation.directive.ts b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/angular/ui/src/app/click-stop-propagation.directive.ts
new file mode 100644
index 0000000000..9def0a3bd0
--- /dev/null
+++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/angular/ui/src/app/click-stop-propagation.directive.ts
@@ -0,0 +1,13 @@
+import {Directive, HostListener} from "@angular/core";
+
+@Directive({
+ selector: '[appClickStopPropagation]'
+})
+export class ClickStopPropagationDirective
+{
+ @HostListener("click", ["$event"])
+ public onClick(event: any): void
+ {
+ event.stopPropagation();
+ }
+}