Jquery代写 | Homework 5: Saving Data on a Server with Flask
本次JS代写是用jquery框架完成与服务器接口的对接
Homework 5: Saving Data on a Server with Flask
Due Wednesday 2/26 @4pm on Courseworks.
You should see a page that simply says “Hello World”. If you have done this, the Flask project is currently running on your machine. Answer the following questions about how the code works in a pdf called Problem1.pdf.
- How many webpages does this code serve?
- Show us screen shots of all of them.
- In hello.html, what syntax makes the <name> show up in the HTML?
- In people.html, which line(s) imports people.js?
- This line has two parameters in it. What are they? What do they represent?
- In people.html, which line(s) get the data sent from the server, put it into JavaScript and parses the string into JSON? (copy them)
- In people.js, what function contains the ajax call?
- What route does that function send data to?
- What data does it send (copy an example of it)?
- Conceptually, how would you describe the data it sends? (1 sentence answer is fine)
- If everything goes perfectly on the server side, what line(s) of code will execute on the front end (copy them here)?
- If something goes wrong on the server side, what line(s) of code will execute on thefront end? (copy them)
- On the server, what does the add_name function do (verbalize it in a few sentences, don’t copy the code)?
- If all goes well, what does the add_name function return? Show us an example.
- If you refresh the web page, will the changes you made to the data still be there? Why or why not?
- If you restart the server will the changes you made to the data still be there? Why or why not?
Problem 2. Saving paper sales on the server
Start a new Flask project to be the backend behind the log_sales application from HW4. As long as the server is running, the changes you make to the sales will persist even when you close and open the webpage (or refresh the page).
You may adapt the example code if you wish.
- On the server, you must have 3 variables that store all the data. (see the following page)
- You must have a route for “/infinity” that renders a template called cu-paper- infinity.html (similar to 1_log_sales.html)
- This file must contain all your static HTML and your CSS
- It may contain JavaScript variables, but no functions.
- Your infinity.html file must load/include an infinity.js file
- In cu-paper-infinity.js you must have three functions:
-
var display_sales_list = function(sales){…}
- This takes in an array of sales and displays them on the UI. This contains no ajax calls.
-
var save_sale = function(new_sale){ …}
- this takes one sale in the following format (note: there is no id field):
{
“salesperson”: salesperson, “client”: client,
“reams”: reams
}
- It must make an ajax call to the server.
- If the server was successful, the UI updates accordingly:
- The new sale appears at the top of the list of sales
- The if client (if any) is in the autocomplete.
-
var delete_sale = function(id){ …}
- this takes in one sales id (for example, 1 or 3)
- it must make an ajax call to the server.
- The sales array is returned to the JavaScript ajax call.
- If the server was successful, the UI updates accordingly.
- You may have other JavaScript functions to add click handles when the document is ready, and process inputs, etc. All the functionality from HW5 is still required.
-
- this takes one sale in the following format (note: there is no id field):
-
- On the server, you must have two routes (and function) that don’t render pages, but do process data. Call them:
- “save_sale”
- It takes in a sale (like in b.i),
- It adds a unique id
- It updates the data
- It returns two things: all the sales and all the clients
- “delete_sale”
- It takes in an id of a sale
- It updates the data
- It returns all the sales.
- “save_sale”
Variables on the server
current_id = 4
sales = [
{
“id”: 1,
“salesperson”: “James D. Halpert”, “client”: “Shake Shack”,
“reams”: 1000
},
{
“id”: 2,
“salesperson”: “Stanley Hudson”, “client”: “Toast”,
“reams”: 4000
},
{
“id”: 3,
“salesperson”: “Michael G. Scott”, “client”: “Computer Science Department”, “reams”: 10000
},
]
clients = [
“Shake Shack”, “Toast”,
“Computer Science Department”, “Teacher’s College”,
“Starbucks”, “Subsconsious”, “Flat Top”, “Joe’s Coffee”, “Max Caffe”,
“Nussbaum & Wu”, “Taco Bell”,
];
Problem 3. Saving the PPC on the server
In the same Flask application from Problem 2, extend it to have another page for the drag and drop party planning committee UI. However, how every time a name is dropped to a new list, it will save. If you close and open the webpage the changes you made to the PPC and non-PPC will persist.
Again, you may adapt the example code if you wish.
- On the server, you must have 2 variables that store all the data. (see the following page)
- You must have a route for “/ppc” that renders a template called ppc.html (similar to 2_ppc.html from HW5)
- This file must contain all your static HTML and your CSS
- It may contain JavaScript variables, but no functions.
- Your ppc.html file must load/include an ppc.js file
- In ppc.js you must have three functions:
-
var display_lists = function(non_ppc, ppc){…}
- This takes in two arrays and displays them on the UI. This contains no ajax calls.
-
var move_to_ppc = function(name){ …}
- this takes one name in the following format:
{
“name”: name
}
- It must make an ajax call to the server.
- On the server, the non_ppc_people array and ppc_people arrays must update accordingly.
- The both updated arrays are returned to the JavaScript ajax call
- If the server was successful, the UI updates accordingly.
-
var move_to_non_ppc = function(name){ …}
- this takes in one name (for example “Angela”) in the same format asmove_to_ppc
- it must make an ajax call to the server.
- On the server, the non_ppc_people array and ppc_people arrays must update accordingly.
- The both updated arrays are returned to the JavaScript ajax call
- If the server was successful, the UI updates accordingly.
- You may have other JavaScript functions to add click handles when the document is ready, and process inputs, etc. All the functionality from HW5 is still required.
-
- this takes one name in the following format:
-
- On the server, create the route(s) that process the ajax calls.
Variables on the server
non_ppc_people = [ “Phyllis”,
“Dwight”,
“Oscar”,
“Creed”,
“Pam”,
“Jim”, “Stanley”, “Michael”, “Kevin”, “Kelly”
]
ppc_people = [ “Angela”
]