single page apps with breeze and ruby. //github.com/johnpapa/pluralsightspajumpstartfinal

31
Single Page Apps with Breeze and Ruby

Upload: tristen-ferguson

Post on 28-Mar-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Single Page Apps with

Breeze and Ruby

Page 2: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

http://pluralsight.com/training/Courses/TableOfContents/single-page-apps-jumpstart https://github.com/johnpapa/PluralsightSpaJumpStartFinal

John Papa’s Code Camper Jumpstart

Page 3: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Features

• Multi-entity model• Navigation properties / cached lookup lists• Projections / partial entities• Change notification• Dirty checking• Validation• Save• Local storage

Page 4: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Keys

• Client app is server agnostic (almost)• Ruby on Rails (RoR) server• Straight rails; no breeze.ruby components• “REST” API• Python web server• No MS

Page 5: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Not anti-Microsoft

Page 6: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

If it works in Rubyit can work for you

Page 7: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Run it1. Download from GitHub2. Setup install gems and create sample MySQL database

3. Start rails server bundle exec rails s

4. Start client application server python –m http.server

5. Launch in browser http://localhost:8000

~\ccjs_ruby\rails>bundle exec rails s

Page 8: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Demo

Page 9: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Web Server

HTML, JavaScript, CSS, images

Page 10: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Code Tour

Page 11: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

RoR Server

Page 12: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

RoR Server – Configuration

Locate the My SQL database

Page 13: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

RoR Server – ConfigurationBreeze Metadata

Page 14: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

RoR Server – Model View Controller

Page 15: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

RoR Server – Controllers

Cross Origin Resource Sharing

Page 16: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

RoR Server – Models

Page 17: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

RoR Server - ControllersSessions Controller

GET by id

GET all

PUT

POST

DELETE

Page 18: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Sessions Controller – Index (get all)

Partial entity if $select in query

Default sort order is time_slot_idbut client typically wants by ‘timeslot, track, speaker name’

Make speaker available in case sorting on speaker name

Projection (selected fields)

Page 19: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

RoR Server – Session Views

Page 20: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

RoR Server – Controllers

Page 21: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

RoR Server - Views

Page 22: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

API Differences

Page 23: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Rails serialization vs JSON.NET serialization

Rails Session

JSON.NET Session

• Rails-style entity property_names

• No $id node property

• $type node property is readable (v. anonymous type)

Page 24: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Rails REST update vs Breeze “save changes”

PUT to resource w/ id=1

Send only the changed values

POST to SaveChanges

Send entire entity

Page 25: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Adjust breeze clientfor Rails API

Page 26: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Configure adapters

Inject with RequireJS

Breeze extension points

Page 27: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

AjaxRestInterceptorTweak the breeze ajax adapter to convert OData id-query into a REST URL

e.g., /breeze/Sessions/?$filter=id eq 1 /breeze/Sessions/1

Page 28: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

DataServiceAdapterReplace POST to “SaveChanges” with RESTPUT/POST/DELETE to entity type controllers

Page 29: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

JsonResultsAdapterIdentify “partial entity” JSON data nodes

Page 30: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

NamingConvention Convert property namese.g., timeSlotId time_slot_id

Page 31: Single Page Apps with Breeze and Ruby. //github.com/johnpapa/PluralsightSpaJumpStartFinal

Thank you, RubyTribe