Chapter 3. Creating and setting up a MEAN project
Listing 3.1. Example package.json file in a new Express project
Listing 3.2. Taking the controller code out of the route: step 1
Listing 3.3. Setting up the homepage controller in app_server/controllers/main.js
Listing 3.4. Updating the routes file to use external controllers
Listing 3.5. The complete index.jade file
Listing 3.6. Default layout.jade file
Listing 3.7. Updated layout.jade including Bootstrap references
Chapter 4. Building a static site with Node and Express
Listing 4.1. Requiring the controller files in routes/index.js
Listing 4.2. Defining the routes and mapping them to controllers
Listing 4.3. Others controller file
Listing 4.4. Locations controller file
Listing 4.5. Final code for the layout framework in app_server/views/layout.jade
Listing 4.6. Complete template for app_server/views/locations-list.jade
Listing 4.7. View for the Details page, app_server/views/location-info.js
Listing 4.8. View for the Add Review page, app_server/views/location-review.form.js
Listing 4.9. View for text only pages, app_server/views/generic-text.jade
Listing 4.10. The homelist controller, passing hard-coded data to the view
Listing 4.11. Final view for the homepage, app_server/views/locations-list.jade
Chapter 5. Building a data model with MongoDB and Mongoose
Listing 5.1. Complete database connection file db.js in app_server/models
Listing 5.2. Data in the controller powering the Details page
Listing 5.3. Final location schema definition, including nested schemas
Listing 5.4. Example MongoDB document based on the location schema
Chapter 6. Writing a REST API: Exposing the MongoDB database to the application
Listing 6.1. Routes defined in app_api/routes/locations.js
Listing 6.2. locationsReadOne controller
Listing 6.3. Controller for finding a single review
Listing 6.4. Locations list controller locationsListByDistance
Listing 6.5. Complete controller for creating a new location
Listing 6.6. Controller for creating a review
Listing 6.7. Adding and saving a subdocument
Listing 6.8. Calculating and updating the average rating
Listing 6.9. Making changes to an existing document in MongoDB
Listing 6.10. Updating a subdocument in MongoDB
Listing 6.11. Deleting a document from MongoDB given an ID
Listing 6.12. Finding and deleting a subdocument from MongoDB
Chapter 7. Consuming a REST API: Using an API from inside Express
Listing 7.1. Adding request and default API options to the locations.js controllers file
Listing 7.2. Moving the contents of the homelist controller into an external function
Listing 7.3. Update the homelist controller to call the API before rendering the page
Listing 7.4. Update the contents of the homelist controller to use the API response
Listing 7.5. Update the renderHomepage function to use the data from the API
Listing 7.6. Adding and using a function to format the distance returned by the API
Listing 7.7. Validate that the API has returned some data before trying to use it
Listing 7.8. Outputting messages if the API doesn’t return location data
Listing 7.9. Update the view to display an error message when needed
Listing 7.10. Update the list view to add the location ID to the relevant links
Listing 7.11. Move the contents of the locationInfo controller into an external function
Listing 7.12. Update the locationInfo controller to call the API
Listing 7.13. Preprocessing data in the controller
Listing 7.14. Update renderDetailPage to accept and use data from the API
Listing 7.15. Create a Jade mixin to format the dates
Listing 7.16. Trap any errors caused by the API not returning a 200 status
Listing 7.17. Create an error-handling function for API status codes that aren’t 200
Listing 7.18. Create an external function to hold the contents of the addReview controller
Listing 7.19. Create a new reusable function to get location information
Listing 7.20. Removing hard-coded data from the renderReviewForm function
Listing 7.21. doAddReview controller used to post review data to the API
Listing 7.22. Adding validation to reviews at the schema level
Listing 7.23. Trapping validation errors returned by the API
Listing 7.24. Update the controller to pass a query string error string to the view
Listing 7.25. Adding some simple validation to an Express controller
Chapter 8. Adding Angular components to an Express application
Listing 8.1. Simple Angular binding, binding a model to input and output
Listing 8.2. Adding the Angular library and application code to the HTML
Listing 8.3. Taking the dynamic content out of the renderHomepage Express function
Listing 8.4. Create an Angular controller and some test data in loc8rApp.js
Listing 8.5. Changing the Jade bindings to Angular bindings
Listing 8.6. Creating a custom filter to apply formatting to distances
Listing 8.7. Creating a directive and adding it to the Angular module
Listing 8.8. Updating the directive to use an isolate scope for the rating
Listing 8.9. Update the directive to use an external file for the template
Listing 8.10. Creating the Angular rating star template
Listing 8.11. Creating and applying the text filter for the list of results
Listing 8.12. Creating a simple data service and adding it to the module
Listing 8.13. Updating the controller to work asynchronously with the $http promises
Listing 8.14. Setting an output message at various points in the process
Listing 8.15. Create a geolocation service returning a method to get the current position
Listing 8.16. Updating the controller to use the new geolocation service
Listing 8.17. Updating the loc8rData service to return a function instead of data
Listing 8.18. Update the controller to pass the coordinates to the services
Chapter 9. Building a single-page application with Angular: Foundations
Listing 9.1. Adding ngRoute and config to the Angular application
Listing 9.2. Angular view template for the homepage, home.view.html
Listing 9.3. Creating the new homepage controller
Listing 9.4. Updating the home controller to use vm and the controllerAs syntax
Listing 9.5. Updating the home view to use vm data bindings
Listing 9.6. Create the loc8rData service
Listing 9.7. Create the geolocation service
Listing 9.8. Update the homepage controller to use the two services
Listing 9.9. Updates needed to use $scope.$apply in the home controller
Listing 9.10. Create the formatDistance.filter.js file
Listing 9.11. Create the ratingStars directive file
Listing 9.12. Wrapping Angular application files in IIFEs, for example, app.js
Chapter 10. Building an SPA with Angular: The next level
Listing 10.1. Host page converted into HTML
Listing 10.2. Defining the generic footer as a directive: footerGeneric.directive.js
Listing 10.3. Navigation HTML: navigation.template.html
Listing 10.4. Defining the navigation directive: navigation.directive.js
Listing 10.5. Defining the page header directive: pageHeader.directive.js
Listing 10.6. Complete homepage view template
Listing 10.7. Final index.html file
Listing 10.8. Enabling the HTML5 history API
Listing 10.9. Add a new Angular route definition for the About page
Listing 10.10. Creating the Angular controller for the About page
Listing 10.11. Add the Details page route to the Angular application configuration
Listing 10.12. Controller framework for the Details page
Listing 10.13. Add a method to the data service to call the API
Listing 10.14. Using the service from the controller to get the location data
Listing 10.15. Angular view for the Details page
Listing 10.16. Using ng-switch to display the opening times
Listing 10.17. Showing the reviews by date using the orderBy filter
Listing 10.18. Applying a date filter to format the review dates
Listing 10.19. Adding the method to the controller
Listing 10.20. HTML view for the modal popup
Listing 10.21. Starting point for the review modal controller
Listing 10.22. Using resolve to pass variable values into the modal
Listing 10.23. Adding some basic data validation to the onSubmit handler
Listing 10.24. Adding a new addReviewById method to the data service
Listing 10.25. Sending complete form data to the data service
Listing 10.26. Passing review data into the modal’s close method
Listing 10.27. Resolving the modal instance promise to update the review list
Chapter 11. Authenticating users, managing sessions, and securing APIs
Listing 11.1. Basic Mongoose schema for users
Listing 11.2. Create a schema method to generate a JWT
Listing 11.3. Full Passport local strategy definition
Listing 11.4. Register controller for the API
Listing 11.5. Login controller for the API
Listing 11.6. Update the create review controller to get the user’s name first
Listing 11.7. Use data from the JWT to query the database
Listing 11.8. Saving the username in the review
Listing 11.9. Create the authentication service with the first two methods
Listing 11.10. Full view for the registration page
Listing 11.11. Skeleton of the register controller
Listing 11.12. Using the authentication services methods in the navigation controller
Appendix C. Dealing with all of the views
Listing C.1. locationInfo controller
Listing C.2. location-info.jade view template in app_server/views
Listing C.3. addReview controller
18.216.213.126