diff --git a/app.js b/app.js new file mode 100644 index 0000000..55977db --- /dev/null +++ b/app.js @@ -0,0 +1,66 @@ +var app = angular.module("superCrud", ["ngRoute", "ngResource"]); + +app.config(["$routeProvider", "$locationProvider", function($routeProvider, $locationProvider) { + $routeProvider + .when("/", { + templateUrl: "templates/books/index.html", + controller: "bookIndexCtrl" + }) + .when("/books/:id", { + templateUrl: "templates/books/show.html", + controller: "bookShowCtrl" + }); + $locationProvider + .html5Mode({ + enabled: true, + requireBase: false + }); +}]); + +//api call here +app.factory("Book", ["$resource", function($resource) { +return $resource("https://super-crud.herokuapp.com/books/:id", {id: "@id"}, { + query: { + isArray: true, + transformResponse: function(data) { return angular.fromJson(data).books; } + }, + update: {method: "PUT"} + }); +}]); + + +app.controller("bookIndexCtrl", ["$scope", "Book", function($scope, Book) { + $scope.allBooks = Book.query(); + + $scope.newBook = new Book(); + $scope.save = function(book) { + book.$save(function() { + $scope.newBook = new Book(); + $scope.allBooks.push($scope.newBook); + }); + }; + +}]); +app.controller("bookShowCtrl",["$scope", "$routeParams", "$location", "Book", function($scope, $routeParams, $location, Book) { + var bookId = $routeParams.id; + book = Book.get({id: bookId}, + function(data) { + $scope.book = data; + }, + function(error) { + console.log(error.statusText); + $location.path("/"); + }); + $scope.deleteBook = function() { + Book.delete({id: bookId}, function(data) { + $location.path("/"); + }); + }; + $scope.updateBook = function() { + Book.update({id: bookId}, $scope.book, function(data) { + $location.path("/"); + }); + }; + + +}]); \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..b5c4689 --- /dev/null +++ b/index.html @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + Super Crud + + +
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/templates/.DS_Store b/templates/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/templates/.DS_Store differ diff --git a/templates/books/index.html b/templates/books/index.html new file mode 100644 index 0000000..ec1b2b6 --- /dev/null +++ b/templates/books/index.html @@ -0,0 +1,31 @@ +

All the Books

+
+
+ book image +
+
+

{{book.title}}

+

Author: {{book.author}}

+

Date released: {{book.releaseDate}}

+
+
+
+
+
+

create new book

+
+ Title: +
+
+ Author: +
+
+ Release Date: +
+
+ Image Url: +
+ +
+
+
\ No newline at end of file diff --git a/templates/books/show.html b/templates/books/show.html new file mode 100644 index 0000000..2ffa062 --- /dev/null +++ b/templates/books/show.html @@ -0,0 +1,43 @@ +
+
+

{{book.title}}

+
+
+
+ book image +
+
+

Author: {{book.author}}

+

Release Date: {{book.releaseDate}}

+

+
+ Back + + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+
+
+
\ No newline at end of file