CS 160 and CMPE/SE 131 Software Engineering February 11 Class Meeting Department of Computer Science Department of Computer Engineering San José State.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
Samsung Smart TV is a web-based application running on an application engine installed on digital TVs connected to the Internet.
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
Ruby on Rails Model of MVC. Model-View-Controller Paradigm A way of organizing a software system Benefits: Isolation of business logic from the user interface.
Web Database Programming Connecting Database to Web.
Browsers and Servers CGI Processing Model ( Common Gateway Interface ) © Norman White, 2013.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
CS 160: Software Engineering August 27 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 174: Web Programming February 26 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Creating Databases applications for the Web Reprise. Basic HTML review, forms Preview: Server side vs client side Classwork: create HTML forms and check.
CS 174: Web Programming April 16 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
CS 174: Web Programming April 9 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
CS 1150 – JavaScript Programming Lab TA – Sanjaya Wijeratne – Web Page -
WaveMaker Visual AJAX Studio 4.0 Training Studio Overview.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
AJAX Chat Analysis and Design Rui Zhao CS SPG UCCS.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
Server-side Scripting Powering the webs favourite services.
Web Application Programming Carol Wolf Computer Science.
CS 160: Software Engineering October 8 Class Meeting
Views Carol Wolf Computer Science. Extended Ruby  Views files are written in extended Ruby, erb.  They end in.html.erb.  Ruby code is intermixed with.
Tutorial 121 Creating a New Web Forms Page You will find that creating Web Forms is similar to creating traditional Windows applications in Visual Basic.
Web Design and Development for E-Business By Jensen J. Zhao Copyright 2003 Prentice Hall, Inc. Web Design and Development for E-Business Jensen J. Zhao.
CS 235: User Interface Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Ruby on Rails Your first app. Rails files app/ Contains the controllers, models, views and assets for your application. You’ll focus on this folder for.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
CS 174: Web Programming September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 235: User Interface Design September 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Navigation Framework using CF Architecture for a Client-Server Application using the open standards of the web Kedar Desai presented by.
CS 174: Web Programming August 31 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 174: Web Programming September 2 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
Chapter 15 © 2013 by Pearson Overview of Rails - Rails is a development framework for Web-based applications - Based on MVC architecture for applications.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Implementing The Middle Tier These slides.
CS 174: Web Programming October 12 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
CS 174: Web Programming October 14 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CMPE 226 Database Systems October 28 Class Meeting
PHP A very brief introduction PHP1. PHP = PHP: Hypertext Processor A recursive acronym! PHP scripts are executed on the server side Executed by (a plugin.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
Creating Databases applications for the Web: week 2 Basic HTML review, forms HW: Identify unique source for asp, php, Open Source, MySql, Access.
Rails and routing INFO 2310: Topics in Web Design and Programming.
1 CS 3870/CS 5870: Note07 Prog 4. Master Pages Creating a master page based on another master page MainMasterPage –For all Progs and Tests Prog4MasterPage.
AJAX in Ruby-on-Rails. Ruby on Rails and AJAX AJAX can be done with just Javascript Easier if you use libraries –Prototype –SAJAX –jQuery Libraries only.
CS 160 and CMPE/SE 131 Software Engineering February 9 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
CS 160 and CMPE/SE 131 Software Engineering February 2 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
CS 174: Web Programming November 2 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 235: User Interface Design March 17 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
April 20022/CS/3XAPP 1 Database Design Anatomy of an application John Wordsworth Department of Computer Science The University of Reading
Ruby on Rails. Web Framework for Ruby Designed to make it easier to develop, deploy, and maintain web applications Design with Model-View-Controller –almost.
CMPE 226 Database Systems April 19 Class Meeting Department of Computer Engineering San Jose State University Spring 2016 Instructor: Ron Mak
CS 174: Web Programming October 28 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
University of Kansas Department of Electrical Engineering and Computer Science Dr. Susan Gauch April 21, 2005 I T T C Introduction to Web Technologies.
CMPE/SE 131 Software Engineering September 6 Class Meeting Department of Computer Engineering San José State University Fall 2016 Instructor: Ron Mak
Introduction to Dynamic Web Programming
CMPE 280 Web UI Design and Development October 24 Class Meeting
PHP Training at GoLogica in Bangalore
BASIC PHP and MYSQL Edward S. Flores.
CS 174: Server-Side Web Programming February 12 Class Meeting
(Includes setup) FAQ ON DOCUMENTS (Includes setup)
Chapter 15 Introduction to Rails.
Tutorial 6 PHP & MySQL Li Xu
CMPE/SE 131 Software Engineering February 7 Class Meeting
CMPE 280 Web UI Design and Development May 9 Class Meeting
CMPE/SE 131 Software Engineering February 9 Class Meeting
CMPE 152: Compiler Design April 18 – 30 Labs
Presentation transcript:

CS 160 and CMPE/SE 131 Software Engineering February 11 Class Meeting Department of Computer Science Department of Computer Engineering San José State University Spring 2016 Instructor: Ron Mak

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Eclipse Ruby Plugin  Ruby DLTK Dynamic Languages Toolkit  See 2

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Assignment #1 Suggested Solution 3 class Widgets # Initialize the private instance variables of a Widgets object. def = = = 0 end... # Generate a widgets detail report. def generate_report do_column_headers do_detail_records end INPUT_FILE_NAME = "widgets.csv" w = Widgets.new(INPUT_FILE_NAME) w.generate_report()

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Assignment #1 Suggested Solution, cont’d 4 # Read the column headers record and print the headers. def do_column_headers header_record headers = header_record.split(",") printf("%s %s %s %s %s %s\n\n", headers[0], headers[1], headers[2], headers[3], headers[5], headers[4]) end read the header record and remove the \n split the record apart into the headers STATE,PLANT,DEPT,EMPID,NAME,COUNT 12,34,56,789,George Carter,4 12,34,56,799,Mary Clinton,6...

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Assignment #1 Suggested Solution, cont’d 5 # Read and process the detail records. def do_detail_records first_detail_record = true print_blank_line = false # Loop over each detail { |detail_record| # read each detail record fields = detail_record.split(",") # split the detail record into fields state = fields[0].to_i # convert each field plant = fields[1].to_i # except name to integer dept = fields[2].to_i id = fields[3].to_i name = fields[4] count = fields[5].to_i STATE,PLANT,DEPT,EMPID,NAME,COUNT 12,34,56,789,George Carter,4 12,34,56,799,Mary Clinton,6... Start read loop

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Assignment #1 Suggested Solution, cont’d 6 # Process changes in the state, plant, # and department codes. # Skip for the first detail record. unless first_detail_record if state puts "\n" print_state_total print_blank_line = true elsif plant puts "\n" print_plant_total print_blank_line = true elsif dept puts "\n" print_dept_total print_blank_line = true end

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Assignment #1 Suggested Solution, cont’d 7 if print_blank_line puts "\n" print_blank_line = false end # Remember the codes from the detail record just = = = state # Update the += += += += count

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Assignment #1 Suggested Solution, cont’d 8 # Print a detail line. printf("%5d %5d %4d %5d %5d %s\n", state, plant, dept, id, count, name) first_detail_record = false } print_grand_total end End read loop

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Assignment #1 Suggested Solution, cont’d 9 # Print a department total. def print_dept_total printf("%28d TOTAL FOR DEPT @dept_total = 0 end # First print a department total. # Then print a plant total. def print_plant_total print_dept_total printf("%28d TOTAL FOR PLANT @plant_total = 0 end

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Assignment #1 Suggested Solution, cont’d 10 # First print a plant total. # Then print a state total. def print_state_total print_plant_total printf("%28d TOTAL FOR STATE @state_total = 0 end # First print a state total. # Then print the grand total. def print_grand_total puts "\n" print_state_total puts "\n" printf("%28d GRAND TOTAL end

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak The Comments Controller  Generate a new controller for comments: 11 ~/ruby/code/blog: bin/rails generate controller comments Running via Spring preloader in process 1782 create app/controllers/comments_controller.rb invoke erb create app/views/comments invoke test_unit create test/controllers/comments_controller_test.rb invoke helper create app/helpers/comments_helper.rb invoke test_unit invoke assets invoke coffee create app/assets/javascripts/comments.coffee invoke scss create app/assets/stylesheets/comments.scss empty controller empty directory

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak The Comments Controller, cont’d 12 class CommentsController < ApplicationController def = Post.find(params[:post_id]) notice: 'Comment was successfully created.' else alert: 'Error creating comment' end private def comment_params params.require(:comment).permit(:author, :body) end

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Views  The view is your application’s user interface.  Presents a user-friendly visual rendition of the application’s model. 13

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Embedded Ruby  An embedded Ruby.erb file is a template from which Rails generates an HTML page.  The HTML page is dynamic. It contains embedded Ruby code that executes before the page is sent to the client.  The embedded Ruby code dynamically creates content which replaces the embedded code within the HTML page. 14

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Output Tags  Output tags. Example: app/views/post/show.html.erb 15 Title: Body: |

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Control Flow Tags  Tags enclose Ruby code that executes to do control flow. Example: app/views/post/index.html.erb 16 <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Helpers  Ruby methods that simplify your view code. create links format numbers other common tasks  Avoid having too much embedded code.  Write your own helpers. 17

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Helpers, cont’d  URL helpers Example: generates  Number helpers number conversion number formatting 18 link_to 'Show', post Show

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Write Your Own Helpers  Put in app/helpers Example: app/helpers/post_helper.rb for post views. 19 module ApplicationHelper def friendly_date(d) d.strftime("%B %e, %Y") end friendly_date Time.new(2016, 2, 11)

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Index Page Generation Example  The index page is dynamically generated. app/views/posts/index.html.erb 20

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Index Page Generation Example, cont’d 21 Listing Posts Title Body...

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Index Page Generation Example, cont’d <%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Layouts  Good UI design includes having a consistent layout for your application’s web pages. common headers, footers. common page structure etc.  A Rails layout is a file containing the common HTML code for every application page. app/views/layouts/application.html.erb 23

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Layouts, cont’d 24 Blog <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> Change to default for Windows. Assets such as JavaScript and CSS files are kept in app/assets.

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Forms  HTML forms enable users to submit data to the application code running on the web server. app/views/posts/_form.html.erb 25

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Forms, cont’d 26 prohibited this post from being saved:... Check for and handle form errors. Bind a form to a model.

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Forms, cont’d 27...

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Assignment #2  Team assignment.  Use Ruby on Rails to generate the first draft of your web project. home page plus other pages at least one form model, view, and controller components at least two database tables  The application should be functional. You can change things later. 28

Computer Science Dept. Spring 2016: February 11 CS 160 and CMPE/SE 131: Software Engineering © R. Mak Assignment #2, cont’d  Create a zip file containing: Rails commands to generate your application Brief instructions on how to run the application Screen shots of your web pages in action  Submit the zip file into Canvas: Assignment #2 I will create group accounts for team submissions.  Due Friday, Feb. 19 at 11:59 PM 29