SLIDE 1 Sa Saving ng Da Data o
n the he Se Server
COMS 4170 19 February 2020 No screens
Say your name
SLIDE 2 My goal is to use your time well.
2
- I want you to understand how design is a useful skill in your life.
- I want to interact with you on an individual basis
- I do not want anyone to be bored, lost, zoned-out, or stalking their ex
- n Facebook.
If you are lost, interact. No screens.
SLIDE 3
This is when the class starts to get hard.
SLIDE 4 Please don’t underestimate this class
4
Simple, functional design is deceptively difficult
SLIDE 5 Reason #1:
Although websites look easy, there is so much going on beneath the surface that you don’t see.
SLIDE 6 Reason #2:
Systems programming is hard.
HTML CSS JavaScript JQuery Bootstrap Events Interaction Model / View Data Storage Visual Information hierarchy
Individually, they are not hard. But together, they are complex.
SLIDE 7 7
- I do not want anyone to be confused, bored, or zoned-out.
- Using screens distracts your neighbors, and makes it harder for them
to pay attention.
If you are lost, interact. No screens.
SLIDE 8 Sa Saving ng Da Data o
n the he Se Server
COMS 4170 19 February 2020 No screens
Say your name
SLIDE 9
Homework 4
SLIDE 10 In HW4, you dynamically create widgets
Autocomplete Drag and Drop Buttons
Added minor customization (hovering and drop target feedback)
SLIDE 11
And users interacting data
Create / Delete data Update data
SLIDE 12
But there’s a big problem:
SLIDE 13
Th The data doesn sn’t t sa save
Problem:
SLIDE 14 If you refresh the page, your new data is gone. Why?
Add data Data appears
REFRESH PAGE
Data is gone!
The data is only stored
SLIDE 15 To keep data around, we need to store it somewhere else – another computer that will never get turned off.
Client: gets data from server (and displays it to all users) Server: keeps the data
SLIDE 16 What data does the server keep?
Client: gets data from server (and displays it to all users) Server: keeps the data
emails = [ { “from”: “bollinger”, “to”: “chilton”, “subject”: “4170 is awesome!” }, { “from”: “obama”, “to”: “chilton”, “subject”: “belated medal of freedom” }, ]
SLIDE 17 What data does the server keep?
Client: gets data from server (and displays it to all users) Server: keeps the data
products = [ { “title”: “Ivy League Web Design”, “author”: “chilton”, “stars”: “5” }, { “title”: “JavaScript and You”, “author”: “chilton”, “stars”: “6” }, ]
SLIDE 18 What data does the server keep?
Client: gets data from server (and displays it to all users) Server: keeps the data
cars = [ { “location”: “116 and broadway”, “driver”: “kenny”, “car type”: “uber XL” }, { “location”: “times square”, “driver”: “jen”, “car type”: “normal” }, ]
SLIDE 19 What data does the server keep?
Client: gets data from server (and displays it to all users) Server: keeps the data
profiles = [ { “name”: “maddy”, “image”: “./maddy.png”, “likes”: “1000”, ”dislikes”: 0, }, { “name”: “julia”, “image”: “./julia.png”, “likes”: “1000”, “dislikes”: 0, }, ]
SLIDE 20 We need to have another computer st store and serve the data. That server is running a Python application called Fl Flask sk.
Client: gets data from server (and displays it to all users) Server: keeps the data
SLIDE 21
Example application:
Storing and Serving data in Flask
SLIDE 22
You must first install Flask
SLIDE 23
Example project for storing a list of names. (code is on the webpage)
SLIDE 24
You have written the world’s smallest Flask app. Now what?
SLIDE 25
How to render an HTML page with data
SLIDE 26
How to send an array of data to JavaScript?
SLIDE 27
How to send an array of data to JavaScript?
SLIDE 28
Iterate over the data
SLIDE 29
Display all the names
SLIDE 30
How do we allow people to add names?
SLIDE 31
What does the click handler do?
SLIDE 32
Now what does the click handler do?
SLIDE 33
This is MVC updating. It will add names to the list. Wi Will it sa save? NO. The changes are only on the client
SLIDE 34
Save the data to the server
?????
SLIDE 35
Save the data to the server
saveName(name)
SLIDE 36
What happens on the server?
SLIDE 37
How do we test if the data saves to the server?
Refresh the page to see if the new data stays
SLIDE 38
Next Homework
SLIDE 39
Problem 1. Get the Flask sample code to run
SLIDE 40
Problem 2. Put a backend behind Log Sales
SLIDE 41
Problem 3. Put a backend behind PPC
SLIDE 42 HW5: Due Wednesday Feb 26th:
Problem 2. Put a backend behind Log Sales Problem 3. Put a backend behind PPC Problem 1. Get the Flask sample code to run Please get this done today.
SLIDE 43
Fill out participation now! HW 5 is out.
SLIDE 44
Participation