Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab 9 branch #201

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Labs/.DS_Store
Binary file not shown.
15 changes: 15 additions & 0 deletions Labs/Lab6/cat.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
body{

display:inline-block;
}

.div1{
width : 50%;
float:left;

}

.div2{
width:50%;
float:right;
}
67 changes: 67 additions & 0 deletions Labs/Lab6/cat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// function myfunction() {
// var count = parseInt(document.getElementById("span1").innerText);
// count = count + 1;
// document.getElementById("span1").innerText = count;
// }

$("#cat_img").click(function(){
var count = parseInt(document.getElementById("span1").innerText);
count = count + 1;
document.getElementById("span1").innerText = count;



});

$("#cat_img2").click(function(){
var count = parseInt(document.getElementById("span2").innerText);
count = count + 1;
document.getElementById("span2").innerText = count;

});

$("#cat_img3").click(function(){
var count = parseInt(document.getElementById("span3").innerText);
count = count + 1;
document.getElementById("span3").innerText = count;

});

$("#cat_img4").click(function(){
var count = parseInt(document.getElementById("span4").innerText);
count = count + 1;
document.getElementById("span4").innerText = count;

});

$("#button_1").click(function(){
$("#div1").show();
$("#div2").hide();
$("#div3").hide();
$("#div4").hide();

});

$("#button_2").click(function(){
$("#div1").hide();
$("#div2").show();
$("#div3").hide();
$("#div4").hide();

});

$("#button_3").click(function(){
$("#div1").hide();
$("#div2").hide();
$("#div3").show();
$("#div4").hide();

});

$("#button_4").click(function(){
$("#div1").hide();
$("#div2").hide();
$("#div3").hide();
$("#div4").show();

});
43 changes: 43 additions & 0 deletions Labs/Lab6/practice.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="cat.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>
<body>
<div id ="div1">
<span> Mr. Fright </span>
<p>

</p>
<span id="span1"> 0</span> clicks


<p>

</p>

<!-- <button onclick="myfunction()"><img id="cat_img" src="https://pbs.twimg.com/profile_images/424484505915621376/EOwsjaMZ_400x400.png"> </button> -->

<img id="cat_img" src="https://pbs.twimg.com/profile_images/424484505915621376/EOwsjaMZ_400x400.png">
</div>
<p>

</p>
<div id ="div2">
<span> Mr. Geek </span>
<p>

</p>
<span id="span2"> 0</span> clicks
<p>

</p>

<!-- <button onclick="myfunction()"><img id="cat_img" src="https://pbs.twimg.com/profile_images/424484505915621376/EOwsjaMZ_400x400.png"> </button> -->

<img id="cat_img2" src="https://pbs.twimg.com/profile_images/447460759329460224/mt2UmwGG_400x400.jpeg ">

<script type='text/javascript' src='cat.js'></script>
</div>
</body>
</html>
89 changes: 89 additions & 0 deletions Labs/Lab6/practice1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="cat.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
</head>

<body>
<table>
<tr>
<td><button id="button_1">Cat 1</button></td>
<td><button id="button_2">Cat 2</button></td>
<td><button id="button_3">Cat 3</button></td>
<td><button id="button_4">Cat 4</button></td>

</tr>
</table>
<div id ="div1" style="display:none;">
<span> Mr. Fright </span>
<p>

</p>
<span id="span1"> 0</span> clicks


<p>

</p>

<!-- <button onclick="myfunction()"><img id="cat_img" src="https://pbs.twimg.com/profile_images/424484505915621376/EOwsjaMZ_400x400.png"> </button> -->

<img id="cat_img" src="https://pbs.twimg.com/profile_images/424484505915621376/EOwsjaMZ_400x400.png">
</div>
<p>

</p>
<div id ="div2" style="display:none;">
<span> Mr. Geek </span>
<p>

</p>
<span id="span2"> 0</span> clicks
<p>

</p>

<!-- <button onclick="myfunction()"><img id="cat_img" src="https://pbs.twimg.com/profile_images/424484505915621376/EOwsjaMZ_400x400.png"> </button> -->

<img id="cat_img2" src="https://pbs.twimg.com/profile_images/447460759329460224/mt2UmwGG_400x400.jpeg ">

</div>


<div id ="div3" style="display:none;">
<span> Mr. Shower </span>
<p>

</p>
<span id="span3"> 0</span> clicks


<p>

</p>

<!-- <button onclick="myfunction()"><img id="cat_img" src="https://pbs.twimg.com/profile_images/424484505915621376/EOwsjaMZ_400x400.png"> </button> -->

<img id="cat_img3" src="http://www.our-happy-cat.com/images/cat-drinking-from-tap.jpg">
</div>

<div id ="div4" style="display:none;">
<span> Mr. Cute </span>
<p>

</p>
<span id="span4"> 0</span> clicks


<p>

</p>

