UMass Lowell Dept. of Computer Science

COMP 4620 — GUI Programming II

Spring 2016 Semester, Section 201

Prof. Jesse M. Heines

Notes for Class No. 7

Building a Static Site with Node and Express (continued)

Tuesday, February 9, 2016

A video of this class is (or will be) posted at:  http://echo360.uml.edu/heines2016/comp4620-201.html


Handouts and Materials


Openings / Announcements / Reminders

General Comments


Student Mentoring Opportunity


Class Notes

Related reading for this class:  GetMEAN: Chap. 4


Lessons from Weaving the Web

Weaving the Web: The Original Design and Ultimate Destiny of the World Wide Web by Tim Berners-Lee


Getting MEAN, Chapter 4  (continued)

Review from last class ...

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)


4.1 Defining Routes in Express (p. 82)

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

New material begins here ...

The loc8r/app_server/routes/index.js file


4.2 Building Controllers (p. 84)

The loc8r/app_server/controllers/main.js file

The loc8r/app_server/controllers/others.js file (p. 85)

The loc8r/app_server/controllers/locations.js file (pp. 85-86)

This should now work if you enter the following URLs


4.3 Creating Views (p. 87)


Bootstrap Responsive Grid System (p. 88)


The Basic Application Layout (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)


Building the Homepage template (p. 93)

(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


Building the rest of the views (pp. 98-105)

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)



This is document http://jesseheines.com:8080/~heines/91.462/91.462-2015-16s/462-lecs/lecture07.jsp.  It was last modified on Friday, August 26, 2022 at 4:09 PM.
Copyright © 2022 by Jesse M. Heines.  All rights reserved.  May be freely copied or excerpted for educational purposes with credit to the author.