BAEL-797 Adding book stuff to the UI

This commit is contained in:
tschiman 2017-04-17 20:25:36 -06:00
parent ae7a684d99
commit dbd9a0ea28
20 changed files with 109 additions and 87577 deletions

View File

@ -24,9 +24,45 @@
</div>
</nav>
<div class="container">
<div class="jumbotron">
<div class="jumbotron">
<div class="container">
<h1>Book Rater App</h1>
<p class="lead">Keep track of all the latest books and their ratings.</p>
</div>
</div>
<section class="books">
<div class="container">
<div class="row">
<div class="col-md">
<div class="row">
<div class="col-md-12" *ngFor="let book of books" (click)="selectBook(book)">
<div class="card">
<div class="card-block">
<h4 class="card-title">Title: {{book.title}}</h4>
<h6 class="card-subtitle mb-2 text-muted">Author: {{book.author}}</h6>
<p class="card-text">A quick summary of the book</p>
</div>
</div>
</div>
</div>
</div>
<div *ngIf="selectedBook != null" class="col-md-3">
<div class="card">
<div class="card-block">
<button type="button" class="close" aria-label="Close" (click)="closeBookDetail()">
<span aria-hidden="true">&times;</span>
</button>
<h4 class="card-title">Title: {{selectedBook.title}}</h4>
<h6 class="card-subtitle mb-2 text-muted">Author: {{selectedBook.author}}</h6>
<p class="card-text">A quick summary of the book</p>
Rating: <div *ngIf="principal.authenticated" class="progress">
<div class="progress-bar bg-success" role="progressbar" style="width: 20%" aria-valuenow="1" aria-valuemin="0" aria-valuemax="5"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>

View File

@ -3,6 +3,7 @@ import {Principal} from "./principal";
import {Response, RequestOptions, Headers, Http} from "@angular/http";
import {Observable} from "rxjs";
import {NgForm} from "@angular/forms";
import {Book} from "./book";
@Component({
selector: 'app-root',
@ -15,17 +16,21 @@ export class AppComponent {
password: ''
};
books: Book[] = [];
selectedBook: Book = null;
private username: String = '';
private password: String = '';
principal: Principal = new Principal(false, []);
principal: Principal = new Principal(true, []);
loginFailed: boolean = false;
constructor(private http: Http){}
ngOnInit(): void {
this.loadBooks();
}
onLogin(form: NgForm) {
@ -72,4 +77,20 @@ export class AppComponent {
}
});
}
loadBooks() {
let book: Book = new Book(1, 'Tom Sawyer', 'Huckleberry Finn');
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);
}
selectBook(book: Book) {
this.selectedBook = book;
}
closeBookDetail() {
this.selectedBook = null;
}
}

View File

