A video of this class is (or will be) posted at: http://echo360.uml.edu/heines2016/comp4620-201.html
General Comments
Student Mentoring Opportunity
Related reading for this class: GetMEAN: Chap. 4
Weaving the Web: The Original Design and Ultimate Destiny of the World Wide Web by Tim Berners-Lee
The goal of this chapter is to “have intelligent views that can display data passed to them, and controllers passing hard-coded data to the views.” (p. 81)
Holmes’s “collections” of pages (p. 82)
File relationships (p. 83)
“The application includes the routes file, which in turn includes multiple controller files, each named according to the relevant collection.” (p. 83)
What’s where
Loc8r
└──app_server
├──controllers
│ locations.js
│ main.js
│ others.js
├──routes
│ index.js
│ users.js
└──views
error.jade
generic-text.jade
index.jade
layout.jade
location-info.jade
location-review-form.jade
locations-list.jade
The loc8r/app.js file
require statementsapp itself is an express object (line 121)
“A closure is an inner function that has access to the outer (enclosing) function’s variables—scope chain. The closure has three scope chains: it has access to its own scope (variables defined between its curly brackets), it has access to the outer function's variables, and it has access to the global variables.”
source: http://javascriptissexy.com/understand-javascript-closures-with-ease
module.exports statement at the very bottom of the fileThe loc8r/app_server/routes/index.js file
.js extension is optional (lines 216-217)router.get statements (lines 239-243)module.exports statement at the very bottom of the file (line 246)The loc8r/app_server/controllers/main.js file
The loc8r/app_server/controllers/others.js file (p. 85)
title property from 'Express' to 'About''index' to 'generic-text' was done later, after creating the generic-text.jade file)The loc8r/app_server/controllers/locations.js file (pp. 85-86)
This should now work if you enter the following URLs
This specification indicates that “the element it’s applied to will take up 6 columns on screens of size
smand larger.”
“The
col-xs-12class tells the layout to use 12 columns on extra-small devices, and thecol-sm-6class tells the layout to use 6 columns for small devices and above.” (p. 89)
“This framework for a layout is pretty simple, but it suits our needs. It will give a consistent look and feel, while allowing for all types of content layouts to go in the middle.” (p. 90)
“Creating the framework in a layout file means that you only have to do it once, and only have to maintain it in one place.” (p. 90)
The initial loc8r/app_server/views/layout.jade file (p. 90)
Adding a navigation section above the content block and a footer below it (pp. 90-92)
div with a class of container causes the content to be “centered in the window, and constrained to sensible maximum widths on large displays.” (p. 91)container div with the content block(1) Create a new view file: loc8r/app_server/views/locations-list.jade
(2) Modify the controller for the homepage in loc8r/app_server/controllers/locations.js to use this view (p. 94)
module.exports.homelist = function(req, res){
res.render('locations-list', { title: 'Home' });
};
(3) Code the 3 main areas of the page (p. 95) — file loc8r/app_server/views/locations-list.jade
(4) Code the main page area (p. 97) — file loc8r/app_server/views/locations-list.jade
|) at the beginnings of lines enable continuation of paragraph text|) can contain HTML tags if you want them.”These are done similarly to building the Home page view, so you should be able to follow the book
Error on page 99: Listing 4.7 is file app_server/views/location-info.jade, not location-info.js
Listing 4.7 itself is very difficult to follow due to the indentation and wrapping of long lines
Note that the CSS listed at the bottom of page 101 is in public/stylesheets, not app_server/views
This ends what Holmes refers to as the “views” part of Chapter 4
The next step is to take the data out of the views (p. 106)