<!-- <button onclick="myfunction()"><img id="cat_img" src="https://pbs.twimg.com/profile_images/424484505915621376/EOwsjaMZ_400x400.png"> </button> -->

<img id="cat_img4" src="http://www.portraits-online.com/uploads/1/3/5/2/13522906/2607694_orig.jpg">
</div>

<script type='text/javascript' src='cat.js'></script>
</body>
</html>
Binary file added Labs/Lab9 - Flask Survey/.DS_Store
Binary file not shown.
Binary file added Labs/Lab9 - Flask Survey/Flask Lab 2.docx
Binary file not shown.
46 changes: 46 additions & 0 deletions Labs/Lab9 - Flask Survey/Flask Lab 2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Flask Lab 2
In this lab we�ll be implementing a simple survey web app using Flask.
The general concepts we�ll be covering are:
* Routing
* Templating
* Passing Parameters
* Sessions
We will walk through this lab in class and for homework you should redesign the questions and the survey and get creative. Also, make the e-mail link work and send the survey results to us!
Requirements
1. Download the flaskLab2.zip file from bCourses>Files>Labs
Creating a login page
2. Open the �login.html� template in your text editor
a. Make this file an extension of the �base.html� template
b. Use the existing form and create form inputs that capture the user�s name and email
c. Make sure the HTML in this file is replacing the block called �content� in the �base.html� template
d. Make the form submit to the �/login� endpoint
Creating a session
3. Open the �views.py� file in your text editor
a. Find the route for �/login�
b. Within the �login()� function, if the request method is POST
i. set the session�s �username� key to whatever the user entered for their username
ii. Redirect the user to the �index� route
Extending and reusing content from the �base.html� template for the �survey.html� template
4. Open the �survey.html� template in your text editor
a. Make this file an extension of the �base.html� template
b. The HTML in this file for the form with the id of �logout� is currently replacing the entire contents of the <header> tag in the �base.html� template. Using the super() function, pull in the original contents of the <header> tag from the �base.html� template
c. Make sure the HTML in this file from the <h1> and down is replacing the block called �content� in the �base.html� template
Creating an Ajax request with the user�s form inputs from �survey.html�
5. Open the �interaction.js� script in your text editor
a. Notice that the button from the �survey.html� template with the id �submit-survey� has a click event binding
b. Also notice that there are variable declarations for each of the form input fields
c. Create a $.post() Ajax request within this �click� event handler
i. The url for this Ajax request should point to �submit-survey�
ii. The data parameter of this Ajax request should be an object whose key-value pairs correspond to the variables for each form input field
iii. The success function for this Ajax request should set the innerHTML of document.body.parentNode to the response data object
Rendering the survey results via Flask
6. Go back to the �views.py� file in your text editor
a. Find the route for �/submit-survey�
b. You�ll notice that an empty object has been assigned to the variable name �surveyResponse�
c. You�ll also notice that �fe-before� and �fe-after� keys in the �surveyResponse� object have been assigned values that correspond to values in the data object we passed in from step 5 above.
i. Assign the keys �color�, �food�, and �vacation� for the �surveyResponse� object to corresponding values from the passed-in data object in a similar fashion
7. You should now be able to do the following:
a. Log into this simple survey web app with a username and email
b. Take the survey
c. See the survey results displayed

Binary file added Labs/Lab9 - Flask Survey/flaskLab2/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 0
}
Binary file added Labs/Lab9 - Flask Survey/flaskLab2/.spyderworkspace
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions Labs/Lab9 - Flask Survey/flaskLab2/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from flask import Flask

myapp = Flask(__name__)
from app import views
Binary file added Labs/Lab9 - Flask Survey/flaskLab2/app/__init__.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
41 changes: 41 additions & 0 deletions Labs/Lab9 - Flask Survey/flaskLab2/app/static/interactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
$('#submit-survey').on('click', function submitSurvey() {
var color = $("input[name=color]").val();
var food = $("input[name=food]").val();
var vacation = $("input[name=vacation]").val();
var feBefore = $("input[name=front-end-before]").val();
var feAfter = $("input[name=front-end-after]").val();
var course = $("input[name=course").val();
$.post("submit-survey",
{color : color,
food:food,
vacation:vacation,
feBefore:feBefore,
feAfter:feAfter,
course:course},
function(data){
$("html").html(data);
})

});

$("#results-email-container").on('click', '#email-results-button', function emailResults() {
console.log($(this));
});

$("#site-title-wrapper").on('click', function goHome() {
window.location.href = '/';
});

$(document).ready(function applySliderLabels() {
var currentValue = $("#fe-before").val();
$("#fe-before").next().html(currentValue);

currentValue = $("#fe-after").val();
$("#fe-after").next().html(currentValue);
});


$("input[type='range']").on('change', function updateLabel() {
var currentValue = $(this).val();
$(this).next().html(currentValue);
});
Loading