@ -4,10 +4,12 @@ import {FormsModule} from "@angular/forms";
import {HttpModule} from "@angular/http";
import {AppComponent} from "./app.component";
import {NgbModule} from "@ng-bootstrap/ng-bootstrap";
import {RatingComponent} from "./rating/rating.component";
@NgModule({
declarations: [
AppComponent
AppComponent,
RatingComponent
],
imports: [
BrowserModule,

View File

@ -0,0 +1,13 @@
/**
* Created by tschi on 4/17/2017.
*/
export class Book {
id: number;
author: String;
title: String;
constructor(id: number, author: String, title: String){
this.id = id;
this.author = author;
this.title = title;
}
}

View File

@ -0,0 +1,14 @@
/**
* Created by tschi on 4/17/2017.
*/
export class Rating{
id: number;
bookId: number;
stars: number;
constructor(id: number, bookId: number, stars: number) {
this.id = id;
this.bookId = bookId;
this.stars = stars;
}
}

View File

@ -0,0 +1,15 @@
import {Component, OnInit} from "@angular/core";
@Component({
selector: 'app-rating',
templateUrl: './rating.component.html',
styleUrls: ['./rating.component.css']
})
export class RatingComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -1,14 +0,0 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ui</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root>Loading...</app-root>
<script type="text/javascript" src="inline.bundle.js"></script><script type="text/javascript" src="polyfills.bundle.js"></script><script type="text/javascript" src="styles.bundle.js"></script><script type="text/javascript" src="vendor.bundle.js"></script><script type="text/javascript" src="main.bundle.js"></script></body>
</html>

View File

@ -1,146 +0,0 @@
/******/ (function(modules) { // webpackBootstrap
/******/ // install a JSONP callback for chunk loading
/******/ var parentJsonpFunction = window["webpackJsonp"];
/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules, executeModules) {
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
/******/ var moduleId, chunkId, i = 0, resolves = [], result;
/******/ for(;i < chunkIds.length; i++) {
/******/ chunkId = chunkIds[i];
/******/ if(installedChunks[chunkId])
/******/ resolves.push(installedChunks[chunkId][0]);
/******/ installedChunks[chunkId] = 0;
/******/ }
/******/ for(moduleId in moreModules) {
/******/ if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {
/******/ modules[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules, executeModules);
/******/ while(resolves.length)
/******/ resolves.shift()();
/******/ if(executeModules) {
/******/ for(i=0; i < executeModules.length; i++) {
/******/ result = __webpack_require__(__webpack_require__.s = executeModules[i]);
/******/ }
/******/ }
/******/ return result;
/******/ };
/******/
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // objects to store loaded and loading chunks
/******/ var installedChunks = {
/******/ 4: 0
/******/ };
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/ // This file contains only the entry chunk.
/******/ // The chunk loading function for additional chunks
/******/ __webpack_require__.e = function requireEnsure(chunkId) {
/******/ if(installedChunks[chunkId] === 0)
/******/ return Promise.resolve();
/******/
/******/ // an Promise means "currently loading".
/******/ if(installedChunks[chunkId]) {
/******/ return installedChunks[chunkId][2];
/******/ }
/******/ // start chunk loading
/******/ var head = document.getElementsByTagName('head')[0];
/******/ var script = document.createElement('script');
/******/ script.type = 'text/javascript';
/******/ script.charset = 'utf-8';
/******/ script.async = true;
/******/ script.timeout = 120000;
/******/
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__.nc);
/******/ }
/******/ script.src = __webpack_require__.p + "" + chunkId + ".chunk.js";
/******/ var timeout = setTimeout(onScriptComplete, 120000);
/******/ script.onerror = script.onload = onScriptComplete;
/******/ function onScriptComplete() {
/******/ // avoid mem leaks in IE.
/******/ script.onerror = script.onload = null;
/******/ clearTimeout(timeout);
/******/ var chunk = installedChunks[chunkId];
/******/ if(chunk !== 0) {
/******/ if(chunk) chunk[1](new Error('Loading chunk ' + chunkId + ' failed.'));
/******/ installedChunks[chunkId] = undefined;
/******/ }
/******/ };
/******/
/******/ var promise = new Promise(function(resolve, reject) {
/******/ installedChunks[chunkId] = [resolve, reject];
/******/ });
/******/ installedChunks[chunkId][2] = promise;
/******/
/******/ head.appendChild(script);
/******/ return promise;
/******/ };
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // identity function for calling harmony imports with the correct context
/******/ __webpack_require__.i = function(value) { return value; };
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // on error function for async loading
/******/ __webpack_require__.oe = function(err) { console.error(err); throw err; };
/******/ })
/************************************************************************/
/******/ ([]);
//# sourceMappingURL=inline.bundle.js.map

View File

@ -1,267 +0,0 @@
webpackJsonp([1,4],{
/***/ 196:
/***/ (function(module, exports) {
function webpackEmptyContext(req) {
throw new Error("Cannot find module '" + req + "'.");
}
webpackEmptyContext.keys = function() { return []; };
webpackEmptyContext.resolve = webpackEmptyContext;
module.exports = webpackEmptyContext;
webpackEmptyContext.id = 196;
/***/ }),
/***/ 197:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__angular_core__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__angular_platform_browser_dynamic__ = __webpack_require__(202);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__app_app_module__ = __webpack_require__(208);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__environments_environment__ = __webpack_require__(210);
if (__WEBPACK_IMPORTED_MODULE_3__environments_environment__["a" /* environment */].production) {
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__angular_core__["a" /* enableProdMode */])();
}
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__angular_platform_browser_dynamic__["a" /* platformBrowserDynamic */])().bootstrapModule(__WEBPACK_IMPORTED_MODULE_2__app_app_module__["a" /* AppModule */]);
//# sourceMappingURL=main.js.map
/***/ }),
/***/ 207:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__angular_core__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__principal__ = __webpack_require__(209);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__angular_http__ = __webpack_require__(102);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_rxjs__ = __webpack_require__(269);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3_rxjs___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_3_rxjs__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return AppComponent; });
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var AppComponent = (function () {
function AppComponent(http) {
this.http = http;
this.credentials = {
username: '',
password: ''
};
this.username = '';
this.password = '';
this.principal = new __WEBPACK_IMPORTED_MODULE_1__principal__["a" /* Principal */](false, []);
this.loginFailed = false;
}
AppComponent.prototype.ngOnInit = function () {
};
AppComponent.prototype.onLogin = function (form) {
var _this = this;
this.loginFailed = false;
var headers = new __WEBPACK_IMPORTED_MODULE_2__angular_http__["b" /* Headers */]({ 'Content-Type': 'application/json' });
this.username = form.value.username;
this.password = form.value.password;
headers.append('Authorization', 'Basic ' + btoa(form.value.username + ':' + form.value.password));
headers.append('X-Requested-With', 'XMLHttpRequest');
var options = new __WEBPACK_IMPORTED_MODULE_2__angular_http__["c" /* RequestOptions */]({ headers: headers });
this.http.get("/me", options)
.map(function (response) { return response.json(); })
.catch(function (error) {
if (error.status === 401) {
_this.loginFailed = true;
}
console.log(error);
return __WEBPACK_IMPORTED_MODULE_3_rxjs__["Observable"].throw(error);
})
.map(function (data) { return new __WEBPACK_IMPORTED_MODULE_1__principal__["a" /* Principal */](data.authenticated, data.authorities); })
.subscribe(function (principal) {
console.log(principal);
_this.principal = principal;
});
};
AppComponent.prototype.onLogout = function () {
var _this = this;
var headers = new __WEBPACK_IMPORTED_MODULE_2__angular_http__["b" /* Headers */]({ 'Content-Type': 'application/json' });
headers.append('Authorization', 'Basic ' + btoa(this.username + ':' + this.password));
headers.append('X-Requested-With', 'XMLHttpRequest');
var options = new __WEBPACK_IMPORTED_MODULE_2__angular_http__["c" /* RequestOptions */]({ headers: headers });
this.http.post("/logout", '', options)
.catch(function (error) {
console.log(error);
return __WEBPACK_IMPORTED_MODULE_3_rxjs__["Observable"].throw(error);
})
.subscribe(function (response) {
if (response.status === 204) {
_this.loginFailed = false;
_this.credentials.username = '';
_this.credentials.password = '';
_this.principal = new __WEBPACK_IMPORTED_MODULE_1__principal__["a" /* Principal */](false, []);
}
});
};
return AppComponent;
}());
AppComponent = __decorate([
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_0__angular_core__["D" /* Component */])({
selector: 'app-root',
template: __webpack_require__(267),
styles: [__webpack_require__(265)]
}),
__metadata("design:paramtypes", [typeof (_a = typeof __WEBPACK_IMPORTED_MODULE_2__angular_http__["d" /* Http */] !== "undefined" && __WEBPACK_IMPORTED_MODULE_2__angular_http__["d" /* Http */]) === "function" && _a || Object])
], AppComponent);
var _a;
//# sourceMappingURL=app.component.js.map
/***/ }),
/***/ 208:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__angular_platform_browser__ = __webpack_require__(43);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__angular_core__ = __webpack_require__(1);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__angular_forms__ = __webpack_require__(23);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__angular_http__ = __webpack_require__(102);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__app_component__ = __webpack_require__(207);
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__ng_bootstrap_ng_bootstrap__ = __webpack_require__(205);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return AppModule; });
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var AppModule = (function () {
function AppModule() {
}
return AppModule;
}());
AppModule = __decorate([
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_1__angular_core__["b" /* NgModule */])({
declarations: [
__WEBPACK_IMPORTED_MODULE_4__app_component__["a" /* AppComponent */]
],
imports: [
__WEBPACK_IMPORTED_MODULE_0__angular_platform_browser__["a" /* BrowserModule */],
__WEBPACK_IMPORTED_MODULE_2__angular_forms__["a" /* FormsModule */],
__WEBPACK_IMPORTED_MODULE_3__angular_http__["a" /* HttpModule */],
__WEBPACK_IMPORTED_MODULE_5__ng_bootstrap_ng_bootstrap__["a" /* NgbModule */].forRoot()
],
providers: [],
bootstrap: [__WEBPACK_IMPORTED_MODULE_4__app_component__["a" /* AppComponent */]]
})
], AppModule);
//# sourceMappingURL=app.module.js.map
/***/ }),
/***/ 209:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Principal; });
/* unused harmony export Authority */
/**
* Created by tschi on 4/16/2017.
*/
var Principal = (function () {
function Principal(authenticated, authorities) {
var _this = this;
this.authorities = [];
this.authenticated = authenticated;
authorities.map(function (auth) { return _this.authorities.push(new Authority(auth.authority)); });
}
Principal.prototype.isAdmin = function () {
return this.authorities.some(function (auth) { return auth.authority.indexOf('ADMIN') > -1; });
};
return Principal;
}());
var Authority = (function () {
function Authority(authority) {
this.authority = authority;
}
return Authority;
}());
//# sourceMappingURL=principal.js.map
/***/ }),
/***/ 210:
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return environment; });
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
// The file contents for the current environment will overwrite these during build.
var environment = {
production: false
};
//# sourceMappingURL=environment.js.map
/***/ }),
/***/ 265:
/***/ (function(module, exports, __webpack_require__) {
exports = module.exports = __webpack_require__(50)();
// imports
// module
exports.push([module.i, "", ""]);
// exports
/*** EXPORTS FROM exports-loader ***/
module.exports = module.exports.toString();
/***/ }),
/***/ 267:
/***/ (function(module, exports) {
module.exports = "<nav class=\"navbar navbar-toggleable-md navbar-inverse fixed-top bg-inverse\">\n <button class=\"navbar-toggler navbar-toggler-right\" type=\"button\" data-toggle=\"collapse\" data-target=\"#navbarCollapse\" aria-controls=\"navbarCollapse\" aria-expanded=\"false\" aria-label=\"Toggle navigation\">\n <span class=\"navbar-toggler-icon\"></span>\n </button>\n <a class=\"navbar-brand\" href=\"#\">Book Rater</a>\n <div class=\"collapse navbar-collapse\" id=\"navbarCollapse\">\n <ul class=\"navbar-nav mr-auto\">\n </ul>\n <div *ngIf=\"!principal.authenticated; then loginForm else loginMessage\"></div>\n <ng-template #loginForm>\n <form (ngSubmit)=\"onLogin(f)\" class=\"form-inline mt-2 mt-md-0\" #f=\"ngForm\">\n <input name=\"username\" [(ngModel)]=\"credentials.username\" required class=\"form-control mr-sm-2\" type=\"text\" placeholder=\"Username\">\n <input name=\"password\" [(ngModel)]=\"credentials.password\" required class=\"form-control mr-sm-2\" type=\"password\" placeholder=\"Password\">\n <button class=\"btn btn-outline-success my-2 my-sm-0\" type=\"submit\" [disabled]=\"!f.valid\">Login</button>\n </form>\n </ng-template>\n <ng-template #loginMessage>\n <button type=\"button\" class=\"btn btn-link\" (click)=\"onLogout()\">Logout</button>\n </ng-template>\n <div *ngIf=\"loginFailed\">\n <div class=\"alert alert-warning\">Login Failed</div>\n </div>\n\n </div>\n</nav>\n\n<div class=\"container\">\n <div class=\"jumbotron\">\n <h1>Book Rater App</h1>\n <p class=\"lead\">Keep track of all the latest books and their ratings.</p>\n </div>\n</div>\n"
/***/ }),
/***/ 537:
/***/ (function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(197);
/***/ })
},[537]);
//# sourceMappingURL=main.bundle.js.map

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long