SPA workshop SPA workshop with Django and AngularJS with Django - - PowerPoint PPT Presentation

spa workshop spa workshop
SMART_READER_LITE
LIVE PREVIEW

SPA workshop SPA workshop with Django and AngularJS with Django - - PowerPoint PPT Presentation

SPA workshop SPA workshop with Django and AngularJS with Django and AngularJS Agenda Agenda 1. Intro 2. Coding 3. Summary Intro Intro Broken code #1 Broken code #1 <script> {% if user.is_authenticated %} var USER = {


slide-1
SLIDE 1

SPA workshop SPA workshop

with Django and AngularJS with Django and AngularJS

slide-2
SLIDE 2

Agenda Agenda

  • 1. Intro
  • 2. Coding
  • 3. Summary
slide-3
SLIDE 3

Intro Intro

slide-4
SLIDE 4

Broken code #1 Broken code #1

<script> </script> {% if user.is_authenticated %} var USER = { 'username': '{{ user.username }}' }; {% endif %}

slide-5
SLIDE 5

Broken code #2 Broken code #2

<p> {{ user.username }} shopping cart: <span id="cart"><%= items.length %> items</span> </p>

slide-6
SLIDE 6

Broken code #3 Broken code #3

<script> $('#cart').text(items.length + ' items'); </script> <p> {{ user.username }} shopping cart: <span id="cart"></span> </p>

slide-7
SLIDE 7

Problems Problems

strongly coupled frontend and backend HTML manipulation/rendering by frontend and backend hard to test frontend code

slide-8
SLIDE 8

Single-page application Single-page application

slide-9
SLIDE 9

Pros Pros

separation of responsibilities easier to maintain and test ready to use API for other clients (eg. mobile) better UX easier collaboration within team less data transferred

  • ffline mode

easier integration with latest frontend tools independent releases

slide-10
SLIDE 10

Cons Cons

two apps instead of one SEO required JS

slide-11
SLIDE 11

Examples Examples

Trello GMail Twitter (?)

slide-12
SLIDE 12

Stack Stack

slide-13
SLIDE 13

Coding Coding

slide-14
SLIDE 14

Lightning talks manager Lightning talks manager

slide-15
SLIDE 15

Django (Rest Framework) Django (Rest Framework)

models views serializers routing

slide-16
SLIDE 16

AngularJS AngularJS

controllers templates routing

slide-17
SLIDE 17

Pull & checkout Pull & checkout

$ git pull $ git checkout workshop

slide-18
SLIDE 18

Tasks Tasks

  • 0. Warm-up
  • 1. Session details
  • 2. Create talk
  • 3. Limit talks
  • 4. Update talk
slide-19
SLIDE 19
  • 0. Warm-up
  • 0. Warm-up

activate virtualenv run backend application run frontend application increase REQUEST_DELAY

$ workon spaworkshop $ ./manage.py runserver $ gulp serve $ edit backend/lightningtalks/settings

slide-20
SLIDE 20
  • 1. Session details
  • 1. Session details

create DRF view create DRF serializer configure Django routing configure AngularJS routing implement AngularJS controller fetch session fill HTML template add loader

slide-21
SLIDE 21
  • 2. Create talk
  • 2. Create talk

fill HTML form template bind inputs with controller properties add form submit handler add loaders create AngularJS controller fetch sessions send data to backend handle errors show toast message on success redirect on success force user to be logged in assign current user to newly created talk

slide-22
SLIDE 22
  • 3. Limit talks
  • 3. Limit talks

add new field to Talk Django model define field ./manage.py makemigrations ./manage.py migrate add validation method in Talk DRF serializer update session HTML template disable "Add talk" button mark talk counter with red color

slide-23
SLIDE 23
  • 4. Update talk
  • 4. Update talk

fill HTML form template bind inputs with controller properties add form submit handler add loaders display errors add PUT method to talk resource create AngularJS controller fetch talk send data to backend handle errors show toast message on success redirect on success force user to be logged in create custom permission

slide-24
SLIDE 24

Summary Summary

slide-25
SLIDE 25

Tools Tools

yo gulp Grunt bower

slide-26
SLIDE 26
slide-27
SLIDE 27

Build process/testing tools Build process/testing tools

useref ngAnnotate UglifyJS csso Autoprefixer rev JSHint imagemin Karma protractor jasmine BrowserSync ngHtml2js

slide-28
SLIDE 28

AngularJS libs AngularJS libs

Restangular ui-router